28 #ifndef AsyncComm_IOHandler_h
29 #define AsyncComm_IOHandler_h
44 #include <sys/types.h>
45 #include <sys/socket.h>
47 #if defined(__APPLE__) || defined(__FreeBSD__)
48 #include <sys/event.h>
49 #elif defined(__linux__)
50 #include <sys/epoll.h>
51 #if !defined(POLLRDHUP)
52 #define POLLRDHUP 0x2000
54 #elif defined(__sun__)
56 #include <sys/port_impl.h>
121 #if defined(__APPLE__) || defined(__FreeBSD__)
129 #elif defined(__linux__)
137 #elif defined(__sun__)
155 if (m_socket_internally_created)
175 HT_INFOF(
"%s", event->to_str().c_str());
240 std::lock_guard<std::mutex> lock(
m_mutex);
248 std::lock_guard<std::mutex> lock(
m_mutex);
269 #if defined(__APPLE__) || defined(__FreeBSD__)
276 #elif defined(__linux__)
283 #elif defined(__sun__)
304 std::lock_guard<std::mutex> lock(
m_mutex);
320 std::lock_guard<std::mutex> lock(
m_mutex);
426 #if defined(__APPLE__) || defined(__sun__) || defined(__FreeBSD__)
428 #elif defined(__linux__)
429 struct epoll_event event;
430 if (epoll_ctl(
m_reactor->poll_fd, EPOLL_CTL_DEL,
m_sd, &event) < 0) {
431 HT_ERRORF(
"epoll_ctl(%d, EPOLL_CTL_DEL, %d) failed : %s",
486 bool m_socket_internally_created {
true};
491 #endif // AsyncComm_IOHandler_h
int start_polling(int mode=PollEvent::READ)
Start polling on the handler with the poll interest specified in mode.
static void get_reactor(ReactorPtr &reactor, Reactor::Priority priority=Reactor::Priority::NORMAL)
This method returns the 'next' reactor.
int reset_poll_interest()
Resets poll interest by adding m_poll_interest to the polling interface for this handler.
void set_proxy(const String &proxy)
Sets the proxy name for this connection.
virtual void disconnect()
Disconnect connection.
InetAddr get_local_address()
Get local socket address for connection.
InetAddr m_alias
Address alias for connection.
std::string String
A String is simply a typedef to std::string.
chrono::time_point< fast_clock > time_point
Abstract base class for application dispatch handlers registered with AsyncComm.
size_t m_reference_count
Reference count.
void set_alias(const InetAddr &alias)
Set alias address for this connection.
InetAddr get_address()
Gets the handler socket address.
void increment_reference_count()
Increment reference count.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Declarations for ExpireTimer.
int remove_poll_interest(int mode)
Removes the poll interest specified in mode to the polling interface for this handler.
std::mutex m_mutex
Mutex for serializing concurrent access
virtual ~IOHandler()
Destructor.
void display_event(struct pollfd *event)
Display polling event from poll() interface to stderr.
Data structure for mapping socket addresses to I/O handlers.
void decrement_reference_count()
Decrement reference count.
DispatchHandlerPtr m_dispatch_handler
Default dispatch hander for connection.
Declarations for DispatchHandler.
bool m_decomissioned
Decomissioned flag.
const String & get_proxy()
Gets the proxy name for this connection.
Encapsulate an internet address.
void decomission()
Decomission handler.
Logging routines and macros.
IOHandler(int sd)
Constructor.
Base class for socket descriptor I/O handlers.
int m_sd
Socket descriptor.
std::shared_ptr< Reactor > ReactorPtr
Shared smart pointer to Reactor.
bool test_and_set_error(int32_t error)
Sets m_error to error if it has not already been set.
Declarations for PollEvent.
Time related declarations.
void stop_polling()
Stops polling by removing socket from polling interface.
short poll_events(int mode)
Return poll() interface events corresponding to the normalized polling interest in mode...
InetAddr get_alias()
Get alias address for this connection.
Writing can be performed without blocking.
uint32_t m_free_flag
Free flag (for testing)
int get_sd()
Gets the socket descriptor for this connection.
#define HT_INFOF(msg,...)
virtual bool handle_event(struct pollfd *event, ClockT::time_point arrival_time)=0
Event handler method for Unix poll interface.
String m_proxy
Proxy name for this connection.
void get_reactor(ReactorPtr &reactor)
Get the reactor that this handler is assigned to.
int add_poll_interest(int mode)
Adds the poll interest specified in mode to the polling interface for this handler.
int32_t m_error
Error code.
Priority
Enumeration for reactor priority.
Declarations for ReactorFactory.
size_t reference_count()
Return reference count.
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
void deliver_event(EventPtr &event, DispatchHandler *dh=0)
Convenience method for delivering event to application.
int m_poll_interest
Current polling interest.
#define HT_ERRORF(msg,...)
IOHandler(int sd, const DispatchHandlerPtr &dhp, Reactor::Priority rp=Reactor::Priority::NORMAL)
Constructor.
ReactorPtr m_reactor
Reactor to which this handler is assigned.
int32_t get_error()
Returns first error code encountered by handler.
void alias(const String &cmdline_opt, const String &file_opt, bool overwrite)
Setup command line option alias for config file option.
bool is_decomissioned()
Checks to see if handler is decomissioned.
InetAddr m_addr
Handler socket address.
InetAddr m_local_addr
Local address of connection.