Add fd injection and in-process pipe connect for vws server#11
Open
vrtql wants to merge 3 commits into
Open
Conversation
Adds three new APIs that together allow an in-process WebSocket connection over a uv_socketpair(): - vws_tcp_svr_inject_fd(server, fd): thread-safe injection of an already-connected stream fd into a running server's libuv loop. Pushes onto a per-server queue and signals a uv_async_t; the loop thread drains the queue and adopts each fd as a uv_pipe_t. - vws_cnx_from_fd(cnx, fd): bypass DNS/TCP and adopt an existing fd as a vws client, switching it to non-blocking and running the standard handshake. - vws_pipe_connect(server): one-shot helper that creates a socketpair, hands one end to the server, wraps the other as a fully-handshaken vws_cnx and returns it. The server must be running on a different thread than the caller of vws_pipe_connect(), since the client handshake blocks waiting for the server's HTTP upgrade response. Includes test/test_pipe_server demonstrating the round trip.
The previous docstring said the function "switches the fd to non-blocking" which was misleading -- the client API is intentionally blocking-with- timeout. The fd is placed in O_NONBLOCK only so the internal poll()-driven read/write loops can drive it (same as vws_connect() does after a TCP connect). Caller-facing send/recv semantics are unchanged.
Frame masking exists to defeat cache-poisoning attacks on intermediate proxies. A socketpair has no proxies, so masking is pure overhead -- it adds a 4-byte mask key per frame, an RAND_bytes() call, and a per-byte XOR over the payload. Calling vws_cnx_set_server_mode() inside vws_pipe_connect() skips all of that. The server's frame parser already accepts both masked and unmasked frames so no server-side change is needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds three new APIs that together allow an in-process WebSocket
connection over a uv_socketpair():
vws_tcp_svr_inject_fd(server, fd): thread-safe injection of an
already-connected stream fd into a running server's libuv loop.
Pushes onto a per-server queue and signals a uv_async_t; the loop
thread drains the queue and adopts each fd as a uv_pipe_t.
vws_cnx_from_fd(cnx, fd): bypass DNS/TCP and adopt an existing fd
as a vws client, switching it to non-blocking and running the
standard handshake.
vws_pipe_connect(server): one-shot helper that creates a
socketpair, hands one end to the server, wraps the other as a
fully-handshaken vws_cnx and returns it.
The server must be running on a different thread than the caller of
vws_pipe_connect(), since the client handshake blocks waiting for
the server's HTTP upgrade response.
Includes test/test_pipe_server demonstrating the round trip.