mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
net: add new method Sock::GetSockName() that wraps getsockname()
This will help to increase `Sock` usage and make more code mockable.
This commit is contained in:
@@ -111,6 +111,11 @@ int Sock::SetSockOpt(int level, int opt_name, const void* opt_val, socklen_t opt
|
||||
return setsockopt(m_socket, level, opt_name, static_cast<const char*>(opt_val), opt_len);
|
||||
}
|
||||
|
||||
int Sock::GetSockName(sockaddr* name, socklen_t* name_len) const
|
||||
{
|
||||
return getsockname(m_socket, name, name_len);
|
||||
}
|
||||
|
||||
bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
|
||||
{
|
||||
// We need a `shared_ptr` owning `this` for `WaitMany()`, but don't want
|
||||
|
||||
@@ -126,6 +126,13 @@ public:
|
||||
const void* opt_val,
|
||||
socklen_t opt_len) const;
|
||||
|
||||
/**
|
||||
* getsockname(2) wrapper. Equivalent to
|
||||
* `getsockname(this->Get(), name, name_len)`. Code that uses this
|
||||
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
|
||||
*/
|
||||
[[nodiscard]] virtual int GetSockName(sockaddr* name, socklen_t* name_len) const;
|
||||
|
||||
using Event = uint8_t;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user