From: Stephan Bosch Date: Wed, 24 Jan 2018 22:02:03 +0000 (+0100) Subject: lib: iostream: Record the ioloop that the iostream was last switched to. X-Git-Tag: 2.3.1~168 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0cb6dc4e66ff336c16164d5504e50f9677b78df0;p=thirdparty%2Fdovecot%2Fcore.git lib: iostream: Record the ioloop that the iostream was last switched to. --- diff --git a/src/lib/iostream-private.h b/src/lib/iostream-private.h index d56fcf43b1..9aa72e9b92 100644 --- a/src/lib/iostream-private.h +++ b/src/lib/iostream-private.h @@ -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); @@ -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 diff --git a/src/lib/iostream.c b/src/lib/iostream.c index bdf139adca..f2ba00088d 100644 --- a/src/lib/iostream.c +++ b/src/lib/iostream.c @@ -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; } @@ -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); +} diff --git a/src/lib/istream.c b/src/lib/istream.c index d1c3f99fd6..1486f24dbf 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -928,6 +928,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); diff --git a/src/lib/ostream.c b/src/lib/ostream.c index 23a68582b7..7004d858ea 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -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); }