|
Sponge
CS144's user-space TCP library
|
Go to the documentation of this file. 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);
124 #endif // SPONGE_LIBSPONGE_SOCKET_HH
TCPSocket accept()
Accept a new incoming connection.
A wrapper around TCP sockets.
Address source_address
Address from which this datagram was received.
UDPSocket()
Default: construct an unbound, unconnected UDP socket.
A non-owning temporary view (similar to std::string_view) of a discontiguous string.
Returned by UDPSocket::recv; carries received data and information about the sender.
A reference-counted handle to a file descriptor.
void sendto(const Address &destination, const BufferViewList &payload)
Send a datagram to specified Address.
Wrapper around IPv4 addresses and DNS operations.
LocalStreamSocket(FileDescriptor &&fd)
Construct from a file descriptor.
UDPSocket(FileDescriptor &&fd)
Construct from FileDescriptor (used by TCPOverUDPSocketAdapter)
std::string payload
UDP datagram payload.
A wrapper around Unix-domain stream sockets.
void bind(const Address &address)
Bind a socket to a specified address with bind(2), usually for listen/accept.
void listen(const int backlog=16)
Mark a socket as listening for incoming connections.
TCPSocket(FileDescriptor &&fd)
Construct from FileDescriptor (used by accept())
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.
void connect(const Address &address)
Connect a socket to a specified peer address with connect(2).
received_datagram recv(const size_t mtu=65536)
Receive a datagram and the Address of its sender.
void set_reuseaddr()
Allow local address to be reused sooner via SO_REUSEADDR.
A wrapper around UDP sockets.
void send(const BufferViewList &payload)
Send datagram to the socket's connected address (must call connect() first)
Address local_address() const
Get local address of socket with getsockname(2).
Base class for network sockets (TCP, UDP, etc.)
void setsockopt(const int level, const int option, const option_type &option_value)
Wrapper around setsockopt(2).
void shutdown(const int how)
Shut down a socket via shutdown(2).
Socket(const int domain, const int type)
Construct via socket(2).
Address peer_address() const
Get peer address of socket with getpeername(2).
TCPSocket()
Default: construct an unbound, unconnected TCP socket.