Merge branch 'master' of gitea.larke.org:kevin/libcw

This commit is contained in:
kevin 2023-07-25 20:24:39 -04:00
commit 06a8a8ec88
3 changed files with 15 additions and 0 deletions

View File

@ -727,6 +727,7 @@ namespace cw
{ .id=sock::kMultiCastLoopFl, .label="multicast_loop" }, // { .id=sock::kMultiCastLoopFl, .label="multicast_loop" }, //
{ .id=sock::kListenFl, .label="listen" }, // Use this socket to listen for incoming connections { .id=sock::kListenFl, .label="listen" }, // Use this socket to listen for incoming connections
{ .id=sock::kStreamFl, .label="stream" }, // Connected stream (vs. Datagram) { .id=sock::kStreamFl, .label="stream" }, // Connected stream (vs. Datagram)
{ .id=sock::kTcpNoDelayFl, .label="tcp_no_delay" }, // Implements TCP_NODELAY
{ .id=0, .label=nullptr, } { .id=0, .label=nullptr, }
}; };

View File

@ -8,6 +8,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <net/if.h> #include <net/if.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> // close #include <unistd.h> // close
@ -502,6 +503,7 @@ namespace cw
goto errLabel; goto errLabel;
} }
errLabel: errLabel:
return rc; 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 // create the 32 bit local address
if((rc = _initAddr( localAddr, port, &s->localSockAddr )) != kOkRC ) if((rc = _initAddr( localAddr, port, &s->localSockAddr )) != kOkRC )
goto errLabel; goto errLabel;

View File

@ -28,6 +28,7 @@ namespace cw
kMultiCastLoopFl = 0x040, // kMultiCastLoopFl = 0x040, //
kListenFl = 0x080, // Use this socket to listen for incoming connections kListenFl = 0x080, // Use this socket to listen for incoming connections
kStreamFl = 0x100, // Connected stream (not Datagram) kStreamFl = 0x100, // Connected stream (not Datagram)
kTcpNoDelayFl = 0x200, // TCP stream option only (Implements TCP_NODELAY)
}; };
enum enum