[Libwebsockets] [libwebsockets] #42: calculates number of actually sent bytes incorrectly in libwebsockets_write

Trac trac at libwebsockets.org
Wed Oct 16 21:46:44 CEST 2013


#42: calculates number of actually sent bytes incorrectly in libwebsockets_write
-------------------------------------+-----------------
  Reporter:  andreaspakulat          |      Owner:
      Type:  defect                  |     Status:  new
  Priority:  major                   |  Milestone:
 Component:  libwebsocket test apps  |    Version:
Resolution:                          |   Keywords:
-------------------------------------+-----------------

Comment (by dtgriscom):

 I believe the problem is that libwebsockets_write() returns the number of
 bytes actually sent down the socket, which due to format overhead is
 greater than the number of bytes you hand it. That's why I use the
 following check code:


 {{{
 j = libwebsocket_write(socket, p, i, LWS_WRITE_TEXT);
 if (i <= 125) {
         if (j != i + 4) {
                 printf("Tried to send %d chars (small), "
                                 "but return value %d\n", i, j);
         }
 } else {
         if (j != i + 8) {
                 printf("Tried to send %d chars (large), "
                                 "but return value %d\n", i, j);
         }
 }
 }}}

 A small note: my code will fail when sending more than about 2^16^ bytes,
 as WebSockets adds yet more header bytes to handle that. I'll never use
 that many in my current app, so I didn't spend time on that case.

 A larger note: boy, is this messy. It looks like andreaspakulat is trying
 to patch {{{libwebsockets_write}}} to fix a bug in how it calculates the
 actual number of bytes sent down the socket. IMO, it would be far better
 to redefine {{{libwebsockets_write}}} to return the number of the user's
 bytes that it took and sent down the socket, ignoring the added format
 data. I don't see any value in knowing how many bytes went over TCP/IP,
 while there's a clear need to detect when {{{libwebsockets_write}}} didn't
 send everything requested.

--
Ticket URL: <http://libwebsockets.org/trac/libwebsockets/ticket/42#comment:1>
libwebsockets <http://libwebsockets.org>
libwebsockets C library



More information about the Libwebsockets mailing list