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

Make TCP server websocket-aware #408

Merged
merged 9 commits into from
Feb 13, 2025

Conversation

karlseguin
Copy link
Contributor

@karlseguin karlseguin commented Feb 6, 2025

Adding HTTP & websocket awareness to the TCP server.

HTTP server handles GET /json/version and websocket upgrade requests.

Conceptually, websocket handling is the same code as before, but receiving
data will parse the websocket frames and writing data will wrap it in
a websocket frame.

The previous Ctx was split into a Server and a Client. This was
largely done to make it easy to write unit tests, since the Client is
a generic, all its dependencies (i.e. the server) can be mocked out. This
also makes it a bit nicer to know if there is or isn't a client (via the
server's client optional).

Added a MemoryPool for the Send object (I thought that was a nice touch!)

Removed MacOS hack on accept/conn completion usage.

@karlseguin karlseguin changed the title [WIP] Make TCP server websocket-aware Make TCP server websocket-aware Feb 7, 2025
@karlseguin karlseguin mentioned this pull request Feb 12, 2025
@krichprollsch
Copy link
Member

@karlseguin The change LGTM. thank you!
Can you just fix the conflict created by 39b3786 please?

@krichprollsch krichprollsch self-requested a review February 12, 2025 13:53
Adding HTTP & websocket awareness to the TCP server.

HTTP server handles `GET /json/version` and websocket upgrade requests.

Conceptually, websocket handling is the same code as before, but receiving
data will parse the websocket frames and writing data will wrap it in
a websocket frame.

The previous `Ctx` was split into a `Server` and a `Client`. This was
largely done to make it easy to write unit tests, since the `Client` is
a generic, all its dependencies (i.e. the server) can be mocked out. This
also makes it a bit nicer to know if there is or isn't a client (via the
server's client optional).

Added a MemoryPool for the Send object (I thought that was a nice touch!)

Removed MacOS hack on accept/conn completion usage.

Known issues:
- When framing an outgoing message, the entire message has to be duped. This
is no worse than how it was before, but it should be possible to eliminate
this in the future. Probably not part of this PR.

- Websocket parsing will reject continuation frames. I don't know of a single
client that will send a fragmented message (websocket has its own
message fragmentation), but we should probably still support this just in
case.

- I don't think the receive, timeout and close completions can safely be
re-used like we're doing. I believe they need to be associated with a specific
client socket.

- A new connection creates a new browser session. I think this is right (??),
but for the very first, we're throwing out a perfectly usable session. I'm
thinking this might be a change to how Browser/Sessions work.

- zig build test won't compile. This branch reproduces the issue with none
of these changes:
https://github.com/karlseguin/browser/tree/broken_test_build

(or, as a diff to main):
lightpanda-io/browser@main...karlseguin:broken_test_build
Move more logic into the reader. Avoid copying partial messages in
cases where we know that the buffer is large enough.

This is mostly groundwork for trying to add support for continuation
frames.
@karlseguin
Copy link
Contributor Author

@karlseguin The change LGTM. thank you! Can you just fix the conflict created by 39b3786 please?

done

@krichprollsch krichprollsch merged commit d8fae5b into lightpanda-io:main Feb 13, 2025
9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 13, 2025
@karlseguin karlseguin deleted the websocket_server branch February 13, 2025 09:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants