[Libwebsockets] R: Segmentation fault on Raspberry
Andy Green
andy at warmcat.com
Mon Aug 24 20:31:23 CEST 2020
On 8/24/20 5:22 PM, Stefano Mora wrote:
> Thanks,
> in my code I have the following:
>
> /* notice we allowed for LWS_PRE in the payload already */
> m = lws_write(wsi, (unsigned char*)pmsg->payload + LWS_PRE, pmsg->len,
> LWS_WRITE_TEXT);
> if (m < (int)pmsg->len) {
> lwsl_err("[wc] WRITEABLE ERROR: ret %d lws_writing to ws\n", m);
> return -1;
> }
>
> I added some debug string in the log and I discovered that a payload
> buffer was null 🙁
Yep...
> ...
> [2020/08/24 18:15:49:5937] Firmware - pckt len=5 - 00 02 01 28 54
> +send
> 0x68dfc 0x68c78 - 0x688a8
> -send
> WRITEABLE pss=0x68c78 pmsg:0x68c90 idxMsg:0 payload:0x68500
> lws_issue_raw: ssl_capable_write (31) says 31
>
> [2020/08/24 18:16:01:1145] Firmware - pckt len=5 - 00 02 01 28 54
> +send
> 0x68dfc 0x68c78 - 0x688a8
> -send
> WRITEABLE pss=0x68c78 pmsg:0x68c90 idxMsg:0 payload:0x68500
> lws_issue_raw: ssl_capable_write (31) says 31
>
> lws_validity_cb: wsi 0x688a8: scheduling validity check
> rops_handle_POLLOUT_ws: issuing ping on wsi 0x688a8: ws lws-minimal h2: 0
> lws_issue_raw: ssl_capable_write (2) says 2
> WRITEABLE pss=0x68c78 pmsg:0x68c90 idxMsg:0 payload:0x68500
> lws_issue_raw: ssl_capable_write (31) says 31
> WRITEABLE pss=0x68c78 pmsg:0x68c98 idxMsg:1 payload:(nil)
>
> Something is triggering the LWS_CALLBACK_SERVER_WRITEABLE twice, the
> first one with 2 bytes (?) and the second one with a null payload ..
There's no 1:1 relationship between asking for writeable and getting
them... you may ask ten times and get one or ask for one and get two, or
get some gratuitous ones later, because lws needed to add a PING on the
connection, or had to send the remaining data in the background due to a
partial write, and didn't know if doing that consumed a writeable slot
you had asked for in a race.
WRITEABLE is just saying, "it's writeable", you have to hold state on
the connection (in the pss in the examples) to understand what if
anything you want to take the opportunity to write. If nothing, just
return 0.
-Andy
More information about the Libwebsockets
mailing list