[Libwebsockets] lws_write

Andy Green andy at warmcat.com
Tue Mar 17 18:22:31 CET 2020



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/df6597cf/attachment.htm>


More information about the Libwebsockets mailing list