[Libwebsockets] lws_callback_on_writable

andy at warmcat.com andy at warmcat.com
Fri Mar 13 19:49:29 CET 2020

On March 13, 2020 6:28:14 PM UTC, Pranjali Chumbhale <pranjalic at safeai.ai> wrote:
>Hello Team,
>Is it possible to call lws_callback_on_writable with the data to be

No... lws' concept is only produce data "just in time" and don't pretend the system has endless heap.  "Just in time" means when the networking stack indicates it can take more data for that particular connection, we should produce it and send it.

When you realized you want to send something and when you actually can send something are two different things that may not have much relationship... normally it'll take more in ms, but if your phone switches cells or you go in a tunnel or drops into the sea it may not take more data for seconds or minutes.  So they're treated as two different things.

If you need to make it look like one thing you can use a side buffer or lws_buflist to hold your data for when the socket does signal its writeble.  But that disconnects that data production from being regulated by the connection... eg if you had 10MB or 100MB or whatevetto send it will lead to all 10MB or whatever going on the heap if the connection is slow.  This doesn't scale or work on small devices whereas the lws way does.


More information about the Libwebsockets mailing list