De-duplicated a small bit of systems code
[net] Added SetSocketNoDelay() utility function #10061
pull tjps wants to merge 1 commits into bitcoin:master from tjps:tjps_nodelay changing 3 files +12 −12-
tjps commented at 5:17 AM on March 23, 2017: contributor
-
in src/netbase.cpp:731 in ffaae8b1ca outdated
723 | @@ -728,6 +724,19 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking) 724 | return true; 725 | } 726 | 727 | +bool SetSocketNoDelay(SOCKET& hSocket) 728 | +{ 729 | + int set = 1; 730 | + int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, 731 | +#ifdef WIN32
paveljanik commented at 6:35 AM on March 23, 2017:I don't like this ;-) #ifdef in the middle of the function is worst in my eyes than the previuos solution.
tjps commented at 7:03 AM on March 23, 2017:You mean in the middle of the function call? I agree it looks visually worse, but I like deduplicating code as much as possible.
However on longer consideration, I realized that the conversion from (const char) to (const void) will happen implicitly on any platform, so this ifdef isn't even needed.
fanquake added the label P2P on Mar 24, 2017sipa commented at 10:02 PM on March 24, 2017: memberutACK
in src/netbase.cpp:730 in b36cc2b239 outdated
723 | @@ -728,6 +724,13 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking) 724 | return true; 725 | } 726 | 727 | +bool SetSocketNoDelay(SOCKET& hSocket) 728 | +{ 729 | + int set = 1; 730 | + int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int));
laanwj commented at 11:39 AM on April 3, 2017:Indeed, seems like the WIN32 check was unnecessary, every pointer can be passed to a
void*parameter includingchar*so the redundant cast doesn't matter.[net] Added SetSocketNoDelay() utility function ad415bc16ain src/netbase.cpp:731 in b36cc2b239 outdated
723 | @@ -728,6 +724,13 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking) 724 | return true; 725 | } 726 | 727 | +bool SetSocketNoDelay(SOCKET& hSocket) 728 | +{ 729 | + int set = 1; 730 | + int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int)); 731 | + return rc != -1;
laanwj commented at 11:41 AM on April 3, 2017:I'd feel slightly better with
rc == 0. 0 is guaranteed to be the success value both in Windows and UNIX, whereas on failure windows returns.aspx)SOCKET_ERROR(which may or may not be -1, it's not mentioned).
tjps commented at 6:32 PM on April 5, 2017:But of course, I usually idiomatically check rc == 0 from system calls. Not sure why I went with != -1.
tjps commented at 5:31 PM on April 21, 2017: contributorbump on an easy dedupe merge
TheBlueMatt commented at 8:36 PM on May 8, 2017: member@theuni ping Seems this stuff could generally use a cleanup (merge SetSocketNonBlocking/SetSocketNoDelay, also do we need to set SO_NOSIGPIPE on the newly-listened socket (looks like it inherits), maybe would be nice to merge that too?
Anyway, utACK ad415bc16afdb4fdb6d619624762f1324751a824 this itself, its still a strict improvement.
theuni commented at 4:20 PM on May 16, 2017: memberutACK ad415bc16afdb4fdb6d619624762f1324751a824. @TheBlueMatt We're about to get new socket creation handling from libevent (I'm working on it now), so I'm not too worried about further refactors here.
sipa merged this on May 18, 2017sipa closed this on May 18, 2017sipa referenced this in commit ae786098bc on May 18, 2017tjps deleted the branch on May 18, 2017PastaPastaPasta referenced this in commit 090054898d on Jun 10, 2019PastaPastaPasta referenced this in commit f1dfe1df8a on Jun 11, 2019PastaPastaPasta referenced this in commit 1bf45aed3e on Jun 11, 2019PastaPastaPasta referenced this in commit 7a84309bdb on Jun 15, 2019PastaPastaPasta referenced this in commit 5b42f72d58 on Jun 19, 2019PastaPastaPasta referenced this in commit c20f48cd7d on Jun 19, 2019PastaPastaPasta referenced this in commit 30c11b55e8 on Jun 19, 2019PastaPastaPasta referenced this in commit 9644194b12 on Jun 19, 2019PastaPastaPasta referenced this in commit ade50a09ca on Jun 19, 2019PastaPastaPasta referenced this in commit f5e4383fc6 on Jun 20, 2019PastaPastaPasta referenced this in commit f0bd5ac9b5 on Jun 22, 2019PastaPastaPasta referenced this in commit fd50b5eb4d on Jun 22, 2019PastaPastaPasta referenced this in commit 0bdc3a2474 on Jun 22, 2019PastaPastaPasta referenced this in commit 71dd6b3e34 on Jun 22, 2019PastaPastaPasta referenced this in commit d15f7b19d5 on Jun 22, 2019PastaPastaPasta referenced this in commit 64d4113e01 on Jun 24, 2019barrystyle referenced this in commit 4ad704de66 on Jan 22, 2020DrahtBot locked this on Sep 8, 2021ContributorsLabels
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 12:15 UTC
More mirrored repositories can be found on mirror.b10c.me