Skip to content

Conversation

tjps
Copy link
Contributor

@tjps tjps commented Mar 23, 2017

De-duplicated a small bit of systems code

@fanquake fanquake added the P2P label Mar 24, 2017
@sipa
Copy link
Member

sipa commented Mar 24, 2017

utACK

bool SetSocketNoDelay(SOCKET& hSocket)
{
int set = 1;
int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, seems like the WIN32 check was unnecessary, every pointer can be passed to a void* parameter including char* so the redundant cast doesn't matter.

src/netbase.cpp Outdated
{
int set = 1;
int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int));
return rc != -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SOCKET_ERROR (which may or may not be -1, it's not mentioned).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But of course, I usually idiomatically check rc == 0 from system calls. Not sure why I went with != -1.

@tjps
Copy link
Contributor Author

tjps commented Apr 21, 2017

bump on an easy dedupe merge

@TheBlueMatt
Copy link
Contributor

@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 ad415bc this itself, its still a strict improvement.

@theuni
Copy link
Member

theuni commented May 16, 2017

utACK ad415bc.

@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 sipa merged commit ad415bc into bitcoin:master May 18, 2017
sipa added a commit that referenced this pull request May 18, 2017
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
@tjps tjps deleted the tjps_nodelay branch May 18, 2017 00:53
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 10, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 11, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 11, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 15, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 19, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 19, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 19, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 19, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 19, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 20, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 22, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 22, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 22, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 22, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 22, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 24, 2019
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants