Base socket class.
#include <nrg_socket.h>
Public Member Functions | |
Socket (int type, int family=PF_UNSPEC) | |
Constructs a socket with the given type and family. | |
Socket (int type, const NetAddress &addr) | |
Constructs a socket with the given type and a family derived from the given address. | |
void | setFamilyFromAddress (const NetAddress &addr) |
Sets the socket's family using the family of the given address. | |
Status | bind (const NetAddress &addr) |
Bind the socket to the given local address. | |
Status | connect (const NetAddress &addr) |
Connects the socket to the given remote address. | |
void | disconnect () |
Disconnects the socket. | |
bool | isConnected () const |
Returns true if the socket is connected. | |
Status | sendPacket (const Packet &p) const |
Sends a Packet to the address this socket is connected to. | |
Status | sendPacket (const Packet &p, const NetAddress &addr) const |
Sends a Packet to the given address. | |
Status | recvPacket (Packet &p) const |
Receive a Packet from this socket's connected address. | |
Status | recvPacket (Packet &p, NetAddress &addr) |
Receive a Packet from anyone, and put their address into addr. | |
template<typename T > | |
bool | setOption (int level, int name, const T &opt) |
Template wrapper around setsockopt. | |
bool | dataPending (int usToBlock=0) const |
Uses select() to determine if data is available for reading on this socket. | |
void | setNonBlocking (bool nonblock) |
Sets this socket as non-blocking. | |
void | enableTimestamps (bool enable) |
Enables or disables the use of getLastTimestamp() | |
void | handleUnconnectedICMPErrors (bool enable) |
Enables or disables checking for ICMP related errors on this socket, if available. | |
const std::unique_ptr < NetAddress > & | getBoundAddress () const |
Returns the address this socket is bound to. | |
const std::unique_ptr < NetAddress > & | getConnectedAddress () const |
Returns the address this socket is connected to. | |
uint64_t | getLastTimestamp () const |
Gets a timestamp of when the last packet was received, if available and enabled. | |
virtual | ~Socket () |
Default destructor. | |