ADTF  3.18.3
abstractthreadedserver.h
1 #ifndef ABSTRACTTHREADEDSERVER_H
2 #define ABSTRACTTHREADEDSERVER_H
3 
4 #include "abstractserverconnector.h"
5 #include "threadpool.h"
6 #include <memory>
7 #include <thread>
8 
9 namespace jsonrpc {
11 public:
12  AbstractThreadedServer(size_t threads);
13  virtual ~AbstractThreadedServer();
14 
15  virtual bool StartListening();
16  virtual bool StopListening();
17 
18 protected:
23  virtual bool InitializeListener() = 0;
24 
30  virtual int CheckForConnection() = 0;
31 
37  virtual void HandleConnection(int connection) = 0;
38 
39 private:
40  bool running;
41  std::unique_ptr<std::thread> listenerThread;
42  ThreadPool threadPool;
43  size_t threads;
44 
45  void ListenLoop();
46 };
47 }
48 
49 #endif // ABSTRACTTHREADEDSERVER_H
virtual int CheckForConnection()=0
CheckForConnection should poll for a new connection.
virtual bool InitializeListener()=0
InitializeListener should initialize sockets, file descriptors etc.
virtual bool StopListening()
This method should signal the Connector to stop waiting for requests, in any way that is appropriate ...
virtual bool StartListening()
This method should signal the Connector to start waiting for requests, in any way that is appropriate...
virtual void HandleConnection(int connection)=0
HandleConnection must handle connection information for a given handle that has been returned by Chec...