28 #ifndef AsyncComm_Comm_h
29 #define AsyncComm_Comm_h
73 std::lock_guard<std::mutex> lock(
ms_mutex);
526 #endif // AsyncComm_Comm_h
static Comm * instance()
Creates/returns singleton instance of the Comm class.
Declarations for ConnectionHandlerFactory.
int register_socket(int sd, const CommAddress &addr, RawSocketHandler *handler)
Registers an externally managed socket with comm event loop.
static std::atomic< uint32_t > ms_next_request_id
Atomic integer used for assinging request IDs.
bool m_verbose
Verbose flag.
std::string String
A String is simply a typedef to std::string.
Declarations for RawSocketHandler.
int connect(const CommAddress &addr, const DispatchHandlerPtr &default_handler)
Establishes a TCP connection and attaches a default dispatch handler.
chrono::time_point< fast_clock > time_point
Abstract base class for application dispatch handlers registered with AsyncComm.
bool wait_for_proxy_load(Timer &timer)
Waits until a CommHeader::FLAGS_BIT_PROXY_MAP_UPDATE message is received from the proxy master...
int set_alias(const InetAddr &addr, const InetAddr &alias)
Sets an alias for a TCP connection.
bool translate_proxy(const String &proxy, InetAddr *addr)
Translates a proxy name to an IP address.
Declarations for CommAddress.
int send_datagram(const CommAddress &addr, const CommAddress &send_addr, CommBufPtr &cbuf)
Sends a datagram to a remote address.
static void destroy()
Destroys singleton instance of the Comm class.
Abstract base class for application raw socket handlers registered with AsyncComm.
InetAddr m_local_addr
Local address initialized to primary interface and empty port.
Declarations for DispatchHandler.
std::shared_ptr< HandlerMap > HandlerMapPtr
Smart pointer to HandlerMap.
std::shared_ptr< ConnectionHandlerFactory > ConnectionHandlerFactoryPtr
Smart pointer to ConnectionHandlerFactory.
void find_available_tcp_port(InetAddr &addr)
Finds an unused TCP port starting from addr.
Encapsulate an internet address.
void close_socket(const CommAddress &addr)
Closes the socket specified by the addr argument.
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
std::unordered_map< String, ProxyAddressInfo > ProxyMapT
Forward mapping hash type from proxy name to ProxyAddressInfo.
int connect_socket(int sd, const CommAddress &addr, const DispatchHandlerPtr &default_handler)
Creates a TCP socket connection.
I/O handler for TCP sockets.
std::shared_ptr< Reactor > ReactorPtr
Shared smart pointer to Reactor.
Declarations for HandlerMap.
ReactorPtr m_timer_reactor
Pointer to dedicated reactor for handling timer events.
Comm()
Private constructor (prevent non-singleton usage).
int send_response(const CommAddress &addr, CommBufPtr &cbuf)
Sends a response message back over a connection.
static Comm * ms_instance
Pointer to singleton instance of this class.
void find_available_udp_port(InetAddr &addr)
Finds an unused UDP port starting from addr.
Entry point to AsyncComm service.
static std::mutex ms_mutex
Mutex for serializing access to ms_instance
void get_proxy_map(ProxyMapT &proxy_map)
Returns the proxy map.
Declarations for CommBuf.
HandlerMapPtr m_handler_map
Pointer to IOHandler map.
void create_datagram_receive_socket(CommAddress &addr, int tos, const DispatchHandlerPtr &handler)
Creates a socket for receiving datagrams and attaches handler as the default dispatch handler...
A timer class to keep timeout states across AsyncComm related calls.
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
void listen(const CommAddress &addr, ConnectionHandlerFactoryPtr &chf)
Creates listen (accept) socket on addr.
int set_timer_absolute(ClockT::time_point expire_time, const DispatchHandlerPtr &handler)
Sets a timer for absolute time expire_time.
int set_timer(uint32_t duration_millis, const DispatchHandlerPtr &handler)
Sets a timer for duration_millis milliseconds in the future.
void cancel_timer(const DispatchHandlerPtr &handler)
Cancels all scheduled timers registered with the dispatch handler handler.
void alias(const String &cmdline_opt, const String &file_opt, bool overwrite)
Setup command line option alias for config file option.
int send_request(const CommAddress &addr, uint32_t timeout_ms, CommBufPtr &cbuf, DispatchHandler *response_handler)
Sends a request message over a connection, expecting a response.
int add_proxy(const String &proxy, const String &hostname, const InetAddr &addr)
Adds a proxy name for a TCP connection.
Address abstraction to hold either proxy name or IPv4:port address.
int remove_proxy(const String &proxy)
Removes a proxy name for a TCP connection.