1 #ifndef SPONGE_LIBSPONGE_SOCKET_HH
2 #define SPONGE_LIBSPONGE_SOCKET_HH
10 #include <sys/socket.h>
18 const std::function<
int(
int, sockaddr *, socklen_t *)> &
function)
const;
22 Socket(
const int domain,
const int type);
28 template <
typename option_type>
29 void setsockopt(
const int level,
const int option,
const option_type &option_value);
99 void listen(
const int backlog = 16);
Wrapper around IPv4 addresses and DNS operations.
A non-owning temporary view (similar to std::string_view) of a discontiguous string.
A reference-counted handle to a file descriptor.
A wrapper around Unix-domain stream sockets.
LocalStreamSocket(FileDescriptor &&fd)
Construct from a file descriptor.
Base class for network sockets (TCP, UDP, etc.)
void connect(const Address &address)
Connect a socket to a specified peer address with connect(2).
void shutdown(const int how)
Shut down a socket via shutdown(2).
Address get_address(const std::string &name_of_function, const std::function< int(int, sockaddr *, socklen_t *)> &function) const
Get the local or peer address the socket is connected to.
Socket(const int domain, const int type)
Construct via socket(2).
void setsockopt(const int level, const int option, const option_type &option_value)
Wrapper around setsockopt(2).
void bind(const Address &address)
Bind a socket to a specified address with bind(2), usually for listen/accept.
Address local_address() const
Get local address of socket with getsockname(2).
Address peer_address() const
Get peer address of socket with getpeername(2).
void set_reuseaddr()
Allow local address to be reused sooner via SO_REUSEADDR.
A wrapper around TCP sockets.
TCPSocket accept()
Accept a new incoming connection.
TCPSocket()
Default: construct an unbound, unconnected TCP socket.
void listen(const int backlog=16)
Mark a socket as listening for incoming connections.
TCPSocket(FileDescriptor &&fd)
Construct from FileDescriptor (used by accept())
A wrapper around UDP sockets.
received_datagram recv(const size_t mtu=65536)
Receive a datagram and the Address of its sender.
UDPSocket()
Default: construct an unbound, unconnected UDP socket.
Address source_address
Address from which this datagram was received.
void send(const BufferViewList &payload)
Send datagram to the socket's connected address (must call connect() first)
std::string payload
UDP datagram payload.
void sendto(const Address &destination, const BufferViewList &payload)
Send a datagram to specified Address.
UDPSocket(FileDescriptor &&fd)
Construct from FileDescriptor (used by TCPOverUDPSocketAdapter)
void recv(received_datagram &datagram, const size_t mtu=65536)
Receive a datagram and the Address of its sender (caller can allocate storage)
Returned by UDPSocket::recv; carries received data and information about the sender.