[Libwebsockets] [libwebsockets] #49: Does not provide correct buffer for reentrant calls of LWS_CALLBACK_RECEIVE

Trac trac at libwebsockets.org
Thu Nov 21 16:08:14 CET 2013


#49: Does not provide correct buffer for reentrant calls of LWS_CALLBACK_RECEIVE
-----------------------------------+-----------------
 Reporter:  andreaspakulat         |      Owner:
     Type:  defect                 |     Status:  new
 Priority:  major                  |  Milestone:
Component:  libwebsockets library  |    Version:
 Keywords:                         |
-----------------------------------+-----------------
 This took me quite a bit of debugging to notice as its not documented
 anywhere in the library as far as I can see.

 It seems like the buffer used by libwebsockets to store received data
 thats handed over to the callback for LWS_CALLBACK_RECEIVE is being
 appended to as long as the callback does not return and new data is
 becoming available.

 Lets assume that the callback is called first with the data 'loaded', this
 directly leads to sending data to the remote side and then 'waiting' for
 an answer by calling the libwebsocket_service repeatedly and checking
 wether an answer has been received. When the answer data is received the
 callback is called again, but the 'in' variable still points to 'loaded'.
 Just the len parameter is extended to include the new data.

 If the code ensures to exit the callback first before sending the data to
 the remote side this does not happen, the second time the callback is
 called the in data points to just the answer for the sent data.

 IMO libwebsockets should handle the bookkeeping of the buffer better here,
 i.e. give an 'in' parameter to the callback which is set to point to the
 new data only and not to any data that was already given to the callback
 before.

 Debugging this scenario can take quite some time and is hard on platforms
 which do not allow to inspect TCP data sent through local loopback
 connections (ms windows for example).

--
Ticket URL: <http://libwebsockets.org/trac/libwebsockets/ticket/49>
libwebsockets <http://libwebsockets.org>
libwebsockets C library



More information about the Libwebsockets mailing list