[Spice-devel] [spice-gtk v2 2/4] spice-channel: spice_channel_read_wire() improvements
Christophe Fergeau
cfergeau at redhat.com
Tue Feb 21 17:13:26 UTC 2017
On Tue, Feb 21, 2017 at 06:11:54PM +0100, Christophe Fergeau wrote:
> Looks good
>
> Acked-by: Christophe Fergeau <cfergeau at redhat.com>
I take that ACK back, this was meant to be sent for 3/4 !
Christophe
>
> On Fri, Feb 03, 2017 at 04:13:38PM +0100, Victor Toso wrote:
> > From: Victor Toso <me at victortoso.com>
> >
> > * Removes the reread label by having while(TRUE);
> >
> > The label is being used after g_coroutine_socket_wait() is called,
> > which is context switch while we can't do the reading as it would
> > block. Moving this inside a while() makes the code more straight
> > forward to be read and should not impact the performance.
> >
> > * Move local variables inside the block they will be used.
> >
> > Related: https://bugs.freedesktop.org/show_bug.cgi?id=96598
> > Signed-off-by: Victor Toso <victortoso at redhat.com>
> > ---
> > src/spice-channel.c | 38 ++++++++++++++++++++------------------
> > 1 file changed, 20 insertions(+), 18 deletions(-)
> >
> > diff --git a/src/spice-channel.c b/src/spice-channel.c
> > index a17c402..d1714df 100644
> > --- a/src/spice-channel.c
> > +++ b/src/spice-channel.c
> > @@ -1025,32 +1025,34 @@ static int spice_channel_read_wire_nonblocking(SpiceChannel *channel,
> > static int spice_channel_read_wire(SpiceChannel *channel, void *data, size_t len)
> > {
> > SpiceChannelPrivate *c = channel->priv;
> > - GIOCondition cond;
> > - gssize ret;
> >
> > -reread:
> > + while (TRUE) {
> > + gssize ret;
> > + GIOCondition cond;
> >
> > - if (c->has_error) return 0; /* has_error is set by disconnect(), return no error */
> > + if (c->has_error) {
> > + /* has_error is set by disconnect(), return no error */
> > + return 0;
> > + }
> >
> > - ret = spice_channel_read_wire_nonblocking(channel, data, len, &cond);
> > + ret = spice_channel_read_wire_nonblocking(channel, data, len, &cond);
> > + if (ret > 0)
> > + return ret;
> >
> > - if (ret == -1) {
> > - if (cond != 0) {
> > - // TODO: should use g_pollable_input/output_stream_create_source() ?
> > - g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
> > - goto reread;
> > - } else {
> > + if (ret == 0) {
> > + CHANNEL_DEBUG(channel, "Closing the connection: spice_channel_read() - ret=0");
> > + c->has_error = TRUE;
> > + return 0;
> > + }
> > +
> > + if (cond == 0) {
> > c->has_error = TRUE;
> > return -errno;
> > }
> > - }
> > - if (ret == 0) {
> > - CHANNEL_DEBUG(channel, "Closing the connection: spice_channel_read() - ret=0");
> > - c->has_error = TRUE;
> > - return 0;
> > - }
> >
> > - return ret;
> > + // TODO: should use g_pollable_input/output_stream_create_source() ?
> > + g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
> > + }
> > }
> >
> > #ifdef HAVE_SASL
> > --
> > 2.9.3
> >
> > _______________________________________________
> > Spice-devel mailing list
> > Spice-devel at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170221/cdd870e6/attachment.sig>
More information about the Spice-devel
mailing list