Skip to content

Commit

Permalink
lib: iostream: Record the ioloop that the iostream was last switched to.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch authored and sirainen committed Jan 30, 2018
1 parent 2f2c523 commit b3b813a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/iostream-private.h
Expand Up @@ -14,6 +14,7 @@ struct iostream_private {
int refcount;
char *name;
char *error;
struct ioloop *ioloop;

void (*close)(struct iostream_private *streami, bool close_parent);
void (*destroy)(struct iostream_private *stream);
Expand Down Expand Up @@ -43,4 +44,8 @@ void io_stream_set_error(struct iostream_private *stream,
void io_stream_set_verror(struct iostream_private *stream,
const char *fmt, va_list args) ATTR_FORMAT(2, 0);

void io_stream_switch_ioloop_to(struct iostream_private *stream,
struct ioloop *ioloop);
struct ioloop *io_stream_get_ioloop(struct iostream_private *stream);

#endif
12 changes: 12 additions & 0 deletions src/lib/iostream.c
Expand Up @@ -23,6 +23,7 @@ void io_stream_init(struct iostream_private *stream)
stream->close = io_stream_default_close;
if (stream->destroy == NULL)
stream->destroy = io_stream_default_destroy;
stream->ioloop = current_ioloop;

stream->refcount = 1;
}
Expand Down Expand Up @@ -140,3 +141,14 @@ const char *io_stream_get_disconnect_reason(struct istream *input,
else
return t_strdup_printf("Connection closed: %s", errstr);
}

void io_stream_switch_ioloop_to(struct iostream_private *stream,
struct ioloop *ioloop)
{
stream->ioloop = ioloop;
}

struct ioloop *io_stream_get_ioloop(struct iostream_private *stream)
{
return (stream->ioloop == NULL ? current_ioloop : stream->ioloop);
}
3 changes: 3 additions & 0 deletions src/lib/istream.c
Expand Up @@ -922,6 +922,9 @@ void i_stream_set_input_pending(struct istream *stream, bool pending)

void i_stream_switch_ioloop(struct istream *stream)
{
io_stream_switch_ioloop_to(&stream->real_stream->iostream,
current_ioloop);

do {
if (stream->real_stream->switch_ioloop != NULL)
stream->real_stream->switch_ioloop(stream->real_stream);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ostream.c
Expand Up @@ -503,6 +503,8 @@ void o_stream_switch_ioloop(struct ostream *stream)
{
struct ostream_private *_stream = stream->real_stream;

io_stream_switch_ioloop_to(&_stream->iostream, current_ioloop);

_stream->switch_ioloop(_stream);
}

Expand Down

0 comments on commit b3b813a

Please sign in to comment.