[Spice-devel] [PATCH v2 25/40] server/red_channel: add red_channel_get_first_socket

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


Use in main_channel. This is just for backward portability later
when multiple clients are introduced - needs to be considered (which
sockets do we want to export from libspiceserver?)
---
 server/main_channel.c |    9 +++++----
 server/red_channel.c  |    8 ++++++++
 server/red_channel.h  |    2 ++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/server/main_channel.c b/server/main_channel.c
index 75accac..1f407e2 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -823,22 +823,23 @@ int main_channel_getsockname(Channel *channel, struct sockaddr *sa, socklen_t *s
 {
     MainChannel *main_chan = channel->data;
 
-    return main_chan ? getsockname(main_chan->base.stream->socket, sa, salen) : -1;
+    return main_chan ? getsockname(red_channel_get_first_socket(&main_chan->base), sa, salen) : -1;
 }
 
 int main_channel_getpeername(Channel *channel, struct sockaddr *sa, socklen_t *salen)
 {
     MainChannel *main_chan = channel->data;
 
-    return main_chan ? getpeername(main_chan->base.stream->socket, sa, salen) : -1;
+    return main_chan ? getpeername(red_channel_get_first_socket(&main_chan->base), sa, salen) : -1;
 }
 
 void main_channel_close(Channel *channel)
 {
     MainChannel *main_chan = channel->data;
+    int socketfd;
 
-    if (main_chan && main_chan->base.stream) {
-        close(main_chan->base.stream->socket);
+    if (main_chan && (socketfd = red_channel_get_first_socket(&main_chan->base)) != -1) {
+        close(socketfd);
     }
 }
 
diff --git a/server/red_channel.c b/server/red_channel.c
index 1b705d6..a1bce11 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -711,3 +711,11 @@ RedsStream *red_channel_get_stream(RedChannel *channel)
 {
     return channel->stream;
 }
+
+int red_channel_get_first_socket(RedChannel *channel)
+{
+    if (!channel->stream) {
+        return -1;
+    }
+    return channel->stream->socket;
+}
diff --git a/server/red_channel.h b/server/red_channel.h
index d0f7fb7..9d13dd7 100644
--- a/server/red_channel.h
+++ b/server/red_channel.h
@@ -249,6 +249,8 @@ void red_channel_push_set_ack(RedChannel *channel);
 
 void red_channel_shutdown(RedChannel *channel);
 
+int red_channel_get_first_socket(RedChannel *channel);
+
 // TODO: unstaticed for display/cursor channels. they do some specific pushes not through
 // adding elements or on events. but not sure if this is actually required (only result
 // should be that they ""try"" a little harder, but if the event system is correct it
-- 
1.7.4.1



More information about the Spice-devel mailing list