From 9c726a22cb2e1f7cf750c688e217034c33d2fbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sun, 27 Feb 2011 09:46:14 +0100 Subject: [PATCH] server: add reds_stream_{read,write,free,remove_watch}() https://bugs.freedesktop.org/show_bug.cgi?id=34795 --- server/red_channel.c | 2 +- server/red_worker.c | 6 +--- server/reds.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++- server/reds.h | 16 +++++++++++- server/snd_worker.c | 4 +- 5 files changed, 78 insertions(+), 10 deletions(-) diff --git a/server/red_channel.c b/server/red_channel.c index 788960f..5fcbda4 100644 --- a/server/red_channel.c +++ b/server/red_channel.c @@ -320,7 +320,7 @@ RedChannel *red_channel_create(int size, RedsStream *peer, error: spice_marshaller_destroy(channel->send_data.marshaller); free(channel); - peer->cb_free(peer); + reds_stream_free(peer); return NULL; } diff --git a/server/red_worker.c b/server/red_worker.c index 96d5c94..fc21bce 100644 --- a/server/red_worker.c +++ b/server/red_worker.c @@ -8548,9 +8548,7 @@ static void red_disconnect_channel(RedChannel *channel) { channel_release_res(channel); red_pipe_clear(channel); - - channel->peer->cb_free(channel->peer); - + reds_stream_free(channel->peer); channel->peer = NULL; channel->send_data.blocked = FALSE; channel->send_data.size = channel->send_data.pos = 0; @@ -9420,7 +9418,7 @@ static RedChannel *__new_channel(RedWorker *worker, int size, uint32_t channel_i error2: free(channel); error1: - peer->cb_free(peer); + reds_stream_free(peer); return NULL; } diff --git a/server/reds.c b/server/reds.c index 2edf3e8..bdc0601 100644 --- a/server/reds.c +++ b/server/reds.c @@ -392,7 +392,7 @@ static int reds_ssl_writev(void *ctx, const struct iovec *vector, int count) return return_code; } -static int reds_ssl_free(RedsStream *peer) +static int reds_ssl_free(RedsStream* peer) { reds_channel_event(peer, SPICE_CHANNEL_EVENT_DISCONNECTED); SSL_free(peer->ssl); @@ -401,6 +401,33 @@ static int reds_ssl_free(RedsStream *peer) return 0; } +static void reds_stream_remove_watch(RedsStream* s) +{ + if (s->watch) { + core->watch_remove(s->watch); + s->watch = NULL; + } +} + +static void reds_link_free(RedLinkInfo *link) +{ + reds_stream_free(link->peer); + link->peer = NULL; + + free(link->link_mess); + link->link_mess = NULL; + + BN_free(link->tiTicketing.bn); + link->tiTicketing.bn = NULL; + + if (link->tiTicketing.rsa) { + RSA_free(link->tiTicketing.rsa); + link->tiTicketing.rsa = NULL; + } + + free(link); +} + static void __reds_release_link(RedLinkInfo *link) { ASSERT(link->peer); @@ -3170,3 +3197,34 @@ __visible__ int spice_server_migrate_switch(SpiceServer *s) reds_mig_switch(); return 0; } + +ssize_t reds_stream_read(RedsStream *s, void *buf, size_t nbyte) +{ + return s->read(s, buf, nbyte); +} + +ssize_t reds_stream_write(RedsStream *s, const void *buf, size_t nbyte) +{ + return s->write(s, buf, nbyte); +} + +ssize_t reds_stream_writev(RedsStream *s, const struct iovec *iov, int iovcnt) +{ + return s->writev(s, iov, iovcnt); +} + +void reds_stream_free(RedsStream *s) +{ + if (!s) + return; + + reds_channel_event(s, SPICE_CHANNEL_EVENT_DISCONNECTED); + + if (s->ssl) + SSL_free(s->ssl); + + reds_stream_remove_watch(s); + close(s->socket); + + free(s); +} diff --git a/server/reds.h b/server/reds.h index b974eda..235e532 100644 --- a/server/reds.h +++ b/server/reds.h @@ -28,7 +28,9 @@ #define __visible__ __attribute__ ((visibility ("default"))) -typedef struct RedsStream { +typedef struct RedsStream RedsStream; + +struct RedsStream { void *ctx; int socket; @@ -46,7 +48,12 @@ typedef struct RedsStream { int (*cb_writev)(void *, const struct iovec *vector, int count); int (*cb_free)(struct RedsStream *); -} RedsStream; + + /* private */ + ssize_t (*read)(RedsStream *s, void *buf, size_t nbyte); + ssize_t (*write)(RedsStream *s, const void *buf, size_t nbyte); + ssize_t (*writev)(RedsStream *s, const struct iovec *iov, int iovcnt); +}; typedef struct Channel { struct Channel *next; @@ -73,6 +80,11 @@ struct SpiceNetWireState { struct TunnelWorker *worker; }; +ssize_t reds_stream_read(RedsStream *s, void *buf, size_t nbyte); +ssize_t reds_stream_write(RedsStream *s, const void *buf, size_t nbyte); +ssize_t reds_stream_writev(RedsStream *s, const struct iovec *iov, int iovcnt); +void reds_stream_free(RedsStream *s); + void reds_desable_mm_timer(); void reds_enable_mm_timer(); void reds_update_mm_timer(uint32_t mm_time); diff --git a/server/snd_worker.c b/server/snd_worker.c index 2cd4d92..fcfaf97 100644 --- a/server/snd_worker.c +++ b/server/snd_worker.c @@ -188,7 +188,7 @@ static void snd_disconnect_channel(SndChannel *channel) worker->connection = NULL; core->watch_remove(channel->peer->watch); channel->peer->watch = NULL; - channel->peer->cb_free(channel->peer); + reds_stream_free(channel->peer); spice_marshaller_destroy(channel->send_data.marshaller); free(channel); } @@ -800,7 +800,7 @@ error2: free(channel); error1: - peer->cb_free(peer); + reds_stream_free(peer); return NULL; } -- 1.7.4