45#ifndef COMMONCPP_SOCKET_H_
46#define COMMONCPP_SOCKET_H_
50#ifndef COMMONCPP_CONFIG_H_
51#include <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
90typedef socket_t SOCKET;
103 typedef enum State State;
112 typedef enum Family Family;
136 errServiceUnavailable,
137 errMulticastDisabled,
146 typedef enum Error Error;
155 typedef enum Tos Tos;
162 typedef enum Pending Pending;
167 mutable const char *errstr;
170 void setSocket(
void);
173 static socket_t dupSocket(socket_t s,Socket::State state);
187 State
volatile state;
197 Error
error(Error error,
const char *err = NULL,
long systemError = 0)
const;
205 inline void error(
const char *err)
const {
206 error(errExtended, err);
215 inline void setError(
bool enable) {
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);
249 Error sendTimeout(timeout_t timer);
257 Error receiveTimeout(timeout_t timer);
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);
335 inline Error join(
const IPV4Multicast &ia) {
339 inline Error join(
const IPV6Multicast &ia,
int iface = 0) {
351 Error drop(
const IPV4Multicast &ia) {
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);
422 ssize_t readLine(
char *buf,
size_t len, timeout_t timeout = 0);
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);
456 inline Error getErrorNumber(
void)
const {
466 inline const char *getErrorString(
void)
const {
470 inline long getSystemError(
void)
const {
474 const char *getSystemErrorString(
void)
const;
485 virtual bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
493 static bool check(Family fam);
499 bool operator!()
const;
501 operator bool()
const;
506 Socket &operator=(
const Socket &from);
519 virtual IPV4Host getIPV4Sender(in_port_t *port = NULL)
const;
521 inline IPV4Host getSender(in_port_t *port)
const {
522 return getIPV4Sender(port);
526 virtual IPV6Host getIPV6Sender(in_port_t *port = NULL)
const;
540 IPV4Host getIPV4Peer(in_port_t *port = NULL)
const;
542 inline IPV4Host getPeer(in_port_t *port)
const {
543 return getIPV4Peer(port);
547 IPV6Host getIPV6Peer(in_port_t *port = NULL)
const;
557 IPV4Host getIPV4Local(in_port_t *port = NULL)
const;
559 inline IPV4Host getLocal(in_port_t *port)
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;
632 inline bool isBroadcast(
void)
const {
633 return flags.broadcast;
641 inline bool isRouted(
void)
const {
646 inline struct in_addr getaddress(const IPV4Address &ia)
const {
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 {
GNU Common C++ exception model base classes.
Network addresses and sockets related classes.
AppLog & error(AppLog &sl)
Manipulator for error level.
A generic socket base class.
A generic socket address class.
Common C++ generic string class.