From: Christophe Fergeau <cfergeau@xxxxxxxxxx> These methods wrap the RedsCoreInterface::watch_add, RedsCoreInterface::watch_remove and RedsCoreInterface::watch_update_mask vfuncs. --- server/reds-stream.c | 9 ++++--- server/reds.c | 66 ++++++++++++++++++++++++++++++++++++++++------------ server/reds.h | 10 ++++++++ server/sound.c | 11 ++++----- 4 files changed, 70 insertions(+), 26 deletions(-) diff --git a/server/reds-stream.c b/server/reds-stream.c index 140b767..294223a 100644 --- a/server/reds-stream.c +++ b/server/reds-stream.c @@ -168,7 +168,7 @@ static ssize_t stream_ssl_read_cb(RedsStream *s, void *buf, size_t size) void reds_stream_remove_watch(RedsStream* s) { if (s->watch) { - reds_get_core_interface(s->priv->reds)->watch_remove(s->watch); + reds_core_watch_remove(s->priv->reds, s->watch); s->watch = NULL; } } @@ -502,10 +502,9 @@ static void async_read_handler(G_GNUC_UNUSED int fd, switch (errno) { case EAGAIN: if (!stream->watch) { - stream->watch = reds_get_core_interface(reds)->watch_add(reds_get_core_interface(reds), - stream->socket, - SPICE_WATCH_EVENT_READ, - async_read_handler, async); + stream->watch = reds_core_watch_add(reds, stream->socket, + SPICE_WATCH_EVENT_READ, + async_read_handler, async); } return; case EINTR: diff --git a/server/reds.c b/server/reds.c index b784310..7006420 100644 --- a/server/reds.c +++ b/server/reds.c @@ -2277,10 +2277,12 @@ static void reds_handle_ssl_accept(int fd, int event, void *data) reds_link_free(link); return; case REDS_STREAM_SSL_STATUS_WAIT_FOR_READ: - reds->core->watch_update_mask(link->stream->watch, SPICE_WATCH_EVENT_READ); + reds_core_watch_update_mask(reds, link->stream->watch, + SPICE_WATCH_EVENT_READ); return; case REDS_STREAM_SSL_STATUS_WAIT_FOR_WRITE: - reds->core->watch_update_mask(link->stream->watch, SPICE_WATCH_EVENT_WRITE); + reds_core_watch_update_mask(reds, link->stream->watch, + SPICE_WATCH_EVENT_WRITE); return; case REDS_STREAM_SSL_STATUS_OK: reds_stream_remove_watch(link->stream); @@ -2359,12 +2361,14 @@ static RedLinkInfo *reds_init_client_ssl_connection(RedsState *reds, int socket) case REDS_STREAM_SSL_STATUS_ERROR: goto error; case REDS_STREAM_SSL_STATUS_WAIT_FOR_READ: - link->stream->watch = reds->core->watch_add(reds->core, link->stream->socket, SPICE_WATCH_EVENT_READ, - reds_handle_ssl_accept, link); + link->stream->watch = reds_core_watch_add(reds, link->stream->socket, + SPICE_WATCH_EVENT_READ, + reds_handle_ssl_accept, link); break; case REDS_STREAM_SSL_STATUS_WAIT_FOR_WRITE: - link->stream->watch = reds->core->watch_add(reds->core, link->stream->socket, SPICE_WATCH_EVENT_WRITE, - reds_handle_ssl_accept, link); + link->stream->watch = reds_core_watch_add(reds, link->stream->socket, + SPICE_WATCH_EVENT_WRITE, + reds_handle_ssl_accept, link); break; } return link; @@ -2556,9 +2560,9 @@ static int reds_init_net(RedsState *reds) if (-1 == reds->listen_socket) { return -1; } - reds->listen_watch = reds->core->watch_add(reds->core, reds->listen_socket, - SPICE_WATCH_EVENT_READ, - reds_accept, reds); + reds->listen_watch = reds_core_watch_add(reds, reds->listen_socket, + SPICE_WATCH_EVENT_READ, + reds_accept, reds); if (reds->listen_watch == NULL) { spice_warning("set fd handle failed"); return -1; @@ -2571,9 +2575,9 @@ static int reds_init_net(RedsState *reds) if (-1 == reds->secure_listen_socket) { return -1; } - reds->secure_listen_watch = reds->core->watch_add(reds->core, reds->secure_listen_socket, - SPICE_WATCH_EVENT_READ, - reds_accept_ssl_connection, reds); + reds->secure_listen_watch = reds_core_watch_add(reds, reds->secure_listen_socket, + SPICE_WATCH_EVENT_READ, + reds_accept_ssl_connection, reds); if (reds->secure_listen_watch == NULL) { spice_warning("set fd handle failed"); return -1; @@ -2582,9 +2586,9 @@ static int reds_init_net(RedsState *reds) if (reds->spice_listen_socket_fd != -1 ) { reds->listen_socket = reds->spice_listen_socket_fd; - reds->listen_watch = reds->core->watch_add(reds->core, reds->listen_socket, - SPICE_WATCH_EVENT_READ, - reds_accept, reds); + reds->listen_watch = reds_core_watch_add(reds, reds->listen_socket, + SPICE_WATCH_EVENT_READ, + reds_accept, reds); if (reds->listen_watch == NULL) { spice_warning("set fd handle failed"); return -1; @@ -4048,6 +4052,38 @@ SpiceCoreInterfaceInternal* reds_get_core_interface(RedsState *reds) return reds->core; } +SpiceWatch *reds_core_watch_add(RedsState *reds, + int fd, int event_mask, + SpiceWatchFunc func, + void *opaque) +{ + g_return_val_if_fail(reds != NULL, NULL); + g_return_val_if_fail(reds->core != NULL, NULL); + g_return_val_if_fail(reds->core->watch_add != NULL, NULL); + + return reds->core->watch_add(reds->core, fd, event_mask, func, opaque); +} + +void reds_core_watch_update_mask(RedsState *reds, + SpiceWatch *watch, + int event_mask) +{ + g_return_if_fail(reds != NULL); + g_return_if_fail(reds->core != NULL); + g_return_if_fail(reds->core->watch_update_mask != NULL); + + reds->core->watch_update_mask(watch, event_mask); +} + +void reds_core_watch_remove(RedsState *reds, SpiceWatch *watch) +{ + g_return_if_fail(reds != NULL); + g_return_if_fail(reds->core != NULL); + g_return_if_fail(reds->core->watch_remove != NULL); + + reds->core->watch_remove(watch); +} + void reds_update_client_mouse_allowed(RedsState *reds) { static int allowed = FALSE; diff --git a/server/reds.h b/server/reds.h index 8e9bbbc..6dd0c81 100644 --- a/server/reds.h +++ b/server/reds.h @@ -117,4 +117,14 @@ void reds_client_monitors_config(RedsState *reds, VDAgentMonitorsConfig *monitor void reds_set_mm_time(RedsState *reds, uint32_t mm_time); MainDispatcher* reds_get_main_dispatcher(RedsState *reds); +/* fd watches/timers */ +SpiceWatch *reds_core_watch_add(RedsState *reds, + int fd, int event_mask, + SpiceWatchFunc func, + void *opaque); +void reds_core_watch_update_mask(RedsState *reds, + SpiceWatch *watch, + int event_mask); +void reds_core_watch_remove(RedsState *reds, SpiceWatch *watch); + #endif diff --git a/server/sound.c b/server/sound.c index 4e61986..3732f94 100644 --- a/server/sound.c +++ b/server/sound.c @@ -221,7 +221,7 @@ static void snd_disconnect_channel(SndChannel *channel) channel->cleanup(channel); red_channel_client_disconnect(worker->connection->channel_client); worker->connection->channel_client = NULL; - reds_get_core_interface(reds)->watch_remove(channel->stream->watch); + reds_core_watch_remove(reds, channel->stream->watch); channel->stream->watch = NULL; reds_stream_free(channel->stream); channel->stream = NULL; @@ -275,7 +275,7 @@ static int snd_send_data(SndChannel *channel) if (channel->blocked) { channel->blocked = FALSE; - reds_get_core_interface(reds)->watch_update_mask(channel->stream->watch, SPICE_WATCH_EVENT_READ); + reds_core_watch_update_mask(reds, channel->stream->watch, SPICE_WATCH_EVENT_READ); } break; } @@ -287,7 +287,7 @@ static int snd_send_data(SndChannel *channel) switch (errno) { case EAGAIN: channel->blocked = TRUE; - reds_get_core_interface(reds)->watch_update_mask(channel->stream->watch, SPICE_WATCH_EVENT_READ | + reds_core_watch_update_mask(reds, channel->stream->watch, SPICE_WATCH_EVENT_READ | SPICE_WATCH_EVENT_WRITE); return FALSE; case EINTR: @@ -957,9 +957,8 @@ static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_i channel->receive_data.end = channel->receive_data.buf + sizeof(channel->receive_data.buf); channel->send_data.marshaller = spice_marshaller_new(); - stream->watch = reds_get_core_interface(reds)->watch_add(reds_get_core_interface(reds), - stream->socket, SPICE_WATCH_EVENT_READ, - snd_event, channel); + stream->watch = reds_core_watch_add(reds, stream->socket, SPICE_WATCH_EVENT_READ, + snd_event, channel); if (stream->watch == NULL) { spice_printerr("watch_add failed, %s", strerror(errno)); goto error2; -- 2.5.0 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel