Skip to content

Commit

Permalink
lib: Added ostream.blocking boolean
Browse files Browse the repository at this point in the history
Similar to istream.blocking.
  • Loading branch information
sirainen authored and cmouse committed Oct 14, 2016
1 parent 85df9a4 commit 2892649
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/ostream-buffer.c
Expand Up @@ -59,6 +59,7 @@ struct ostream *o_stream_create_buffer(buffer_t *buf)
struct ostream *output;

bstream = i_new(struct buffer_ostream, 1);
bstream->ostream.ostream.blocking = TRUE;
bstream->ostream.max_buffer_size = (size_t)-1;
bstream->ostream.seek = o_stream_buffer_seek;
bstream->ostream.sendv = o_stream_buffer_sendv;
Expand Down
1 change: 1 addition & 0 deletions src/lib/ostream-file.c
Expand Up @@ -1023,6 +1023,7 @@ o_stream_create_fd_file(int fd, uoff_t offset, bool autoclose_fd)
fstream_init_file(fstream);
fstream->real_offset = offset;
fstream->buffer_offset = offset;
ostream->blocking = fstream->file;
ostream->offset = offset;
return ostream;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/ostream-null.c
Expand Up @@ -23,6 +23,7 @@ struct ostream *o_stream_create_null(void)
struct ostream *output;

stream = i_new(struct ostream_private, 1);
stream->ostream.blocking = TRUE;
stream->sendv = o_stream_null_sendv;

output = o_stream_create(stream, NULL, -1);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/ostream.c
Expand Up @@ -262,6 +262,7 @@ ssize_t o_stream_sendv(struct ostream *stream, const struct const_iovec *iov,
stream->last_failed_errno = stream->stream_errno;
errno = stream->stream_errno;
} else {
i_assert(!stream->blocking);
stream->overflow = TRUE;
}
}
Expand Down Expand Up @@ -570,6 +571,7 @@ o_stream_create(struct ostream_private *_stream, struct ostream *parent, int fd)
_stream->fd = fd;
_stream->ostream.real_stream = _stream;
if (parent != NULL) {
_stream->ostream.blocking = parent->blocking;
_stream->parent = parent;
o_stream_ref(parent);

Expand Down Expand Up @@ -622,6 +624,7 @@ struct ostream *o_stream_create_error(int stream_errno)
struct ostream *output;

stream = i_new(struct ostream_private, 1);
stream->ostream.blocking = TRUE;
stream->ostream.closed = TRUE;
stream->ostream.stream_errno = stream_errno;
stream->ostream.last_failed_errno = stream_errno;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ostream.h
Expand Up @@ -16,6 +16,8 @@ struct ostream {
functions was neither sent nor buffered. It's never unset inside
ostream code. */
unsigned int overflow:1;
/* o_stream_send() writes all the data or returns failure */
unsigned int blocking:1;
unsigned int closed:1;

struct ostream_private *real_stream;
Expand Down

0 comments on commit 2892649

Please sign in to comment.