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

Andy Green andy at warmcat.com
Mon Aug 18 02:56:15 CEST 2014

On 18 August 2014 07:34:47 GMT+08:00, nil100 at ig.com.br wrote:
>Hello everybody, 
>I'm using the library and in my case I want to handle truncated send
>myself but I ran into a situation. Linux's send function is returning
>which in turn is causing libwebsockets to disregard my wish to handle
>truncated sends and consequently causes an assert failure later on. 

I'm not sure what your plan is for dealing with it in user code.

>Everything is happening in file output.c at line 130 which is the
>from linux's native send (I'm not using SSL so lws_ssl_capable_write is
>actually lws_ssl_capable_write_no_ssl). Now when this returns
>LWS_SSL_CAPABLE_MORE_SERVICE (value -2) then the value of variable "n"

So looking at the code, the actual send() didn't send anything just came back with -EAGAIN or similar.  Then that function translates that to a generic "I didn't send anything because I would have blocked" enum return you mentioned.

>is set to 0 which causes the condition at line 172 (n &&
>wsi->u.ws.clean_buffer) to be false and continue execution as if

Yes I see.

>libwebsockets was handling truncates and consequent calls to fail
>assertion at line 112. 

I don't see why it fails that assertion though, did you understand why during your debugging?  Not having sent anything and buffer the whole thing should have been okay.

>I'm a new libwebsockets user and wasn't sure how to proceed in getting
>this fixed. 

There seems to be two separate issues here, one is you don't want it to buffer things if nothing got sent, and the other is you get an assert firing when it does.

If you remove the n && from line 172 it might do something towards what you want.  But I am not sure if that leaves whatever blew the assert just waiting to blow the assert another time.


>I'm using version 1.3 on a Kubuntu 12.04 VirtualBox VM but I'm also
>using the same version cross compiled to an ARM (beaglebone black)
>running Ubuntu 13.10 and having the same behavior. 
>Anyone else running into this situation? 
>Nilson N. da Silva 
>nil100 at ig.com.br 
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list