My Project
EPoll.h
1 #ifndef __EPoll_h__
2 #define __EPoll_h__
3 
4 #include "Log.h"
5 #include "Socket.h"
6 #include "Thread.h"
7 #include "TCPSession.h"
8 #include "Command.h"
9 
10 namespace core {
11 
30 
31  class EPoll : public Command {
32 
33  public:
34 
38 
39  EPoll();
40 
44 
45  ~EPoll();
46 
53 
54  bool start(int numberOfThreads, int maxSockets);
55 
61 
62  bool stop();
63 
68 
69  bool isStopping();
70 
79 
80  bool registerSocket(Socket *socket);
81 
85 
86  bool unregisterSocket(Socket *socket);
87 
91 
92  int getDescriptor();
93 
97 
98  int maxSockets;
99 
103 
104  void eventReceived(struct epoll_event event);
105 
112 
113  int processCommand(std::string command, TCPSession *session, std::stringstream &data) override;
114 
115  private:
116 
117  int epfd;
118  int numberOfThreads;
119  std::map<int, Socket *> sockets;
120  std::vector<Thread> threads;
121  volatile bool terminateThreads;
122  std::mutex lock;
123 
124  };
125 
126 }
127 
128 #endif
129 
void eventReceived(struct epoll_event event)
Dispatch event to appropriate socket.
Definition: EPoll.cpp:97
Definition: EPoll.h:31
Definition: Command.cpp:3
int processCommand(std::string command, TCPSession *session, std::stringstream &data) override
Output the threads array to the console.
Definition: EPoll.cpp:113
Definition: TCPSession.h:21
~EPoll()
Definition: EPoll.cpp:17
int getDescriptor()
Return the descriptor for the ePoll socket.
Definition: EPoll.cpp:109
bool unregisterSocket(Socket *socket)
Unregister a BMASocket from monitoring by BMAEPoll.
Definition: EPoll.cpp:84
Definition: Socket.h:32
bool isStopping()
Returns a true if the stop command has been requested.
Definition: EPoll.cpp:67
EPoll()
Definition: EPoll.cpp:8
Definition: Command.h:19
bool registerSocket(Socket *socket)
Register a BMASocket for monitoring by BMAEPoll.
Definition: EPoll.cpp:71
int maxSockets
The maximum number of socket allowed.
Definition: EPoll.h:98
bool start(int numberOfThreads, int maxSockets)
Start the BMAEPoll processing.
Definition: EPoll.cpp:21
bool stop()
Stop and shut down the BMAEPoll processing.
Definition: EPoll.cpp:47