summaryrefslogtreecommitdiff
path: root/server/reds.c
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2016-01-07 17:25:19 +0000
committerFrediano Ziglio <fziglio@redhat.com>2016-01-11 16:40:17 +0000
commitba175f9be1bafd6642ebe31f065fe3ffc9674c7c (patch)
tree5bd6ed5fe4bf596c69f022ed9d976f988f664f7f /server/reds.c
parent9745ef5f9a9be41cedeaccc2d5b304d5a8c54920 (diff)
channel: add interface parameters to SpiceCoreInterfaceInternal
This patch and previous ones want to solve the problem of not having a context in SpiceCoreInterface. SpiceCoreInterface defines a set of callbacks to handle events in spice-server. These callbacks allow to handle timers, watch for file descriptors and send channel events. All these callbacks do not accept a context (usually in C passed as a void* parameter) so it is hard for them to differentiate the interface specified. Unfortunately this structure is used even internally from different contexts for instance every RedWorker thread has a different context. To solve this issue some workarounds are used. Currently for timers a variable depending on the current thread is used while for watches the opaque parameter to pass to the event callback is used as it currently points just to RedChannelClient structure. This however imposes some implicit maintainance problem in the future. What happens for instance if for some reason a timer is registered during worker initialization, run in another thread? What if we decide to register a file descriptor callback for something not a RedChannelClient? Could be that the program will run without any issue till some bytes change and weird things could happen. The implementation of this solution is done implementing an internal "core" interface that has context specific and use it to differentiate the context instead of relying on some other, hard to maintain, detail. Then an adapter structure (name inpired to the adapter pattern) will provide the internal core interface using the external, public, definition (in the future this technique can be used to extend the external interface without breaking the ABI). Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Christophe Fergeau <cfergeau@redhat.com>
Diffstat (limited to 'server/reds.c')
-rw-r--r--server/reds.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/server/reds.c b/server/reds.c
index d9d0e0a1..b9929119 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -76,7 +76,7 @@ SpiceCoreInterfaceInternal *core = NULL;
static SpiceCoreInterface *core_public = NULL;
-static SpiceTimer *adapter_timer_add(SpiceTimerFunc func, void *opaque)
+static SpiceTimer *adapter_timer_add(const SpiceCoreInterfaceInternal *iface, SpiceTimerFunc func, void *opaque)
{
return core_public->timer_add(func, opaque);
}
@@ -96,7 +96,8 @@ static void adapter_timer_remove(SpiceTimer *timer)
core_public->timer_remove(timer);
}
-static SpiceWatch *adapter_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+static SpiceWatch *adapter_watch_add(const SpiceCoreInterfaceInternal *iface,
+ int fd, int event_mask, SpiceWatchFunc func, void *opaque)
{
return core_public->watch_add(fd, event_mask, func, opaque);
}
@@ -2358,11 +2359,11 @@ static RedLinkInfo *reds_init_client_ssl_connection(int socket)
case REDS_STREAM_SSL_STATUS_ERROR:
goto error;
case REDS_STREAM_SSL_STATUS_WAIT_FOR_READ:
- link->stream->watch = core->watch_add(link->stream->socket, SPICE_WATCH_EVENT_READ,
+ link->stream->watch = core->watch_add(core, link->stream->socket, SPICE_WATCH_EVENT_READ,
reds_handle_ssl_accept, link);
break;
case REDS_STREAM_SSL_STATUS_WAIT_FOR_WRITE:
- link->stream->watch = core->watch_add(link->stream->socket, SPICE_WATCH_EVENT_WRITE,
+ link->stream->watch = core->watch_add(core, link->stream->socket, SPICE_WATCH_EVENT_WRITE,
reds_handle_ssl_accept, link);
break;
}
@@ -2555,7 +2556,7 @@ static int reds_init_net(void)
if (-1 == reds->listen_socket) {
return -1;
}
- reds->listen_watch = core->watch_add(reds->listen_socket,
+ reds->listen_watch = core->watch_add(core, reds->listen_socket,
SPICE_WATCH_EVENT_READ,
reds_accept, NULL);
if (reds->listen_watch == NULL) {
@@ -2570,7 +2571,7 @@ static int reds_init_net(void)
if (-1 == reds->secure_listen_socket) {
return -1;
}
- reds->secure_listen_watch = core->watch_add(reds->secure_listen_socket,
+ reds->secure_listen_watch = core->watch_add(core, reds->secure_listen_socket,
SPICE_WATCH_EVENT_READ,
reds_accept_ssl_connection, NULL);
if (reds->secure_listen_watch == NULL) {
@@ -2581,7 +2582,7 @@ static int reds_init_net(void)
if (spice_listen_socket_fd != -1 ) {
reds->listen_socket = spice_listen_socket_fd;
- reds->listen_watch = core->watch_add(reds->listen_socket,
+ reds->listen_watch = core->watch_add(core, reds->listen_socket,
SPICE_WATCH_EVENT_READ,
reds_accept, NULL);
if (reds->listen_watch == NULL) {
@@ -3343,7 +3344,7 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
ring_init(&reds->mig_wait_disconnect_clients);
reds->vm_running = TRUE; /* for backward compatibility */
- if (!(reds->mig_timer = core->timer_add(migrate_timeout, NULL))) {
+ if (!(reds->mig_timer = core->timer_add(core, migrate_timeout, NULL))) {
spice_error("migration timer create failed");
}