HomePhabricator

refactor: wrap accept() and extend usage of Sock

Description

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

Reviewers: #bitcoin_abc, roqqit

Reviewed By: roqqit

Subscribers: roqqit

Differential Revision: https://reviews.bitcoinabc.org/D17130

Details

Provenance
Vasil Dimov <vd@FreeBSD.org>Authored on Apr 23 2021, 07:43
PiRKCommitted on Mon, Nov 18, 06:42
PiRKPushed on Mon, Nov 18, 06:42
Reviewer
roqqit
Differential Revision
D17130: refactor: wrap accept() and extend usage of Sock
Parents
rABC5bea016076f0: fuzz: Add fuzzing harness for Socks5(...)
Branches
Unknown
Tags
Unknown