diff options
author | Frediano Ziglio <fziglio@redhat.com> | 2016-01-07 17:25:19 +0000 |
---|---|---|
committer | Frediano Ziglio <fziglio@redhat.com> | 2016-01-11 16:40:17 +0000 |
commit | ba175f9be1bafd6642ebe31f065fe3ffc9674c7c (patch) | |
tree | 5bd6ed5fe4bf596c69f022ed9d976f988f664f7f /server/red-channel.c | |
parent | 9745ef5f9a9be41cedeaccc2d5b304d5a8c54920 (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/red-channel.c')
-rw-r--r-- | server/red-channel.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/server/red-channel.c b/server/red-channel.c index f79605a6..704f3192 100644 --- a/server/red-channel.c +++ b/server/red-channel.c @@ -832,7 +832,7 @@ void red_channel_client_start_connectivity_monitoring(RedChannelClient *rcc, uin */ if (rcc->latency_monitor.timer == NULL) { rcc->latency_monitor.timer = rcc->channel->core->timer_add( - red_channel_client_ping_timer, rcc); + rcc->channel->core, red_channel_client_ping_timer, rcc); if (!rcc->client->during_target_migrate) { red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } @@ -841,7 +841,7 @@ void red_channel_client_start_connectivity_monitoring(RedChannelClient *rcc, uin if (rcc->connectivity_monitor.timer == NULL) { rcc->connectivity_monitor.state = CONNECTIVITY_STATE_CONNECTED; rcc->connectivity_monitor.timer = rcc->channel->core->timer_add( - red_channel_client_connectivity_timer, rcc); + rcc->channel->core, red_channel_client_connectivity_timer, rcc); rcc->connectivity_monitor.timeout = timeout_ms; if (!rcc->client->during_target_migrate) { rcc->channel->core->timer_start(rcc->connectivity_monitor.timer, @@ -906,7 +906,8 @@ RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedCl ring_init(&rcc->pipe); rcc->pipe_size = 0; - stream->watch = channel->core->watch_add(stream->socket, + stream->watch = channel->core->watch_add(channel->core, + stream->socket, SPICE_WATCH_EVENT_READ, red_channel_client_event, rcc); rcc->id = channel->clients_num; @@ -917,7 +918,7 @@ RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedCl if (monitor_latency && reds_stream_get_family(stream) != AF_UNIX) { rcc->latency_monitor.timer = channel->core->timer_add( - red_channel_client_ping_timer, rcc); + channel->core, red_channel_client_ping_timer, rcc); if (!client->during_target_migrate) { red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); } @@ -1070,7 +1071,8 @@ static void dummy_watch_update_mask(SpiceWatch *watch, int event_mask) { } -static SpiceWatch *dummy_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque) +static SpiceWatch *dummy_watch_add(const SpiceCoreInterfaceInternal *iface, + int fd, int event_mask, SpiceWatchFunc func, void *opaque) { return NULL; // apparently allowed? } |