[Libwebsockets] libwebsocket_write usage

Andy Green andy at warmcat.com
Mon Nov 10 23:12:54 CET 2014



On 11 November 2014 00:45:37 GMT+08:00, Srikar Vadlamani <SrikarVadlamani at trafficware.com> wrote:
>Hello,
>
>
>I want to know the correct usage of libwebsocket_write, from the readme
>files I understand that libwebsocket_write should only be called from
>the LWS_CALLBACK_SERVER_WRITEABLE callback.

Yes.

>I was calling libwebsocket_write in a loop over all the clients and
>sending data to each client.

No, it's bad.

>FOR all Active Clients:
>
>        Libewebsocket_write(data_to_send);
>
>The above code was ASSERTING at lwsl_err("****** %x Sending new,
>pending truncated ...\n", wsi);

Your clients each have a different story about their network connection, some are on your lan, some in the next country, on a satellite link or on gprs or 3G.  They take data at different speeds.

Put another way, *each client connection becomes writeable individually*.  The callback about WRITEABLE is per-connection.

>The simplest change I can make for the code is
>
>
>
>FOR all Active Clients:
>
>        if(!lws_send_pipe_choked(client))
>
>                Libewebsocket_write(data_to_send);
>
>
>
>The above code does drop lot of packets.
>
>Does the above if statement catch all the conditions which we can
>expect due to lot of data transfer?

No.

>I might be willing to drop packets with heavy traffic.

For individual connections you will have no choice but to drop data if they can't keep up with your data source.

Please go back and look at the test server sources again, especially libwebsocket_callback_on_writable_all_protocol().

-Andy

>Srikar
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list