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 #ifndef CEYLAN_SOCKET_H_
00028 #define CEYLAN_SOCKET_H_
00029
00030
00031 #include "CeylanInputOutputStream.h"
00032 #include "CeylanFeatures.h"
00033 #include "CeylanTypes.h"
00034
00035
00036
00037 #include "CeylanSystem.h"
00038
00039
00040
00041
00042 namespace Ceylan
00043 {
00044
00045
00046
00047 namespace Network
00048 {
00049
00050
00051
00052
00054 class IPAddress ;
00055
00056
00057
00069 class SystemSpecificSocketAddress ;
00070
00071
00072
00077 typedef Ceylan::Uint32 Port ;
00078
00079
00080
00081
00093 class CEYLAN_DLL Socket : public System::InputOutputStream
00094 {
00095
00096
00097 public:
00098
00099
00100
00102 class CEYLAN_DLL SocketException:
00103 public System::SystemException
00104 {
00105 public:
00106
00107 explicit SocketException( const std::string & reason ) ;
00108
00109 virtual ~SocketException() throw() ;
00110
00111 } ;
00112
00113
00114
00115
00116
00117
00118
00120 virtual ~Socket() throw() ;
00121
00122
00123
00129 virtual bool isConnected() const = 0 ;
00130
00131
00132
00133
00134
00135
00136
00137
00143 virtual bool hasAvailableData() const ;
00144
00145
00146
00163 virtual System::Size read( char * buffer,
00164 System::Size maxLength ) ;
00165
00166
00167
00168
00169
00170
00171
00172
00184 virtual System::Size write( const std::string & message ) ;
00185
00186
00187
00202 virtual System::Size write( const char * buffer,
00203 System::Size maxLength ) ;
00204
00205
00206
00221 System::FileDescriptor getOriginalFileDescriptor() const ;
00222
00223
00224
00241 virtual System::FileDescriptor getFileDescriptorForTransport()
00242 const ;
00243
00244
00245
00252 virtual Port getLocalPort() const ;
00253
00254
00255
00264 virtual Port getPeerPort() const ;
00265
00266
00267
00281 virtual IPAddress * getLocalIPAddress() const ;
00282
00283
00284
00293 virtual IPAddress * getPeerIPAddress() const ;
00294
00295
00296
00305 virtual System::StreamID getInputStreamID() const ;
00306
00307
00308
00317 virtual System::StreamID getOutputStreamID() const ;
00318
00319
00320
00333 virtual const std::string toString(
00334 Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00335
00336
00337
00338
00339 protected:
00340
00341
00342
00353 explicit Socket( bool blocking = true ) ;
00354
00355
00356
00369 Socket( Port localPort, bool blocking = true ) ;
00370
00371
00372
00399 virtual void createSocket( Port localPort ) = 0 ;
00400
00401
00402
00411 virtual bool close() ;
00412
00413
00414
00426 virtual void setBlocking( bool newStatus ) ;
00427
00428
00429
00430
00441 Port _port ;
00442
00443
00444
00454 SystemSpecificSocketAddress * _address ;
00455
00456
00457
00472 System::FileDescriptor _originalFD ;
00473
00474
00475
00476
00477
00478 private:
00479
00480
00481
00490 Socket( const Socket & source ) ;
00491
00492
00493
00502 Socket & operator = ( const Socket & source ) ;
00503
00504
00505
00506 } ;
00507
00508
00509 }
00510
00511 }
00512
00513
00514
00515 #endif // CEYLAN_SOCKET_H_
00516