diff --git a/cwIo.cpp b/cwIo.cpp index 339f883..00422ff 100644 --- a/cwIo.cpp +++ b/cwIo.cpp @@ -727,6 +727,7 @@ namespace cw { .id=sock::kMultiCastLoopFl, .label="multicast_loop" }, // { .id=sock::kListenFl, .label="listen" }, // Use this socket to listen for incoming connections { .id=sock::kStreamFl, .label="stream" }, // Connected stream (vs. Datagram) + { .id=sock::kTcpNoDelayFl, .label="tcp_no_delay" }, // Implements TCP_NODELAY { .id=0, .label=nullptr, } }; diff --git a/cwSocket.cpp b/cwSocket.cpp index b50ee47..ae3b391 100644 --- a/cwSocket.cpp +++ b/cwSocket.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include // close @@ -502,6 +503,7 @@ namespace cw goto errLabel; } + errLabel: return rc; } @@ -740,6 +742,17 @@ cw::rc_t cw::sock::create( handle_t h, goto errLabel; } } + + if( cwIsFlag(flags,kTcpFl) && cwIsFlag(flags,kTcpNoDelayFl) ) + { + int nodelay_flag = 1; + if( setsockopt( s->sockH, IPPROTO_TCP, TCP_NODELAY, (void *)&nodelay_flag, sizeof(nodelay_flag)) == cwSOCKET_SYS_ERR ) + { + rc = cwLogSysError(kOpFailRC,errno, "Attempt to set the socket NODELAY attribute failed." ); + goto errLabel; + } + + } // create the 32 bit local address if((rc = _initAddr( localAddr, port, &s->localSockAddr )) != kOkRC ) diff --git a/cwSocketDecls.h b/cwSocketDecls.h index 4a23c56..f4bd2b6 100644 --- a/cwSocketDecls.h +++ b/cwSocketDecls.h @@ -28,6 +28,7 @@ namespace cw kMultiCastLoopFl = 0x040, // kListenFl = 0x080, // Use this socket to listen for incoming connections kStreamFl = 0x100, // Connected stream (not Datagram) + kTcpNoDelayFl = 0x200, // TCP stream option only (Implements TCP_NODELAY) }; enum