refactor(websocket): migrate TCP receive path to std::span and update protocol API#323
Merged
Merged
Conversation
… protocol API - Update websocket_protocol::process_data() to accept std::span<const uint8_t> instead of const std::vector<uint8_t>& - Update websocket_socket to use tcp_socket::set_receive_callback_view() for zero-copy TCP-to-WebSocket data flow - Change on_tcp_receive() to accept std::span<const uint8_t> - Update all handshake callbacks to use span-based receive This eliminates per-read std::vector allocation solely for TCP-to-protocol handoff. Data is copied once into the protocol's internal buffer for frame processing. Part of Epic #315 (TCP receive zero-allocation hot path) Closes #318
Contributor
Performance ComparisonBase Branch ResultsNo base results PR Branch ResultsNo PR results |
Add is_open() check in do_read() to prevent UBSAN errors from accessing null descriptor_state when the socket has already been closed. This fixes BoundaryTest.HandlesSingleByteMessage failure under undefined behavior sanitizer.
Contributor
Performance ComparisonBase Branch ResultsNo base results PR Branch ResultsNo PR results |
Document the socket validity check fix in all changelog files: - Added is_open() check before async_read_some() in tcp_socket::do_read() - Prevents null descriptor_state access when socket is already closed - Fixes BoundaryTest.HandlesSingleByteMessage UBSAN failure
Contributor
Performance ComparisonBase Branch ResultsNo base results PR Branch ResultsNo PR results |
5 tasks
kcenon
added a commit
that referenced
this pull request
Apr 13, 2026
… protocol API (#323) * refactor(websocket): migrate TCP receive path to std::span and update protocol API - Update websocket_protocol::process_data() to accept std::span<const uint8_t> instead of const std::vector<uint8_t>& - Update websocket_socket to use tcp_socket::set_receive_callback_view() for zero-copy TCP-to-WebSocket data flow - Change on_tcp_receive() to accept std::span<const uint8_t> - Update all handshake callbacks to use span-based receive This eliminates per-read std::vector allocation solely for TCP-to-protocol handoff. Data is copied once into the protocol's internal buffer for frame processing. Part of Epic #315 (TCP receive zero-allocation hot path) Closes #318 * docs: add WebSocket zero-copy receive path to changelogs Document the WebSocket receive path migration to std::span callback: - websocket_protocol::process_data() API change - websocket_socket using tcp_socket::set_receive_callback_view() - Performance improvement details Part of Epic #315, #318 * fix(tcp_socket): add socket validity check before async read operation Add is_open() check in do_read() to prevent UBSAN errors from accessing null descriptor_state when the socket has already been closed. This fixes BoundaryTest.HandlesSingleByteMessage failure under undefined behavior sanitizer. * docs: add tcp_socket UBSAN fix to changelogs Document the socket validity check fix in all changelog files: - Added is_open() check before async_read_some() in tcp_socket::do_read() - Prevents null descriptor_state access when socket is already closed - Fixes BoundaryTest.HandlesSingleByteMessage UBSAN failure
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.
Summary
std::span<const uint8_t>callbackswebsocket_protocol::process_data()to accept span instead of vectorwebsocket_socketto usetcp_socket::set_receive_callback_view()for zero-copy TCP-to-WebSocket data flowChanges
websocket_protocol
process_data(const std::vector<uint8_t>&)→process_data(std::span<const uint8_t>)<span>header includewebsocket_socket
set_receive_callback_view()instead ofset_receive_callback()for all TCP receive callbackson_tcp_receive(const std::vector<uint8_t>&)→on_tcp_receive(std::span<const uint8_t>)Performance Impact
std::vectorallocation solely for TCP-to-protocol handoffTest Plan
-DNETWORK_BUILD_TESTS=ONRelated Issues