I/O handler for datagram (UDP) sockets. More...
#include <IOHandlerDatagram.h>
Public Member Functions | |
IOHandlerDatagram (int sd, const DispatchHandlerPtr &dhp, Reactor::Priority rp) | |
Constructor. More... | |
virtual | ~IOHandlerDatagram () |
Destructor. More... | |
int | send_message (const InetAddr &addr, CommBufPtr &cbp) |
Sends a message. More... | |
int | flush_send_queue () |
Flushes send queue. More... | |
bool | handle_event (struct pollfd *event, ClockT::time_point arrival_time) override |
Handle poll() interface events. More... | |
int | handle_write_readiness () |
Handles write readiness. More... | |
![]() | |
IOHandler (int sd, const DispatchHandlerPtr &dhp, Reactor::Priority rp=Reactor::Priority::NORMAL) | |
Constructor. More... | |
IOHandler (int sd) | |
Constructor. More... | |
virtual | ~IOHandler () |
Destructor. More... | |
void | deliver_event (EventPtr &event, DispatchHandler *dh=0) |
Convenience method for delivering event to application. More... | |
int | start_polling (int mode=PollEvent::READ) |
Start polling on the handler with the poll interest specified in mode . More... | |
int | add_poll_interest (int mode) |
Adds the poll interest specified in mode to the polling interface for this handler. More... | |
int | remove_poll_interest (int mode) |
Removes the poll interest specified in mode to the polling interface for this handler. More... | |
int | reset_poll_interest () |
Resets poll interest by adding m_poll_interest to the polling interface for this handler. More... | |
InetAddr | get_address () |
Gets the handler socket address. More... | |
InetAddr | get_local_address () |
Get local socket address for connection. More... | |
void | set_proxy (const String &proxy) |
Sets the proxy name for this connection. More... | |
const String & | get_proxy () |
Gets the proxy name for this connection. More... | |
int | get_sd () |
Gets the socket descriptor for this connection. More... | |
void | get_reactor (ReactorPtr &reactor) |
Get the reactor that this handler is assigned to. More... | |
void | display_event (struct pollfd *event) |
Display polling event from poll() interface to stderr. More... | |
Public Attributes | |
ImplementMe | |
Private Types | |
typedef std::pair< struct sockaddr_in, CommBufPtr > | SendRec |
Send queue message record. More... | |
Private Attributes | |
uint8_t * | m_message |
Message receive buffer. More... | |
std::list< SendRec > | m_send_queue |
Send queue. More... | |
Additional Inherited Members | |
![]() | |
bool | test_and_set_error (int32_t error) |
Sets m_error to error if it has not already been set. More... | |
int32_t | get_error () |
Returns first error code encountered by handler. More... | |
InetAddr | get_alias () |
Get alias address for this connection. More... | |
void | set_alias (const InetAddr &alias) |
Set alias address for this connection. More... | |
void | increment_reference_count () |
Increment reference count. More... | |
void | decrement_reference_count () |
Decrement reference count. More... | |
size_t | reference_count () |
Return reference count. More... | |
void | decomission () |
Decomission handler. More... | |
bool | is_decomissioned () |
Checks to see if handler is decomissioned. More... | |
virtual void | disconnect () |
Disconnect connection. More... | |
short | poll_events (int mode) |
Return poll() interface events corresponding to the normalized polling interest in mode . More... | |
void | stop_polling () |
Stops polling by removing socket from polling interface. More... | |
![]() | |
std::mutex | m_mutex |
Mutex for serializing concurrent access More... | |
size_t | m_reference_count |
Reference count. More... | |
uint32_t | m_free_flag |
Free flag (for testing) More... | |
int32_t | m_error |
Error code. More... | |
String | m_proxy |
Proxy name for this connection. More... | |
InetAddr | m_addr |
Handler socket address. More... | |
InetAddr | m_local_addr |
Local address of connection. More... | |
InetAddr | m_alias |
Address alias for connection. More... | |
int | m_sd |
Socket descriptor. More... | |
DispatchHandlerPtr | m_dispatch_handler |
Default dispatch hander for connection. More... | |
ReactorPtr | m_reactor |
Reactor to which this handler is assigned. More... | |
int | m_poll_interest |
Current polling interest. More... | |
bool | m_decomissioned |
Decomissioned flag. More... | |
bool m_socket_internally_created | true |
Socket was internally created and should be closed on destroy. More... | |
I/O handler for datagram (UDP) sockets.
Definition at line 50 of file IOHandlerDatagram.h.
|
private |
Send queue message record.
Definition at line 197 of file IOHandlerDatagram.h.
|
inline |
Constructor.
This method initializes the handler by allocating a receive buffer and copying the locally bound address to m_addr.
sd | Socket descriptor bound to an address |
dhp | Default dispatch handler |
Definition at line 59 of file IOHandlerDatagram.h.
|
inlinevirtual |
Destructor.
Definition at line 66 of file IOHandlerDatagram.h.
int IOHandlerDatagram::flush_send_queue | ( | ) |
Flushes send queue.
This method tries to write all messages on the send queue. If a write succeeds, but writes fewer bytes than requested, that implies the send buffer is full. The send queue holds a list of CommBuf objects (and associated destination addresses) that contain next write pointers that are updated by this method and allow it to pick up where it left off in the event of a short write.
Definition at line 383 of file IOHandlerDatagram.cc.
|
overridevirtual |
Handle poll()
interface events.
This method is called by its reactor thread to handle I/O events. It handles POLLOUT
events with a call to handle_write_readiness. If handle_write_readiness returns true the handler is disconnected with a call to handle_disconnect() and true is returned. POLLIN
events are handled in a loop by reading messages off the socket in their entirety with a call to recvfrom
. The message buffer is 65536 bytes in size and therefore this method can only handle messages of that size or less. Messages are delivered to the application by creating an Event object, initializing it with the message header and arrival_time
, and delivering it with the default dispatch handler. POLLERR
and errors are handled by decomissioning the handler and delivering an Event::ERROR event to the application.
event | Pointer to pollfd structure describing event |
arrival_time | Time of event arrival |
Implements Hypertable::IOHandler.
Definition at line 56 of file IOHandlerDatagram.cc.
int IOHandlerDatagram::handle_write_readiness | ( | ) |
Handles write readiness.
This method handles write readiness by flushing the send queue with a call to flush_send_queue and then removes write interest from the polling interface for this handler if the send queue becomes empty.
Definition at line 327 of file IOHandlerDatagram.cc.
int IOHandlerDatagram::send_message | ( | const InetAddr & | addr, |
CommBufPtr & | cbp | ||
) |
Sends a message.
This method pushes the message pointed to by cbp
onto the send queue, flushes the send queue with a call to flush_send_queue, and then updates polling interest depending on the state of the send queue.
addr | Remote address to send message to |
cbp | Pointer to message to send |
Definition at line 349 of file IOHandlerDatagram.cc.
Hypertable::IOHandlerDatagram::ImplementMe |
Definition at line 183 of file IOHandlerDatagram.h.
|
private |
Message receive buffer.
Definition at line 200 of file IOHandlerDatagram.h.
|
private |
Send queue.
Definition at line 203 of file IOHandlerDatagram.h.