[Spice-devel] [PATCH 10/26] server/red_channel: add red_channel_get_first_socket

Alon Levy alevy at redhat.com
Fri Feb 11 09:48:55 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 21e0156..9809fc8 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -822,22 +822,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.peer->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.peer->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.peer) {
-        close(main_chan->base.peer->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 2aa5f83..44dd99e 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -704,3 +704,11 @@ void red_channel_set_shut(RedChannel *channel)
     channel->incoming.shut = TRUE;
 }
 
+int red_channel_get_first_socket(RedChannel *channel)
+{
+    if (!channel->peer) {
+        return -1;
+    }
+    return channel->peer->socket;
+}
+
diff --git a/server/red_channel.h b/server/red_channel.h
index 713056f..e3f4f8e 100644
--- a/server/red_channel.h
+++ b/server/red_channel.h
@@ -250,6 +250,8 @@ void red_channel_push_set_ack(RedChannel *channel);
 
 void red_channel_set_shut(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



More information about the Spice-devel mailing list