mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 15:39:05 +01:00
net: add new method Sock::Bind() that wraps bind()
This will help to increase `Sock` usage and make more code mockable.
This commit is contained in:
@@ -74,6 +74,11 @@ int Sock::Connect(const sockaddr* addr, socklen_t addr_len) const
|
||||
return connect(m_socket, addr, addr_len);
|
||||
}
|
||||
|
||||
int Sock::Bind(const sockaddr* addr, socklen_t addr_len) const
|
||||
{
|
||||
return bind(m_socket, addr, addr_len);
|
||||
}
|
||||
|
||||
std::unique_ptr<Sock> Sock::Accept(sockaddr* addr, socklen_t* addr_len) const
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -97,6 +97,12 @@ public:
|
||||
*/
|
||||
[[nodiscard]] virtual int Connect(const sockaddr* addr, socklen_t addr_len) const;
|
||||
|
||||
/**
|
||||
* bind(2) wrapper. Equivalent to `bind(this->Get(), addr, addr_len)`. Code that uses this
|
||||
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
|
||||
*/
|
||||
[[nodiscard]] virtual int Bind(const sockaddr* addr, socklen_t addr_len) 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