[Libwebsockets] Truncated send handled by user not working as expected

Andy Green andy.green at linaro.org
Mon Aug 18 16:11:31 CEST 2014


On 18 Aug 2014 21:51, "Roger Light" <roger at atchoo.org> wrote:
>
> On Mon, Aug 18, 2014 at 1:23 PM, Andy Green <andy at warmcat.com> wrote:
>
> > As soon as libwebsocket_write() figured it needed to buffer something,
you are
> > not allowed to send anything new on libwebsocket_write() until the
buffered stuff
> > is used up.
> >
> > Instead you must return to the service loop, where lws will service its
buffer until
> > it is empty, before giving you any new WRITEABLE callbacks.
>
> Great, this is exactly what I'd expect. What does libwebsocket_write()
> return to tell us that we aren't allowed to send anything new until it
> has been serviced?

If you send one thing per writeable callback, you would be fine without
this.  Because you won't get another callback until the buffer is emptied.

>From this discussion though it's clear the stuff in lws at the minute
that's supposed to turn partial handling off should be removed, because
under some common conditions partial handling in lws is absolutely required
(and the turn it off thing no longer does what it says either).

For the return value, currently it's defined to tell how much it sent (or
buffered) or negative for something fatal.

Lws is 4 years old now there's a fair amount of user code and all of it
uses libwebsocket_write(), I think if it changed to, eg, returning a
negative code for 'I buffered it', which is not an error, it will cause a
lot of reasonable existing code to break.

So I think the next best thing is add a cheap accessor to detect if it's
still possible to write on the wsi, ie, check if there's an active partial
buffer.

Does that sound okay for you?

-Andy

>
> Cheers,
>
> Roger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20140818/84335cd5/attachment-0001.html>


More information about the Libwebsockets mailing list