Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JControlHostServer.hh
Go to the documentation of this file.
1 #ifndef __JNET__JCONTROLHOSTSERVER__
2 #define __JNET__JCONTROLHOSTSERVER__
3 
4 #include <limits>
5 
6 #include "JNet/JServerSocket.hh"
7 #include "JNet/JControlHost.hh"
8 #include "JLang/JTimeval.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JNET {}
16 namespace JPP { using namespace JNET; }
17 
18 namespace JNET {
19 
20  namespace {
21  using JLANG::JTimeval;
22  }
23 
24 
25  /**
26  * Light-weight wrapper class around server socket.
27  */
29  public JServerSocket
30  {
31  public:
32  /**
33  * Constructor.
34  *
35  * \param port port number
36  * \param backlog backlog
37  */
39  const int backlog = 1) :
40  JServerSocket(port, backlog)
41  {}
42 
43 
44  /**
45  * Accept new client.
46  *
47  * \param timeout timeout
48  * \return pointer to newly created ControlHost client (or NULL)
49  */
51  {
52  if (in_avail(timeout)) {
53 
54  JSocket socket;
55 
56  socket.accept(getFileDescriptor());
57 
58  return new JControlHost(socket);
59 
60  } else
61 
62  return NULL;
63  }
64  };
65 
66 
67  /**
68  * Match name.
69  */
71 }
72 
73 
74 #endif
static const int DISPATCH_PORT
Default ControlHost port.
Definition: JHostname.hh:24
ControlHost class.
TCP Server socket.
JControlHostServer(const int port=DISPATCH_PORT, const int backlog=1)
Constructor.
Socket class.
Definition: JSocket.hh:42
Auxiliary class for time values.
Definition: JTimeval.hh:26
bool in_avail(JTimeval timeout=JTimeval::min()) const
Check availability of input.
Definition: JFile.hh:100
JControlHostServer ControlServ
Match name.
int getFileDescriptor() const
Get file descriptor.
static JTimeval max()
Get maximal time value.
Definition: JTimeval.hh:131
void accept(const int server)
Accept connection from a server.
Definition: JSocket.hh:372
JControlHost * AcceptClient(JTimeval timeout=JTimeval::max())
Accept new client.
Light-weight wrapper class around server socket.