On Mon, 2016-02-15 at 16:01 +0000, Frediano Ziglio wrote: > From: Jonathon Jongsma <jjongsma@xxxxxxxxxx> > > Allows us to remove use of global 'reds' variable from reds-stream.c. > Requires changing the RedsStream constructor to accept a RedsState > arg. > --- > server/reds-stream.c | 22 +++++++++++++--------- > server/reds-stream.h | 3 ++- > server/reds.c | 2 +- > server/tests/stream-test.c | 8 +++++--- > 4 files changed, 21 insertions(+), 14 deletions(-) > > diff --git a/server/reds-stream.c b/server/reds-stream.c > index 2eb8f89..ec720e0 100644 > --- a/server/reds-stream.c > +++ b/server/reds-stream.c > @@ -21,9 +21,9 @@ > > #include "main-dispatcher.h" > #include "red-common.h" > +#include "common/log.h" > #include "reds-stream.h" > #include "reds.h" > -#include "common/log.h" > > #include <errno.h> > #include <netdb.h> > @@ -95,6 +95,7 @@ struct RedsStreamPrivate { > ssize_t (*write)(RedsStream *s, const void *buf, size_t nbyte); > ssize_t (*writev)(RedsStream *s, const struct iovec *iov, int > iovcnt); > > + RedsState *reds; > }; > > static ssize_t stream_write_cb(RedsStream *s, const void *buf, > size_t size) > @@ -167,7 +168,7 @@ static ssize_t stream_ssl_read_cb(RedsStream *s, > void *buf, size_t size) > void reds_stream_remove_watch(RedsStream* s) > { > if (s->watch) { > - reds_get_core_interface(reds)->watch_remove(s->watch); > + reds_get_core_interface(s->priv->reds)->watch_remove(s- > >watch); > s->watch = NULL; > } > } > @@ -378,13 +379,14 @@ void reds_stream_set_channel(RedsStream > *stream, int connection_id, > stream->priv->info->id = channel_id; > } > > -RedsStream *reds_stream_new(int socket) > +RedsStream *reds_stream_new(RedsState *reds, int socket) > { > RedsStream *stream; > > stream = spice_malloc0(sizeof(RedsStream) + > sizeof(RedsStreamPrivate)); > stream->priv = (RedsStreamPrivate *)(stream+1); > stream->priv->info = spice_new0(SpiceChannelEventInfo, 1); > + stream->priv->reds = reds; > reds_stream_set_socket(stream, socket); > > stream->priv->read = stream_read_cb; > @@ -485,21 +487,23 @@ static void async_read_handler(G_GNUC_UNUSED > int fd, > void *data) > { > AsyncRead *async = (AsyncRead *)data; > + RedsStream *stream = async->stream; > + RedsState *reds = stream->priv->reds; > > for (;;) { > int n = async->end - async->now; > > spice_assert(n > 0); > - n = reds_stream_read(async->stream, async->now, n); > + n = reds_stream_read(stream, async->now, n); > if (n <= 0) { > if (n < 0) { > switch (errno) { > case EAGAIN: > - if (!async->stream->watch) { > - async->stream->watch = > reds_get_core_interface(reds)- > >watch_add(reds_get_core_interface(reds), > - > async->stream->socket, > - > SPICE_WATCH_EVENT_READ, > - > async_read_handler, async); > + if (!stream->watch) { > + stream->watch = > reds_get_core_interface(reds)- > >watch_add(reds_get_core_interface(reds), > + > stream->socket, > + > SPICE_WATCH_EVENT_READ, > + > async_read_handler, async); > } > return; > case EINTR: > diff --git a/server/reds-stream.h b/server/reds-stream.h > index 72e5dd1..1123048 100644 > --- a/server/reds-stream.h > +++ b/server/reds-stream.h > @@ -28,6 +28,7 @@ > typedef void (*AsyncReadDone)(void *opaque); > typedef void (*AsyncReadError)(void *opaque, int err); > > +typedef struct RedsState RedsState; > typedef struct RedsStream RedsStream; > typedef struct RedsStreamPrivate RedsStreamPrivate; > > @@ -67,7 +68,7 @@ void reds_stream_push_channel_event(RedsStream *s, > int event); > void reds_stream_remove_watch(RedsStream* s); > void reds_stream_set_channel(RedsStream *stream, int connection_id, > int channel_type, int channel_id); > -RedsStream *reds_stream_new(int socket); > +RedsStream *reds_stream_new(RedsState *reds, int socket); > bool reds_stream_is_ssl(RedsStream *stream); > RedsStreamSslStatus reds_stream_ssl_accept(RedsStream *stream); > int reds_stream_enable_ssl(RedsStream *stream, SSL_CTX *ctx); > diff --git a/server/reds.c b/server/reds.c > index 80bf9ff..18152f9 100644 > --- a/server/reds.c > +++ b/server/reds.c > @@ -2324,7 +2324,7 @@ static RedLinkInfo > *reds_init_client_connection(RedsState *reds, int socket) > > link = spice_new0(RedLinkInfo, 1); > link->reds = reds; > - link->stream = reds_stream_new(socket); > + link->stream = reds_stream_new(reds, socket); > > /* gather info + send event */ > > diff --git a/server/tests/stream-test.c b/server/tests/stream-test.c > index f83f0e1..3aa059c 100644 > --- a/server/tests/stream-test.c > +++ b/server/tests/stream-test.c > @@ -7,10 +7,12 @@ > #include "reds-stream.h" > #include "basic_event_loop.h" > > +static SpiceServer *server = NULL; > + > static int server_init(void) > { > SpiceCoreInterface *core = basic_event_loop_init(); > - SpiceServer *server = spice_server_new(); > + server = spice_server_new(); > > return spice_server_init(server, core); > } > @@ -89,9 +91,9 @@ int main(int argc, char *argv[]) > return -1; > } > > - st[0] = reds_stream_new(sv[0]); > + st[0] = reds_stream_new(server, sv[0]); > spice_assert(reds_stream_is_plain_unix(st[0])); > - st[1] = reds_stream_new(sv[1]); > + st[1] = reds_stream_new(server, sv[1]); > spice_assert(reds_stream_is_plain_unix(st[1])); > > /* send stdin, for the fun of it */ Acked-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx> _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel