Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

socketport.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2003 Open Source Telecom Corporation. 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 // 00017 // As a special exception to the GNU General Public License, permission is 00018 // granted for additional uses of the text contained in its release 00019 // of Common C++. 00020 // 00021 // The exception is that, if you link the Common C++ library with other files 00022 // to produce an executable, this does not by itself cause the 00023 // resulting executable to be covered by the GNU General Public License. 00024 // Your use of that executable is in no way restricted on account of 00025 // linking the Common C++ library code into it. 00026 // 00027 // This exception does not however invalidate any other reasons why 00028 // the executable file might be covered by the GNU General Public License. 00029 // 00030 // This exception applies only to the code released under the 00031 // name Common C++. If you copy code from other releases into a copy of 00032 // Common C++, as the General Public License permits, the exception does 00033 // not apply to the code that you add in this way. To avoid misleading 00034 // anyone as to the status of such modified files, you must delete 00035 // this exception notice from them. 00036 // 00037 // If you write modifications of your own for Common C++, it is your choice 00038 // whether to permit this exception to apply to your modifications. 00039 // If you do not wish that, delete this exception notice. 00040 00046 #ifndef CCXX_SOCKETPORT_H_ 00047 #define CCXX_SOCKETPORT_H_ 00048 00049 #ifndef CCXX_ADDRESS_H_ 00050 #include <cc++/address.h> 00051 #endif 00052 00053 #ifndef CCXX_SOCKET_H_ 00054 #include <cc++/socket.h> 00055 #endif 00056 00057 #ifdef CCXX_NAMESPACES 00058 namespace ost { 00059 #endif 00060 00061 class __EXPORT SocketPort; 00062 class __EXPORT SocketService; 00063 00083 class __EXPORT SocketPort : public Socket, public TimerPort 00084 { 00085 private: 00086 SocketPort *next, *prev; 00087 SocketService *service; 00088 #ifndef WIN32 00089 struct timeval porttimer; 00090 #ifdef USE_POLL 00091 struct pollfd * ufd; 00092 #endif 00093 #else 00094 HANDLE event; 00095 #endif 00096 bool detect_pending; 00097 bool detect_output; 00098 bool detect_disconnect; 00099 00100 friend class SocketService; 00101 00102 protected: 00111 SocketPort(SocketService *svc, TCPSocket &tcp); 00112 #ifdef CCXX_IPV6 00113 SocketPort(SocketService *svc, TCPV6Socket &tcp); 00114 #endif 00115 00124 SocketPort(SocketService *svc, const IPV4Address &ia, tpport_t port); 00125 #ifdef CCXX_IPV6 00126 SocketPort(SocketService *svc, const IPV6Address &ia, tpport_t port); 00127 #endif 00128 00142 SocketPort(SocketService *svc, const IPV4Host &ih, tpport_t port); 00143 #ifdef CCXX_IPV6 00144 SocketPort(SocketService *svc, const IPV6Host &ih, tpport_t port); 00145 #endif 00146 00152 void attach( SocketService* svc ); 00153 00154 00159 virtual ~SocketPort(); 00160 00165 void setDetectPending( bool ); 00166 00170 bool getDetectPending( void ) const 00171 { return detect_pending; } 00172 00177 void setDetectOutput( bool ); 00178 00182 bool getDetectOutput( void ) const 00183 { return detect_output; } 00184 00189 virtual void expired(void) 00190 {return;}; 00191 00196 virtual void pending(void) 00197 {return;}; 00198 00203 virtual void output(void) 00204 {return;}; 00205 00210 virtual void disconnect(void) 00211 {return;}; 00212 00223 Error connect(const IPV4Address &ia, tpport_t port); 00224 #ifdef CCXX_IPV6 00225 Error connect(const IPV6Address &ia, tpport_t port); 00226 #endif 00227 00237 inline ssize_t send(const void *buf, size_t len) 00238 {return _IORET64 ::send(so, (const char *)buf, _IOLEN64 len, 0);}; 00239 00248 inline ssize_t receive(void *buf, size_t len) 00249 {return _IORET64 ::recv(so, (char *)buf, _IOLEN64 len, 0);}; 00250 00259 inline ssize_t peek(void *buf, size_t len) 00260 {return _IORET64 ::recv(so, (char *)buf, _IOLEN64 len, MSG_PEEK);}; 00261 00262 public: 00270 void setTimer(timeout_t timeout = 0); 00271 00279 void incTimer(timeout_t timeout); 00280 }; 00281 00294 class __EXPORT SocketService : public Thread, private Mutex 00295 { 00296 private: 00297 #ifndef WIN32 00298 fd_set connect; 00299 int iosync[2]; 00300 int hiwater; 00301 #else 00302 // private syncronization class 00303 class Sync; 00304 Sync* sync; 00305 #endif 00306 int volatile count; 00307 SocketPort* volatile first, *last; 00308 00314 void attach(SocketPort *port); 00320 void detach(SocketPort *port); 00321 00325 void run(void); 00326 00327 friend class SocketPort; 00328 00329 protected: 00335 virtual void onUpdate(unsigned char buf) 00336 {return;}; 00337 00343 virtual void onEvent(void) 00344 {return;}; 00345 00353 virtual void onCallback(SocketPort *port) 00354 {return;}; 00355 00356 public: 00367 void update(unsigned char flag = 0xff); 00368 00377 SocketService(int pri = 0, size_t stack = 0, const char *id = NULL); 00378 00383 virtual ~SocketService(); 00384 00391 inline int getCount(void) const 00392 {return count;}; 00393 }; 00394 00395 #ifdef CCXX_NAMESPACES 00396 } 00397 #endif 00398 00399 #endif 00400

Generated on Fri Jan 21 13:36:02 2005 for GNU CommonC++ by doxygen 1.3.8