[Spice-devel] [PATCH v2 22/40] server/red_channel (all): add red_channel_get_stream

Alon Levy alevy at redhat.com
Wed Mar 2 00:31:45 PST 2011


use in config_socket, this makes the stream internal to the RedChannel
implementation that will change later for multiple client support.
---
 server/inputs_channel.c    |    7 ++++---
 server/red_channel.c       |    6 ++++++
 server/red_channel.h       |    4 ++++
 server/red_tunnel_worker.c |    7 ++++---
 server/red_worker.c        |    2 +-
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/server/inputs_channel.c b/server/inputs_channel.c
index 8140c04..5e2681a 100644
--- a/server/inputs_channel.c
+++ b/server/inputs_channel.c
@@ -491,15 +491,16 @@ static int inputs_channel_config_socket(RedChannel *channel)
 {
     int flags;
     int delay_val = 1;
+    RedsStream *stream = red_channel_get_stream(channel);
 
-    if (setsockopt(channel->stream->socket, IPPROTO_TCP, TCP_NODELAY,
+    if (setsockopt(stream->socket, IPPROTO_TCP, TCP_NODELAY,
             &delay_val, sizeof(delay_val)) == -1) {
         red_printf("setsockopt failed, %s", strerror(errno));
         return FALSE;
     }
 
-    if ((flags = fcntl(channel->stream->socket, F_GETFL)) == -1 ||
-                 fcntl(channel->stream->socket, F_SETFL, flags | O_ASYNC) == -1) {
+    if ((flags = fcntl(stream->socket, F_GETFL)) == -1 ||
+                 fcntl(stream->socket, F_SETFL, flags | O_ASYNC) == -1) {
         red_printf("fcntl failed, %s", strerror(errno));
         return FALSE;
     }
diff --git a/server/red_channel.c b/server/red_channel.c
index 5749dc3..f8944c0 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -706,7 +706,13 @@ void red_channel_ack_set_client_window(RedChannel *channel, int client_window)
     channel->ack_data.client_window = client_window;
 }
 
+/* accessors for RedChannel */
 SpiceMarshaller *red_channel_get_marshaller(RedChannel *channel)
 {
     return channel->send_data.marshaller;
 }
+
+RedsStream *red_channel_get_stream(RedChannel *channel)
+{
+    return channel->stream;
+}
diff --git a/server/red_channel.h b/server/red_channel.h
index 1841de4..f991f2d 100644
--- a/server/red_channel.h
+++ b/server/red_channel.h
@@ -272,6 +272,10 @@ void red_channel_pipe_clear(RedChannel *channel);
 //  handle_channel_events - this is the only one that was used before, and was in red_channel.c
 void red_channel_receive(RedChannel *channel);
 void red_channel_send(RedChannel *channel);
+
+/* accessors for RedChannel */
+/* Note: the valid times to call red_channel_get_marshaller are just during send_item callback. */
 SpiceMarshaller *red_channel_get_marshaller(RedChannel *channel);
+RedsStream *red_channel_get_stream(RedChannel *channel);
 
 #endif
diff --git a/server/red_tunnel_worker.c b/server/red_tunnel_worker.c
index 0366290..c990bd1 100644
--- a/server/red_tunnel_worker.c
+++ b/server/red_tunnel_worker.c
@@ -3335,20 +3335,21 @@ static int tunnel_channel_config_socket(RedChannel *channel)
 {
     int flags;
     int delay_val;
+    RedsStream *stream = red_channel_get_stream(channel);
 
-    if ((flags = fcntl(channel->stream->socket, F_GETFL)) == -1) {
+    if ((flags = fcntl(stream->socket, F_GETFL)) == -1) {
         red_printf("accept failed, %s", strerror(errno)); // can't we just use red_error?
         return FALSE;
     }
 
-    if (fcntl(channel->stream->socket, F_SETFL, flags | O_NONBLOCK) == -1) {
+    if (fcntl(stream->socket, F_SETFL, flags | O_NONBLOCK) == -1) {
         red_printf("accept failed, %s", strerror(errno));
         return FALSE;
     }
 
     delay_val = 1;
 
-    if (setsockopt(channel->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val,
+    if (setsockopt(stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val,
                    sizeof(delay_val)) == -1) {
         red_printf("setsockopt failed, %s", strerror(errno));
     }
diff --git a/server/red_worker.c b/server/red_worker.c
index dd89e3f..b8e4825 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -9026,7 +9026,7 @@ int common_channel_config_socket(RedChannel *channel)
 {
     int flags;
     int delay_val;
-    RedsStream *stream = channel->stream;
+    RedsStream *stream = red_channel_get_stream(channel);
 
     if ((flags = fcntl(stream->socket, F_GETFL)) == -1) {
         red_printf("accept failed, %s", strerror(errno));
-- 
1.7.4.1



More information about the Spice-devel mailing list