1#ifndef NET_SimpleSocket_h__
2#define NET_SimpleSocket_h__
34 const char*
what() const noexcept {
return m_message.c_str(); }
37 int errorCode() const noexcept {
return m_errorcode; }
40 std::string m_message;
113 typedef void raw_type;
368 IOResult sendTo( const
void* buffer,
size_t len, const SockAddress& addr);
371 IOResult receiveFrom(
void* buffer,
size_t len, SockAddress& addr);
374 IOStatus waitReadable(
int timeout);
377 int acceptNative() const;
383 int timedAccept(
int timeout) const;
389 ConnectResult timedConnect( const SockAddress& addr,
int timeout);
IOResult send(const void *buffer, size_t len)
send data through a connected socket
void shutdown(ShutdownDirection type)
shutdown the connection in the specified direction
IOResult receiveAll(void *buffer, size_t len)
receive exactly the requested amount unless the peer disconnects
bool isBlocking() const
returns true if socket is in blocking mode
bool m_connectionOriented
SimpleSocket(AdoptSocketTag, int sockfd, int type)
allows a subclass to take ownership of an existing socket
SimpleSocket & operator=(const SimpleSocket &)=delete
void listen(int backlog=128)
listen for incoming connections
IOResult receive(void *buffer, size_t len)
receive data from a bound socket
SimpleSocket(const SimpleSocket &)=delete
IOResult sendAll(const void *buffer, size_t len)
send data through a connected socket
bool valid() const noexcept
Returns true if socket is in a usable (non-moved) state and open.
bool peerDisconnected() const
returns whether a currently associated peer disconnected
ConnectResult finishConnect(int timeout=0)
check if a previously started connected attempt is finished
int nativeHandle() noexcept
Return the native descriptor. Ownership remains with the object.
void setReceiveBufferSize(int bytes)
override default receive buffer size for this socket
IOResult timedReceive(void *buffer, size_t len, int timeout)
receive data from a bound socket, return after the given timespan
void setBlocking(bool blocking)
set socket to blocking or non-blocking I/O operations
int duplicateNativeHandle() const
Duplicates the underlaying native socket descriptor.
bool isConnected() const
check if the kernel currently has an associated peer address
void setSendBufferSize(int bytes)
override default send buffer size for this socket
~SimpleSocket() noexcept
protected destructor to avoid delete via base class
void disconnect()
Disconnect and unset any foreign addresses.
const char * what() const noexcept
Returns a C-string describing the cause of the current error.
SocketException(const SocketException &)=default
SocketException(std::string_view message, int error)
~SocketException() noexcept
Provided just to guarantee that no exceptions are thrown.
int errorCode() const noexcept
Returns the glibc errno code of the current error.
SocketException(std::string_view message, bool inclErrno=true)
IOStatus
status of the I/O operation
AddressFamily
used by internet socket types
ShutdownDirection
direction to close for a stream socket
@ STOP_SEND
disable all variants of send() on the socket, receive calls still work
@ STOP_BOTH
disable all send() and receive() calls on the socket
@ STOP_RECEIVE
disable all variants of receive() on the socket, send calls still work
ConnectResult
result of the connection attempt
@ InProgress
the attempt is still pending, check again with finishConnect()
@ Connected
the connection is established
@ Unreachable
no route to the host or network
@ Aborted
the connection attempt was aborted or reset
@ Refused
the peer refused the connection
used to safely adopt internal socket descriptor