diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-04-23 15:15:23 +0200 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2022-01-28 06:41:09 +0100 |
commit | c41a1162ac4da437c5d755e8fe2bf636bed22b0f (patch) | |
tree | e87383af9ba4902a062d8e298766e60dbee354cb /src/net.h | |
parent | c5dd72e146dd8fa77d29c8689a42322a4d1ec780 (diff) |
net: use Sock in CNode
Change `CNode` to use a pointer to `Sock` instead of a bare `SOCKET`.
This will help mocking / testing / fuzzing more code.
Diffstat (limited to 'src/net.h')
-rw-r--r-- | src/net.h | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -402,7 +402,17 @@ public: NetPermissionFlags m_permissionFlags{NetPermissionFlags::None}; std::atomic<ServiceFlags> nServices{NODE_NONE}; - SOCKET hSocket GUARDED_BY(cs_hSocket); + + /** + * Socket used for communication with the node. + * May not own a Sock object (after `CloseSocketDisconnect()` or during tests). + * `shared_ptr` (instead of `unique_ptr`) is used to avoid premature close of + * the underlying file descriptor by one thread while another thread is + * poll(2)-ing it for activity. + * @see https://github.com/bitcoin/bitcoin/issues/21744 for details. + */ + std::shared_ptr<Sock> m_sock GUARDED_BY(cs_hSocket); + /** Total size of all vSendMsg entries */ size_t nSendSize GUARDED_BY(cs_vSend){0}; /** Offset inside the first vSendMsg already sent */ @@ -578,8 +588,7 @@ public: * criterium in CConnman::AttemptToEvictConnection. */ std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()}; - CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion); - ~CNode(); + CNode(NodeId id, ServiceFlags nLocalServicesIn, std::shared_ptr<Sock> sock, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion); CNode(const CNode&) = delete; CNode& operator=(const CNode&) = delete; |