Net: Fix WebSocket sendFrame delay by enabling TCP_NODELAY#5077
Merged
Net: Fix WebSocket sendFrame delay by enabling TCP_NODELAY#5077
Conversation
- Enable TCP_NODELAY in WebSocketImpl constructor to prevent Nagle's algorithm from buffering small WebSocket frames - Add check to skip TCP_NODELAY for Unix domain sockets - Add documentation about TCP_NODELAY behavior to WebSocket class - Tested with existing WebSocket test suite - all tests pass Co-authored-by: aleks-f <2429093+aleks-f@users.noreply.github.com>
- Avoid unnecessary SocketAddress object construction by calling family() directly - Use specific exception type (Poco::Exception) instead of catch-all Co-authored-by: aleks-f <2429093+aleks-f@users.noreply.github.com>
- Catch specific exception types (NetException, IOException, InvalidArgumentException) instead of broad Poco::Exception - Improve error handling comments for clarity Co-authored-by: aleks-f <2429093+aleks-f@users.noreply.github.com>
- Combine catch blocks since all exceptions are handled identically - Improve code clarity with more descriptive comments Co-authored-by: aleks-f <2429093+aleks-f@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix delay in WebSocket sendFrame method
Fix WebSocket sendFrame delay by enabling TCP_NODELAY
Dec 8, 2025
aleks-f
approved these changes
Dec 8, 2025
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.
WebSocket
sendFrame()experiences ~2 second delays because Nagle's algorithm buffers small frames. While client-side WebSockets inherit TCP_NODELAY from HTTPClientSession, server-side WebSockets created from HTTPServerRequest do not.Changes
WebSocketImpl.cpp: Enable TCP_NODELAY in constructor for all WebSocket connections
WebSocket.h: Document TCP_NODELAY behavior
Implementation
This eliminates the artificial delays caused by Nagle's algorithm buffering small WebSocket frames, making frame sends immediate regardless of whether the WebSocket originated from a client or server connection.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
192.168.168.192./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest /tmp/ccsAxjaq.s ork/�� ch=" --green --p-I -I nit/include -I k/poco/poco/Net/-I t.cpp.o -D_LARGEFILE64_-I -qui�� /bin/c++ -DPOCO_-I /home/REDACTED/wor/home/REDACTED/work/poco/poco/CppUnit/include nit/include /home/REDACTED/woras -I /home/REDACTED/wor/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(packet block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest CMakeFiles/Net.dir/src/WebSocketImpl.cpp.d -MF t/testsuite/all -MT Net/CMakeFiles/Net.dir/src/WebSocketImpl.cpp.o -D_GNU_SOURCE -D Net_EXPORTS -D -DPO�� cpp.o -DPOCO_ENABLE_CPP20 dation/include _FD_EPOLL -DPOCOas nit/include -D_FILE_OFFSET_B/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(packet block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest FFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_REENTRAN -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_OS_FAMILYbash nit/include -DUTF8PROC_STATI--noprofile FFSET_BITS=64 -D_LARGEFILE64_SOU872727f6db7dcd22990d7845dae167444594bf63 -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_HAVE_SEND/bin/sh nit/include -DUTF8PROC_STATIcd /home/REDACTED/work/poco/poco/cmake-build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/REDACTED/work/poco/poco /home/REDACTED/work/poco/poco/Foundation /home/REDACTED/work/poco/poco/cmake-build /home/REDACTED/work/poco/poco/cmak e-build/Foundat(packet block)239.255.1.2REDACTED, pid is -1(packet block)255.255.255.255REDACTED, pid is -1(packet block)86.195.122.80.in-addr.arpa./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest /tmp/ccsAxjaq.s ork/�� ch=" --green --p-I -I nit/include -I k/poco/poco/Net/-I t.cpp.o -D_LARGEFILE64_-I -qui�� /bin/c++ -DPOCO_-I /home/REDACTED/wor/home/REDACTED/work/poco/poco/CppUnit/include nit/include /home/REDACTED/woras -I /home/REDACTED/wor/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(dns block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest CMakeFiles/Net.dir/src/WebSocketImpl.cpp.d -MF t/testsuite/all -MT Net/CMakeFiles/Net.dir/src/WebSocketImpl.cpp.o -D_GNU_SOURCE -D Net_EXPORTS -D -DPO�� cpp.o -DPOCO_ENABLE_CPP20 dation/include _FD_EPOLL -DPOCOas nit/include -D_FILE_OFFSET_B/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(dns block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest FFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_REENTRAN -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_OS_FAMILYbash nit/include -DUTF8PROC_STATI--noprofile FFSET_BITS=64 -D_LARGEFILE64_SOU872727f6db7dcd22990d7845dae167444594bf63 -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_HAVE_SEND/bin/sh nit/include -DUTF8PROC_STATIcd /home/REDACTED/work/poco/poco/cmake-build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/REDACTED/work/poco/poco /home/REDACTED/work/poco/poco/Foundation /home/REDACTED/work/poco/poco/cmake-build /home/REDACTED/work/poco/poco/cmak e-build/Foundat(dns block)aliastest.pocoproject.org./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest /tmp/ccsAxjaq.s ork/�� ch=" --green --p-I -I nit/include -I k/poco/poco/Net/-I t.cpp.o -D_LARGEFILE64_-I -qui�� /bin/c++ -DPOCO_-I /home/REDACTED/wor/home/REDACTED/work/poco/poco/CppUnit/include nit/include /home/REDACTED/woras -I /home/REDACTED/wor/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(dns block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest CMakeFiles/Net.dir/src/WebSocketImpl.cpp.d -MF t/testsuite/all -MT Net/CMakeFiles/Net.dir/src/WebSocketImpl.cpp.o -D_GNU_SOURCE -D Net_EXPORTS -D -DPO�� cpp.o -DPOCO_ENABLE_CPP20 dation/include _FD_EPOLL -DPOCOas nit/include -D_FILE_OFFSET_B/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(dns block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest FFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_REENTRAN -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_OS_FAMILYbash nit/include -DUTF8PROC_STATI--noprofile FFSET_BITS=64 -D_LARGEFILE64_SOU872727f6db7dcd22990d7845dae167444594bf63 -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_HAVE_SEND/bin/sh nit/include -DUTF8PROC_STATIcd /home/REDACTED/work/poco/poco/cmake-build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/REDACTED/work/poco/poco /home/REDACTED/work/poco/poco/Foundation /home/REDACTED/work/poco/poco/cmake-build /home/REDACTED/work/poco/poco/cmak e-build/Foundat(dns block)pocoproject.org./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest /tmp/ccsAxjaq.s ork/�� ch=" --green --p-I -I nit/include -I k/poco/poco/Net/-I t.cpp.o -D_LARGEFILE64_-I -qui�� /bin/c++ -DPOCO_-I /home/REDACTED/wor/home/REDACTED/work/poco/poco/CppUnit/include nit/include /home/REDACTED/woras -I /home/REDACTED/wor/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(dns block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest CMakeFiles/Net.dir/src/WebSocketImpl.cpp.d -MF t/testsuite/all -MT Net/CMakeFiles/Net.dir/src/WebSocketImpl.cpp.o -D_GNU_SOURCE -D Net_EXPORTS -D -DPO�� cpp.o -DPOCO_ENABLE_CPP20 dation/include _FD_EPOLL -DPOCOas nit/include -D_FILE_OFFSET_B/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(dns block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest FFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_REENTRAN -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_OS_FAMILYbash nit/include -DUTF8PROC_STATI--noprofile FFSET_BITS=64 -D_LARGEFILE64_SOU872727f6db7dcd22990d7845dae167444594bf63 -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_HAVE_SEND/bin/sh nit/include -DUTF8PROC_STATIcd /home/REDACTED/work/poco/poco/cmake-build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/REDACTED/work/poco/poco /home/REDACTED/work/poco/poco/Foundation /home/REDACTED/work/poco/poco/cmake-build /home/REDACTED/work/poco/poco/cmak e-build/Foundat(dns block)pool.ntp.org./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest /tmp/ccsAxjaq.s ork/�� ch=" --green --p-I -I nit/include -I k/poco/poco/Net/-I t.cpp.o -D_LARGEFILE64_-I -qui�� /bin/c++ -DPOCO_-I /home/REDACTED/wor/home/REDACTED/work/poco/poco/CppUnit/include nit/include /home/REDACTED/woras -I /home/REDACTED/wor/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(dns block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest CMakeFiles/Net.dir/src/WebSocketImpl.cpp.d -MF t/testsuite/all -MT Net/CMakeFiles/Net.dir/src/WebSocketImpl.cpp.o -D_GNU_SOURCE -D Net_EXPORTS -D -DPO�� cpp.o -DPOCO_ENABLE_CPP20 dation/include _FD_EPOLL -DPOCOas nit/include -D_FILE_OFFSET_B/home/REDACTED/work/poco/poco/Net/include FFSET_BITS=64 -D-I(dns block)./bin/Net-testREDACTED ./bin/Net-testREDACTED -all WebSocketTest FFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_REENTRAN -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_OS_FAMILYbash nit/include -DUTF8PROC_STATI--noprofile FFSET_BITS=64 -D_LARGEFILE64_SOU872727f6db7dcd22990d7845dae167444594bf63 -DPO�� include -DPOCO_ENABLE_CPP20 dation/include -DPOCO_HAVE_SEND/bin/sh nit/include -DUTF8PROC_STATIcd /home/REDACTED/work/poco/poco/cmake-build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/REDACTED/work/poco/poco /home/REDACTED/work/poco/poco/Foundation /home/REDACTED/work/poco/poco/cmake-build /home/REDACTED/work/poco/poco/cmak e-build/Foundat(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.