00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _DECAF_NET_SERVERSOCKET_H_
00018 #define _DECAF_NET_SERVERSOCKET_H_
00019
00020 #include <decaf/util/Config.h>
00021
00022 #include <decaf/net/InetAddress.h>
00023 #include <decaf/net/SocketImpl.h>
00024 #include <decaf/net/SocketImplFactory.h>
00025
00026 #include <decaf/lang/exceptions/NullPointerException.h>
00027 #include <decaf/lang/exceptions/IllegalArgumentException.h>
00028 #include <decaf/net/UnknownHostException.h>
00029 #include <decaf/net/SocketTimeoutException.h>
00030 #include <decaf/io/IOException.h>
00031
00032 #include <string>
00033
00034 namespace decaf{
00035 namespace net{
00036
00037 class Socket;
00038 class SocketImpl;
00039
00050 class DECAF_API ServerSocket {
00051 private:
00052
00053
00054 static SocketImplFactory* factory;
00055
00056
00057 mutable SocketImpl* impl;
00058 mutable volatile bool created;
00059
00060 bool closed;
00061 bool bound;
00062
00063 int backlog;
00064 int port;
00065
00066 private:
00067
00068 ServerSocket( const ServerSocket& );
00069 ServerSocket& operator= ( const ServerSocket& );
00070
00071 public:
00072
00076 ServerSocket();
00077
00094 ServerSocket( int port );
00095
00115 ServerSocket( int port, int backlog );
00116
00139 ServerSocket( int port, int backlog, const InetAddress* address );
00140
00144 virtual ~ServerSocket();
00145
00146 protected:
00147
00158 ServerSocket( SocketImpl* impl );
00159
00160 public:
00161
00175 virtual void bind( const std::string& host, int port );
00176
00195 virtual void bind( const std::string& host, int port, int backlog );
00196
00209 virtual Socket* accept();
00210
00217 virtual void close();
00218
00222 virtual bool isClosed() const;
00223
00227 virtual bool isBound() const;
00228
00237 virtual int getReceiveBufferSize() const;
00238
00248 virtual void setReceiveBufferSize( int size );
00249
00257 virtual bool getReuseAddress() const;
00258
00267 virtual void setReuseAddress( bool reuse );
00268
00276 virtual int getSoTimeout() const;
00277
00288 virtual void setSoTimeout( int timeout );
00289
00295 virtual int getLocalPort() const;
00296
00300 virtual std::string toString() const;
00301
00302 public:
00303
00315 static void setSocketImplFactory( SocketImplFactory* factory );
00316
00317 protected:
00318
00328 virtual void implAccept( Socket* socket );
00329
00335 virtual int getDefaultBacklog();
00336
00337 protected:
00338
00339
00340 void checkClosed() const;
00341
00342
00343 void ensureCreated() const;
00344
00345
00346 void setupSocketImpl( int port, int backlog, const InetAddress* ifAddress );
00347
00348 };
00349
00350 }}
00351
00352 #endif // _DECAF_NET_SERVERSOCKETIMPL_H_
00353