[Libwebsockets] lws_write

Pranjali Chumbhale pranjalic at safeai.ai
Tue Mar 17 20:31:12 CET 2020


case LWS_CALLBACK_CLIENT_WRITEABLE:
{
lws_write(wsi, ptr, actual_data_length, LWS_WRITE_TEXT);
if (data in send buffer) {
lws_callback_on_writable(web_socket); }
}

hi Andy,

Can I do something like what I mentioned above?
Do you see any possible issues?

Basically my design is, I store in a buffer whenever data is generated.
When the web socket becomes writable I select one block from buffered data
to send. Then if I happen to have more in buffered, I request a callback
again when the websocket becomes writeable.


Regards,
Pranjali


On Tue, Mar 17, 2020 at 10:22 AM Andy Green <andy at warmcat.com> wrote:

>
>
> On Tue, Mar 17, 2020 at 09:41, Pranjali Chumbhale <pranjalic at safeai.ai>
> wrote:
>
> Hello Team,
>
> I am a bit confused with the pointer to pass to lws_write call.
> On websocket data goes like: LWS_SEND_BUFFER_PRE_PADDING + DATA +
> LWS_SEND_BUFFER_POST_PADDING
>
>
> For many years you just need to add LWS_PRE size before the buffer.  You
> don't need any POST padding just LWS_PRE before.  It's used by the protocol
> to prepend protocol framing data without having to copy the payload around.
>
> So should the buf point to start of pre-padding and len should be
> inclusive of pre paddinga nd post padding? Or just the length of the actual
>
>
> You should point to LWS_PRE bytes past the start of the buffer and give
> the length as the length of the actual data.
>
> So if you want to send "HELLO" then in memory
>
> [ LWS_PRE BYTES UNINITIALIZED ][ HELLO ]
>
> actual buffer start -> [ LWS_PRE BYTES UNINITIALIZED ]   pointer given to
> lws_write ---> [ HELLO ]
>
> and the length to lws_write is 5.
>
> -Andy
>
> data?
>
>
> LWS_VISIBLE LWS_EXTERN int
> lws_write(struct lws *wsi, unsigned char *buf, size_t len,
> enum lws_write_protocol protocol);
>
> Regards,
> Pranjali
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200317/f4cab6d0/attachment.htm>


More information about the Libwebsockets mailing list