summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2015-02-10 15:40:40 -0600
committerFabiano FidĂȘncio <fidencio@redhat.com>2015-02-23 23:00:46 +0100
commitcbd01efa7ef3e6a8aa21403abe2ed88465685baa (patch)
tree093f49f9167c95f2680e731190e50c903d2b7b50
parent70ca8cd0d4f871e95a05ead32117e2646fc40a96 (diff)
downloadspice-cbd01efa7ef3e6a8aa21403abe2ed88465685baa.tar.gz
spice-cbd01efa7ef3e6a8aa21403abe2ed88465685baa.tar.xz
spice-cbd01efa7ef3e6a8aa21403abe2ed88465685baa.zip
Add RedsState reference to RedsStream
Allows us to remove use of global 'reds' variable from reds-stream.c. Requires changing the RedsStream constructor to accept a RedsState arg.
-rw-r--r--server/reds-stream.c20
-rw-r--r--server/reds-stream.h3
-rw-r--r--server/reds.c2
3 files changed, 15 insertions, 10 deletions
diff --git a/server/reds-stream.c b/server/reds-stream.c
index 4698bf7a..fd239cec 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -20,10 +20,10 @@
#endif
#include "common.h"
+#include "common/log.h"
#include "main-dispatcher.h"
#include "reds-stream.h"
#include "reds.h"
-#include "common/log.h"
#include <errno.h>
#include <netdb.h>
@@ -94,6 +94,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)
@@ -166,7 +167,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;
}
}
@@ -310,13 +311,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 *)(((char *)stream) + sizeof(RedsStream));
stream->priv->info = spice_new0(SpiceChannelEventInfo, 1);
+ stream->priv->reds = reds;
reds_stream_set_socket(stream, socket);
stream->priv->read = stream_read_cb;
@@ -417,20 +419,22 @@ 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(async->stream->socket,
- SPICE_WATCH_EVENT_READ,
- async_read_handler, async);
+ if (!stream->watch) {
+ stream->watch = reds_get_core_interface(reds)->watch_add(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 6cbbbbbe..c4110e97 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 4c615323..07f551f9 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2223,7 +2223,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 */