00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00045 #ifndef CCXX_SOCKET_H_
00046 #define CCXX_SOCKET_H_
00047
00048 #ifndef CCXX_ADDRESS_H_
00049 #include <cc++/address.h>
00050 #endif
00051
00052 #if defined(WIN32) && !defined(__CYGWIN32__)
00053 #include <io.h>
00054 #define _IOLEN64 (unsigned)
00055 #define _IORET64 (int)
00056 #define TIMEOUT_INF ~((timeout_t) 0)
00057 typedef int socklen_t;
00058 #else
00059 #define INVALID_SOCKET -1
00060 typedef int SOCKET;
00061 #endif
00062
00063 #ifndef _IOLEN64
00064 #define _IOLEN64
00065 #endif
00066
00067 #ifndef _IORET64
00068 #define _IORET64
00069 #endif
00070
00071 #ifndef MSG_DONTWAIT
00072 #define MSG_DONTWAIT 0
00073 #endif
00074
00075 #ifndef MSG_NOSIGNAL
00076 #define MSG_NOSIGNAL 0
00077 #endif
00078
00079 #ifndef SOCK_DCCP
00080 #define SOCK_DCCP 6
00081 #endif
00082 #ifndef IPPROTO_DCCP
00083 #define IPPROTO_DCCP 33
00084 #endif
00085 #ifndef SOL_DCCP
00086 #define SOL_DCCP 269
00087 #endif
00088 #define DCCP_SOCKOPT_AVAILABLE_CCIDS 12
00089 #define DCCP_SOCKOPT_CCID 13
00090 #define DCCP_SOCKOPT_TX_CCID 14
00091 #define DCCP_SOCKOPT_RX_CCID 15
00092
00093 #ifdef CCXX_NAMESPACES
00094 namespace ost {
00095 #endif
00096
00100 typedef unsigned short tpport_t;
00101
00119 class __EXPORT Socket
00120 {
00121 public:
00122 enum Family {
00123 #ifdef CCXX_IPV6
00124 IPV6 = AF_INET6,
00125 #endif
00126 IPV4 = AF_INET
00127 };
00128
00129 typedef enum Family Family;
00130
00131 enum Error {
00132 errSuccess = 0,
00133 errCreateFailed,
00134 errCopyFailed,
00135 errInput,
00136 errInputInterrupt,
00137 errResourceFailure,
00138 errOutput,
00139 errOutputInterrupt,
00140 errNotConnected,
00141 errConnectRefused,
00142 errConnectRejected,
00143 errConnectTimeout,
00144 errConnectFailed,
00145 errConnectInvalid,
00146 errConnectBusy,
00147 errConnectNoRoute,
00148 errBindingFailed,
00149 errBroadcastDenied,
00150 errRoutingDenied,
00151 errKeepaliveDenied,
00152 errServiceDenied,
00153 errServiceUnavailable,
00154 errMulticastDisabled,
00155 errTimeout,
00156 errNoDelay,
00157 errExtended,
00158 errLookupFail,
00159 errSearchErr,
00160 errInvalidValue
00161 };
00162
00163 typedef enum Error Error;
00164
00165 enum Tos {
00166 tosLowDelay = 0,
00167 tosThroughput,
00168 tosReliability,
00169 tosMinCost,
00170 tosInvalid
00171 };
00172 typedef enum Tos Tos;
00173
00174 enum Pending {
00175 pendingInput,
00176 pendingOutput,
00177 pendingError
00178 };
00179 typedef enum Pending Pending;
00180
00181 protected:
00182 enum State {
00183 INITIAL,
00184 AVAILABLE,
00185 BOUND,
00186 CONNECTED,
00187 CONNECTING,
00188 STREAM
00189 };
00190 typedef enum State State;
00191
00192 private:
00193
00194 mutable Error errid;
00195 mutable const char *errstr;
00196 mutable long syserr;
00197
00198 void setSocket(void);
00199 friend SOCKET dupSocket(SOCKET s,Socket::State state);
00200
00201 protected:
00202 static Mutex mutex;
00203
00204 mutable struct {
00205 bool thrown: 1;
00206 bool broadcast: 1;
00207 bool route: 1;
00208 bool keepalive: 1;
00209 bool loopback: 1;
00210 bool multicast: 1;
00211 bool completion: 1;
00212 bool linger: 1;
00213 unsigned ttl: 8;
00214 } flags;
00215
00221 SOCKET volatile so;
00222 State volatile state;
00223
00232 Error error(Error error, const char *err = NULL, long systemError = 0) const;
00233
00240 inline void error(const char *err) const
00241 {error(errExtended, err);};
00242
00249 inline void setError(bool enable)
00250 {flags.thrown = !enable;};
00251
00257 void endSocket(void);
00258
00264 Error connectError(void);
00265
00269 Error sendLimit(int limit = 2048);
00270
00274 Error receiveLimit(int limit = 1);
00275
00282 Error sendTimeout(timeout_t timer);
00283
00290 Error receiveTimeout(timeout_t timer);
00291
00299 Error sendBuffer(unsigned size);
00300
00308 Error receiveBuffer(unsigned size);
00309
00317 Error bufferSize(unsigned size);
00318
00327 Error setBroadcast(bool enable);
00328
00340 Error setMulticastByFamily(bool enable, Family family = IPV4);
00341
00350 Error setLoopbackByFamily(bool enable, Family family = IPV4);
00351
00359 Error setTimeToLiveByFamily(unsigned char ttl, Family fam = IPV4);
00360
00367 Error join(const IPV4Multicast &ia);
00368 #ifdef CCXX_IPV6
00369 Error join(const IPV6Multicast &ia);
00370 #endif
00371
00378 Error drop(const IPV4Multicast &ia);
00379 #ifdef CCXX_IPV6
00380 Error drop(const IPV6Multicast &ia);
00381 #endif
00382
00390 Error setRouting(bool enable);
00391
00392
00399 Error setNoDelay(bool enable);
00400
00412 Socket(int domain, int type, int protocol = 0);
00413
00421 Socket(SOCKET fd);
00422
00426 Socket();
00427
00435 Socket(const Socket &source);
00436
00446 ssize_t readLine(char *buf, size_t len, timeout_t timeout = 0);
00447
00459 virtual ssize_t readData(void * buf,size_t len,char separator=0,timeout_t t=0);
00460
00469 virtual ssize_t writeData(const void* buf,size_t len,timeout_t t=0);
00470
00471 public:
00479 virtual ~Socket();
00480
00487 static bool check(Family fam);
00488
00492 Socket &operator=(const Socket &from);
00493
00503 IPV4Host getIPV4Sender(tpport_t *port = NULL) const;
00504
00505 inline IPV4Host getSender(tpport_t *port = NULL) const
00506 {return getIPV4Sender(port);}
00507
00508 #ifdef CCXX_IPV6
00509 IPV6Host getIPV6Sender(tpport_t *port = NULL) const;
00510 #endif
00511
00521 IPV4Host getIPV4Peer(tpport_t *port = NULL) const;
00522
00523 inline IPV4Host getPeer(tpport_t *port = NULL) const
00524 {return getIPV4Peer(port);}
00525
00526 #ifdef CCXX_IPV6
00527 IPV6Host getIPV6Peer(tpport_t *port = NULL) const;
00528 #endif
00529
00537 IPV4Host getIPV4Local(tpport_t *port = NULL) const;
00538
00539 inline IPV4Host getLocal(tpport_t *port = NULL) const
00540 {return getIPV4Local(port);}
00541
00542 #ifdef CCXX_IPV6
00543 IPV6Host getIPV6Local(tpport_t *port = NULL) const;
00544 #endif
00545
00573 IPV4Host getIPV4NAT(tpport_t *port = NULL) const;
00574
00575 inline IPV4Host getNAT(tpport_t *port) const
00576 {return getIPV4NAT(port);}
00577
00578 #ifdef CCXX_IPV6
00579 IPV6Host getIPV6NAT(tpport_t *port = NULL) const;
00580 #endif
00581
00592 void setCompletion(bool immediate);
00593
00599 Error setLinger(bool linger);
00600
00608 Error setKeepAlive(bool enable);
00609
00618 Error setTypeOfService(Tos service);
00619
00628 bool isConnected(void) const;
00629
00637 bool isActive(void) const;
00638
00643 bool operator!() const;
00644
00651 inline bool isBroadcast(void) const
00652 {return flags.broadcast;};
00653
00659 inline bool isRouted(void) const
00660 {return flags.route;};
00661
00668 inline Error getErrorNumber(void) const {return errid;}
00669
00676 inline const char *getErrorString(void) const {return errstr;}
00677
00678 inline long getSystemError(void) const {return syserr;}
00679
00680 const char *getSystemErrorString(void) const;
00681
00691 virtual bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
00692 };
00693
00720 class __EXPORT DCCPSocket : public Socket
00721 {
00722 union {
00723 struct sockaddr_in ipv4;
00724 #ifdef CCXX_IPV6
00725 struct sockaddr_in6 ipv6;
00726 #endif
00727 } peer;
00728
00729 Family family;
00730
00731 public:
00743 virtual bool onAccept(const IPV4Host &ia, tpport_t port);
00744 #ifdef CCXX_IPV6
00745 virtual bool onAccept(const IPV6Host &ia, tpport_t port);
00746 #endif
00747
00759 DCCPSocket(const IPV4Address &bind, tpport_t port, unsigned backlog = 5);
00760 #ifdef CCXX_IPV6
00761 DCCPSocket(const IPV6Address &bind, tpport_t port, unsigned backlog = 5);
00762 #endif
00763
00773 DCCPSocket(const char *name, Family family = IPV4, unsigned backlog = 5);
00774
00778 DCCPSocket(Family family = IPV4);
00779
00783 DCCPSocket(DCCPSocket& server, timeout_t timeout = 0);
00784
00788 void reject(void);
00789
00793 void disconnect(void);
00794
00798 bool setCCID(uint8_t ccid);
00799
00807 void connect(const IPV4Host &host, tpport_t port, timeout_t timeout = 0);
00808 #ifdef CCXX_IPV6
00809 void connect(const IPV6Host &host, tpport_t port, timeout_t timeout = 0);
00810 #endif
00811
00815 void connect(const char *name);
00816
00822 inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF)
00823 {return Socket::isPending(Socket::pendingInput, timeout);}
00824
00828 virtual ~DCCPSocket();
00829 };
00830
00863 class __EXPORT UDPSocket : public Socket
00864 {
00865 private:
00866 inline Error setKeepAlive(bool enable)
00867 {return Socket::setKeepAlive(enable);};
00868
00869 protected:
00870 #ifdef CCXX_IPV6
00871 union {
00872 struct sockaddr_in6 ipv6;
00873 struct sockaddr_in ipv4;
00874 } peer;
00875 #else
00876 union {
00877 struct sockaddr_in ipv4;
00878 } peer;
00879 #endif
00880
00881 Family family;
00882
00883 public:
00887 UDPSocket(Family family = IPV4);
00888
00892 UDPSocket(const char *name, Family family = IPV4);
00893
00903 UDPSocket(const IPV4Address &bind, tpport_t port);
00904 #ifdef CCXX_IPV6
00905 UDPSocket(const IPV6Address &bind, tpport_t port);
00906 #endif
00907
00911 virtual ~UDPSocket();
00912
00916 inline Error setLoopback(bool enable)
00917 {return Socket::setLoopbackByFamily(enable, family);}
00918
00922 inline Error setMulticast(bool enable)
00923 {return Socket::setMulticastByFamily(enable, family);}
00924
00928 inline Error setTimeToLive(char ttl)
00929 {return Socket::setTimeToLiveByFamily(ttl, family);}
00930
00938 void setPeer(const IPV4Host &host, tpport_t port);
00939 void connect(const IPV4Host &host, tpport_t port);
00940 #ifdef CCXX_IPV6
00941 void setPeer(const IPV6Host &host, tpport_t port);
00942 void connect(const IPV6Host &host, tpport_t port);
00943 #endif
00944
00952 Socket::Error getInterfaceIndex(const char *ethX,int& InterfaceIndex);
00953
00962 Socket::Error join(const IPV4Multicast &ia,int InterfaceIndex);
00963
00964
00972 ssize_t send(const void *buf, size_t len);
00973
00982 ssize_t receive(void *buf, size_t len, bool reply = false);
00983
00992 IPV4Host getIPV4Peer(tpport_t *port = NULL) const;
00993 inline IPV4Host getPeer(tpport_t *port = NULL) const
00994 {return getIPV4Peer(port);}
00995
00996 #ifdef CCXX_IPV6
00997 IPV6Host getIPV6Peer(tpport_t *port = NULL) const;
00998 #endif
00999
01007 inline ssize_t peek(void *buf, size_t len)
01008 {return _IORET64 ::recv(so, (char *)buf, _IOLEN64 len, MSG_PEEK);};
01009
01013 void setPeer(const char *service);
01014 void connect(const char *service);
01015
01020 Error disconnect(void);
01021 };
01022
01023
01032 class __EXPORT UDPBroadcast : public UDPSocket
01033 {
01034 private:
01035 void setPeer(const IPV4Host &ia, tpport_t port);
01036
01037 Error setBroadcast(bool enable)
01038 {return Socket::setBroadcast(enable);};
01039
01040 public:
01047 UDPBroadcast(const IPV4Address &ia, tpport_t port);
01048
01055 void setPeer(const IPV4Broadcast &subnet, tpport_t port);
01056 };
01057
01066 class __EXPORT UDPTransmit : protected UDPSocket
01067 {
01068 private:
01076 Error cConnect(const IPV4Address &ia, tpport_t port);
01077
01078 protected:
01082 UDPTransmit(Family family = IPV4);
01083
01095 UDPTransmit(const IPV4Address &bind, tpport_t port = 5005);
01096 #ifdef CCXX_IPV6
01097 UDPTransmit(const IPV6Address &bind, tpport_t port = 5005);
01098 #endif
01099
01109 Error connect(const IPV4Host &host, tpport_t port);
01110 #ifdef CCXX_IPV6
01111 Error connect(const IPV6Address &host, tpport_t port);
01112 #endif
01113
01123 Error connect(const IPV4Broadcast &subnet, tpport_t port);
01124
01132 Error connect(const IPV4Multicast &mgroup, tpport_t port);
01133 #ifdef CCXX_IPV6
01134 Error connect(const IPV6Multicast &mgroup, tpport_t port);
01135 #endif
01136
01144 inline ssize_t send(const void *buf, size_t len)
01145 {return _IORET64 ::send(so, (const char *)buf, _IOLEN64 len, MSG_NOSIGNAL);}
01146
01150 inline void endTransmitter(void)
01151 {Socket::endSocket();}
01152
01153
01154
01155
01156
01157
01158 inline SOCKET getTransmitter(void)
01159 {return so;};
01160
01161 inline Error setMulticast(bool enable)
01162 {return Socket::setMulticastByFamily(enable, family);}
01163
01164 inline Error setTimeToLive(unsigned char ttl)
01165 {return Socket::setTimeToLiveByFamily(ttl, family);};
01166
01167 public:
01177 inline ssize_t transmit(const char *buffer, size_t len)
01178 {return _IORET64 ::send(so, buffer, _IOLEN64 len, MSG_DONTWAIT|MSG_NOSIGNAL);}
01179
01186 inline bool isOutputReady(unsigned long timeout = 0l)
01187 {return Socket::isPending(Socket::pendingOutput, timeout);};
01188
01189
01190 inline Error setRouting(bool enable)
01191 {return Socket::setRouting(enable);};
01192
01193 inline Error setTypeOfService(Tos tos)
01194 {return Socket::setTypeOfService(tos);};
01195
01196 inline Error setBroadcast(bool enable)
01197 {return Socket::setBroadcast(enable);};
01198 };
01199
01208 class __EXPORT UDPReceive : protected UDPSocket
01209 {
01210 protected:
01221 UDPReceive(const IPV4Address &bind, tpport_t port);
01222 #ifdef CCXX_IPV6
01223 UDPReceive(const IPV6Address &bind, tpport_t port);
01224 #endif
01225
01235 Error connect(const IPV4Host &host, tpport_t port);
01236 #ifdef CCXX_IPV6
01237 Error connect(const IPV6Host &host, tpport_t port);
01238 #endif
01239
01246 bool isPendingReceive(timeout_t timeout)
01247 {return Socket::isPending(Socket::pendingInput, timeout);};
01248
01252 inline void endReceiver(void)
01253 {Socket::endSocket();}
01254
01255 inline SOCKET getReceiver(void) const
01256 {return so;};
01257
01258 inline Error setRouting(bool enable)
01259 {return Socket::setRouting(enable);}
01260
01261 inline Error setMulticast(bool enable)
01262 {return Socket::setMulticastByFamily(enable, family);}
01263
01264 inline Error join(const IPV4Multicast &ia)
01265 {return Socket::join(ia);}
01266
01267 #ifdef CCXX_IPV6
01268 inline Error join(const IPV6Multicast &ia)
01269 {return Socket::join(ia);}
01270 #endif
01271
01272 inline Error drop(const IPV4Multicast &ia)
01273 {return Socket::drop(ia);}
01274
01275 #ifdef CCXX_IPV6
01276 inline Error drop(const IPV6Multicast &ia)
01277 {return Socket::drop(ia);}
01278 #endif
01279
01280 public:
01288 inline ssize_t receive(void *buf, size_t len)
01289 {return _IORET64 ::recv(so, (char *)buf, _IOLEN64 len, 0);};
01290
01297 inline bool isInputReady(timeout_t timeout = TIMEOUT_INF)
01298 {return Socket::isPending(Socket::pendingInput, timeout);};
01299 };
01300
01311 class __EXPORT UDPDuplex : public UDPTransmit, public UDPReceive
01312 {
01313 public:
01321 UDPDuplex(const IPV4Address &bind, tpport_t port);
01322 #ifdef CCXX_IPV6
01323 UDPDuplex(const IPV6Address &bind, tpport_t port);
01324 #endif
01325
01335 Error connect(const IPV4Host &host, tpport_t port);
01336 #ifdef CCXX_IPV6
01337 Error connect(const IPV6Host &host, tpport_t port);
01338 #endif
01339
01346 Error disconnect(void);
01347 };
01348
01349
01374 class __EXPORT TCPSocket : protected Socket
01375 {
01376 protected:
01377 int segsize;
01378 void setSegmentSize(unsigned mss);
01379
01380 public:
01392 virtual bool onAccept(const IPV4Host &ia, tpport_t port);
01393
01397 inline SOCKET getSocket(void)
01398 {return so;};
01399
01403 inline int getSegmentSize(void)
01404 {return segsize;};
01405
01418 TCPSocket(const IPV4Address &bind, tpport_t port, unsigned backlog = 5, unsigned mss = 536);
01419
01430 TCPSocket(const char *name, unsigned backlog = 5, unsigned mss = 536);
01431
01440 inline IPV4Host getRequest(tpport_t *port = NULL) const
01441 {return Socket::getIPV4Sender(port);}
01442
01446 void reject(void);
01447
01451 inline IPV4Host getLocal(tpport_t *port = NULL) const
01452 {return Socket::getIPV4Local(port);}
01453
01459 inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF)
01460 {return Socket::isPending(Socket::pendingInput, timeout);}
01461
01465 virtual ~TCPSocket();
01466 };
01467
01468 #ifdef CCXX_IPV6
01469
01493 class __EXPORT TCPV6Socket : protected Socket
01494 {
01495 private:
01496 int segsize;
01497 void setSegmentSize(unsigned mss);
01498
01499 public:
01511 virtual bool onAccept(const IPV6Host &ia, tpport_t port);
01512
01516 inline SOCKET getSocket(void)
01517 {return so;};
01518
01519 inline int getSegmentSize(void)
01520 {return segsize;};
01521
01534 TCPV6Socket(const IPV6Address &bind, tpport_t port, unsigned backlog = 5, unsigned mss = 536);
01535
01546 TCPV6Socket(const char *name, unsigned backlog = 5, unsigned mss = 536);
01547
01556 inline IPV6Host getRequest(tpport_t *port = NULL) const
01557 {return Socket::getIPV6Sender(port);}
01558
01562 void reject(void);
01563
01567 inline IPV6Host getLocal(tpport_t *port = NULL) const
01568 {return Socket::getIPV6Local(port);}
01569
01575 inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF)
01576 {return Socket::isPending(Socket::pendingInput, timeout);}
01577
01581 virtual ~TCPV6Socket();
01582 };
01583
01584 #endif
01585
01586
01587
01588
01589
01590
01591
01592
01593 #ifdef _MSC_VER
01594 #pragma warning(disable:4275) // disable C4275 warning
01595 #endif
01596
01610 class __EXPORT TCPStream : protected std::streambuf, public Socket, public std::iostream
01611 {
01612 private:
01613 int doallocate();
01614
01615 void segmentBuffering(unsigned mss);
01616
01617 friend TCPStream& crlf(TCPStream&);
01618 friend TCPStream& lfcr(TCPStream&);
01619
01620 protected:
01621 timeout_t timeout;
01622 size_t bufsize;
01623 Family family;
01624 char *gbuf, *pbuf;
01625
01626 public:
01631 TCPStream(Family family = IPV4, bool throwflag = true, timeout_t to = 0);
01632
01636 void disconnect(void);
01637
01641 int getSegmentSize(void);
01642
01643 protected:
01650 void allocate(size_t size);
01651
01656 void endStream(void);
01657
01664 int underflow();
01665
01674 int uflow();
01675
01683 int overflow(int ch);
01684
01693 void connect(const IPV4Host &host, tpport_t port, unsigned mss = 536);
01694 #ifdef CCXX_IPV6
01695 void connect(const IPV6Host &host, tpport_t port, unsigned mss = 536);
01696 #endif
01697
01705 void connect(const char *name, unsigned mss = 536);
01706
01714 std::iostream *tcp(void)
01715 {return ((std::iostream *)this);};
01716
01717 public:
01727 TCPStream(TCPSocket &server, bool throwflag = true, timeout_t timeout = 0);
01728 #ifdef CCXX_IPV6
01729 TCPStream(TCPV6Socket &server, bool throwflag = true, timeout_t timeout = 0);
01730 #endif
01731
01737 void connect(TCPSocket &server);
01738 #ifdef CCXX_IPV6
01739 void connect(TCPV6Socket &server);
01740 #endif
01741
01752 TCPStream(const IPV4Host &host, tpport_t port, unsigned mss = 536, bool throwflag = true, timeout_t timeout = 0);
01753 #ifdef CCXX_IPV6
01754 TCPStream(const IPV6Host &host, tpport_t port, unsigned mss = 536, bool throwflag = true, timeout_t timeout = 0);
01755 #endif
01756
01766 TCPStream(const char *name, Family family = IPV4, unsigned mss = 536, bool throwflag = false, timeout_t timer = 0);
01767
01773 inline void setTimeout(timeout_t timer)
01774 {timeout = timer;};
01775
01782 TCPStream(const TCPStream &source);
01783
01788 virtual ~TCPStream();
01789
01796 int sync(void);
01797
01798 #ifdef HAVE_SNPRINTF
01799
01805 size_t printf(const char *format, ...);
01806 #endif
01807
01815 bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
01816
01824 inline ssize_t peek(void *buf, size_t len)
01825 {return _IORET64 ::recv(so, (char *)buf, _IOLEN64 len, MSG_PEEK);};
01826
01832 inline size_t getBufferSize(void) const
01833 {return bufsize;};
01834 };
01835
01846 class __EXPORT TCPSession : public Thread, public TCPStream
01847 {
01848 private:
01849 TCPSession(const TCPSession &rhs);
01850 protected:
01863 int waitConnection(timeout_t timeout = TIMEOUT_INF);
01864
01871 void initial(void);
01872
01873 public:
01884 TCPSession(const IPV4Host &host,
01885 tpport_t port, size_t size = 536, int pri = 0, size_t stack = 0);
01886 #ifdef CCXX_IPV6
01887 TCPSession(const IPV6Host &host,
01888 tpport_t port, size_t size = 536, int pri = 0, size_t stack = 0);
01889 #endif
01890
01900 TCPSession(TCPSocket &server, int pri = 0, size_t stack = 0);
01901 #ifdef CCXX_IPV6
01902 TCPSession(TCPV6Socket &server, int pri = 0, size_t stack = 0);
01903 #endif
01904
01908 virtual ~TCPSession();
01909 };
01910
01911 #if defined(WIN32)
01912
01922 class init_WSA
01923 {
01924 public:
01925 init_WSA();
01926 ~init_WSA();
01927 };
01928
01929 #endif // WIN32
01930
01931 class __EXPORT SimpleTCPStream;
01932
01944 class __EXPORT SimpleTCPStream : public Socket
01945 {
01946 private:
01947
01948 IPV4Host getSender(tpport_t *port) const;
01949
01950 protected:
01955 SimpleTCPStream();
01956
01961 void endStream(void);
01962
01971 void Connect(const IPV4Host &host, tpport_t port, size_t size);
01972
01973
01974 public:
01983 SimpleTCPStream(TCPSocket &server, size_t size = 512);
01984
01993 SimpleTCPStream(const IPV4Host &host, tpport_t port, size_t size = 512);
01994
02000 SimpleTCPStream(const SimpleTCPStream &source);
02001
02006 virtual ~SimpleTCPStream();
02007
02019 bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
02020
02021 void flush() {}
02022
02034 ssize_t read(char *bytes, size_t length, timeout_t timeout = 0);
02035
02047 ssize_t write(const char *bytes, size_t length, timeout_t timeout = 0);
02048
02062 ssize_t peek(char *bytes, size_t length, timeout_t timeout = 0);
02063
02064 };
02065
02066 #ifdef COMMON_STD_EXCEPTION
02067 class __EXPORT SockException : public IOException
02068 {
02069 private:
02070 Socket::Error _socketError;
02071
02072 public:
02073 SockException(const String &str, Socket::Error socketError, long systemError = 0) :
02074 IOException(str, systemError), _socketError(socketError) {};
02075
02076 inline Socket::Error getSocketError() const
02077 { return _socketError; }
02078 };
02079 #endif
02080
02081 #ifdef CCXX_NAMESPACES
02082 }
02083 #endif
02084
02085 #endif
02086