[Spice-devel] [PATCH 4/6] Add APIs for injecting a client connection socket

Daniel P. Berrange berrange at redhat.com
Fri Oct 28 05:09:48 PDT 2011


From: "Daniel P. Berrange" <berrange at redhat.com>

Allow applications to pass a pre-accepted client socket file
descriptor in. The new APIs are spice_server_add_ssl_client
and spice_server_add_client

* server/reds.c: Implement new APIs
* server/spice.h: Define new APIs

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 server/reds.c            |   29 +++++++++++++++++++++++++----
 server/spice-server.syms |    2 ++
 server/spice.h           |    3 +++
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 977ff90..6c93a40 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2700,8 +2700,6 @@ static void reds_accept_ssl_connection(int fd, int event, void *data)
 
 static void reds_accept(int fd, int event, void *data)
 {
-    RedLinkInfo *link;
-    RedsStream *stream;
     int socket;
 
     if ((socket = accept(reds->listen_socket, NULL, 0)) == -1) {
@@ -2709,11 +2707,20 @@ static void reds_accept(int fd, int event, void *data)
         return;
     }
 
+    if (spice_server_add_client(reds, socket) < 0)
+        close(socket);
+}
 
+
+SPICE_GNUC_VISIBLE int spice_server_add_client(SpiceServer *s, int socket)
+{
+    RedLinkInfo *link;
+    RedsStream *stream;
+
+    ASSERT(reds == s);
     if (!(link = reds_init_client_connection(socket))) {
         red_printf("accept failed");
-        close(socket);
-        return;
+        return -1;
     }
 
     stream = link->stream;
@@ -2722,8 +2729,22 @@ static void reds_accept(int fd, int event, void *data)
     stream->writev = stream_writev_cb;
 
     reds_handle_new_link(link);
+    return 0;
 }
 
+
+SPICE_GNUC_VISIBLE int spice_server_add_ssl_client(SpiceServer *s, int socket)
+{
+    RedLinkInfo *link;
+
+    ASSERT(reds == s);
+    if (!(link = reds_init_client_ssl_connection(socket))) {
+        return -1;
+    }
+    return 0;
+}
+
+
 static int reds_init_socket(const char *addr, int portnr, int family)
 {
     static const int on=1, off=0;
diff --git a/server/spice-server.syms b/server/spice-server.syms
index f1374bd..c34ff86 100644
--- a/server/spice-server.syms
+++ b/server/spice-server.syms
@@ -89,5 +89,7 @@ global:
     spice_server_record_set_mute;
     spice_server_record_set_volume;
     spice_server_get_num_clients;
+    spice_server_add_client;
+    spice_server_add_ssl_client;
 } SPICE_SERVER_0.8.2;
 
diff --git a/server/spice.h b/server/spice.h
index 74f9fdb..25c9278 100644
--- a/server/spice.h
+++ b/server/spice.h
@@ -425,6 +425,9 @@ int spice_server_set_tls(SpiceServer *s, int port,
                          const char *private_key_file, const char *key_passwd,
                          const char *dh_key_file, const char *ciphersuite);
 
+int spice_server_add_client(SpiceServer *s, int socket);
+int spice_server_add_ssl_client(SpiceServer *s, int socket);
+
 int spice_server_add_interface(SpiceServer *s,
                                SpiceBaseInstance *sin);
 int spice_server_remove_interface(SpiceBaseInstance *sin);
-- 
1.7.6.4



More information about the Spice-devel mailing list