diff --git a/configure.ac b/configure.ac index b19faea2..51c0bcde 100644 --- a/configure.ac +++ b/configure.ac @@ -300,6 +300,7 @@ AC_CHECK_HEADERS([argz.h \ malloc.h \ netdb.h \ netinet/in.h \ + netinet/tcp.h \ poll.h \ port.h \ stddef.h \ diff --git a/src/HttpServerCommand.cc b/src/HttpServerCommand.cc index 18aae01c..75abb543 100644 --- a/src/HttpServerCommand.cc +++ b/src/HttpServerCommand.cc @@ -163,6 +163,7 @@ bool HttpServerCommand::execute() httpServer_->feedUpgradeResponse("websocket", fmt("Sec-WebSocket-Accept: %s\r\n", serverKey.c_str())); + httpServer_->getSocket()->setTcpNodelay(true); Command* command = new rpc::WebSocketResponseCommand(getCuid(), httpServer_, e_, socket_); diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 7430e0a1..ec92571b 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -506,6 +506,12 @@ void SocketCore::joinMulticastGroup setSockOpt(IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); } +void SocketCore::setTcpNodelay(bool f) +{ + int val = f; + setSockOpt(IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); +} + void SocketCore::setNonBlockingMode() { #ifdef __MINGW32__ diff --git a/src/SocketCore.h b/src/SocketCore.h index eaf6d946..1627f4f1 100644 --- a/src/SocketCore.h +++ b/src/SocketCore.h @@ -125,6 +125,9 @@ public: (const std::string& multicastAddr, uint16_t multicastPort, const std::string& localAddr); + // Enables TCP_NODELAY socket option if f == true. + void setTcpNodelay(bool f); + void create(int family, int protocol = 0); void bindWithFamily(uint16_t port, int family, int flags = AI_PASSIVE); diff --git a/src/a2netcompat.h b/src/a2netcompat.h index 5d4689fd..01be9c25 100644 --- a/src/a2netcompat.h +++ b/src/a2netcompat.h @@ -73,6 +73,10 @@ # include #endif // HAVE_NETINET_IN_H +#ifdef HAVE_NETINET_TCP_H +# include +#endif // HAVE_NETINET_TCP_H + #ifdef HAVE_ARPA_INET_H # include #endif // HAVE_ARPA_INET_H