In my use case my messages are small but there are many and they come very fast. Some times my application has to respond. However, I want it to respond only if it has processed all the messages that it has received.
I receive messages in the following way:
static int lws_event_callback(struct lws* conn, enum lws_callback_reasons reason, void* user, void* data, size_t len)
{
switch(reason)
{
case LWS_CALLBACK_CLIENT_RECEIVE:
{
my_callback_client_receive(data);
}}}
I don't know much about the internals of libwebsockets, but conceptually I can imagine that it's possible that by the time that my_callback_client_receive
is called, other messages have arrived.
In my ideal world there would be a variable n
which meant "number of messages waiting in a buffer to be processed" that I could pass into my call back
case LWS_CALLBACK_CLIENT_RECEIVE:
{
my_callback_client_receive(data, n);
}
So that I would know not to respond until I've processed as many messages as possible. Something like:
void my_callback_client_receive(data, n)
{
process(data);
if (n>1):
return; // this msg is not the most recent, keep processing
else:
send_response();
return;
}
Is this or something like this possible with LWS?