[Spice-devel] [PATCH spice-server 04/10] reds: move handle_channel_event logic from main_dispatcher to reds

Yonit Halperin yhalperi at redhat.com
Wed May 8 07:58:59 PDT 2013


On 05/08/2013 10:46 AM, Marc-André Lureau wrote:
> ack (would be nice to describe the motivation, although I guess it is to
> avoid code duplication)
>
Sure, I'll add a comment. I did it because I believe main_dispatcher 
role is only to pass events to the main thread, and not handle the 
events by itself.
>
> On Wed, May 8, 2013 at 4:06 PM, Yonit Halperin <yhalperi at redhat.com
> <mailto:yhalperi at redhat.com>> wrote:
>
>     ---
>       server/main_dispatcher.c |  5 +----
>       server/reds.c            | 19 ++++++++++++++-----
>       server/reds.h            |  4 ++++
>       3 files changed, 19 insertions(+), 9 deletions(-)
>
>     diff --git a/server/main_dispatcher.c b/server/main_dispatcher.c
>     index 8402402..92b0791 100644
>     --- a/server/main_dispatcher.c
>     +++ b/server/main_dispatcher.c
>     @@ -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,
>     diff --git a/server/reds.c b/server/reds.c
>     index b8db905..a378f80 100644
>     --- a/server/reds.c
>     +++ b/server/reds.c
>     @@ -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) {
>     diff --git a/server/reds.h b/server/reds.h
>     index 59f13ce..c5c557d 100644
>     --- a/server/reds.h
>     +++ b/server/reds.h
>     @@ -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);
>     --
>     1.8.1.4
>
>     _______________________________________________
>     Spice-devel mailing list
>     Spice-devel at lists.freedesktop.org
>     <mailto:Spice-devel at lists.freedesktop.org>
>     http://lists.freedesktop.org/mailman/listinfo/spice-devel
>
>
>
>
> --
> Marc-André Lureau



More information about the Spice-devel mailing list