Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoupling the websocket protocol from the transport layer #3148

Open
sumitd2 opened this issue May 18, 2024 · 6 comments
Open

Decoupling the websocket protocol from the transport layer #3148

sumitd2 opened this issue May 18, 2024 · 6 comments

Comments

@sumitd2
Copy link

sumitd2 commented May 18, 2024

Hi team,
I would like to use libwebsockets with my own transport layer which is based on io_uring. Basically, I have a io_uring completion events based (single threaded) main loop (which runs a state machine) with non blocking socket calls. Is it possible with libwebsockets? Do you have any future plans to decouple the the websocket protocol from the transport layer?
Thank you.

@lws-team
Copy link
Member

We do have custom event lib support, where you can tell lws to handle socket events on an abstracted "event library", which can be you own implementation. I'm not sure if that's enough for this or not.

Eg,

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples-lowlevel/http-server/minimal-http-server-eventlib-custom/minimal-http-server.c

@sumitd2
Copy link
Author

sumitd2 commented May 19, 2024

Thanks for the quick reply.

I am not sure if I understand the example, but one thing I certainly cannot do is to dedicate a thread to lws_service(). That way it will either occupy a core or incur a context switching overhead. My application is single threaded where it does all its work.

Ideally, what I want to be able to do is this:
When I receive data on my socket, I call LWS with that data. LWS then parses it and calls the registered callback with an appropriate event. This event could include data to be sent back through the socket. The data could be an http upgrade, or subsequent websocket frames. When my application wants to send data, it submits it to LWS which frames it and returns it to my application, which then sends it with one of io_uring's non-blocking send calls.

@lws-team
Copy link
Member

... nothing about this requires a dedicated thread. In fact it requires a single-threaded event loop.

Ideally, what I want to be able to do is this:

I'm afraid we're in the parallel universe where I wrote this 13 years ago without any reference to you, or your ideals you might arrive at in 2024. You're welcome to use or modify what's available, but nobody's going to rewrite it to your specifications for free.

@sumitd2
Copy link
Author

sumitd2 commented May 19, 2024

I'm afraid we're in the parallel universe where I wrote this 13 years ago without any reference to you, or your ideals you might arrive at in 2024. You're welcome to use or modify what's available, but nobody's going to rewrite it to your specifications for free.

I certainly did not want you to rewrite it. I just thought you could let me know if there is something already there which could help me achieve similar to what I want. I am sure you would have come up with something better if you like the idea of decoupling the websocket protocol from the transport layer.
Thanks.

@lws-team
Copy link
Member

It's better to spend a bit more serious time understanding the custom event loop stuff (eg, that it is unrelated to any separate thread) that I did suggest. You're basically making an event library along the lines of libuv etc and that is how to interface to such a thing.

@sumitd2
Copy link
Author

sumitd2 commented May 19, 2024

@lws-team
The custom event loop stuff is now making sense to me, but the example still relies on socket io being done by LWS. Is there an example, if decoupling is possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants