mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-29 18:05:58 +02:00
net: add connect() and getsockopt() wrappers to Sock
Extend the `Sock` class with wrappers to `connect()` and `getsockopt()`. This will make it possible to mock code which uses those.
This commit is contained in:
@@ -66,6 +66,16 @@ ssize_t Sock::Recv(void* buf, size_t len, int flags) const
|
||||
return recv(m_socket, static_cast<char*>(buf), len, flags);
|
||||
}
|
||||
|
||||
int Sock::Connect(const sockaddr* addr, socklen_t addr_len) const
|
||||
{
|
||||
return connect(m_socket, addr, addr_len);
|
||||
}
|
||||
|
||||
int Sock::GetSockOpt(int level, int opt_name, void* opt_val, socklen_t* opt_len) const
|
||||
{
|
||||
return getsockopt(m_socket, level, opt_name, static_cast<char*>(opt_val), opt_len);
|
||||
}
|
||||
|
||||
bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
|
||||
{
|
||||
#ifdef USE_POLL
|
||||
|
||||
@@ -80,16 +80,29 @@ public:
|
||||
|
||||
/**
|
||||
* send(2) wrapper. Equivalent to `send(this->Get(), data, len, flags);`. Code that uses this
|
||||
* wrapper can be unit-tested if this method is overridden by a mock Sock implementation.
|
||||
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
|
||||
*/
|
||||
virtual ssize_t Send(const void* data, size_t len, int flags) const;
|
||||
|
||||
/**
|
||||
* recv(2) wrapper. Equivalent to `recv(this->Get(), buf, len, flags);`. Code that uses this
|
||||
* wrapper can be unit-tested if this method is overridden by a mock Sock implementation.
|
||||
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
|
||||
*/
|
||||
virtual ssize_t Recv(void* buf, size_t len, int flags) const;
|
||||
|
||||
/**
|
||||
* connect(2) wrapper. Equivalent to `connect(this->Get(), addr, addrlen)`. Code that uses this
|
||||
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
|
||||
*/
|
||||
virtual int Connect(const sockaddr* addr, socklen_t addr_len) const;
|
||||
|
||||
/**
|
||||
* getsockopt(2) wrapper. Equivalent to
|
||||
* `getsockopt(this->Get(), level, opt_name, opt_val, opt_len)`. Code that uses this
|
||||
* wrapper can be unit tested if this method is overridden by a mock Sock implementation.
|
||||
*/
|
||||
virtual int GetSockOpt(int level, int opt_name, void* opt_val, socklen_t* opt_len) const;
|
||||
|
||||
using Event = uint8_t;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user