return bytes_sent;
}
-static void o_stream_ssl_switch_ioloop(struct ostream_private *stream)
+static void o_stream_ssl_switch_ioloop_to(struct ostream_private *stream,
+ struct ioloop *ioloop)
{
struct ssl_ostream *sstream = (struct ssl_ostream *)stream;
- o_stream_switch_ioloop(sstream->ssl_io->plain_output);
+ o_stream_switch_ioloop_to(sstream->ssl_io->plain_output, ioloop);
}
static int plain_flush_callback(struct ssl_ostream *sstream)
sstream->ostream.iostream.destroy = o_stream_ssl_destroy;
sstream->ostream.sendv = o_stream_ssl_sendv;
sstream->ostream.flush = o_stream_ssl_flush;
- sstream->ostream.switch_ioloop = o_stream_ssl_switch_ioloop;
+ sstream->ostream.switch_ioloop_to = o_stream_ssl_switch_ioloop_to;
sstream->ostream.get_used_size = o_stream_ssl_get_used_size;
sstream->ostream.flush_pending = o_stream_ssl_flush_pending;
static void o_stream_file_cork(struct ostream_private *stream, bool set)
{
struct file_ostream *fstream = (struct file_ostream *)stream;
+ struct iostream_private *iostream = &fstream->ostream.iostream;
int ret;
if (stream->corked != set && !stream->ostream.closed) {
if (fstream->io == NULL &&
(ret == 0 || fstream->flush_pending) &&
!stream->ostream.closed) {
- fstream->io = io_add(fstream->fd, IO_WRITE,
- stream_send_io, fstream);
+ fstream->io = io_add_to(
+ io_stream_get_ioloop(iostream),
+ fstream->fd, IO_WRITE,
+ stream_send_io, fstream);
}
}
o_stream_file_flush_pending(struct ostream_private *stream, bool set)
{
struct file_ostream *fstream = (struct file_ostream *) stream;
+ struct iostream_private *iostream = &fstream->ostream.iostream;
fstream->flush_pending = set;
if (set && !stream->corked && fstream->io == NULL) {
- fstream->io = io_add(fstream->fd, IO_WRITE,
- stream_send_io, fstream);
+ fstream->io = io_add_to(io_stream_get_ioloop(iostream),
+ fstream->fd, IO_WRITE,
+ stream_send_io, fstream);
}
}
static void stream_send_io(struct file_ostream *fstream)
{
struct ostream *ostream = &fstream->ostream.ostream;
+ struct iostream_private *iostream = &fstream->ostream.iostream;
bool use_cork = !fstream->ostream.corked;
int ret;
might have just returned 0 without there being any data
to be sent. */
if (fstream->io == NULL) {
- fstream->io = io_add(fstream->fd, IO_WRITE,
- stream_send_io, fstream);
+ fstream->io = io_add_to(io_stream_get_ioloop(iostream),
+ fstream->fd, IO_WRITE,
+ stream_send_io, fstream);
}
}
static size_t o_stream_add(struct file_ostream *fstream,
const void *data, size_t size)
{
+ struct iostream_private *iostream = &fstream->ostream.iostream;
size_t unused, sent;
int i;
if (sent != 0 && fstream->io == NULL &&
!fstream->ostream.corked && !fstream->file) {
- fstream->io = io_add(fstream->fd, IO_WRITE, stream_send_io,
- fstream);
+ fstream->io = io_add_to(io_stream_get_ioloop(iostream),
+ fstream->fd, IO_WRITE, stream_send_io,
+ fstream);
}
return sent;
return io_stream_copy_same_stream(outstream, instream);
}
-static void o_stream_file_switch_ioloop(struct ostream_private *stream)
+static void o_stream_file_switch_ioloop_to(struct ostream_private *stream,
+ struct ioloop *ioloop)
{
struct file_ostream *fstream = (struct file_ostream *)stream;
if (fstream->io != NULL)
- fstream->io = io_loop_move_io(&fstream->io);
+ fstream->io = io_loop_move_io_to(ioloop, &fstream->io);
}
struct ostream *
fstream->ostream.sendv = o_stream_file_sendv;
fstream->ostream.write_at = o_stream_file_write_at;
fstream->ostream.send_istream = o_stream_file_send_istream;
- fstream->ostream.switch_ioloop = o_stream_file_switch_ioloop;
+ fstream->ostream.switch_ioloop_to = o_stream_file_switch_ioloop_to;
fstream->writev = o_stream_file_writev;
return OSTREAM_SEND_ISTREAM_RESULT_FINISHED;
}
-void o_stream_switch_ioloop(struct ostream *stream)
+void o_stream_switch_ioloop_to(struct ostream *stream, struct ioloop *ioloop)
{
struct ostream_private *_stream = stream->real_stream;
- io_stream_switch_ioloop_to(&_stream->iostream, current_ioloop);
+ io_stream_switch_ioloop_to(&_stream->iostream, ioloop);
+
+ _stream->switch_ioloop_to(_stream, ioloop);
+}
- _stream->switch_ioloop(_stream);
+void o_stream_switch_ioloop(struct ostream *stream)
+{
+ o_stream_switch_ioloop_to(stream, current_ioloop);
}
static void o_stream_default_close(struct iostream_private *stream,
return io_stream_copy(&outstream->ostream, instream);
}
-static void o_stream_default_switch_ioloop(struct ostream_private *_stream)
+static void
+o_stream_default_switch_ioloop_to(struct ostream_private *_stream,
+ struct ioloop *ioloop)
{
if (_stream->parent != NULL)
- o_stream_switch_ioloop(_stream->parent);
+ o_stream_switch_ioloop_to(_stream->parent, ioloop);
}
struct ostream *
_stream->write_at = o_stream_default_write_at;
if (_stream->send_istream == NULL)
_stream->send_istream = o_stream_default_send_istream;
- if (_stream->switch_ioloop == NULL)
- _stream->switch_ioloop = o_stream_default_switch_ioloop;
+ if (_stream->switch_ioloop_to == NULL)
+ _stream->switch_ioloop_to = o_stream_default_switch_ioloop_to;
io_stream_init(&_stream->iostream);
return &_stream->ostream;