ANNA Suite  2020b
Multipurpose development suite for Telco applications
ServerSocket.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_comm_ServerSocket_hpp
10 #define anna_comm_ServerSocket_hpp
11 
14 
15 #include <anna/comm/Socket.hpp>
17 
18 namespace anna {
19 
20 namespace comm {
21 
22 class INetAddress;
23 class BinderSocket;
24 
37 class ServerSocket : public Socket {
38 public:
44 
46 
50  static const int defaultBacklog = 30;
51 
60  Socket(domain, type, transportFactory),
61  a_backlog(defaultBacklog),
62  a_sharedBind(false),
63  a_binderSocket(NULL),
64  a_msBindDelay(DefaultBindDelay) {}
65 
74  ServerSocket(const INetAddress& localAddress, const bool sharedBind, TransportFactory* transportFactory = NULL) :
75  Socket(localAddress, Socket::Type::Stream, transportFactory),
76  a_backlog(defaultBacklog),
77  a_sharedBind(sharedBind),
78  a_binderSocket(NULL),
79  a_msBindDelay(DefaultBindDelay) {}
80 
84  virtual ~ServerSocket();
85 
92  const Millisecond &getBindDelay() { return a_msBindDelay; }
93 
98  BinderSocket* getBinderSocket() { return a_binderSocket; }
99 
106  bool isSharedBind() const { return a_sharedBind; }
107 
112  void setBacklog(const int backlog) { a_backlog = backlog; }
113 
125  void setBindDelay(const Millisecond &bindDelay) { a_msBindDelay = bindDelay; }
126 
131  virtual void prepare() noexcept(false);
132 
145  LocalConnection* accept() noexcept(false);
146 
155  void release(LocalConnection* localConnection) noexcept(false);
156 
161  iterator begin() { return a_localConnections.begin(); }
162 
167  iterator end() { return a_localConnections.end(); }
168 
173  virtual std::string asString() const ;
174 
180  virtual xml::Node* asXML(xml::Node* parent) const noexcept(false);
181 
194  virtual bool eventAcceptConnection(const ClientSocket &clientSocket) noexcept(false) { return true; }
195 
196 // /**
197 // Informa sobre la rotura de una conexion que se creo a partir de un ServerSocket
198 //
199 // @param localConnection Socket que se acepto sobre el server socket y que se ha roto.
200 // */
201 // virtual void eventBreakLocalConnection (LocalConnection* localConnection) noexcept(false) {;}
202 
203 
209 
214  static const char* className() { return "anna::comm::ServerSocket"; }
215 
216 protected:
227  ServerSocket(const INetAddress& localAddress, const bool sharedBind, Type::_v type, TransportFactory* transportFactory = NULL) :
228  Socket(localAddress, type, transportFactory),
229  a_backlog(defaultBacklog),
230  a_sharedBind(false),
231  a_binderSocket(NULL),
232  a_msBindDelay(DefaultBindDelay) {}
233 
234 private:
235  int a_backlog;
236  Recycler <LocalConnection> a_localConnections;
237  const bool a_sharedBind;
238  BinderSocket* a_binderSocket;
239  Millisecond a_msBindDelay;
240 
241  virtual ClientSocket* allocateClientSocket() const ;
242  int do_bind(const struct sockaddr *, const int len) noexcept(false);
243 
244  friend class BinderSocket;
245 };
246 
247 }
248 }
249 
250 
251 #endif
252 
253 
254 
Definition: INetAddress.hpp:34
void setBacklog(const int backlog)
Definition: ServerSocket.hpp:112
static T * data(iterator ii)
Definition: Recycler.hpp:233
Definition: Millisecond.hpp:24
void release(LocalConnection *localConnection) noexcept(false)
iterator begin()
Definition: ServerSocket.hpp:161
Definition: Node.hpp:56
static const Millisecond DefaultBindDelay
Definition: ServerSocket.hpp:43
Definition: LocalConnection.hpp:31
static const int defaultBacklog
Definition: ServerSocket.hpp:50
Definition: Socket.hpp:44
void setBindDelay(const Millisecond &bindDelay)
Definition: ServerSocket.hpp:125
Definition: ClientSocket.hpp:38
iterator end()
Definition: ServerSocket.hpp:167
virtual xml::Node * asXML(xml::Node *parent) const noexcept(false)
ServerSocket(const INetAddress &localAddress, const bool sharedBind, Type::_v type, TransportFactory *transportFactory=NULL)
Definition: ServerSocket.hpp:227
LocalConnection * accept() noexcept(false)
Definition: Socket.hpp:49
bool isSharedBind() const
Definition: ServerSocket.hpp:106
_v
Definition: Socket.hpp:49
_v
Definition: Socket.hpp:44
Definition: Recycler.hpp:30
container::iterator iterator
Definition: Recycler.hpp:33
Definition: BinderSocket.hpp:27
Definition: Socket.hpp:39
Definition: ServerSocket.hpp:37
static LocalConnection * localConnection(iterator &ii)
Definition: ServerSocket.hpp:208
virtual std::string asString() const
Definition: app.hpp:12
const Millisecond & getBindDelay()
Definition: ServerSocket.hpp:92
ServerSocket(const INetAddress &localAddress, const bool sharedBind, TransportFactory *transportFactory=NULL)
Definition: ServerSocket.hpp:74
static const char * className()
Definition: ServerSocket.hpp:214
Definition: Socket.hpp:49
virtual bool eventAcceptConnection(const ClientSocket &clientSocket) noexcept(false)
Definition: ServerSocket.hpp:194
Definition: TransportFactory.hpp:30
ServerSocket(TransportFactory *transportFactory=NULL, Domain::_v domain=Socket::Domain::Inet, Type::_v type=Socket::Type::Stream)
Definition: ServerSocket.hpp:59
Recycler< LocalConnection >::iterator iterator
Definition: ServerSocket.hpp:45
BinderSocket * getBinderSocket()
Definition: ServerSocket.hpp:98
virtual void prepare() noexcept(false)