Parent Issue
Part of #315 (TCP receive std::span callback migration)
Summary
Migrate WebSocket receive flow to use tcp_socket's std::span<const uint8_t> callback so WebSocket receive does not require per-TCP-read std::vector construction just to hand off bytes to the protocol layer.
Background
websocket_socket currently registers a vector-based receive callback:
tcp_socket_->set_receive_callback([...] (const std::vector<uint8_t>& data) { on_tcp_receive(data); }) (src/internal/websocket_socket.cpp:72)
websocket_protocol::process_data() also currently takes const std::vector<uint8_t>& (include/kcenon/network/internal/websocket_protocol.h:127).
With the new span callback in tcp_socket (#316), WebSocket should consume bytes as a view and let the protocol layer append into its internal buffer, avoiding an intermediate vector allocation on every read.
Proposed Solution
1) Update websocket_protocol API to accept a view
Change:
websocket_protocol::process_data(const std::vector<uint8_t>&)
To:
websocket_protocol::process_data(std::span<const uint8_t>)
Implementation: append incoming bytes into buffer_ (already a std::vector<uint8_t>), then parse frames as today.
2) Update websocket_socket to register span callback
- Use
tcp_socket_->set_receive_callback_view(...)
- Update
websocket_socket::on_tcp_receive to accept std::span<const uint8_t> and forward to protocol_.process_data(span).
3) Update tests and docs
- Update
tests/unit/websocket_protocol_test.cpp call sites for the new signature
- Update any docs/examples referencing
process_data(vector) (e.g. docs/FEATURES_KO.md)
Files to Update
include/kcenon/network/internal/websocket_protocol.h
src/internal/websocket_protocol.cpp
include/kcenon/network/internal/websocket_socket.h
src/internal/websocket_socket.cpp
tests/unit/websocket_protocol_test.cpp
- Docs as needed (search for
process_data( usage)
Acceptance Criteria
Test Plan
- Run:
ctest --output-on-failure -R websocket
ctest --output-on-failure (full suite as time permits)
Parent Issue
Part of #315 (TCP receive std::span callback migration)
Summary
Migrate WebSocket receive flow to use
tcp_socket'sstd::span<const uint8_t>callback so WebSocket receive does not require per-TCP-readstd::vectorconstruction just to hand off bytes to the protocol layer.Background
websocket_socketcurrently registers a vector-based receive callback:tcp_socket_->set_receive_callback([...] (const std::vector<uint8_t>& data) { on_tcp_receive(data); })(src/internal/websocket_socket.cpp:72)websocket_protocol::process_data()also currently takesconst std::vector<uint8_t>&(include/kcenon/network/internal/websocket_protocol.h:127).With the new span callback in
tcp_socket(#316), WebSocket should consume bytes as a view and let the protocol layer append into its internal buffer, avoiding an intermediate vector allocation on every read.Proposed Solution
1) Update websocket_protocol API to accept a view
Change:
websocket_protocol::process_data(const std::vector<uint8_t>&)To:
websocket_protocol::process_data(std::span<const uint8_t>)Implementation: append incoming bytes into
buffer_(already astd::vector<uint8_t>), then parse frames as today.2) Update websocket_socket to register span callback
tcp_socket_->set_receive_callback_view(...)websocket_socket::on_tcp_receiveto acceptstd::span<const uint8_t>and forward toprotocol_.process_data(span).3) Update tests and docs
tests/unit/websocket_protocol_test.cppcall sites for the new signatureprocess_data(vector)(e.g.docs/FEATURES_KO.md)Files to Update
include/kcenon/network/internal/websocket_protocol.hsrc/internal/websocket_protocol.cppinclude/kcenon/network/internal/websocket_socket.hsrc/internal/websocket_socket.cpptests/unit/websocket_protocol_test.cppprocess_data(usage)Acceptance Criteria
tcp_socketspan callbackwebsocket_protocol::process_dataacceptsstd::span<const uint8_t>std::vectoris required solely to adapt TCP bytes into the protocol layerwebsocket_protocol_testand any WebSocket integration tests)Test Plan
ctest --output-on-failure -R websocketctest --output-on-failure(full suite as time permits)