Skip to content

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Feb 16, 2022

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

Sock::Wait() waits for IO events on one socket. Introduce a similar virtual method WaitMany() that waits simultaneously for IO events on more than one socket.

Use WaitMany() instead of CConnman::SocketEvents() (and ditch the latter). Given that the former is a virtual method, it can be mocked by unit and fuzz tests. This will help to make bigger parts of CConnman testable (unit and fuzz).

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 17, 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:

  • #21878 (Make all networking code mockable 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.

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.

Approach ACK, first pass tested almost-ACK af45eee. Read the code, each commit debug builds cleanly / unit tests green, ran signet bitcoind on this branch rebased to master. As well as improving testability, this seems like a nice clean-up too. Reviewers may find man select helpful.

@vasild
Copy link
Contributor Author

vasild commented Mar 10, 2022

af45eeea03...c9420b3cce: address suggestions

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 c9420b3 per re-review of git diff af45eee c9420b3 following my previous #24356 (review), rebased to master at 05957a8, debug build with Debian clang version 15, unit tests

@vasild
Copy link
Contributor Author

vasild commented Apr 27, 2022

c9420b3cce...ca8dcfabb7: rebase due to conflicts

Invalidates ACK from @jonatack

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.

re-ACK ca8dcfa per git range-diff 132d5f8 c9420b3 ca8dcfa, rebase-only for added thread safety annotations and assertions

src/net.h Outdated
EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);

/**
* Accept incoming connections, one from each read-ready listening socket.
* @param[in] recv_set Sockets that are ready for read.
* @param[in] what Sockets that are ready for IO.
Copy link
Member

Choose a reason for hiding this comment

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

If you agree, maybe change the names of the what method params to ones that are more descriptive and unique (e.g. socket_data, wait_sockets, wait_data, sockets_ready_for_io, etc.) and for the what localvars, either the same or i.e. s where unimportant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to EventsPerSock. That map contains, per socket, the requested and the occurred events (just like poll(2)). And the variables then become the blatant events_per_sock ;-)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, that seems better. In the last commit, I sort of hesitated in the two places where you do @param[in] events_per_sock Sockets that are ready for IO. ... thinking it should be something like "Events for each socket that is ready for IO."

@vasild
Copy link
Contributor Author

vasild commented May 19, 2022

ca8dcfabb7...6747729cb8: rebase due to conflicts and rename WaitData to EventsPerSock

Invalidates ACK from @jonatack

@jonatack
Copy link
Member

re-ACK 6747729

@jonatack
Copy link
Member

jonatack commented Jun 8, 2022

Anyone else like to have a look here?

@laanwj
Copy link
Member

laanwj commented Jun 8, 2022

Yes, I'll have a look.

vasild added 2 commits June 9, 2022 13:34
This mimics closely `CConnman::SocketEvents()` and the underlying
`poll(2)`.
It allows waiting concurrently on more than one socket. Being a
`virtual` `Sock` method it can be overriden by tests.

Will be used to replace `CConnman::SocketEvents()`.
@vasild
Copy link
Contributor Author

vasild commented Jun 9, 2022

6747729cb8...358dab76aa: address some suggestions

Invalidates ACK from @jonatack

Rename `GenerateSelectSet()` to `GenerateWaitSockets()` and adapt it to
generate a wait data suitable for `Sock::WaitMany()`. Then call it from
`CConnman::SocketHandler()` and feed the generated data to
`Sock::WaitMany()`.

This way `CConnman::SocketHandler()` can be unit tested because
`Sock::WaitMany()` is mockable, so the usage of real sockets can be
avoided.

Resolves bitcoin#21744
@vasild
Copy link
Contributor Author

vasild commented Jun 9, 2022

358dab76aa...6e68ccbefe: use Span for CConnman::GenerateWaitSockets() argument.

Previously invalidated ACK from @jonatack.

@jonatack
Copy link
Member

jonatack commented Jun 9, 2022

There's a fuzz addressSAN issue, but it seems unrelated and there is the same one on the last push on master https://cirrus-ci.com/task/4544256453902336.

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.

re-ACK 6e68ccb per git range-diff e18fd47 6747729 6e68ccb, and verified rebase to master and debug build

@laanwj
Copy link
Member

laanwj commented Jun 9, 2022

Code review ACK 6e68ccb

@laanwj laanwj merged commit 0ea92ca into bitcoin:master Jun 16, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 17, 2022
…mockable Sock::WaitMany()

6e68ccb net: use Sock::WaitMany() instead of CConnman::SocketEvents() (Vasil Dimov)
ae26346 net: introduce Sock::WaitMany() (Vasil Dimov)
cc74459 net: also wait for exceptional events in Sock::Wait() (Vasil Dimov)

Pull request description:

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

  `Sock::Wait()` waits for IO events on one socket. Introduce a similar `virtual` method `WaitMany()` that waits simultaneously for IO events on more than one socket.

  Use `WaitMany()` instead of `CConnman::SocketEvents()` (and ditch the latter). Given that the former is a `virtual` method, it can be mocked by unit and fuzz tests. This will help to make bigger parts of `CConnman` testable (unit and fuzz).

ACKs for top commit:
  laanwj:
    Code review ACK 6e68ccb
  jonatack:
    re-ACK 6e68ccb per `git range-diff e18fd47 6747729 6e68ccb`, and verified rebase to master and debug build

Tree-SHA512: 917fb6ad880d64d3af1ebb301c06fbd01afd8ff043f49e4055a088ebed6affb7ffe1dcf59292d822f10de5f323b6d52d557cb081dd7434634995f9148efcf08f
@vasild vasild deleted the WaitMany branch June 17, 2022 09:05
Empact added a commit to Empact/bitcoin that referenced this pull request Apr 25, 2023
As far as I can tell, the code calling for these includes was removed in:
6e68ccb bitcoin#24356
82d360b bitcoin#21387
@bitcoin bitcoin locked and limited conversation to collaborators Jun 17, 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.

4 participants