ostream.c revision 46631c1d903c409444b1b1c4a1d41a033c09ee37
5e0ce63bb65db34d7f48b34bbb5545fa791781c4Timo Sirainen/* Copyright (c) 2002-2014 Dovecot authors, see the included COPYING file */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenvoid o_stream_set_name(struct ostream *stream, const char *name)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen stream->real_stream->iostream.name = i_strdup(name);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenconst char *o_stream_get_name(struct ostream *stream)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen while (stream->real_stream->iostream.name == NULL) {
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenconst char *o_stream_get_error(struct ostream *stream)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen /* we'll only return errors for streams that have stream_errno set.
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen we might be returning unintended error otherwise. */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen return "<no error>";
6a9f9a5101b665fd2ef80c9e048a5eace78e01efTimo Sirainen for (s = stream; s != NULL; s = s->real_stream->parent) {
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenstatic void o_stream_close_full(struct ostream *stream, bool close_parents)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen if (!stream->closed && !stream->real_stream->closing) {
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen /* first mark the stream as being closed so the
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen o_stream_copy_error_from_parent() won't recurse us back
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen here. but don't immediately mark the stream closed, because
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen we may still want to write something to it. */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen io_stream_close(&stream->real_stream->iostream, close_parents);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen io_stream_ref(&stream->real_stream->iostream);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen if (stream->real_stream->last_errors_not_checked &&
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen !stream->real_stream->error_handling_disabled &&
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen stream->real_stream->iostream.refcount == 1) {
a29a5b7520f7b8d6cdaf97e66d184b6a9e4f4ecfTimo Sirainen i_panic("output stream %s is missing error handling",
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen io_stream_unref(&stream->real_stream->iostream);
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenvoid o_stream_set_flush_callback(struct ostream *stream,
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen struct ostream_private *_stream = stream->real_stream;
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen _stream->set_flush_callback(_stream, callback, context);
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenvoid o_stream_unset_flush_callback(struct ostream *stream)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen struct ostream_private *_stream = stream->real_stream;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen _stream->set_flush_callback(_stream, NULL, NULL);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainenvoid o_stream_set_max_buffer_size(struct ostream *stream, size_t max_size)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen io_stream_set_max_buffer_size(&stream->real_stream->iostream, max_size);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainensize_t o_stream_get_max_buffer_size(struct ostream *stream)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen struct ostream_private *_stream = stream->real_stream;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen struct ostream_private *_stream = stream->real_stream;
9453e8d75cfd8fab2232cf772e9b120f308fb3eeTimo Sirainenbool o_stream_is_corked(struct ostream *stream)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen struct ostream_private *_stream = stream->real_stream;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstatic void o_stream_clear_error(struct ostream *stream)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen i_free_and_null(stream->real_stream->iostream.error);
return ret;
unsigned int iov_count)
if (total_size == 0)
if (ret < 0) {
return ret;
unsigned int iov_count)
return ret;
int ret;
return ret;
const unsigned char *data;
if (ret <= 0) {
if (ret == 0)
bool close_parent)
if (set) {
int ret;
return ret;
void *context)
static size_t
struct ostream *
return output;
struct ostream *
return output;