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
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 #ifndef _PSOCKETS
00189 #define _PSOCKETS
00190
00191 #ifdef P_USE_PRAGMA
00192 #pragma interface
00193 #endif
00194
00195 #include <ptlib/channel.h>
00196
00197 #ifdef __NUCLEUS_PLUS__
00198 #include <sys/socket.h>
00199 #endif
00200
00201 class PSocket;
00202
00203 PLIST(PSocketList, PSocket);
00204
00205
00212 class PSocket : public PChannel
00213 {
00214 PCLASSINFO(PSocket, PChannel);
00215
00216 protected:
00217 PSocket();
00218
00219 public:
00232 virtual BOOL Connect(
00233 const PString & address
00234 );
00235
00236
00238 enum Reusability {
00239 CanReuseAddress,
00240 AddressIsExclusive
00241 };
00242
00256 virtual BOOL Listen(
00257 unsigned queueSize = 5,
00258 WORD port = 0,
00259 Reusability reuse = AddressIsExclusive
00260 );
00261
00262
00284 virtual BOOL Accept(
00285 PSocket & socket
00286 );
00287
00293 virtual BOOL Shutdown(
00294 ShutdownValue option
00295 );
00297
00306 BOOL SetOption(
00307 int option,
00308 int value,
00309 int level = SOL_SOCKET
00310 );
00311
00318 BOOL SetOption(
00319 int option,
00320 const void * valuePtr,
00321 PINDEX valueSize,
00322 int level = SOL_SOCKET
00323 );
00324
00331 BOOL GetOption(
00332 int option,
00333 int & value,
00334 int level = SOL_SOCKET
00335 );
00336
00343 BOOL GetOption(
00344 int option,
00345 void * valuePtr,
00346 PINDEX valueSize,
00347 int level = SOL_SOCKET
00348 );
00350
00358 static WORD GetProtocolByName(
00359 const PString & name
00360 );
00361
00367 static PString GetNameByProtocol(
00368 WORD proto
00369 );
00370
00371
00373 virtual WORD GetPortByService(
00374 const PString & service
00375 ) const;
00393 static WORD GetPortByService(
00394 const char * protocol,
00395 const PString & service
00396 );
00397
00399 virtual PString GetServiceByPort(
00400 WORD port
00401 ) const;
00419 static PString GetServiceByPort(
00420 const char * protocol,
00421 WORD port
00422 );
00423
00424
00426 void SetPort(
00427 WORD port
00428 );
00441 void SetPort(
00442 const PString & service
00443 );
00444
00450 WORD GetPort() const;
00451
00459 PString GetService() const;
00461
00464
00465 class SelectList : public PSocketList
00466 {
00467 PCLASSINFO(SelectList, PSocketList)
00468 public:
00469 SelectList()
00470 { DisallowDeleteObjects(); }
00472 void operator+=(PSocket & sock )
00473 { Append(&sock); }
00475 void operator-=(PSocket & sock )
00476 { Remove(&sock); }
00477 };
00478
00480 static int Select(
00481 PSocket & sock1,
00482 PSocket & sock2
00483 );
00485 static int Select(
00486 PSocket & sock1,
00487 PSocket & sock2,
00488 const PTimeInterval & timeout
00489 );
00491 static Errors Select(
00492 SelectList & read
00493 );
00495 static Errors Select(
00496 SelectList & read,
00497 const PTimeInterval & timeout
00498 );
00500 static Errors Select(
00501 SelectList & read,
00502 SelectList & write
00503 );
00505 static Errors Select(
00506 SelectList & read,
00507 SelectList & write,
00508 const PTimeInterval & timeout
00509 );
00511 static Errors Select(
00512 SelectList & read,
00513 SelectList & write,
00514 SelectList & except
PString GetNameByProtocol(
00368 WORD proto
00369 );
00370
00371
00373 virtual WORD GetPortByService(
00374 const PString & service
00375 ) const;
00393 static WORD GetPortByService(
00394 const char * protocol,
00395 const PString & service
00396 );
00397
00399 virtual PString GetServiceByPort(
00400 WORD port
00401 ) const;
00419 static PString GetServiceByPort(
00420 const char * protocol,
00421 WORD port
00422 );
00423
00424
00426 void SetPort(
00427 WORD port
00428 );
00441 void SetPort(
00442 const PString & service
00443 );
00444
00450 WORD GetPort() const;
00451
00459 PString GetService() const;
00461
00464
00465 class SelectList : public PSocketList
00466 {
00467 PCLASSINFO(SelectList, PSocketList)
00468 public:
00469 SelectList()
00470 { DisallowDeleteObjects(); }
00472 void operator+=(PSocket & sock )
00473 { Append(&sock); }
00475 void operator-=(PSocket & sock )
00476 { Remove(&sock); }
00477 };
00478
00480 static int Select(
00481 PSocket & sock1,
00482 PSocket & sock2
00483 );
00485 static int Select(
00486 PSocket & sock1,
00487 PSocket & sock2,
00488 const PTimeInterval & timeout
00489 );
00491 static Errors Select(
00492 SelectList & read
00493 );
00495 static Errors Select(
00496 SelectList & read,
00497 const PTimeInterval & timeout
00498 );
00500 static Errors Select(
00501 SelectList & read,
00502 SelectList & write
00503 );
00505 static Errors Select(
00506 SelectList & read,
00507 SelectList & write,
00508 const PTimeInterval & timeout
00509 );
00511 static Errors Select(
00512 SelectList & read,
00513 SelectList & write,
00514 SelectList & except
PString GetNameByProtocol(
00368 WORD proto
00369 );
00370
00371
00373 virtual WORD GetPortByService(
00374 const PString & service
00375 ) const;
00393 static WORD GetPortByService(
00394 const char * protocol,
00395 const PString & service
00396 );
00397
00399 virtual PString GetServiceByPort(
00400 WORD port
00401 ) const;
00419 static PString GetServiceByPort(
00420 const char * protocol,
00421 WORD port
00422 );
00423
00424
00426 void SetPort(
00427 WORD port
00428 );
00441 void SetPort(
00442 const PString & service
00443 );
00444
00450 WORD GetPort() const;
00451
00459 PString GetService() const;
00461
00464
00465 class SelectList : public PSocketList
00466 {
00467 PCLASSINFO(SelectList, PSocketList)
00468 public:
00469 SelectList()
00470 { DisallowDeleteObjects(); }
00472 void operator+=(PSocket & sock )
00473 { Append(&sock); }
00475 void operator-=(PSocket & sock )
00476 { Remove(&sock); }
00477 };
00478
00480 static int Select(
00481 PSocket & sock1,
00482 PSocket & sock2
00483 );
00485 static int Select(
00486 PSocket & sock1,
00487 PSocket & sock2,
00488 const PTimeInterval & timeout
0048