Page MenuHomePhabricator

refactor: wrap accept() and extend usage of Sock
ClosedPublic

Authored by PiRK on Nov 13 2024, 17:37.

Details

Reviewers
roqqit
Group Reviewers
Restricted Project
Commits
rABC7e5ca9440c2f: refactor: wrap accept() and extend usage of Sock
Summary

Introduce an accept(2) wrapper Sock::Accept() and extend the usage of Sock in CConnman::ListenSocket and CreateNodeFromAcceptedSocket().

The aim of this change is to progress towards making all network code mockable.

net: add new method Sock::Accept() that wraps accept()

This will help to increase Sock usage and make more code mockable.

net: use Sock in CConnman::ListenSocket

Change CConnman::ListenSocket to use a pointer to Sock instead of a
bare SOCKET and use Sock::Accept() instead of bare accept(). This
will help mocking / testing / fuzzing more code.

net: change CreateNodeFromAcceptedSocket() to take Sock

Change CConnman::CreateNodeFromAcceptedSocket() to take a Sock
argument instead of SOCKET.

This makes the method mockable and also a little bit shorter as some
CloseSocket() calls are removed (the socket will be closed
automatically by the Sock destructor on early return).

net: don't check if the listening socket is valid

Listening sockets in CConnman::vhListenSocket are always valid
(underlying file descriptor is not INVALID_SOCKET).

This is a backport of core#21879 and core#23601
Depends on D17137

Test Plan

ninja all check-all bitcoin-fuzzers

Event Timeline

PiRK requested review of this revision.Nov 13 2024, 17:37
roqqit added a subscriber: roqqit.
roqqit added inline comments.
src/net.cpp
1891 ↗(On Diff #50839)

This is a backport of PR23601. Can you add this to the summary?

This revision is now accepted and ready to land.Nov 13 2024, 21:21
PiRK edited the summary of this revision. (Show Details)
PiRK edited the test plan for this revision. (Show Details)

rebase onto D17137, include relevant fuzzer changes