45#ifndef COMMONCPP_SOCKET_H_
46#define COMMONCPP_SOCKET_H_
50#ifndef COMMONCPP_CONFIG_H_
54#ifndef COMMONCPP_STRING_H_
58#ifndef COMMONCPP_ADDRESS_H_
62#ifndef COMMONCPP_EXCEPTION_H_
78#define IPPROTO_DCCP 33
83#define DCCP_SOCKOPT_AVAILABLE_CCIDS 12
84#define DCCP_SOCKOPT_CCID 13
85#define DCCP_SOCKOPT_TX_CCID 14
86#define DCCP_SOCKOPT_RX_CCID 15
170 void setSocket(
void);
205 inline void error(
const char *err)
const {
206 error(errExtended, err);
216 flags.thrown = !enable;
224 void endSocket(
void);
231 Error connectError(
void)
const;
236 Error sendLimit(
int limit = 2048);
241 Error receiveLimit(
int limit = 1);
266 Error sendBuffer(
unsigned size);
275 Error receiveBuffer(
unsigned size);
284 Error bufferSize(
unsigned size);
294 Error setBroadcast(
bool enable);
307 Error setMulticastByFamily(
bool enable, Family family = IPV4);
317 Error setLoopbackByFamily(
bool enable, Family family = IPV4);
326 Error setTimeToLiveByFamily(uint8_t ttl, Family fam = IPV4);
339 inline Error join(
const IPV6Multicast &ia,
int iface = 0) {
355 Error drop(
const IPV6Multicast &ia,
int iface = 0) {
367 Error setRouting(
bool enable);
375 Error setNoDelay(
bool enable);
388 Socket(
int domain,
int type,
int protocol = 0);
411 Socket(
const Socket &source);
435 virtual ssize_t readData(
void * buf,
size_t len,
char separator=0,
timeout_t t=0);
445 virtual ssize_t writeData(
const void* buf,
size_t len,
timeout_t t=0);
474 const char *getSystemErrorString(
void)
const;
493 static bool check(Family fam);
499 bool operator!()
const;
501 operator bool()
const;
519 virtual IPV4Host getIPV4Sender(in_port_t *
port = NULL)
const;
522 return getIPV4Sender(
port);
526 virtual IPV6Host getIPV6Sender(in_port_t *
port = NULL)
const;
543 return getIPV4Peer(
port);
547 IPV6Host getIPV6Peer(in_port_t *
port = NULL)
const;
560 return getIPV4Local(
port);
564 IPV6Host getIPV6Local(in_port_t *
port = NULL)
const;
579 void setCompletion(
bool immediate);
586 Error setLinger(
bool linger);
595 Error setKeepAlive(
bool enable);
605 Error setTypeOfService(Tos service);
615 bool isConnected(
void)
const;
624 bool isActive(
void)
const;
633 return flags.broadcast;
647 return ia.getAddress();
651 inline struct in6_addr
getaddress(const IPV6Address &ia)
const {
652 return ia.getAddress();
658#if defined(CCXX_EXCEPTIONS)
660class __EXPORT SockException :
public IOException
663 Socket::Error _socketError;
666 inline SockException(
const String &str, Socket::Error socketError,
long systemError = 0) :
667 IOException(
str, systemError), _socketError(socketError) {}
669 inline Socket::Error getSocketError()
const {
Network addresses and sockets related classes.
The network name and address objects are all derived from a common IPV4Address base class.
This object is used to hold the actual and valid internet address of a specific host machine that wil...
A specialization of IPV4Address that provides address validation for multicast addresses.
IPV4Host getLocal(in_port_t *port) const
bool isRouted(void) const
Return if socket routing is enabled.
IPV4Host getSender(in_port_t *port) const
void setError(bool enable)
This service is used to turn the error handler on or off for "throwing" exceptions by manipulating th...
Error getErrorNumber(void) const
Often used by a "catch" to fetch the last error of a thrown socket.
long getSystemError(void) const
const char * getErrorString(void) const
Often used by a "catch" to fetch the user set error string of a thrown socket, but only if EXTENDED e...
bool isBroadcast(void) const
Return if broadcast has been enabled for the specified socket.
Error drop(const IPV4Multicast &ia)
void error(const char *err) const
This service is used to throw application defined socket errors where the application specific error ...
Error join(const IPV4Multicast &ia)
IPV4Host getPeer(in_port_t *port) const
A generic socket address class.
A generic socket base class.
Common C++ generic string class.
GNU Common C++ exception model base classes.
static shell::numericopt timeout('t', "--timeout", _TEXT("optional keyboard input timeout"), "seconds", 0)
struct in_addr getaddress(const IPV4Address &ia)
String str(Socket &so, size_t size)
static shell::stringopt error('e', "--error", _TEXT("stderr path to use"), "filename")
static shell::numericopt port('p', "--port", _TEXT("port to use"), "port", 0)