mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-26 22:48:19 +00:00
Introduce reds_core_watch_*
These methods wrap the RedsCoreInterface::watch_add, RedsCoreInterface::watch_remove and RedsCoreInterface::watch_update_mask vfuncs. Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
d82b8b0789
commit
ebbe4779fc
@ -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:
|
||||
|
||||
@ -2274,10 +2274,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);
|
||||
@ -2356,12 +2358,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;
|
||||
@ -2555,9 +2559,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;
|
||||
@ -2570,9 +2574,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;
|
||||
@ -2581,9 +2585,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;
|
||||
@ -4064,6 +4068,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;
|
||||
|
||||
@ -118,4 +118,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
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user