Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: convert standalone IsSelectableSocket() and SetSocketNonBlocking() to Sock methods #25421

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Jun 20, 2022

This is a piece of #21878, chopped off to ease review.

  • convert standalone IsSelectableSocket() to Sock::IsSelectable()
  • convert standalone SetSocketNonBlocking() to Sock::SetNonBlocking()

This further encapsulates syscalls inside the Sock class and makes the callers mockable.

@laanwj
Copy link
Member

laanwj commented Jun 20, 2022

Concept ACK. These methods clearly belong to the Sock API.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 20, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25619 (net: avoid overriding non-virtual ToString() in CService and use better naming by vasild)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@laanwj
Copy link
Member

laanwj commented Jun 28, 2022

Looks like this is the last one to go for #21878? Needs rebase, though.

@vasild vasild force-pushed the convert_IsSelectableSocket_and_SetSocketNonBlocking branch from e7b846a to 0c4516b Compare June 28, 2022 14:54
@vasild
Copy link
Contributor Author

vasild commented Jun 28, 2022

e7b846aa4d...0c4516b26b: rebase due to conflicts

Looks like this is the last one to go for #21878?

There is more! :) will be two more PRs:

  • remove Sock::Get() and Sock::Sock() - no PR yet because removing Sock::Get() will be possible once the construct IsSelectableSocket(sock->Get()) is removed by this PR
  • the fuzz tests themselves

@luke-jr
Copy link
Member

luke-jr commented Jun 30, 2022

This could be easier to review if you did a MOVEONLY commit before/after the changes

@vasild vasild force-pushed the convert_IsSelectableSocket_and_SetSocketNonBlocking branch from 0c4516b to e99a11e Compare July 5, 2022 10:28
@vasild
Copy link
Contributor Author

vasild commented Jul 5, 2022

0c4516b26b...e99a11eb8c: rebase and add moveonly commits

Cumulative diff is identical before and after this forced push:

before: git diff 55c9e2d790..0c4516b26b
after: git diff 87d012324a..e99a11eb8c

This could be easier to review if you did a MOVEONLY commit before/after the changes

Better now?

@theStack
Copy link
Contributor

Concept ACK

vasild and others added 4 commits July 20, 2022 16:26
To be converted to a method of the `Sock` class.
To be converted to a method of the `Sock` class.
This further encapsulates syscalls inside the `Sock` class.

Co-authored-by: practicalswift <[email protected]>
@vasild vasild force-pushed the convert_IsSelectableSocket_and_SetSocketNonBlocking branch from e99a11e to b527b54 Compare July 20, 2022 14:27
@vasild
Copy link
Contributor Author

vasild commented Jul 20, 2022

e99a11eb8c...b527b54950: rebase due to conflicts

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK b527b54 review/debug build/unit tests at each commit, cross-referenced the changes with man select and man errno, ran a signet node on the last commit with ip4/ip6//tor/i2p/cjdns and network connections were nominal

One global nit, this pull uses the doxygen format for classes on methods and variables that have a different doxygen format, per our developer notes.

@vasild
Copy link
Contributor Author

vasild commented Jul 25, 2022

One global nit, this pull uses the doxygen format for classes on methods and variables that have a different doxygen format, per our developer notes.

That is for consistency with surrounding code and because I assume (assumed) any doxygen-compatible comment is acceptable since the doxygen generated docs are identical either way. If it is desirable I could change all of sock.{h,cpp} to use some other style in a separate PR, but I think that would be just noise and waste of reviewing power.

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

Code review ACK b527b54

}
#else
const int flags{fcntl(m_socket, F_GETFL, 0)};
if (flags == SOCKET_ERROR) {
Copy link
Member

Choose a reason for hiding this comment

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

We were previously not checking for an error on this fcntl call. Is that really necessary or would the next fcntl call fail when being passed SOCKET_ERROR | O_NONBLOCK?

(Not against adding the error check, just wanted to note that i noticed the addition)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know if the next fcntl() call would fail. The doc is a bit unclear what happens when passed unknown/invalid flags to fcntl(). Also, given that SOCKET_ERROR is -1 and O_NONBLOCK is 0x0004, then what is -1 | 0x0004? It is -1 actually, but is definitely something we don't want to do.

@glozow glozow merged commit 7e1007a into bitcoin:master Oct 12, 2022
@vasild vasild deleted the convert_IsSelectableSocket_and_SetSocketNonBlocking branch October 13, 2022 08:56
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 23, 2022
… SetSocketNonBlocking() to Sock methods

b527b54 net: convert standalone SetSocketNonBlocking() to Sock::SetNonBlocking() (Vasil Dimov)
29f66f7 moveonly: move SetSocketNonBlocking() from netbase to util/sock (Vasil Dimov)
b4bac55 net: convert standalone IsSelectableSocket() to Sock::IsSelectable() (Vasil Dimov)
5db7d2c moveonly: move IsSelectableSocket() from compat.h to sock.{h,cpp} (Vasil Dimov)

Pull request description:

  _This is a piece of bitcoin#21878, chopped off to ease review._

  * convert standalone `IsSelectableSocket()` to `Sock::IsSelectable()`
  * convert standalone `SetSocketNonBlocking()` to `Sock::SetNonBlocking()`

  This further encapsulates syscalls inside the `Sock` class and makes the callers mockable.

ACKs for top commit:
  jonatack:
    ACK b527b54 review/debug build/unit tests at each commit, cross-referenced the changes with `man select` and `man errno`, ran a signet node on the last commit with ip4/ip6//tor/i2p/cjdns and network connections were nominal
  dergoegge:
    Code review ACK b527b54

Tree-SHA512: af783ce558c7a89e173f7ab323fb3517103d765c19b5d14de29f64706b4e1fea3653492e8ea73ae972699986aaddf2ae72c7cfaa7dad7614254283083b7d2632
@bitcoin bitcoin locked and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants