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, pid_t threadId);
105 
112 
113  int processCommand(std::string command, TCPSession *session, std::stringstream &data) override;
114 
115  void resetSocket(Socket *socket);
116 
117  private:
118 
119  int epfd;
120  int numberOfThreads;
121  std::map<int, Socket *> sockets;
122  std::vector<Thread> threads;
123  volatile bool terminateThreads;
124  std::mutex lock;
125  void enableSocket(Socket *socket);
126  void disableSocket(Socket *socket);
127 
128  };
129 
130 }
131 
132 #endif
133 
core::EPoll::isStopping
bool isStopping()
Returns a true if the stop command has been requested.
Definition: EPoll.cpp:67
core::EPoll::start
bool start(int numberOfThreads, int maxSockets)
Start the BMAEPoll processing.
Definition: EPoll.cpp:21
core::TCPSession
Definition: TCPSession.h:23
core::Socket
Definition: Socket.h:33
core::EPoll::unregisterSocket
bool unregisterSocket(Socket *socket)
Unregister a BMASocket from monitoring by BMAEPoll.
Definition: EPoll.cpp:83
core::EPoll
Definition: EPoll.h:31
core::EPoll::stop
bool stop()
Stop and shut down the BMAEPoll processing.
Definition: EPoll.cpp:47
core::EPoll::eventReceived
void eventReceived(struct epoll_event event, pid_t threadId)
Dispatch event to appropriate socket.
Definition: EPoll.cpp:95
core::EPoll::maxSockets
int maxSockets
The maximum number of socket allowed.
Definition: EPoll.h:98
core::Command
Definition: Command.h:20
core::EPoll::getDescriptor
int getDescriptor()
Return the descriptor for the ePoll socket.
Definition: EPoll.cpp:107
core::EPoll::processCommand
int processCommand(std::string command, TCPSession *session, std::stringstream &data) override
Output the threads array to the console.
Definition: EPoll.cpp:111
core::EPoll::~EPoll
~EPoll()
Definition: EPoll.cpp:17
core::EPoll::EPoll
EPoll()
Definition: EPoll.cpp:8
core::EPoll::registerSocket
bool registerSocket(Socket *socket)
Register a BMASocket for monitoring by BMAEPoll.
Definition: EPoll.cpp:71