reds: move handle_channel_event logic from main_dispatcher to reds

main_dispactcher role is to pass events to the main thread.
The logic that handles the event better not be inside main_dispatcher.
This commit is contained in:
Yonit Halperin 2013-05-07 12:26:10 -04:00
parent 20cc956764
commit 5fb3d2557e
3 changed files with 19 additions and 9 deletions

View File

@ -64,10 +64,7 @@ static void main_dispatcher_self_handle_channel_event(
int event,
SpiceChannelEventInfo *info)
{
main_dispatcher.core->channel_event(event, info);
if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) {
free(info);
}
reds_handle_channel_event(event, info);
}
static void main_dispatcher_handle_channel_event(void *opaque,

View File

@ -189,11 +189,20 @@ static ChannelSecurityOptions *find_channel_security(int id)
return now;
}
static void reds_stream_channel_event(RedsStream *s, int event)
static void reds_stream_push_channel_event(RedsStream *s, int event)
{
main_dispatcher_channel_event(event, s->info);
}
void reds_handle_channel_event(int event, SpiceChannelEventInfo *info)
{
if (core->base.minor_version < 3 || core->channel_event == NULL)
return;
main_dispatcher_channel_event(event, s->info);
core->channel_event(event, info);
if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) {
free(info);
}
}
static ssize_t stream_write_cb(RedsStream *s, const void *buf, size_t size)
@ -1524,7 +1533,7 @@ static void reds_info_new_channel(RedLinkInfo *link, int connection_id)
link->stream->info->connection_id = connection_id;
link->stream->info->type = link->link_mess->channel_type;
link->stream->info->id = link->link_mess->channel_id;
reds_stream_channel_event(link->stream, SPICE_CHANNEL_EVENT_INITIALIZED);
reds_stream_push_channel_event(link->stream, SPICE_CHANNEL_EVENT_INITIALIZED);
}
static void reds_send_link_result(RedLinkInfo *link, uint32_t error)
@ -2845,7 +2854,7 @@ static RedLinkInfo *reds_init_client_connection(int socket)
getpeername(stream->socket, (struct sockaddr*)(&stream->info->paddr_ext),
&stream->info->plen_ext);
reds_stream_channel_event(stream, SPICE_CHANNEL_EVENT_CONNECTED);
reds_stream_push_channel_event(stream, SPICE_CHANNEL_EVENT_CONNECTED);
openssl_init(link);
@ -4573,7 +4582,7 @@ void reds_stream_free(RedsStream *s)
return;
}
reds_stream_channel_event(s, SPICE_CHANNEL_EVENT_DISCONNECTED);
reds_stream_push_channel_event(s, SPICE_CHANNEL_EVENT_DISCONNECTED);
#if HAVE_SASL
if (s->sasl.conn) {

View File

@ -111,11 +111,15 @@ typedef struct RedsMigSpice {
int sport;
} RedsMigSpice;
/* any thread */
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);
/* main thread only */
void reds_handle_channel_event(int event, SpiceChannelEventInfo *info);
void reds_disable_mm_timer(void);
void reds_enable_mm_timer(void);
void reds_update_mm_timer(uint32_t mm_time);