[Spice-devel] [PATCH spice v2] Add support for clients connecting with the WebSocket protocol.

Jeremy White jwhite at codeweavers.com
Wed Nov 4 07:13:27 PST 2015


Gah, missed a potential problem.

> +int websocket_write(void *opaque, const guchar *buf, int len, guint64 *remainder,
> +         websocket_write_cb_t write_cb)
> +{
> +    guint8 header[WEBSOCKET_MAX_HEADER_SIZE];
> +    int rc;
> +    int header_len;
> +
> +    memset(header, 0, sizeof(header));
> +    header_len = fill_header(header, len);
> +
> +    if (*remainder == 0) {
> +        rc = write_cb(opaque, header, header_len);
> +        if (rc <= 0)
> +            return rc;
> +
> +        if (rc != header_len) {
> +            /* TODO - In theory, we can handle this case.  In practice,
> +                      it does not occur, and does not seem to be worth
> +                      the code complexity */
> +            errno = EPIPE;
> +            return -1;
> +        }
> +    }

Should be an else len = *remainder here, in the case that a previous
write only sent a partial number of bytes.

I'll send a new patch.

> +
> +    rc = write_cb(opaque, buf, len);
> +    if (rc <= 0)
> +        *remainder = len;
> +    else
> +        *remainder = len - rc;
> +    return rc;
> +}

Cheers,

Jeremy


More information about the Spice-devel mailing list