GNU CommonC++
socket.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2009 Leandro Melo de Sales <leandroal@gmail.com>
3 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks,
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27 //
28 // This exception applies only to the code released under the name GNU
29 // Common C++. If you copy code from other releases into a copy of GNU
30 // Common C++, as the General Public License permits, the exception does
31 // not apply to the code that you add in this way. To avoid misleading
32 // anyone as to the status of such modified files, you must delete
33 // this exception notice from them.
34 //
35 // If you write modifications of your own for GNU Common C++, it is your choice
36 // whether to permit this exception to apply to your modifications.
37 // If you do not wish that, delete this exception notice.
38 //
39 
45 #ifndef CCXX_SOCKET_H_
46 #define CCXX_SOCKET_H_
47 
48 #ifndef CCXX_ADDRESS_H_
49 #include <cc++/address.h>
50 #endif
51 
52 #if defined(WIN32) && !defined(__CYGWIN32__)
53 #include <io.h>
54 #define _IOLEN64 (unsigned)
55 #define _IORET64 (int)
56 #define TIMEOUT_INF ~((timeout_t) 0)
57 typedef int socklen_t;
58 #else
59 #define INVALID_SOCKET -1
60 typedef int SOCKET;
61 #endif
62 
63 #ifndef _IOLEN64
64 #define _IOLEN64
65 #endif
66 
67 #ifndef _IORET64
68 #define _IORET64
69 #endif
70 
71 #ifndef MSG_DONTWAIT
72 #define MSG_DONTWAIT 0
73 #endif
74 
75 #ifndef MSG_NOSIGNAL
76 #define MSG_NOSIGNAL 0
77 #endif
78 
79 #ifndef SOCK_DCCP
80 #define SOCK_DCCP 6
81 #endif
82 #ifndef IPPROTO_DCCP
83 #define IPPROTO_DCCP 33
84 #endif
85 #ifndef SOL_DCCP
86 #define SOL_DCCP 269
87 #endif
88 #define DCCP_SOCKOPT_AVAILABLE_CCIDS 12
89 #define DCCP_SOCKOPT_CCID 13
90 #define DCCP_SOCKOPT_TX_CCID 14
91 #define DCCP_SOCKOPT_RX_CCID 15
92 
93 #ifdef CCXX_NAMESPACES
94 namespace ost {
95 #endif
96 
100 typedef unsigned short tpport_t;
101 
120 {
121 public:
122  enum Family {
123 #ifdef CCXX_IPV6
124  IPV6 = AF_INET6,
125 #endif
126  IPV4 = AF_INET
127  };
128 
129  typedef enum Family Family;
130 
131  enum Error {
132  errSuccess = 0,
160  errInvalidValue
161  };
162 
163  typedef enum Error Error;
164 
165  enum Tos {
166  tosLowDelay = 0,
170  tosInvalid
171  };
172  typedef enum Tos Tos;
173 
174  enum Pending {
177  pendingError
178  };
179  typedef enum Pending Pending;
180 
181 protected:
182  enum State {
188  STREAM
189  };
190  typedef enum State State;
191 
192 private:
193  // used by exception handlers....
194  mutable Error errid;
195  mutable const char *errstr;
196  mutable long syserr;
197 
198  void setSocket(void);
200 
201 protected:
202  static Mutex mutex;
203 
204  mutable struct {
205  bool thrown: 1;
206  bool broadcast: 1;
207  bool route: 1;
208  bool keepalive: 1;
209  bool loopback: 1;
210  bool multicast: 1;
211  bool completion: 1;
212  bool linger: 1;
213  unsigned ttl: 8;
214  } flags;
215 
221  SOCKET volatile so;
222  State volatile state;
223 
232  Error error(Error error, const char *err = NULL, long systemError = 0) const;
233 
240  inline void error(const char *err) const
241  {error(errExtended, err);};
242 
249  inline void setError(bool enable)
250  {flags.thrown = !enable;};
251 
257  void endSocket(void);
258 
265 
269  Error sendLimit(int limit = 2048);
270 
274  Error receiveLimit(int limit = 1);
275 
283 
291 
299  Error sendBuffer(unsigned size);
300 
308  Error receiveBuffer(unsigned size);
309 
317  Error bufferSize(unsigned size);
318 
327  Error setBroadcast(bool enable);
328 
340  Error setMulticastByFamily(bool enable, Family family = IPV4);
341 
350  Error setLoopbackByFamily(bool enable, Family family = IPV4);
351 
359  Error setTimeToLiveByFamily(unsigned char ttl, Family fam = IPV4);
360 
368 #ifdef CCXX_IPV6
370 #endif
371 
379 #ifdef CCXX_IPV6
381 #endif
382 
390  Error setRouting(bool enable);
391 
392 
399  Error setNoDelay(bool enable);
400 
412  Socket(int domain, int type, int protocol = 0);
413 
422 
427 
435  Socket(const Socket &source);
436 
446  ssize_t readLine(char *buf, size_t len, timeout_t timeout = 0);
447 
459  virtual ssize_t readData(void * buf,size_t len,char separator=0,timeout_t t=0);
460 
469  virtual ssize_t writeData(const void* buf,size_t len,timeout_t t=0);
470 
471 public:
479  virtual ~Socket();
480 
487  static bool check(Family fam);
488 
492  Socket &operator=(const Socket &from);
493 
503  virtual IPV4Host getIPV4Sender(tpport_t *port = NULL) const;
504 
505  inline IPV4Host getSender(tpport_t *port = NULL) const
506  {return getIPV4Sender(port);}
507 
508 #ifdef CCXX_IPV6
509  virtual IPV6Host getIPV6Sender(tpport_t *port = NULL) const;
510 #endif
511 
521  IPV4Host getIPV4Peer(tpport_t *port = NULL) const;
522 
523  inline IPV4Host getPeer(tpport_t *port = NULL) const
524  {return getIPV4Peer(port);}
525 
526 #ifdef CCXX_IPV6
527  IPV6Host getIPV6Peer(tpport_t *port = NULL) const;
528 #endif
529 
537  IPV4Host getIPV4Local(tpport_t *port = NULL) const;
538 
539  inline IPV4Host getLocal(tpport_t *port = NULL) const
540  {return getIPV4Local(port);}
541 
542 #ifdef CCXX_IPV6
543  IPV6Host getIPV6Local(tpport_t *port = NULL) const;
544 #endif
545 
573  IPV4Host getIPV4NAT(tpport_t *port = NULL) const;
574 
575  inline IPV4Host getNAT(tpport_t *port) const
576  {return getIPV4NAT(port);}
577 
578 #ifdef CCXX_IPV6
579  IPV6Host getIPV6NAT(tpport_t *port = NULL) const;
580 #endif
581 
592  void setCompletion(bool immediate);
593 
599  Error setLinger(bool linger);
600 
608  Error setKeepAlive(bool enable);
609 
619 
628  bool isConnected(void) const;
629 
637  bool isActive(void) const;
638 
643  bool operator!() const;
644 
651  inline bool isBroadcast(void) const
652  {return flags.broadcast;};
653 
659  inline bool isRouted(void) const
660  {return flags.route;};
661 
668  inline Error getErrorNumber(void) const {return errid;}
669 
676  inline const char *getErrorString(void) const {return errstr;}
677 
678  inline long getSystemError(void) const {return syserr;}
679 
680  const char *getSystemErrorString(void) const;
681 
691  virtual bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
692 };
693 
720 class __EXPORT DCCPSocket : public Socket
721 {
722  union {
723  struct sockaddr_in ipv4;
724 #ifdef CCXX_IPV6
725  struct sockaddr_in6 ipv6;
726 #endif
727  } peer;
728 
729  Family family;
730 
731 public:
743  virtual bool onAccept(const IPV4Host &ia, tpport_t port);
744 #ifdef CCXX_IPV6
745  virtual bool onAccept(const IPV6Host &ia, tpport_t port);
746 #endif
747 
748  virtual IPV4Host getIPV4Sender(tpport_t *port = NULL) const;
749 
750 #ifdef CCXX_IPV6
751  virtual IPV6Host getIPV6Sender(tpport_t *port = NULL) const;
752 #endif
753 
765  DCCPSocket(const IPV4Address &bind, tpport_t port, unsigned backlog = 5);
766 #ifdef CCXX_IPV6
767  DCCPSocket(const IPV6Address &bind, tpport_t port, unsigned backlog = 5);
768 #endif
769 
779  DCCPSocket(const char *name, Family family = IPV4, unsigned backlog = 5);
780 
784  DCCPSocket(Family family = IPV4);
785 
789  DCCPSocket(DCCPSocket& server, timeout_t timeout = 0);
790 
794  void reject(void);
795 
799  void disconnect(void);
800 
804  bool setCCID(uint8 ccid);
805 
809  int getTxCCID();
810 
814  int getRxCCID();
815 
819  size_t available();
820 
828  void connect(const IPV4Host &host, tpport_t port, timeout_t timeout = 0);
829 #ifdef CCXX_IPV6
830  void connect(const IPV6Host &host, tpport_t port, timeout_t timeout = 0);
831 #endif
832 
836  void connect(const char *name);
837 
843  inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF) /* not const -- jfc */
844  {return Socket::isPending(Socket::pendingInput, timeout);}
845 
849  virtual ~DCCPSocket();
850 };
851 
884 class __EXPORT UDPSocket : public Socket
885 {
886 private:
887  inline Error setKeepAlive(bool enable)
888  {return Socket::setKeepAlive(enable);};
889 
890 protected:
891 #ifdef CCXX_IPV6
892  union {
893  struct sockaddr_in6 ipv6;
894  struct sockaddr_in ipv4;
895  } peer;
896 #else
897  union {
898  struct sockaddr_in ipv4;
899  } peer;
900 #endif
901 
903 
904 public:
908  UDPSocket(Family family = IPV4);
909 
913  UDPSocket(const char *name, Family family = IPV4);
914 
924  UDPSocket(const IPV4Address &bind, tpport_t port);
925 #ifdef CCXX_IPV6
926  UDPSocket(const IPV6Address &bind, tpport_t port);
927 #endif
928 
932  virtual ~UDPSocket();
933 
937  inline Error setLoopback(bool enable)
938  {return Socket::setLoopbackByFamily(enable, family);}
939 
943  inline Error setMulticast(bool enable)
944  {return Socket::setMulticastByFamily(enable, family);}
945 
949  inline Error setTimeToLive(char ttl)
950  {return Socket::setTimeToLiveByFamily(ttl, family);}
951 
959  void setPeer(const IPV4Host &host, tpport_t port);
960  void connect(const IPV4Host &host, tpport_t port);
961 #ifdef CCXX_IPV6
962  void setPeer(const IPV6Host &host, tpport_t port);
963  void connect(const IPV6Host &host, tpport_t port);
964 #endif
965 
973  Socket::Error getInterfaceIndex(const char *ethX,int& InterfaceIndex);
974 
983  Socket::Error join(const IPV4Multicast &ia,int InterfaceIndex);
984 
985 
993  ssize_t send(const void *buf, size_t len);
994 
1003  ssize_t receive(void *buf, size_t len, bool reply = false);
1004 
1013  IPV4Host getIPV4Peer(tpport_t *port = NULL) const;
1014  inline IPV4Host getPeer(tpport_t *port = NULL) const
1015  {return getIPV4Peer(port);}
1016 
1017 #ifdef CCXX_IPV6
1018  IPV6Host getIPV6Peer(tpport_t *port = NULL) const;
1019 #endif
1020 
1028  inline ssize_t peek(void *buf, size_t len)
1029  {return _IORET64 ::recv(so, (char *)buf, _IOLEN64 len, MSG_PEEK);};
1030 
1034  void setPeer(const char *service);
1035  void connect(const char *service);
1036 
1041  Error disconnect(void);
1042 };
1043 
1044 
1054 {
1055 private:
1056  void setPeer(const IPV4Host &ia, tpport_t port);
1057 
1058  Error setBroadcast(bool enable)
1059  {return Socket::setBroadcast(enable);};
1060 
1061 public:
1069 
1076  void setPeer(const IPV4Broadcast &subnet, tpport_t port);
1077 };
1078 
1087 class __EXPORT UDPTransmit : protected UDPSocket
1088 {
1089 private:
1097  Error cConnect(const IPV4Address &ia, tpport_t port);
1098 
1099 protected:
1103  UDPTransmit(Family family = IPV4);
1104 
1116  UDPTransmit(const IPV4Address &bind, tpport_t port = 5005);
1117 #ifdef CCXX_IPV6
1118  UDPTransmit(const IPV6Address &bind, tpport_t port = 5005);
1119 #endif
1120 
1130  Error connect(const IPV4Host &host, tpport_t port);
1131 #ifdef CCXX_IPV6
1132  Error connect(const IPV6Address &host, tpport_t port);
1133 #endif
1134 
1144  Error connect(const IPV4Broadcast &subnet, tpport_t port);
1145 
1153  Error connect(const IPV4Multicast &mgroup, tpport_t port);
1154 #ifdef CCXX_IPV6
1155  Error connect(const IPV6Multicast &mgroup, tpport_t port);
1156 #endif
1157 
1165  inline ssize_t send(const void *buf, size_t len)
1166  {return _IORET64 ::send(so, (const char *)buf, _IOLEN64 len, MSG_NOSIGNAL);}
1167 
1171  inline void endTransmitter(void)
1172  {Socket::endSocket();}
1173 
1174  /*
1175  * Get transmitter socket.
1176  *
1177  * @return transmitter.
1178  */
1179  inline SOCKET getTransmitter(void)
1180  {return so;};
1181 
1182  inline Error setMulticast(bool enable)
1183  {return Socket::setMulticastByFamily(enable, family);}
1184 
1185  inline Error setTimeToLive(unsigned char ttl)
1186  {return Socket::setTimeToLiveByFamily(ttl, family);};
1187 
1188 public:
1198  inline ssize_t transmit(const char *buffer, size_t len)
1199  {return _IORET64 ::send(so, buffer, _IOLEN64 len, MSG_DONTWAIT|MSG_NOSIGNAL);}
1200 
1207  inline bool isOutputReady(unsigned long timeout = 0l)
1208  {return Socket::isPending(Socket::pendingOutput, timeout);};
1209 
1210 
1211  inline Error setRouting(bool enable)
1212  {return Socket::setRouting(enable);};
1213 
1215  {return Socket::setTypeOfService(tos);};
1216 
1217  inline Error setBroadcast(bool enable)
1218  {return Socket::setBroadcast(enable);};
1219 };
1220 
1229 class __EXPORT UDPReceive : protected UDPSocket
1230 {
1231 protected:
1242  UDPReceive(const IPV4Address &bind, tpport_t port);
1243 #ifdef CCXX_IPV6
1244  UDPReceive(const IPV6Address &bind, tpport_t port);
1245 #endif
1246 
1256  Error connect(const IPV4Host &host, tpport_t port);
1257 #ifdef CCXX_IPV6
1258  Error connect(const IPV6Host &host, tpport_t port);
1259 #endif
1260 
1268  {return Socket::isPending(Socket::pendingInput, timeout);};
1269 
1273  inline void endReceiver(void)
1274  {Socket::endSocket();}
1275 
1276  inline SOCKET getReceiver(void) const
1277  {return so;};
1278 
1279  inline Error setRouting(bool enable)
1280  {return Socket::setRouting(enable);}
1281 
1282  inline Error setMulticast(bool enable)
1283  {return Socket::setMulticastByFamily(enable, family);}
1284 
1285  inline Error join(const IPV4Multicast &ia)
1286  {return Socket::join(ia);}
1287 
1288 #ifdef CCXX_IPV6
1289  inline Error join(const IPV6Multicast &ia)
1290  {return Socket::join(ia);}
1291 #endif
1292 
1293  inline Error drop(const IPV4Multicast &ia)
1294  {return Socket::drop(ia);}
1295 
1296 #ifdef CCXX_IPV6
1297  inline Error drop(const IPV6Multicast &ia)
1298  {return Socket::drop(ia);}
1299 #endif
1300 
1301 public:
1309  inline ssize_t receive(void *buf, size_t len)
1310  {return _IORET64 ::recv(so, (char *)buf, _IOLEN64 len, 0);};
1311 
1318  inline bool isInputReady(timeout_t timeout = TIMEOUT_INF)
1319  {return Socket::isPending(Socket::pendingInput, timeout);};
1320 };
1321 
1333 {
1334 public:
1342  UDPDuplex(const IPV4Address &bind, tpport_t port);
1343 #ifdef CCXX_IPV6
1344  UDPDuplex(const IPV6Address &bind, tpport_t port);
1345 #endif
1346 
1356  Error connect(const IPV4Host &host, tpport_t port);
1357 #ifdef CCXX_IPV6
1358  Error connect(const IPV6Host &host, tpport_t port);
1359 #endif
1360 
1368 };
1369 
1370 
1395 class __EXPORT TCPSocket : protected Socket
1396 {
1397 protected:
1398  int segsize;
1399  void setSegmentSize(unsigned mss);
1400 
1401 public:
1413  virtual bool onAccept(const IPV4Host &ia, tpport_t port);
1414 
1418  inline SOCKET getSocket(void)
1419  {return so;};
1420 
1424  inline int getSegmentSize(void)
1425  {return segsize;};
1426 
1439  TCPSocket(const IPV4Address &bind, tpport_t port, unsigned backlog = 5, unsigned mss = 536);
1440 
1451  TCPSocket(const char *name, unsigned backlog = 5, unsigned mss = 536);
1452 
1461  inline IPV4Host getRequest(tpport_t *port = NULL) const
1462  {return Socket::getIPV4Sender(port);}
1463 
1467  void reject(void);
1468 
1472  inline IPV4Host getLocal(tpport_t *port = NULL) const
1473  {return Socket::getIPV4Local(port);}
1474 
1480  inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF) /* not const -- jfc */
1481  {return Socket::isPending(Socket::pendingInput, timeout);}
1482 
1486  virtual ~TCPSocket();
1487 };
1488 
1489 #ifdef CCXX_IPV6
1490 
1514 class __EXPORT TCPV6Socket : protected Socket
1515 {
1516 private:
1517  int segsize;
1518  void setSegmentSize(unsigned mss);
1519 
1520 public:
1532  virtual bool onAccept(const IPV6Host &ia, tpport_t port);
1533 
1537  inline SOCKET getSocket(void)
1538  {return so;};
1539 
1540  inline int getSegmentSize(void)
1541  {return segsize;};
1542 
1555  TCPV6Socket(const IPV6Address &bind, tpport_t port, unsigned backlog = 5, unsigned mss = 536);
1556 
1567  TCPV6Socket(const char *name, unsigned backlog = 5, unsigned mss = 536);
1568 
1577  inline IPV6Host getRequest(tpport_t *port = NULL) const
1578  {return Socket::getIPV6Sender(port);}
1579 
1583  void reject(void);
1584 
1588  inline IPV6Host getLocal(tpport_t *port = NULL) const
1589  {return Socket::getIPV6Local(port);}
1590 
1596  inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF) /* not const -- jfc */
1597  {return Socket::isPending(Socket::pendingInput, timeout);}
1598 
1602  virtual ~TCPV6Socket();
1603 };
1604 
1605 #endif
1606 
1607 /*
1608 :\projects\libraries\cplusplus\commonc++\win32\socket.h(357) : warning C4275: non dll-interface class 'streambuf' used as base for dll-interface class 'TCPStream'
1609  c:\program files\microsoft visual studio\vc98\include\streamb.h(69) : see declaration of 'streambuf'
1610 c:\projects\libraries\cplusplus\commonc++\win32\socket.h(358) : warning C4275: non dll-interface class 'iostream' used as base for dll-interface class 'TCPStream'
1611  c:\program files\microsoft visual studio\vc98\include\iostream.h(66) : see declaration of 'iostream'
1612 */
1613 
1614 #ifdef _MSC_VER
1615 #pragma warning(disable:4275) // disable C4275 warning
1616 #endif
1617 
1631 class __EXPORT TCPStream : protected std::streambuf, public Socket, public std::iostream
1632 {
1633 private:
1634  int doallocate();
1635 
1636  void segmentBuffering(unsigned mss);
1637 
1640 
1641 protected:
1643  size_t bufsize;
1644  Family family;
1645  char *gbuf, *pbuf;
1646 
1647 public:
1652  TCPStream(Family family = IPV4, bool throwflag = true, timeout_t to = 0);
1653 
1657  void disconnect(void);
1658 
1662  int getSegmentSize(void);
1663 
1664 protected:
1671  void allocate(size_t size);
1672 
1677  void endStream(void);
1678 
1685  int underflow();
1686 
1695  int uflow();
1696 
1704  int overflow(int ch);
1705 
1714  void connect(const IPV4Host &host, tpport_t port, unsigned mss = 536);
1715 #ifdef CCXX_IPV6
1716  void connect(const IPV6Host &host, tpport_t port, unsigned mss = 536);
1717 #endif
1718 
1726  void connect(const char *name, unsigned mss = 536);
1727 
1735  std::iostream *tcp(void)
1736  {return ((std::iostream *)this);};
1737 
1738 public:
1748  TCPStream(TCPSocket &server, bool throwflag = true, timeout_t timeout = 0);
1749 #ifdef CCXX_IPV6
1750  TCPStream(TCPV6Socket &server, bool throwflag = true, timeout_t timeout = 0);
1751 #endif
1752 
1758  void connect(TCPSocket &server);
1759 #ifdef CCXX_IPV6
1760  void connect(TCPV6Socket &server);
1761 #endif
1762 
1773  TCPStream(const IPV4Host &host, tpport_t port, unsigned mss = 536, bool throwflag = true, timeout_t timeout = 0);
1774 #ifdef CCXX_IPV6
1775  TCPStream(const IPV6Host &host, tpport_t port, unsigned mss = 536, bool throwflag = true, timeout_t timeout = 0);
1776 #endif
1777 
1787  TCPStream(const char *name, Family family = IPV4, unsigned mss = 536, bool throwflag = false, timeout_t timer = 0);
1788 
1794  inline void setTimeout(timeout_t timer)
1795  {timeout = timer;};
1796 
1803  TCPStream(const TCPStream &source);
1804 
1809  virtual ~TCPStream();
1810 
1817  int sync(void);
1818 
1819 #ifdef HAVE_SNPRINTF
1820 
1826  size_t printf(const char *format, ...);
1827 #endif
1828 
1836  bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
1837 
1845  inline ssize_t peek(void *buf, size_t len)
1846  {return _IORET64 ::recv(so, (char *)buf, _IOLEN64 len, MSG_PEEK);};
1847 
1853  inline size_t getBufferSize(void) const
1854  {return bufsize;};
1855 };
1856 
1867 class __EXPORT TCPSession : public Thread, public TCPStream
1868 {
1869 private:
1870  TCPSession(const TCPSession &rhs); // not defined
1871 protected:
1885 
1892  void initial(void);
1893 
1894 public:
1905  TCPSession(const IPV4Host &host,
1906  tpport_t port, size_t size = 536, int pri = 0, size_t stack = 0);
1907 #ifdef CCXX_IPV6
1908  TCPSession(const IPV6Host &host,
1909  tpport_t port, size_t size = 536, int pri = 0, size_t stack = 0);
1910 #endif
1911 
1921  TCPSession(TCPSocket &server, int pri = 0, size_t stack = 0);
1922 #ifdef CCXX_IPV6
1923  TCPSession(TCPV6Socket &server, int pri = 0, size_t stack = 0);
1924 #endif
1925 
1929  virtual ~TCPSession();
1930 };
1931 
1932 #if defined(WIN32)
1933 
1943 class init_WSA
1944 {
1945 public:
1946  init_WSA();
1947  ~init_WSA();
1948 };
1949 
1950 #endif // WIN32
1951 
1953 
1966 {
1967 private:
1968 
1969  IPV4Host getSender(tpport_t *port) const;
1970 
1971 protected:
1977 
1982  void endStream(void);
1983 
1992  void Connect(const IPV4Host &host, tpport_t port, size_t size);
1993 
1994 
1995 public:
2004  SimpleTCPStream(TCPSocket &server, size_t size = 512);
2005 
2014  SimpleTCPStream(const IPV4Host &host, tpport_t port, size_t size = 512);
2015 
2022 
2027  virtual ~SimpleTCPStream();
2028 
2040  bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
2041 
2042  void flush() {}
2043 
2055  ssize_t read(char *bytes, size_t length, timeout_t timeout = 0);
2056 
2068  ssize_t write(const char *bytes, size_t length, timeout_t timeout = 0);
2069 
2083  ssize_t peek(char *bytes, size_t length, timeout_t timeout = 0);
2084 
2085 };
2086 
2087 #ifdef COMMON_STD_EXCEPTION
2088 class __EXPORT SockException : public IOException
2089 {
2090 private:
2091  Socket::Error _socketError;
2092 
2093 public:
2094  SockException(const String &str, Socket::Error socketError, long systemError = 0) :
2095  IOException(str, systemError), _socketError(socketError) {};
2096 
2097  inline Socket::Error getSocketError() const
2098  { return _socketError; }
2099 };
2100 #endif
2101 
2102 #ifdef CCXX_NAMESPACES
2103 }
2104 #endif
2105 
2106 #endif
2107 
ost::IPV4Multicast
A specialization of IPV4Address that provides address validation for multicast addresses.
Definition: address.h:635
ost::Socket::thrown
bool thrown
Definition: socket.h:205
ost::UDPReceive::join
Error join(const IPV6Multicast &ia)
Definition: socket.h:1289
ost::tpport_t
unsigned short tpport_t
Transport Protocol Ports.
Definition: address.h:86
ost::DCCPSocket::setCCID
bool setCCID(uint8 ccid)
Set CCID DCCP.
ost::SimpleTCPStream::write
ssize_t write(const char *bytes, size_t length, timeout_t timeout=0)
Write bytes to buffer.
uint8
u_int8_t uint8
Definition: config.h:143
ost::Socket::connectError
Error connectError(void)
Used as a common handler for connection failure processing.
ost::Socket::Socket
Socket(int domain, int type, int protocol=0)
An unconnected socket may be created directly on the local machine.
ost::SimpleTCPStream::SimpleTCPStream
SimpleTCPStream(TCPSocket &server, size_t size=512)
Create a TCP stream by accepting a connection from a bound TCP socket acting as a server.
ost::SimpleTCPStream::~SimpleTCPStream
virtual ~SimpleTCPStream()
Flush and empty all buffers, and then remove the allocated buffers.
ost::Socket::error
void error(const char *err) const
This service is used to throw application defined socket errors where the application specific error ...
Definition: socket.h:240
ost::DCCPSocket::getRxCCID
int getRxCCID()
Get RX CCID DCCP.
ost::UDPTransmit::UDPTransmit
UDPTransmit(const IPV4Address &bind, tpport_t port=5005)
Create a UDP transmitter, bind it to a specific interface and port address so that other UDP sockets ...
ost::TCPStream::TCPStream
TCPStream(const char *name, Family family=IPV4, unsigned mss=536, bool throwflag=false, timeout_t timer=0)
Construct a named TCP Socket connected to a remote machine.
ost::TCPSocket::TCPSocket
TCPSocket(const char *name, unsigned backlog=5, unsigned mss=536)
Create a named tcp socket by service and/or interface id.
ost::TCPStream::connect
void connect(const char *name, unsigned mss=536)
Connect a TCP stream to a named destination host and port number, using getaddrinfo interface if avai...
ost::Socket::Tos
Tos
Definition: socket.h:165
ost::UDPDuplex::connect
Error connect(const IPV6Host &host, tpport_t port)
ost::Socket::setError
void setError(bool enable)
This service is used to turn the error handler on or off for "throwing" exceptions by manipulating th...
Definition: socket.h:249
ost::IPV4Host
This object is used to hold the actual and valid internet address of a specific host machine that wil...
Definition: address.h:562
ost::TCPStream::getBufferSize
size_t getBufferSize(void) const
Return the size of the current stream buffering used.
Definition: socket.h:1853
ost::SimpleTCPStream::endStream
void endStream(void)
Used to terminate the buffer space and cleanup the socket connection.
ost::SimpleTCPStream
Simple TCP Stream, to be used with Common C++ Library.
Definition: socket.h:1966
ost::DCCPSocket
DCCP sockets are used for stream based connected sessions between two sockets.
Definition: socket.h:721
ost::Socket::tosReliability
@ tosReliability
Definition: socket.h:168
ost::Thread
Every thread of execution in an application is created by instantiating an object of a class derived ...
Definition: thread.h:1094
ost::UDPBroadcast::UDPBroadcast
UDPBroadcast(const IPV4Address &ia, tpport_t port)
Create and bind a subnet broadcast socket.
ost::Socket::join
Error join(const IPV6Multicast &ia)
ost::UDPSocket::UDPSocket
UDPSocket(const IPV6Address &bind, tpport_t port)
ost::UDPReceive::connect
Error connect(const IPV4Host &host, tpport_t port)
Associate this socket with a specified peer host.
ost::DCCPSocket::getIPV6Sender
virtual IPV6Host getIPV6Sender(tpport_t *port=NULL) const
ost::UDPSocket::setTimeToLive
Error setTimeToLive(char ttl)
Set time to live.
Definition: socket.h:949
ost::TCPSocket
TCP sockets are used for stream based connected sessions between two sockets.
Definition: socket.h:1396
ost::Socket::isRouted
bool isRouted(void) const
Return if socket routing is enabled.
Definition: socket.h:659
ost::Socket::errNotConnected
@ errNotConnected
Definition: socket.h:140
ost::Socket::receiveBuffer
Error receiveBuffer(unsigned size)
Set the protocol stack network kernel receive buffer size associated with the socket.
ost::UDPTransmit::getTransmitter
SOCKET getTransmitter(void)
Definition: socket.h:1179
ost::UDPReceive::isInputReady
bool isInputReady(timeout_t timeout=TIMEOUT_INF)
See if input queue has data packets available.
Definition: socket.h:1318
ost::UDPTransmit::UDPTransmit
UDPTransmit(Family family=IPV4)
Create a UDP transmitter.
ost::TCPSession::TCPSession
TCPSession(TCPSocket &server, int pri=0, size_t stack=0)
Create a TCP socket from a bound TCP server by accepting a pending connection from that server and ex...
ost::TCPSession::~TCPSession
virtual ~TCPSession()
Make sure destruction happens through a virtual...
ost::Socket::isConnected
bool isConnected(void) const
Can test to see if this socket is "connected", and hence whether a "catch" can safely call getPeer().
ost::UDPTransmit::isOutputReady
bool isOutputReady(unsigned long timeout=0l)
See if output queue is empty for sending more packets.
Definition: socket.h:1207
ost::Socket::readData
virtual ssize_t readData(void *buf, size_t len, char separator=0, timeout_t t=0)
Read in a block of len bytes with specific separator.
ost::DCCPSocket::getTxCCID
int getTxCCID()
Get TX CCID DCCP.
ost::Socket::errKeepaliveDenied
@ errKeepaliveDenied
Definition: socket.h:151
ost::TCPStream::TCPStream
TCPStream(const IPV6Host &host, tpport_t port, unsigned mss=536, bool throwflag=true, timeout_t timeout=0)
ost::TCPStream::disconnect
void disconnect(void)
Disconnect the current session and prepare for a new one.
timeout_t
unsigned long timeout_t
Definition: thread.h:74
ost::TCPStream::setTimeout
void setTimeout(timeout_t timer)
Set the I/O operation timeout for socket I/O operations.
Definition: socket.h:1794
ost::DCCPSocket::DCCPSocket
DCCPSocket(DCCPSocket &server, timeout_t timeout=0)
Create a server session by accepting a DCCP Socket.
ost::UDPDuplex::disconnect
Error disconnect(void)
Disassociate this duplex from any host connection.
ost::Socket::errServiceUnavailable
@ errServiceUnavailable
Definition: socket.h:153
ost::DCCPSocket::disconnect
void disconnect(void)
Disconnect active dccp connection (client use).
ost::Socket::so
SOCKET volatile so
the actual socket descriptor, in Windows, unlike posix it cannot be used as an file descriptor that w...
Definition: socket.h:221
ost::TCPStream::family
Family family
Definition: socket.h:1644
ost::IPV6Host
This object is used to hold the actual and valid internet address of a specific host machine that wil...
Definition: address.h:949
ost::UDPReceive::getReceiver
SOCKET getReceiver(void) const
Definition: socket.h:1276
ost::UDPTransmit::setTypeOfService
Error setTypeOfService(Tos tos)
Definition: socket.h:1214
ost::SimpleTCPStream::SimpleTCPStream
SimpleTCPStream()
The constructor required for "SimpleTCPStream", a more C++ style version of the SimpleTCPStream class...
ost::TCPSocket::~TCPSocket
virtual ~TCPSocket()
Use base socket handler for ending this socket.
ost::Socket::errNoDelay
@ errNoDelay
Definition: socket.h:156
ost::DCCPSocket::isPendingConnection
bool isPendingConnection(timeout_t timeout=TIMEOUT_INF)
Used to wait for pending connection requests.
Definition: socket.h:843
ost::TCPSession::TCPSession
TCPSession(TCPV6Socket &server, int pri=0, size_t stack=0)
ost::Socket::tosThroughput
@ tosThroughput
Definition: socket.h:167
ost::UDPReceive::drop
Error drop(const IPV4Multicast &ia)
Definition: socket.h:1293
ost::TCPStream::connect
void connect(TCPV6Socket &server)
ost::TCPSocket::reject
void reject(void)
Used to reject the next incoming connection request.
ost::Socket::receiveLimit
Error receiveLimit(int limit=1)
Set thr receive limit.
ost::TCPStream::bufsize
size_t bufsize
Definition: socket.h:1643
ost::TCPStream::sync
int sync(void)
Flushes the stream input and output buffers, writes pending output.
ost::UDPTransmit::connect
Error connect(const IPV6Address &host, tpport_t port)
ost::UDPSocket::peek
ssize_t peek(void *buf, size_t len)
Examine contents of next waiting packet.
Definition: socket.h:1028
ost::TCPStream::~TCPStream
virtual ~TCPStream()
Flush and empty all buffers, and then remove the allocated buffers.
ost::Socket::Family
Family
Definition: socket.h:122
ost::TCPStream::underflow
int underflow()
This streambuf method is used to load the input buffer through the established tcp socket connection.
ost::TCPStream::uflow
int uflow()
This streambuf method is used for doing unbuffered reads through the establish tcp socket connection ...
ost::Socket::getSystemError
long getSystemError(void) const
Definition: socket.h:678
ost::DCCPSocket::DCCPSocket
DCCPSocket(const char *name, Family family=IPV4, unsigned backlog=5)
Create a named dccp socket by service and/or interface id.
ost::TCPStream::TCPStream
TCPStream(const TCPStream &source)
A copy constructor creates a new stream buffer.
ost::SimpleTCPStream::read
ssize_t read(char *bytes, size_t length, timeout_t timeout=0)
Read bytes into a buffer.
ost::Mutex
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
Definition: thread.h:187
ost::Socket::errConnectFailed
@ errConnectFailed
Definition: socket.h:144
ost::Socket::setCompletion
void setCompletion(bool immediate)
Used to specify blocking mode for the socket.
ost::DCCPSocket::available
size_t available()
Return number of bytes to be read.
ost::UDPSocket::setPeer
void setPeer(const char *service)
Associate socket with a named connection.
ost::TCPSocket::TCPSocket
TCPSocket(const IPV4Address &bind, tpport_t port, unsigned backlog=5, unsigned mss=536)
A TCP "server" is created as a TCP socket that is bound to a hardware address and port number on the ...
ost::DCCPSocket::reject
void reject(void)
Used to reject the next incoming connection request.
ost::Socket::loopback
bool loopback
Definition: socket.h:209
ost::UDPSocket::setLoopback
Error setLoopback(bool enable)
Set the loopback.
Definition: socket.h:937
ost::Socket::getIPV6Sender
virtual IPV6Host getIPV6Sender(tpport_t *port=NULL) const
ost::UDPSocket::getInterfaceIndex
Socket::Error getInterfaceIndex(const char *ethX, int &InterfaceIndex)
get the interface index for a named network device
ost::UDPSocket::join
Socket::Error join(const IPV4Multicast &ia, int InterfaceIndex)
join a multicast group on a particular interface
ost::UDPTransmit::endTransmitter
void endTransmitter(void)
Stop transmitter.
Definition: socket.h:1171
ost::TCPStream::tcp
std::iostream * tcp(void)
Used in derived classes to refer to the current object via it's iostream.
Definition: socket.h:1735
ost::UDPReceive::setRouting
Error setRouting(bool enable)
Definition: socket.h:1279
ost::error
__EXPORT AppLog & error(AppLog &sl)
Manipulator for error level.
Definition: applog.h:541
ost::Socket::completion
bool completion
Definition: socket.h:211
ost::UDPBroadcast::setPeer
void setPeer(const IPV4Broadcast &subnet, tpport_t port)
Set peer by subnet rather than specific host.
ost::TCPV6Socket::getSocket
SOCKET getSocket(void)
Fetch out the socket.
Definition: socket.h:1537
ost::UDPSocket::getIPV6Peer
IPV6Host getIPV6Peer(tpport_t *port=NULL) const
ost::Socket::errInput
@ errInput
Definition: socket.h:135
ost::Socket::errBindingFailed
@ errBindingFailed
Definition: socket.h:148
ost::Socket::writeData
virtual ssize_t writeData(const void *buf, size_t len, timeout_t t=0)
Write a block of len bytes to socket.
ost::Socket::getIPV4Local
IPV4Host getIPV4Local(tpport_t *port=NULL) const
Get the local address and port number this socket is currently bound to.
ost::UDPSocket::family
Family family
Definition: socket.h:902
ost::Socket::endSocket
void endSocket(void)
Used as the default destructor for ending a socket.
ost::DCCPSocket::DCCPSocket
DCCPSocket(const IPV4Address &bind, tpport_t port, unsigned backlog=5)
A DCCP "server" is created as a DCCP socket that is bound to a hardware address and port number on th...
ost::UDPSocket::~UDPSocket
virtual ~UDPSocket()
Destroy a UDP socket as a socket.
ost::TCPV6Socket::reject
void reject(void)
Used to reject the next incoming connection request.
ost::Socket::setMulticastByFamily
Error setMulticastByFamily(bool enable, Family family=IPV4)
Setting multicast binds the multicast interface used for the socket to the interface the socket itsel...
ost::TCPStream::connect
void connect(TCPSocket &server)
Accept a connection from a TCP Server.
ost::Socket::state
State volatile state
Definition: socket.h:222
ost::Socket::ttl
unsigned ttl
Definition: socket.h:213
ost::TCPSession::TCPSession
TCPSession(const IPV6Host &host, tpport_t port, size_t size=536, int pri=0, size_t stack=0)
ost::Socket::errMulticastDisabled
@ errMulticastDisabled
Definition: socket.h:154
ost::Socket::~Socket
virtual ~Socket()
The socket base class may be "thrown" as a result of an error, and the "catcher" may then choose to d...
ost::Socket::pendingInput
@ pendingInput
Definition: socket.h:175
ost::TCPV6Socket::getLocal
IPV6Host getLocal(tpport_t *port=NULL) const
Used to get local bound address.
Definition: socket.h:1588
ost::TCPStream::getSegmentSize
int getSegmentSize(void)
Get protocol segment size.
ost::Socket::Error
Error
Definition: socket.h:131
ost::UDPSocket::receive
ssize_t receive(void *buf, size_t len, bool reply=false)
Receive a message from any host.
ost::UDPReceive::isPendingReceive
bool isPendingReceive(timeout_t timeout)
Check for pending data.
Definition: socket.h:1267
ost::IPV4Broadcast
The broadcast address object is used to store the broadcast address for a specific subnet.
Definition: address.h:613
ost::UDPSocket::send
ssize_t send(const void *buf, size_t len)
Send a message packet to a peer host.
ost::Socket::AVAILABLE
@ AVAILABLE
Definition: socket.h:184
ost::Socket::errTimeout
@ errTimeout
Definition: socket.h:155
ost::Socket::setKeepAlive
Error setKeepAlive(bool enable)
Set the keep-alive status of this socket and if keep-alive messages will be sent.
address.h
Network addresses and sockets related classes.
ost::UDPSocket::connect
void connect(const char *service)
ost::UDPSocket::setPeer
void setPeer(const IPV6Host &host, tpport_t port)
ost::TCPStream::allocate
void allocate(size_t size)
Used to allocate the buffer space needed for iostream operations.
ost::Socket::linger
bool linger
Definition: socket.h:212
ost::SimpleTCPStream::SimpleTCPStream
SimpleTCPStream(const IPV4Host &host, tpport_t port, size_t size=512)
Create a TCP stream by connecting to a TCP socket (on a remote machine).
ost::Socket::setRouting
Error setRouting(bool enable)
Set the socket routing to indicate if outgoing messages should bypass normal routing (set false).
ost::Socket::check
static bool check(Family fam)
See if a specific protocol family is available in the current runtime environment.
ost::Socket::errRoutingDenied
@ errRoutingDenied
Definition: socket.h:150
ost::SimpleTCPStream::flush
void flush()
Definition: socket.h:2042
ost::TCPStream::timeout
timeout_t timeout
Definition: socket.h:1642
ost::Socket::getPeer
IPV4Host getPeer(tpport_t *port=NULL) const
Definition: socket.h:523
ost::TCPSession::TCPSession
TCPSession(const IPV4Host &host, tpport_t port, size_t size=536, int pri=0, size_t stack=0)
Create a TCP socket that will be connected to a remote TCP server and that will execute under it's ow...
ost::Socket::getIPV6Peer
IPV6Host getIPV6Peer(tpport_t *port=NULL) const
ost::Socket::sendLimit
Error sendLimit(int limit=2048)
Set the send limit.
ost::Socket::getErrorString
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...
Definition: socket.h:676
ost::UDPTransmit::setRouting
Error setRouting(bool enable)
Definition: socket.h:1211
ost::Socket::keepalive
bool keepalive
Definition: socket.h:208
ost::TCPSocket::getRequest
IPV4Host getRequest(tpport_t *port=NULL) const
Return address and port of next connection request.
Definition: socket.h:1461
ost::TCPStream::TCPStream
TCPStream(const IPV4Host &host, tpport_t port, unsigned mss=536, bool throwflag=true, timeout_t timeout=0)
Create a TCP stream by connecting to a TCP socket (on a remote machine).
ost::UDPSocket::getIPV4Peer
IPV4Host getIPV4Peer(tpport_t *port=NULL) const
Examine address of sender of next waiting packet.
ost::TCPSocket::getLocal
IPV4Host getLocal(tpport_t *port=NULL) const
Used to get local bound address.
Definition: socket.h:1472
MSG_DONTWAIT
#define MSG_DONTWAIT
Definition: socket.h:72
ost::Socket::CONNECTED
@ CONNECTED
Definition: socket.h:186
ost::TCPV6Socket::isPendingConnection
bool isPendingConnection(timeout_t timeout=TIMEOUT_INF)
Used to wait for pending connection requests.
Definition: socket.h:1596
ost::DCCPSocket::~DCCPSocket
virtual ~DCCPSocket()
Use base socket handler for ending this socket.
ost::TCPStream
TCP streams are used to represent TCP client connections to a server by TCP protocol servers for acce...
Definition: socket.h:1632
ost::UDPTransmit::connect
Error connect(const IPV4Multicast &mgroup, tpport_t port)
Associate this socket with a multicast group.
ost::TCPStream::TCPStream
TCPStream(TCPSocket &server, bool throwflag=true, timeout_t timeout=0)
Create a TCP stream by accepting a connection from a bound TCP socket acting as a server.
ost::UDPReceive
Representing half of a two-way UDP connection, the UDP receiver can receive data from another peer ho...
Definition: socket.h:1230
__EXPORT
#define __EXPORT
Definition: config.h:979
ost::Socket::pendingOutput
@ pendingOutput
Definition: socket.h:176
ost::IPV6Address
The network name and address objects are all derived from a common IPV6Address base class.
Definition: address.h:754
ost::Socket
The Socket is used as the base for all Internet protocol services under Common C++.
Definition: socket.h:120
ost::IPV4Address
The network name and address objects are all derived from a common IPV4Address base class.
Definition: address.h:351
ost::DCCPSocket::DCCPSocket
DCCPSocket(Family family=IPV4)
Create an unconnected ephemeral DCCP client socket.
ost::Socket::getIPV6NAT
IPV6Host getIPV6NAT(tpport_t *port=NULL) const
ost::UDPSocket::connect
void connect(const IPV4Host &host, tpport_t port)
ost::Socket::mutex
static Mutex mutex
Definition: socket.h:202
ost::DCCPSocket::DCCPSocket
DCCPSocket(const IPV6Address &bind, tpport_t port, unsigned backlog=5)
ost::TCPSession::waitConnection
int waitConnection(timeout_t timeout=TIMEOUT_INF)
Normally called during the thread Initial() method by default, this will wait for the socket connecti...
ost::Socket::Pending
Pending
Definition: socket.h:174
ost::Socket::getNAT
IPV4Host getNAT(tpport_t *port) const
Definition: socket.h:575
ost::Socket::setLoopbackByFamily
Error setLoopbackByFamily(bool enable, Family family=IPV4)
Set the multicast loopback flag for the socket.
ost::SimpleTCPStream::isPending
bool isPending(Pending pend, timeout_t timeout=TIMEOUT_INF)
Get the status of pending stream data.
ost::TCPStream::connect
void connect(const IPV4Host &host, tpport_t port, unsigned mss=536)
Create a TCP stream by connecting to a TCP socket (on a remote machine).
ost::TCPSocket::setSegmentSize
void setSegmentSize(unsigned mss)
ost::TCPStream::pbuf
char * pbuf
Definition: socket.h:1645
ost::Socket::getSender
IPV4Host getSender(tpport_t *port=NULL) const
Definition: socket.h:505
ost::UDPReceive::setMulticast
Error setMulticast(bool enable)
Definition: socket.h:1282
ost::Socket::operator!
bool operator!() const
Operator based testing to see if a socket is currently active.
ost::Socket::setNoDelay
Error setNoDelay(bool enable)
Enable/disable delaying packets (Nagle algorithm)
ost::TCPSession::initial
void initial(void)
The initial method is used to esablish a connection when delayed completion is used.
ost::Socket::isPending
virtual bool isPending(Pending pend, timeout_t timeout=TIMEOUT_INF)
Get the status of pending operations.
ost::UDPReceive::drop
Error drop(const IPV6Multicast &ia)
Definition: socket.h:1297
ost::UDPDuplex::connect
Error connect(const IPV4Host &host, tpport_t port)
Associate the duplex with a specified peer host.
ost::Socket::errLookupFail
@ errLookupFail
Definition: socket.h:158
ost::Socket::isBroadcast
bool isBroadcast(void) const
Return if broadcast has been enabled for the specified socket.
Definition: socket.h:651
ost::Socket::errCopyFailed
@ errCopyFailed
Definition: socket.h:134
ost::TCPStream::isPending
bool isPending(Pending pend, timeout_t timeout=TIMEOUT_INF)
Get the status of pending stream data.
ost::Socket::getLocal
IPV4Host getLocal(tpport_t *port=NULL) const
Definition: socket.h:539
ost::Socket::sendBuffer
Error sendBuffer(unsigned size)
Set the protocol stack network kernel send buffer size associated with the socket.
ost::TCPV6Socket::getRequest
IPV6Host getRequest(tpport_t *port=NULL) const
Return address and port of next connection request.
Definition: socket.h:1577
ost::SimpleTCPStream::peek
ssize_t peek(char *bytes, size_t length, timeout_t timeout=0)
Peek at the incoming data.
ost::Socket::getErrorNumber
Error getErrorNumber(void) const
Often used by a "catch" to fetch the last error of a thrown socket.
Definition: socket.h:668
ost::UDPSocket::setPeer
void setPeer(const IPV4Host &host, tpport_t port)
set the peer address to send message packets to.
ost::TCPStream::TCPStream
TCPStream(TCPV6Socket &server, bool throwflag=true, timeout_t timeout=0)
ost::Socket::getIPV4NAT
IPV4Host getIPV4NAT(tpport_t *port=NULL) const
Perform NAT table lookup for this socket.
ost::Socket::getIPV4Sender
virtual IPV4Host getIPV4Sender(tpport_t *port=NULL) const
May be used to examine the origin of data waiting in the socket receive queue.
ost::TCPSocket::onAccept
virtual bool onAccept(const IPV4Host &ia, tpport_t port)
A method to call in a derived TCPSocket class that is acting as a server when a connection request is...
ost::DCCPSocket::getIPV4Sender
virtual IPV4Host getIPV4Sender(tpport_t *port=NULL) const
ost::Socket::receiveTimeout
Error receiveTimeout(timeout_t timer)
Receive timeout for receiving raw network data.
ost::UDPSocket::UDPSocket
UDPSocket(Family family=IPV4)
Create an unbound UDP socket, mostly for internal use.
ost::Socket::errConnectInvalid
@ errConnectInvalid
Definition: socket.h:145
ost::DCCPSocket::connect
void connect(const char *name)
Connect to a named client.
ost::SimpleTCPStream::SimpleTCPStream
SimpleTCPStream(const SimpleTCPStream &source)
A copy constructor creates a new stream buffer.
ost::Socket::BOUND
@ BOUND
Definition: socket.h:185
ost::TCPSocket::segsize
int segsize
Definition: socket.h:1398
ost::UDPTransmit::setMulticast
Error setMulticast(bool enable)
Definition: socket.h:1182
ost::UDPSocket::getPeer
IPV4Host getPeer(tpport_t *port=NULL) const
Definition: socket.h:1014
ost::UDPSocket::UDPSocket
UDPSocket(const IPV4Address &bind, tpport_t port)
Create a UDP socket and bind it to a specific interface and port address so that other UDP sockets on...
ost::Socket::setTypeOfService
Error setTypeOfService(Tos service)
Set packet scheduling on platforms which support ip quality of service conventions.
ost::Socket::Socket
Socket()
Create an inactive socket object for base constructors.
ost::Socket::operator=
Socket & operator=(const Socket &from)
Sockets may also be duplicated by the assignment operator.
ost
Definition: address.h:64
ost::UDPTransmit
Representing half of a two-way UDP connection, the UDP transmitter can broadcast data to another sele...
Definition: socket.h:1088
ost::DCCPSocket::connect
void connect(const IPV4Host &host, tpport_t port, timeout_t timeout=0)
Create a DCCP client connection to a DCCP socket (on a remote machine).
ost::Socket::errOutput
@ errOutput
Definition: socket.h:138
ost::Socket::dupSocket
friend SOCKET dupSocket(SOCKET s, Socket::State state)
ost::TCPV6Socket
TCPV6 sockets are used for stream based connected sessions between two ipv6 sockets.
Definition: socket.h:1515
ost::UDPSocket
UDP sockets implement the TCP SOCK_DGRAM UDP protocol.
Definition: socket.h:885
ost::Socket::errOutputInterrupt
@ errOutputInterrupt
Definition: socket.h:139
ost::Socket::Socket
Socket(const Socket &source)
A socket can also be constructed from an already existing Socket object.
ost::SimpleTCPStream
class __EXPORT SimpleTCPStream
Definition: socket.h:1952
ost::TCPSocket::getSocket
SOCKET getSocket(void)
Fetch out the socket.
Definition: socket.h:1418
ost::UDPTransmit::connect
Error connect(const IPV4Broadcast &subnet, tpport_t port)
Associate this socket with a subnet of peer hosts for subnet broadcasting.
ost::Socket::tosMinCost
@ tosMinCost
Definition: socket.h:169
ost::DCCPSocket::onAccept
virtual bool onAccept(const IPV6Host &ia, tpport_t port)
ost::UDPReceive::join
Error join(const IPV4Multicast &ia)
Definition: socket.h:1285
ost::Socket::Socket
Socket(SOCKET fd)
A socket object may be created from a file descriptor when that descriptor was created either through...
ost::Socket::multicast
bool multicast
Definition: socket.h:210
ost::TCPV6Socket::getSegmentSize
int getSegmentSize(void)
Definition: socket.h:1540
ost::TCPStream::crlf
friend TCPStream & crlf(TCPStream &)
ost::Socket::errConnectNoRoute
@ errConnectNoRoute
Definition: socket.h:147
SOCKET
int SOCKET
Definition: socket.h:60
ost::Socket::error
Error error(Error error, const char *err=NULL, long systemError=0) const
This service is used to throw all socket errors which usually occur during the socket constructor.
ost::Socket::State
State
Definition: socket.h:182
ost::TCPStream::connect
void connect(const IPV6Host &host, tpport_t port, unsigned mss=536)
ost::DCCPSocket::onAccept
virtual bool onAccept(const IPV4Host &ia, tpport_t port)
A method to call in a derived DCCPSocket class that is acting as a server when a connection request i...
ost::UDPTransmit::setTimeToLive
Error setTimeToLive(unsigned char ttl)
Definition: socket.h:1185
ost::UDPTransmit::transmit
ssize_t transmit(const char *buffer, size_t len)
Transmit "send" to use "connected" send rather than sendto.
Definition: socket.h:1198
ost::Socket::INITIAL
@ INITIAL
Definition: socket.h:183
ost::Socket::join
Error join(const IPV4Multicast &ia)
Join a multicast group.
ost::TCPStream::endStream
void endStream(void)
Used to terminate the buffer space and cleanup the socket connection.
ost::Socket::getIPV6Local
IPV6Host getIPV6Local(tpport_t *port=NULL) const
ost::TCPSession
The TCP session is used to primarily to represent a client connection that can be managed on a sepera...
Definition: socket.h:1868
ost::Socket::readLine
ssize_t readLine(char *buf, size_t len, timeout_t timeout=0)
Process a logical input line from a socket descriptor directly.
ost::Socket::sendTimeout
Error sendTimeout(timeout_t timer)
Set the send timeout for sending raw network data.
ost::UDPTransmit::setBroadcast
Error setBroadcast(bool enable)
Definition: socket.h:1217
ost::UDPTransmit::send
ssize_t send(const void *buf, size_t len)
Transmit "send" to use "connected" send rather than sendto.
Definition: socket.h:1165
ost::Socket::setLinger
Error setLinger(bool linger)
Enable lingering sockets on close.
ost::UDPTransmit::connect
Error connect(const IPV4Host &host, tpport_t port)
Associate this socket with a specified peer host.
ost::UDPReceive::endReceiver
void endReceiver(void)
End receiver.
Definition: socket.h:1273
ost::IPV6Multicast
A specialization of IPV6Address that provides address validation for multicast addresses.
Definition: address.h:1011
ost::Socket::errExtended
@ errExtended
Definition: socket.h:157
_IOLEN64
#define _IOLEN64
Definition: socket.h:64
ost::TCPStream::printf
size_t printf(const char *format,...)
Print content into a socket.
ost::Socket::errServiceDenied
@ errServiceDenied
Definition: socket.h:152
ost::UDPSocket::connect
void connect(const IPV6Host &host, tpport_t port)
ost::Socket::route
bool route
Definition: socket.h:207
ost::UDPBroadcast
Representing a UDP socket used for subnet broadcasts, this class provides an alternate binding and se...
Definition: socket.h:1054
ost::Socket::errConnectBusy
@ errConnectBusy
Definition: socket.h:146
ost::UDPSocket::setMulticast
Error setMulticast(bool enable)
Set the multicast.
Definition: socket.h:943
ost::UDPTransmit::UDPTransmit
UDPTransmit(const IPV6Address &bind, tpport_t port=5005)
ost::Socket::setTimeToLiveByFamily
Error setTimeToLiveByFamily(unsigned char ttl, Family fam=IPV4)
Set the multicast time to live for a multicast socket.
ost::Socket::errCreateFailed
@ errCreateFailed
Definition: socket.h:133
ost::UDPReceive::connect
Error connect(const IPV6Host &host, tpport_t port)
MSG_NOSIGNAL
#define MSG_NOSIGNAL
Definition: socket.h:76
ost::UDPDuplex
UDP duplex connections impliment a bi-directional point-to-point UDP session between two peer hosts.
Definition: socket.h:1333
ost::UDPDuplex::UDPDuplex
UDPDuplex(const IPV6Address &bind, tpport_t port)
ost::Socket::getIPV4Peer
IPV4Host getIPV4Peer(tpport_t *port=NULL) const
Get the host address and port of the socket this socket is connected to.
ost::UDPTransmit::connect
Error connect(const IPV6Multicast &mgroup, tpport_t port)
ost::Socket::bufferSize
Error bufferSize(unsigned size)
Set the total protocol stack network kernel buffer size for both send and receive together.
ost::Socket::drop
Error drop(const IPV4Multicast &ia)
Drop membership from a multicast group.
ost::TCPSocket::isPendingConnection
bool isPendingConnection(timeout_t timeout=TIMEOUT_INF)
Used to wait for pending connection requests.
Definition: socket.h:1480
ost::Socket::errConnectTimeout
@ errConnectTimeout
Definition: socket.h:143
ost::DCCPSocket::connect
void connect(const IPV6Host &host, tpport_t port, timeout_t timeout=0)
ost::TCPSocket::getSegmentSize
int getSegmentSize(void)
Get the buffer size for servers.
Definition: socket.h:1424
ost::UDPSocket::UDPSocket
UDPSocket(const char *name, Family family=IPV4)
Create a UDP socket bound by a service name.
ost::Socket::broadcast
bool broadcast
Definition: socket.h:206
ost::Socket::CONNECTING
@ CONNECTING
Definition: socket.h:187
ost::UDPDuplex::UDPDuplex
UDPDuplex(const IPV4Address &bind, tpport_t port)
Create a UDP duplex as a pair of UDP simplex objects bound to alternating and interconnected port add...
ost::Socket::drop
Error drop(const IPV6Multicast &ia)
ost::Socket::isActive
bool isActive(void) const
Test to see if the socket is at least operating or if it is mearly initialized.
ost::TCPV6Socket::~TCPV6Socket
virtual ~TCPV6Socket()
Use base socket handler for ending this socket.
ost::TCPV6Socket::onAccept
virtual bool onAccept(const IPV6Host &ia, tpport_t port)
A method to call in a derived TCPSocket class that is acting as a server when a connection request is...
ost::TCPStream::peek
ssize_t peek(void *buf, size_t len)
Examine contents of next waiting packet.
Definition: socket.h:1845
ost::String
This is a generic and portable string class.
Definition: string.h:81
ost::Socket::errConnectRefused
@ errConnectRefused
Definition: socket.h:141
ost::UDPReceive::receive
ssize_t receive(void *buf, size_t len)
Receive a data packet from the connected peer host.
Definition: socket.h:1309
ost::Socket::errSearchErr
@ errSearchErr
Definition: socket.h:159
ost::Socket::errConnectRejected
@ errConnectRejected
Definition: socket.h:142
ost::Socket::setBroadcast
Error setBroadcast(bool enable)
Set the subnet broadcast flag for the socket.
ost::UDPReceive::UDPReceive
UDPReceive(const IPV4Address &bind, tpport_t port)
Create a UDP receiver, bind it to a specific interface and port address so that other UDP sockets on ...
ost::TCPStream::overflow
int overflow(int ch)
This streambuf method is used to write the output buffer through the established tcp connection.
ost::TCPStream::lfcr
friend TCPStream & lfcr(TCPStream &)
ost::TCPV6Socket::TCPV6Socket
TCPV6Socket(const char *name, unsigned backlog=5, unsigned mss=536)
Create a TCP server for a named host interface and service port.
ost::UDPReceive::UDPReceive
UDPReceive(const IPV6Address &bind, tpport_t port)
ost::Socket::errInputInterrupt
@ errInputInterrupt
Definition: socket.h:136
ost::Socket::getSystemErrorString
const char * getSystemErrorString(void) const
TIMEOUT_INF
#define TIMEOUT_INF
Definition: thread.h:115
ost::TCPV6Socket::TCPV6Socket
TCPV6Socket(const IPV6Address &bind, tpport_t port, unsigned backlog=5, unsigned mss=536)
A TCP "server" is created as a TCP socket that is bound to a hardware address and port number on the ...
ost::TCPStream::TCPStream
TCPStream(Family family=IPV4, bool throwflag=true, timeout_t to=0)
The constructor required for building other classes or to start an unconnected TCPStream for connect.
ost::SimpleTCPStream::Connect
void Connect(const IPV4Host &host, tpport_t port, size_t size)
Create a TCP stream by connecting to a TCP socket (on a remote machine).
ost::Socket::errBroadcastDenied
@ errBroadcastDenied
Definition: socket.h:149
ost::Socket::errResourceFailure
@ errResourceFailure
Definition: socket.h:137