From e599e35469f0385359ad8aff07d86a9d51beefc4 Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 4 Jul 2023 12:02:13 -0400 Subject: [PATCH] cwSocket.cpp,cwSocketDecls.h,cwIo.cpp : Implement TCP_NODELAY. --- cwIo.cpp | 1 + cwSocket.cpp | 13 +++++++++++++ cwSocketDecls.h | 1 + 3 files changed, 15 insertions(+) diff --git a/cwIo.cpp b/cwIo.cpp index 97eefd2..d4a0356 100644 --- a/cwIo.cpp +++ b/cwIo.cpp @@ -714,6 +714,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