activemq-cpp-3.8.2
ServerSocket.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef _DECAF_NET_SERVERSOCKET_H_
18 #define _DECAF_NET_SERVERSOCKET_H_
19 
20 #include <decaf/util/Config.h>
21 
22 #include <decaf/net/InetAddress.h>
23 #include <decaf/net/SocketImpl.h>
25 
30 #include <decaf/io/IOException.h>
31 
32 #include <string>
33 
34 namespace decaf{
35 namespace net{
36 
37  class Socket;
38  class SocketImpl;
39 
51  private:
52 
53  // Factory for creating sockets, if not set a Plan TCP Socket is created
54  static SocketImplFactory* factory;
55 
56  // The actual Socket that this Socket represents.
57  mutable SocketImpl* impl;
58  mutable volatile bool created;
59 
60  bool closed;
61  bool bound;
62 
63  int backlog;
64  int port;
65 
66  private:
67 
68  ServerSocket( const ServerSocket& );
69  ServerSocket& operator= ( const ServerSocket& );
70 
71  public:
72 
76  ServerSocket();
77 
94  ServerSocket( int port );
95 
115  ServerSocket( int port, int backlog );
116 
139  ServerSocket( int port, int backlog, const InetAddress* address );
140 
144  virtual ~ServerSocket();
145 
146  protected:
147 
158  ServerSocket( SocketImpl* impl );
159 
160  public:
161 
175  virtual void bind( const std::string& host, int port );
176 
195  virtual void bind( const std::string& host, int port, int backlog );
196 
209  virtual Socket* accept();
210 
217  virtual void close();
218 
222  virtual bool isClosed() const;
223 
227  virtual bool isBound() const;
228 
237  virtual int getReceiveBufferSize() const;
238 
248  virtual void setReceiveBufferSize( int size );
249 
257  virtual bool getReuseAddress() const;
258 
267  virtual void setReuseAddress( bool reuse );
268 
276  virtual int getSoTimeout() const;
277 
288  virtual void setSoTimeout( int timeout );
289 
295  virtual int getLocalPort() const;
296 
300  virtual std::string toString() const;
301 
302  public:
303 
315  static void setSocketImplFactory( SocketImplFactory* factory );
316 
317  protected:
318 
328  virtual void implAccept( Socket* socket );
329 
335  virtual int getDefaultBacklog();
336 
337  protected:
338 
339  // Check for already closed and throw an error if so.
340  void checkClosed() const;
341 
342  // Create but don't connect the underlying OS Socket instance, if not already created.
343  void ensureCreated() const;
344 
345  // Binds and sets up the Listen for this Server Socket
346  void setupSocketImpl( int port, int backlog, const InetAddress* ifAddress );
347 
348  };
349 
350 }}
351 
352 #endif // _DECAF_NET_SERVERSOCKETIMPL_H_
353 
Factory class interface for a Factory that creates ScoketImpl objects.
Definition: SocketImplFactory.h:38
Definition: Socket.h:44
Represents an IP address.
Definition: InetAddress.h:33
Acts as a base class for all physical Socket implementations.
Definition: SocketImpl.h:42
#define DECAF_API
Definition: Config.h:29
This class implements server sockets.
Definition: ServerSocket.h:50
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25