From b3b813a6473d1210eee94bd60eaa6bafd2131ed3 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Wed, 24 Jan 2018 23:02:03 +0100 Subject: [PATCH] lib: iostream: Record the ioloop that the iostream was last switched to. --- src/lib/iostream-private.h | 5 +++++ src/lib/iostream.c | 12 ++++++++++++ src/lib/istream.c | 3 +++ src/lib/ostream.c | 2 ++ 4 files changed, 22 insertions(+) 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 6e8897ee03..9f14e4ee4d 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -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); 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); } -- 2.47.3