Enable TCP_NODELAY for WebSocket connection.

pull/13/head
Tatsuhiro Tsujikawa 2012-03-21 02:08:18 +09:00
parent bdd37fe3de
commit 332bda83b4
5 changed files with 15 additions and 0 deletions

View File

@ -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 \

View File

@ -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_);

View File

@ -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__

View File

@ -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);

View File

@ -73,6 +73,10 @@
# include <netinet/in.h>
#endif // HAVE_NETINET_IN_H
#ifdef HAVE_NETINET_TCP_H
# include <netinet/tcp.h>
#endif // HAVE_NETINET_TCP_H
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif // HAVE_ARPA_INET_H