mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
net: add new method Sock::Listen() that wraps listen()
This will help to increase `Sock` usage and make more code mockable.
This commit is contained in:
@@ -79,6 +79,11 @@ int Sock::Bind(const sockaddr* addr, socklen_t addr_len) const
|
||||
return bind(m_socket, addr, addr_len);
|
||||
}
|
||||
|
||||
int Sock::Listen(int backlog) const
|
||||
{
|
||||
return listen(m_socket, backlog);
|
||||
}
|
||||
|
||||
std::unique_ptr<Sock> Sock::Accept(sockaddr* addr, socklen_t* addr_len) const
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -103,6 +103,12 @@ public:
|
||||
*/
|
||||
[[nodiscard]] virtual int Bind(const sockaddr* addr, socklen_t addr_len) const;
|
||||
|
||||
/**
|
||||
* listen(2) wrapper. Equivalent to `listen(this->Get(), backlog)`. Code that uses this
|
||||
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
|
||||
*/
|
||||
[[nodiscard]] virtual int Listen(int backlog) const;
|
||||
|
||||
/**
|
||||
* accept(2) wrapper. Equivalent to `std::make_unique<Sock>(accept(this->Get(), addr, addr_len))`.
|
||||
* Code that uses this wrapper can be unit tested if this method is overridden by a mock Sock
|
||||
|
||||
Reference in New Issue
Block a user