29 #include "nrg_packet.h"
38 Socket(
int type,
int family = PF_UNSPEC);
72 return setsockopt(fd, level, name, &opt,
sizeof(T)) == 0;
92 return connected_addr;
97 return last_timestamp;
105 mutable std::unique_ptr<NetAddress> bound_addr, connected_addr;
106 int fd, family, type;
107 bool do_timestamp, use_errqueue;
108 uint64_t last_timestamp;
void enableTimestamps(bool enable)
Enables or disables the use of getLastTimestamp()
Socket derivative specifically for the User-Datagram Protocol.
Definition: nrg_socket.h:112
virtual ~Socket()
Default destructor.
void setNonBlocking(bool nonblock)
Sets this socket as non-blocking.
bool isConnected() const
Returns true if the socket is connected.
Class for storing data to be sent / received across the network.
Definition: nrg_packet.h:58
Contains the NetAddress class for wrapping POSIX sockaddr structures and resolving hostnames to IP ad...
uint64_t getLastTimestamp() const
Gets a timestamp of when the last packet was received, if available and enabled.
Definition: nrg_socket.h:96
void handleUnconnectedICMPErrors(bool enable)
Enables or disables checking for ICMP related errors on this socket, if available.
void setFamilyFromAddress(const NetAddress &addr)
Sets the socket's family using the family of the given address.
Status connect(const NetAddress &addr)
Connects the socket to the given remote address.
const std::unique_ptr< NetAddress > & getConnectedAddress() const
Returns the address this socket is connected to.
Definition: nrg_socket.h:91
Socket(int type, int family=PF_UNSPEC)
Constructs a socket with the given type and family.
bool setOption(int level, int name, const T &opt)
Template wrapper around setsockopt.
Definition: nrg_socket.h:71
Status bind(const NetAddress &addr)
Bind the socket to the given local address.
Status sendPacket(const Packet &p) const
Sends a Packet to the address this socket is connected to.
const std::unique_ptr< NetAddress > & getBoundAddress() const
Returns the address this socket is bound to.
Class to wrap system and internal errors.
Definition: nrg_status.h:34
bool dataPending(int usToBlock=0) const
Uses select() to determine if data is available for reading on this socket.
Base socket class.
Definition: nrg_socket.h:35
void disconnect()
Disconnects the socket.
Status recvPacket(Packet &p) const
Receive a Packet from this socket's connected address.
Common defines and includes used by all the other nrg header files.
Class to wrap the various POSIX sockaddrs and resolve hostnames.
Definition: nrg_netaddress.h:32