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

Daniel P. Berrange berrange at redhat.com
Fri Oct 21 08:11:02 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            |   32 ++++++++++++++++++++++++++++++++
 server/spice-server.syms |    2 ++
 server/spice.h           |    3 +++
 3 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 977ff90..3321111 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2724,6 +2724,38 @@ static void reds_accept(int fd, int event, void *data)
     reds_handle_new_link(link);
 }
 
+
+int spice_server_add_client(SpiceServer *s, int socket)
+{
+    RedLinkInfo *link;
+    RedsStream *stream;
+
+    if (!(link = reds_init_client_connection(socket))) {
+        red_printf("accept failed");
+        return -1;
+    }
+
+    stream = link->stream;
+    stream->read = stream_read_cb;
+    stream->write = stream_write_cb;
+    stream->writev = stream_writev_cb;
+
+    reds_handle_new_link(link);
+    return 0;
+}
+
+
+int spice_server_add_ssl_client(SpiceServer *s, int socket)
+{
+    RedLinkInfo *link;
+
+    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