[Libwebsockets] Priority in LWS RingBuffer API

Andy Green andy at warmcat.com
Tue Feb 4 17:55:08 CET 2020



On 2/4/20 4:34 PM, Peiffer Eric wrote:
> Hi,
> 
> I use ring buffer api in order to bufferise message that I send to web 
> socket client
> In my application some messages have higher priority than other. Is it a 
> way where a can put message at the top of the ring so that they are 
> written first?

As it is, no.  You can add an api for it (and I'd be happy to see the 
patch).

If you need something different than lws_ring you might find lws_dll2 
useful for that

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-dll2.h#n255

it's a general doubly-linked list abstraction... as such it's normal you 
can add stuff either at the head or the tail.

It also has some interesting features like sorted insertion

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-dll2.h#n303-304

you define the sorting function and it will use that to figure out where 
to place the new guy in the linked-list.

lws_ring is built to handle n clients "subscribing" to the same ring 
with independent tail pointers and only retire the tail when all the 
clients have used it... if that's what you want it's probably easier to 
add a way to insert at the tail to that than add that on top of 
lws_dll2... depends on what you're doing with it.

-Andy


More information about the Libwebsockets mailing list