Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Net/include/Poco/Net/WebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class Net_API WebSocket: public StreamSocket
/// mode, by calling setBlocking(false).
/// Please refer to the sendFrame() and receiveFrame() documentation
/// for non-blocking behavior.
///
/// TCP_NODELAY is automatically enabled on the underlying socket
/// to prevent delays from Nagle's algorithm when sending small
/// WebSocket frames.
{
public:
enum Mode
Expand Down
16 changes: 16 additions & 0 deletions Net/src/WebSocketImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Poco/Net/NetException.h"
#include "Poco/Net/WebSocket.h"
#include "Poco/Net/HTTPSession.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Buffer.h"
#include "Poco/BinaryWriter.h"
#include "Poco/BinaryReader.h"
Expand All @@ -42,6 +43,21 @@ WebSocketImpl::WebSocketImpl(StreamSocketImpl* pStreamSocketImpl, HTTPSession& s
poco_check_ptr(pStreamSocketImpl);
_pStreamSocketImpl->duplicate();
session.drainBuffer(_buffer);
// Enable TCP_NODELAY to prevent delays caused by Nagle's algorithm
// for small WebSocket frames. Skip for Unix domain sockets.
try
{
if (_pStreamSocketImpl->address().family() != SocketAddress::UNIX_LOCAL)
_pStreamSocketImpl->setNoDelay(true);
}
catch (NetException&)
{
// Ignore - socket errors (e.g., not connected or doesn't support TCP options)
}
catch (Poco::Exception&)
{
// Ignore - other configuration errors (IOException, InvalidArgumentException, etc.)
}
}


Expand Down
Loading