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 #ifndef TCP_SOCKET_H
00030 #define TCP_SOCKET_H
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #include "Source.h"
00040 #include "Sink.h"
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00057 class TcpSocket : public Source, public Sink
00058 {
00059 private:
00060
00064 char * host;
00065
00069 unsigned short port;
00070
00074 int sockfd;
00075
00083 void
00084 init ( const char * host,
00085 unsigned short port ) throw ( Exception );
00086
00092 void
00093 strip ( void ) throw ( Exception );
00094
00095
00096 protected:
00097
00103 inline
00104 TcpSocket ( void ) throw ( Exception )
00105 {
00106 throw Exception( __FILE__, __LINE__);
00107 }
00108
00109
00110 public:
00111
00119 inline
00120 TcpSocket( const char * host,
00121 unsigned short port ) throw ( Exception )
00122 {
00123 init( host, port);
00124 }
00125
00132 TcpSocket( const TcpSocket & ss ) throw ( Exception );
00133
00139 inline virtual
00140 ~TcpSocket( void ) throw ( Exception )
00141 {
00142 strip();
00143 }
00144
00152 inline virtual TcpSocket &
00153 operator= ( const TcpSocket & ss ) throw ( Exception );
00154
00160 inline const char *
00161 getHost ( void ) const throw ()
00162 {
00163 return host;
00164 }
00165
00171 inline unsigned int
00172 getPort ( void ) const throw ()
00173 {
00174 return port;
00175 }
00176
00183 virtual bool
00184 open ( void ) throw ( Exception );
00185
00191 inline virtual bool
00192 isOpen ( void ) const throw ()
00193 {
00194 return sockfd != 0;
00195 }
00196
00207 virtual bool
00208 canRead ( unsigned int sec,
00209 unsigned int usec ) throw ( Exception );
00210
00219 virtual unsigned int
00220 read ( void * buf,
00221 unsigned int len ) throw ( Exception );
00222
00223
00234 virtual bool
00235 canWrite ( unsigned int sec,
00236 unsigned int usec ) throw ( Exception );
00237
00246 virtual unsigned int
00247 write ( const void * buf,
00248 unsigned int len ) throw ( Exception );
00249
00256 inline virtual void
00257 flush ( void ) throw ( Exception )
00258 {
00259 }
00260
00266 virtual void
00267 close ( void ) throw ( Exception );
00268 };
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 #endif
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297