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

nil100 at ig.com.br nil100 at ig.com.br
Mon Aug 18 13:06:42 CEST 2014


 

Em 17/08/2014 21:56, Andy Green escreveu: 

> On 18 August 2014 07:34:47 GMT+08:00, nil100 at ig.com.brwrote:
> 
>> 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 -2 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.
> 
> I'm usually sending a large amount of data at a time and so I want to know when the pipe chokes and how many truncated sends it takes to completely send my whole chunk. 
> 
>> Everything is happening in file output.c at line 130 which is the return 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.
> 
> So here the code enters the condition at line 107-110 because wsi->truncated_send_len && buf > (wsi->truncated_send_malloc + wsi->truncated_send_len + wsi->truncated_send_offset). Now, the library was not handling truncated sends in the first place (I configured it not to)but it erroneously started handling after send returned an error and since I don't expect the library to do that I call libwebsocket_write again which makes the library believe I'm trying to send new data when in fact I'm sending the rest of the data too.
> 
>> 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.
> 
> Correct. I don't want it to buffer things and the assert is firing because the library started handling things without me wanting it to.
> 
> 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.
> 
> What blew the assert was wsi->truncated_send_len not being 0 when it should have been.

Sorry for the bad formatting. My webmail is crap. 

Cheers, 

Nilson N. da Silva 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20140818/18eb85ab/attachment-0001.html>


More information about the Libwebsockets mailing list