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

pull vasild wants to merge 4 commits into bitcoin:master from vasild:convert_IsSelectableSocket_and_SetSocketNonBlocking changing 9 files +80 −34
  1. vasild commented at 10:47 AM on June 20, 2022: contributor

    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.

  2. vasild cross-referenced this on Jun 20, 2022 from issue Make all networking code mockable by vasild
  3. DrahtBot added the label P2P on Jun 20, 2022
  4. DrahtBot added the label Utils/log/libs on Jun 20, 2022
  5. laanwj commented at 11:22 AM on June 20, 2022: member

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

  6. DrahtBot cross-referenced this on Jun 20, 2022 from issue net: add new method Sock::GetSockName() that wraps getsockname() and use it in GetBindAddress() by vasild
  7. DrahtBot commented at 1:44 PM on June 20, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    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.

  8. DrahtBot added the label Needs rebase on Jun 28, 2022
  9. laanwj commented at 1:48 PM on June 28, 2022: member

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

  10. vasild force-pushed on Jun 28, 2022
  11. vasild commented at 2:57 PM on June 28, 2022: contributor

    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
  12. DrahtBot removed the label Needs rebase on Jun 28, 2022
  13. luke-jr commented at 12:10 AM on June 30, 2022: member

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

  14. DrahtBot cross-referenced this on Jun 30, 2022 from issue Severity-based logging -- parent PR by jonatack
  15. vasild force-pushed on Jul 5, 2022
  16. vasild commented at 10:30 AM on July 5, 2022: contributor

    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?

  17. DrahtBot cross-referenced this on Jul 16, 2022 from issue net: avoid overriding non-virtual ToString() in CService and use better naming by vasild
  18. theStack commented at 9:03 PM on July 16, 2022: contributor

    Concept ACK

  19. DrahtBot added the label Needs rebase on Jul 20, 2022
  20. moveonly: move IsSelectableSocket() from compat.h to sock.{h,cpp}
    To be converted to a method of the `Sock` class.
    5db7d2ca0a
  21. net: convert standalone IsSelectableSocket() to Sock::IsSelectable()
    This makes the callers mockable.
    b4bac55679
  22. moveonly: move SetSocketNonBlocking() from netbase to util/sock
    To be converted to a method of the `Sock` class.
    29f66f7682
  23. net: convert standalone SetSocketNonBlocking() to Sock::SetNonBlocking()
    This further encapsulates syscalls inside the `Sock` class.
    
    Co-authored-by: practicalswift <practicalswift@users.noreply.github.com>
    b527b54950
  24. vasild force-pushed on Jul 20, 2022
  25. vasild commented at 2:27 PM on July 20, 2022: contributor

    e99a11eb8c...b527b54950: rebase due to conflicts

  26. DrahtBot removed the label Needs rebase on Jul 20, 2022
  27. jonatack commented at 4:23 PM on July 22, 2022: contributor

    ACK b527b549504672704a61f70d2565b9489aaaba91 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.

  28. vasild commented at 11:10 AM on July 25, 2022: contributor

    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.

  29. JeremyRubin cross-referenced this on Aug 18, 2022 from issue Call for Maintainer: P2P & Networking by JeremyRubin
  30. in src/util/sock.cpp:129 in b527b54950
     124 | +    if (ioctlsocket(m_socket, FIONBIO, &on) == SOCKET_ERROR) {
     125 | +        return false;
     126 | +    }
     127 | +#else
     128 | +    const int flags{fcntl(m_socket, F_GETFL, 0)};
     129 | +    if (flags == SOCKET_ERROR) {
    


    dergoegge commented at 9:46 AM on October 7, 2022:

    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)


    vasild commented at 12:15 PM on October 7, 2022:

    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.

  31. dergoegge commented at 9:51 AM on October 7, 2022: member

    Code review ACK b527b549504672704a61f70d2565b9489aaaba91

  32. glozow merged this on Oct 12, 2022
  33. glozow closed this on Oct 12, 2022

  34. vasild deleted the branch on Oct 13, 2022
  35. sidhujag referenced this in commit f73aef5a64 on Oct 23, 2022
  36. bitcoin locked this on Oct 13, 2023

github-metadata-mirror

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-20 06:53 UTC