activemq-cpp-3.9.5
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
25
31
32#include <string>
33
34namespace decaf {
35namespace net {
36
37 class Socket;
38 class SocketImpl;
39
50 class DECAF_API ServerSocket {
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
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
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
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
Represents an IP address.
Definition InetAddress.h:33
ServerSocket()
Creates a non-bound server socket.
ServerSocket(int port, int backlog, const InetAddress *address)
Creates a new ServerSocket bound to the specified port, if the value of port is 0,...
virtual void bind(const std::string &host, int port, int backlog)
Bind and listen to given local IPAddress and port, if the address is empty than a valid local address...
virtual int getDefaultBacklog()
Allows a subclass to override what is considered the default backlog.
virtual ~ServerSocket()
Releases socket handle if close() hasn't been called.
ServerSocket(int port, int backlog)
Creates a new ServerSocket bound to the specified port, if the value of port is 0,...
virtual void close()
Closes the server socket, causing any Threads blocked on an accept call to throw an Exception.
virtual bool getReuseAddress() const
Gets the reuse address flag, SO_REUSEADDR.
virtual bool isClosed() const
virtual int getReceiveBufferSize() const
Gets the receive buffer size for this socket, SO_RCVBUF.
virtual int getLocalPort() const
Gets the port number on the Local machine that this ServerSocket is bound to.
virtual void setSoTimeout(int timeout)
Sets the timeout for socket operations, SO_TIMEOUT.
ServerSocket(SocketImpl *impl)
Creates a ServerSocket wrapping the provided SocketImpl instance, this Socket is considered unconnect...
void ensureCreated() const
virtual std::string toString() const
virtual int getSoTimeout() const
Gets the timeout for socket operations, SO_TIMEOUT.
ServerSocket(int port)
Creates a new ServerSocket bound to the specified port, if the value of port is 0,...
virtual void setReceiveBufferSize(int size)
Sets the receive buffer size for this socket, SO_RCVBUF.
virtual void setReuseAddress(bool reuse)
Sets the reuse address flag, SO_REUSEADDR.
static void setSocketImplFactory(SocketImplFactory *factory)
Sets the instance of a SocketImplFactory that the ServerSocket class should use when new instances of...
void setupSocketImpl(int port, int backlog, const InetAddress *ifAddress)
virtual bool isBound() const
virtual Socket * accept()
Listens for a connection request on the bound IPAddress and Port for this ServerSocket,...
virtual void implAccept(Socket *socket)
Virtual method that allows a ServerSocket subclass to override the accept call and provide its own So...
virtual void bind(const std::string &host, int port)
Bind and listen to given local IPAddress and port, if the address is empty than a valid local address...
Definition Socket.h:44
Factory class interface for a Factory that creates ScoketImpl objects.
Definition SocketImplFactory.h:38
Acts as a base class for all physical Socket implementations.
Definition SocketImpl.h:42
#define DECAF_API
Definition Config.h:29
Definition URLStreamHandlerManager.h:26
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25