10 #ifndef CORAL_NET_REACTOR_HPP 11 #define CORAL_NET_REACTOR_HPP 20 #include "coral/config.h" 45 typedef SOCKET NativeSocket;
47 typedef int NativeSocket;
50 typedef std::chrono::system_clock::time_point TimePoint;
58 void AddSocket(zmq::socket_t& socket, SocketHandler handler);
108 TimerHandler handler);
152 TimePoint nextEventTime,
157 CORAL_DEFINE_DEFAULT_MOVE(Timer,
id, nextEventTime, interval, remaining, handler)
160 TimePoint nextEventTime;
161 std::chrono::milliseconds interval;
163 std::unique_ptr<TimerHandler> handler;
166 void RestartTimerIntervals(
167 std::vector<Timer>::iterator begin,
168 std::vector<Timer>::iterator end);
169 std::chrono::milliseconds TimeToNextEvent() const;
170 void PerformNextEvent();
177 std::vector<SocketHandlerPair> m_sockets;
178 std::vector<NativeSocketHandlerPair> m_nativeSockets;
179 std::vector<
zmq::pollitem_t> m_pollItems;
182 std::vector<Timer> m_timers;
185 bool m_continuePolling;
190 #endif // header guard
void RestartTimerInterval(int id)
Resets the time to the next event for a timer.
int AddTimer(std::chrono::milliseconds interval, int count, TimerHandler handler)
Adds a timer.
void Stop()
Stops the messaging loop.
void AddSocket(zmq::socket_t &socket, SocketHandler handler)
Adds a handler for the given socket.
static const int invalidTimerID
A number which will never be returned by AddTimer().
Definition: reactor.hpp:88
void RemoveSocket(zmq::socket_t &socket) CORAL_NOEXCEPT
Removes all handlers for the given socket.
Definition: variable_io.hpp:28
void RemoveTimer(int id)
Removes a timer.
void Run()
Runs the messaging loop.
void AddNativeSocket(NativeSocket socket, NativeSocketHandler handler)
Adds a handler for the given native socket.
An implementation of the reactor pattern.
Definition: reactor.hpp:41
Definition: variable_io.hpp:25
void RemoveNativeSocket(NativeSocket socket) CORAL_NOEXCEPT
Removes all handlers for the given native socket.