cwSocket.cpp,cwSocketDecls.h,cwIo.cpp : Implement TCP_NODELAY.
This commit is contained in:
parent
a7dbec54ee
commit
e599e35469
1
cwIo.cpp
1
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, }
|
||||
};
|
||||
|
||||
|
13
cwSocket.cpp
13
cwSocket.cpp
@ -8,6 +8,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h> // close
|
||||
@ -502,6 +503,7 @@ namespace cw
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
|
||||
errLabel:
|
||||
return rc;
|
||||
}
|
||||
@ -741,6 +743,17 @@ cw::rc_t cw::sock::create( handle_t h,
|
||||
}
|
||||
}
|
||||
|
||||
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 )
|
||||
goto errLabel;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user