[Libwebsockets] Problems with big messages in custom protocol

Mathias Rudolph mathias-rudolph at web.de
Fri Mar 14 09:35:30 CET 2014


I have a problem where the spill for big messages does not work properly.

What I'm doing is, running two instances of my binary (both make use of the
lib) on the same machine. One is executed on the console (openSuse x64) and
the second is created from within with posix_spawn.

The one within is only an echo server that allows me to test the
functionality. The 'outer' instance runs some tests.

So, my problem now is. If I send a message that is bigger than the rx
buffer, it spills, but only as long as it is not more than 3x bigger than
the rx buffer.

My receive callback section looks like this:

> remaining = libwebsockets_remaining_packet_payload(wsi);
> std::copy((const char *) in, (const char *) in + len,
> if(remaining == 0) {
>   std::string msg = std::string(reinterpret_cast< char const*
>(rcvMessage.data()), rcvMessage.size());
>   doSomething(msg);
>   rcvMessage.clear();
> }

Where recvMessage is a std::vector<unsigned char>

My send section:

>  transmitBuffer = std::make_shared<std::vector<unsigned char>>();
>  // make room for pre padding
>  for(unsigned int idx = 0; idx < LWS_SEND_BUFFER_PRE_PADDING; idx++) {
>    transmitBuffer->push_back((unsigned char)0);
>  }
>  // append actual message
>  std::copy(message.begin(), message.end(),
>  // append post padding
>  for(unsigned int idx = 0; idx < LWS_SEND_BUFFER_POST_PADDING; idx++) {
>    transmitBuffer->push_back((unsigned char)0);
>  }
>  libwebsocket_write(wsi,
transmitBuffer->data()+LWS_SEND_BUFFER_PRE_PADDING, message.size(),

The transmitBuffer exists as long as not a new message is send or the
sender side is shut down.

My debug log looks like this:
>Sender: sent buffer size: 20027
>Recevier: Received data size: 4096, remaining 15909
>Recevier: Received data size: 4096, remaining 11813
>Recevier: Received data size: 4096, remaining 7717

And thats it. I tried to debug it, and it looks like the library is going
into an infinite loop.

I tried different sizes of the rx buffer but that makes no difference.

Is there something I missed?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20140314/6b97c8af/attachment.html>

More information about the Libwebsockets mailing list