 |
Bitcoin Core
21.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_UTIL_SOCK_H
6 #define BITCOIN_UTIL_SOCK_H
85 virtual ssize_t
Send(
const void* data,
size_t len,
int flags)
const;
91 virtual ssize_t
Recv(
void* buf,
size_t len,
int flags)
const;
114 virtual bool Wait(std::chrono::milliseconds timeout,
116 Event* occurred =
nullptr)
const;
129 std::chrono::milliseconds timeout,
143 std::chrono::milliseconds timeout,
151 virtual bool IsConnected(std::string& errmsg)
const;
166 #endif // BITCOIN_UTIL_SOCK_H
SOCKET m_socket
Contained socket.
Sock & operator=(const Sock &)=delete
Copy assignment operator, disabled because closing the same socket twice is undesirable.
bool CloseSocket(SOCKET &hSocket)
Close socket and set hSocket to INVALID_SOCKET.
virtual void SendComplete(const std::string &data, std::chrono::milliseconds timeout, CThreadInterrupt &interrupt) const
Send the given data, retrying on transient errors.
virtual void Reset()
Close if non-empty.
RAII helper class that manages a socket.
virtual ssize_t Recv(void *buf, size_t len, int flags) const
recv(2) wrapper.
virtual bool Wait(std::chrono::milliseconds timeout, Event requested, Event *occurred=nullptr) const
Wait for readiness for input (recv) or output (send).
static constexpr Event SEND
If passed to Wait(), then it will wait for readiness to send to the socket.
virtual ssize_t Send(const void *data, size_t len, int flags) const
send(2) wrapper.
virtual std::string RecvUntilTerminator(uint8_t terminator, std::chrono::milliseconds timeout, CThreadInterrupt &interrupt) const
Read from socket until a terminator character is encountered.
Sock()
Default constructor, creates an empty object that does nothing when destroyed.
virtual SOCKET Get() const
Get the value of the contained socket.
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
virtual bool IsConnected(std::string &errmsg) const
Check if still connected.
static constexpr auto MAX_WAIT_FOR_IO
Maximum time to wait for I/O readiness.
virtual SOCKET Release()
Get the value of the contained socket and drop ownership.
static constexpr Event RECV
If passed to Wait(), then it will wait for readiness to read from the socket.
virtual ~Sock()
Destructor, close the socket or do nothing if empty.