28 #ifndef AsyncComm_Reactor_h
29 #define AsyncComm_Reactor_h
36 #include <boost/thread/thread.hpp>
104 std::lock_guard<std::mutex> lock(
m_mutex);
116 std::lock_guard<std::mutex> lock(
m_mutex);
126 std::lock_guard<std::mutex> lock(
m_mutex);
136 std::lock_guard<std::mutex> lock(
m_mutex);
146 std::lock_guard<std::mutex> lock(
m_mutex);
147 typedef TimerHeap::container_type container_t;
148 container_t container;
153 if (timer.
handler.get() != handler.get())
154 container.push_back(timer);
157 for (
const auto &t : container)
172 std::lock_guard<std::mutex> lock(
m_mutex);
187 std::lock_guard<std::mutex> lock(
m_mutex);
203 #if defined(__linux__) || defined (__sun__)
206 #elif defined (__APPLE__) || defined(__FreeBSD__)
248 std::vector<IOHandler *> &handlers);
299 #endif // AsyncComm_Reactor_h
void purge_requests(IOHandler *handler, int32_t error)
Purges all requests assocated with handler.
void handle_timeouts(PollTimeout &next_timeout)
Processes request timeouts and timers.
int remove_poll_interest(int sd)
Remove poll interest for socket (POSIX poll only).
int modify_poll_interest(int sd, short events)
Modify poll interest for socket (POSIX poll only).
Declarations for PollTimeout.
Class used to hold pending request callback handlers.
RequestCache m_request_cache
Request cache.
void schedule_removal(IOHandler *handler)
Schedules handler for removal.
void add_timer(ExpireTimer &timer)
Adds a timer.
std::set< IOHandler * > m_removed_handlers
Set of IOHandler objects scheduled for removal.
IOHandler * handler
I/O handler associated with descriptor.
chrono::time_point< fast_clock > time_point
Abstract base class for application dispatch handlers registered with AsyncComm.
Comparison function (functor) for timer heap.
Maintains next timeout for event polling loop.
TimerHeap m_timer_heap
ExpireTimer heap.
int poll_loop_continue()
Reset state after call to poll_loop_interrupt.
bool remove(uint32_t id, DispatchHandler *&handler)
Removes a request from the cache.
int poll_loop_interrupt()
Forces polling interface wait call to return.
int add_poll_interest(int sd, short events, IOHandler *handler)
Add poll interest for socket (POSIX poll only).
Declarations for ExpireTimer.
ClockT::time_point expire_time
Absolute expiration time.
int m_interrupt_sd
Interrupt socket.
void cancel_timer(const DispatchHandlerPtr &handler)
Cancels timers associated with handler.
Static class used to setup and manage I/O reactors.
void get_removed_handlers(std::set< IOHandler * > &dst)
Returns set of I/O handlers scheduled for removal.
bool remove_request(uint32_t id, DispatchHandler *&handler)
Removes request associated with id
Socket descriptor poll state for use with POSIX poll()
DispatchHandlerPtr handler
Dispatch handler to receive TIMER event.
static time_point now() noexcept
Manages reactor (polling thread) state including poll interest, request cache, and timers...
void fetch_poll_array(std::vector< struct pollfd > &fdarray, std::vector< IOHandler * > &handlers)
Fetches poll state vectors (POSIX poll only).
int interrupt_sd()
Returns interrupt socket.
Base class for socket descriptor I/O handlers.
Declarations for RequestCache.
std::shared_ptr< Reactor > ReactorPtr
Shared smart pointer to Reactor.
std::vector< PollDescriptorT > m_polldata
Vector of poll descriptor state structures for use with POSIX poll().
void cancel_requests(IOHandler *handler, int32_t error=Error::COMM_BROKEN_CONNECTION)
Cancels outstanding requests associated with handler
void insert(uint32_t id, IOHandler *handler, DispatchHandler *dh, ClockT::time_point &expire)
Inserts pending request callback handler into cache.
std::priority_queue< ExpireTimer, std::vector< ExpireTimer >, LtTimerHeap > TimerHeap
Priority queue for timers.
std::mutex m_mutex
Mutex to protect members.
Priority
Enumeration for reactor priority.
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
ClockT::time_point m_next_wakeup
Next polling interface wait timeout (absolute)
bool m_interrupt_in_progress
Set to true if poll loop interrupt in progress.
std::mutex m_polldata_mutex
Mutex to protect m_polldata member.
void add_request(uint32_t id, IOHandler *handler, DispatchHandler *dh, ClockT::time_point expire)
Adds a request to request cache and adjusts poll timeout if necessary.