0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Hypertable::IOHandler Class Referenceabstract

Base class for socket descriptor I/O handlers. More...

#include <IOHandler.h>

Inheritance diagram for Hypertable::IOHandler:
Inheritance graph
[legend]
Collaboration diagram for Hypertable::IOHandler:
Collaboration graph
[legend]

Public Member Functions

 IOHandler (int sd, const DispatchHandlerPtr &dhp, Reactor::Priority rp=Reactor::Priority::NORMAL)
 Constructor. More...
 
 IOHandler (int sd)
 Constructor. More...
 
virtual bool handle_event (struct pollfd *event, ClockT::time_point arrival_time)=0
 Event handler method for Unix poll interface. 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 Stringget_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...
 

Protected Member Functions

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...
 

Protected Attributes

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...
 

Friends

class HandlerMap
 

Detailed Description

Base class for socket descriptor I/O handlers.

When a socket is created, an I/O handler object is allocated to handle events that occur on the socket. Events are encapsulated in the Event class and are delivered to the application through a DispatchHandler. For example, a TCP socket will have an associated IOHandlerData object that reads messages off the socket and sends then to the application via the installed DispatchHandler object.

Definition at line 76 of file IOHandler.h.

Constructor & Destructor Documentation

Hypertable::IOHandler::IOHandler ( int  sd,
const DispatchHandlerPtr dhp,
Reactor::Priority  rp = Reactor::Priority::NORMAL 
)
inline

Constructor.

Initializes the I/O handler, assigns it a Reactor, and sets m_local_addr to the locally bound address (IPv4:port) of sd (see getsockname).

Parameters
sdSocket descriptor
dhpDispatch handler

Definition at line 87 of file IOHandler.h.

Hypertable::IOHandler::IOHandler ( int  sd)
inline

Constructor.

Initializes handler for raw I/O. Assigns it a Reactor and sets m_local_addr to the locally bound address (IPv4:port) of sd.

Parameters
sdSocket descriptor

Definition at line 103 of file IOHandler.h.

virtual Hypertable::IOHandler::~IOHandler ( )
inlinevirtual

Destructor.

If #m_socket_internally_created is set to true, closes the socket descriptor m_sd.

Definition at line 152 of file IOHandler.h.

Member Function Documentation

int Hypertable::IOHandler::add_poll_interest ( int  mode)

Adds the poll interest specified in mode to the polling interface for this handler.

This method adds the poll interest, specified in mode, to the polling interface for this handler and merges mode into m_poll_interest using bitwise OR (|). If an error is encountered, m_error is set to the approprate error code.

Returns
Error::OK on success, or one of Error::COMM_POLL_ERROR, Error::COMM_SEND_ERROR, or Error::COMM_RECEIVE_ERROR on error
void Hypertable::IOHandler::decomission ( )
inlineprotected

Decomission handler.

This method decomissions the handler by setting the m_decomissioned flag to true. If the reference count is 0, the handler is also scheduled for removal with a call to m_reactor->schedule_removal(this).

Note
This method assumes the caller is serializing access to this and related methods with a mutex lock.
See also
increment_reference_count, decrement_reference_count, reference_count, and is_decomissioned

Definition at line 382 of file IOHandler.h.

void Hypertable::IOHandler::decrement_reference_count ( )
inlineprotected

Decrement reference count.

If reference count drops to 0 and the handler is decomissioned then it is scheduled for removal with a call to m_reactor->schedule_removal(this).

Note
This method assumes the caller is serializing access to this and related methods with a mutex lock.
See also
increment_reference_count, reference_count, and decomission

Definition at line 355 of file IOHandler.h.

void Hypertable::IOHandler::deliver_event ( EventPtr event,
DispatchHandler dh = 0 
)
inline

Convenience method for delivering event to application.

This method will deliver event to the application via the event handler dh if supplied, otherwise the event will be delivered via the default event handler, or no default event handler exists, it will just log the event. This method is (and should always) by called from a reactor thread.

Parameters
eventpointer to Event (deleted by this method)
dhEvent handler via which to deliver event

Definition at line 169 of file IOHandler.h.

virtual void Hypertable::IOHandler::disconnect ( )
inlineprotectedvirtual

Disconnect connection.

Reimplemented in Hypertable::IOHandlerData.

Definition at line 399 of file IOHandler.h.

void IOHandler::display_event ( struct pollfd *  event)

Display polling event from poll() interface to stderr.

Parameters
eventPointer to pollfd structure describing poll() event.

Definition at line 60 of file IOHandler.cc.

InetAddr Hypertable::IOHandler::get_address ( )
inline

Gets the handler socket address.

The socket address is the address of the remote end of the connection for data (TCP) handlers, and the local socket address for datagram and accept handlers.

Returns
Handler socket address

Definition at line 229 of file IOHandler.h.

InetAddr Hypertable::IOHandler::get_alias ( )
inlineprotected

Get alias address for this connection.

Returns
Alias address for this connection.

Definition at line 327 of file IOHandler.h.

int32_t Hypertable::IOHandler::get_error ( )
inlineprotected

Returns first error code encountered by handler.

When an error is encountered during handler methods, the first error code that is encountered is recorded in m_error. This method returns that error or Error::OK if no error has been encountered.

Returns
First error code encountered by this handler, or Error::OK if no error has been encountered

Definition at line 319 of file IOHandler.h.

InetAddr Hypertable::IOHandler::get_local_address ( )
inline

Get local socket address for connection.

Returns
Local socket address for connection.

Definition at line 234 of file IOHandler.h.

const String& Hypertable::IOHandler::get_proxy ( )
inline

Gets the proxy name for this connection.

Returns
Proxy name for this connection.

Definition at line 247 of file IOHandler.h.

void Hypertable::IOHandler::get_reactor ( ReactorPtr reactor)
inline

Get the reactor that this handler is assigned to.

Parameters
reactorReference to returned reactor pointer

Definition at line 260 of file IOHandler.h.

int Hypertable::IOHandler::get_sd ( )
inline

Gets the socket descriptor for this connection.

Returns
Socket descriptor for this connection.

Definition at line 255 of file IOHandler.h.

virtual bool Hypertable::IOHandler::handle_event ( struct pollfd *  event,
ClockT::time_point  arrival_time 
)
pure virtual

Event handler method for Unix poll interface.

Parameters
eventPointer to pollfd structure describing event
arrival_timeArrival time of event
Returns
true if socket should be closed, false otherwise

Implemented in Hypertable::IOHandlerData, Hypertable::IOHandlerDatagram, Hypertable::IOHandlerRaw, and Hypertable::IOHandlerAccept.

void Hypertable::IOHandler::increment_reference_count ( )
inlineprotected

Increment reference count.

Note
This method assumes the caller is serializing access to this and related methods with a mutex lock.
See also
decrement_reference_count, reference_count, and decomission

Definition at line 343 of file IOHandler.h.

bool Hypertable::IOHandler::is_decomissioned ( )
inlineprotected

Checks to see if handler is decomissioned.

Returns
true if it is decomissioned, false otherwise.

Definition at line 393 of file IOHandler.h.

short Hypertable::IOHandler::poll_events ( int  mode)
inlineprotected

Return poll() interface events corresponding to the normalized polling interest in mode.

mode is some bitwise combination of the flags PollEvent::READ and PollEvent::WRITE.

Returns
poll() events correspond to polling interest specified in mode.

Definition at line 408 of file IOHandler.h.

size_t Hypertable::IOHandler::reference_count ( )
inlineprotected

Return reference count.

Note
This method assumes the caller is serializing access to this and related methods with a mutex lock.
See also
increment_reference_count, decrement_reference_count, and decomission

Definition at line 368 of file IOHandler.h.

int Hypertable::IOHandler::remove_poll_interest ( int  mode)

Removes the poll interest specified in mode to the polling interface for this handler.

This method removes the poll interest, specified in mode, from the polling interface for this handler and strips mode from m_poll_interest using boolean operations. If an error is encountered, m_error is set to the approprate error code.

Returns
Error::OK on success, or one of Error::COMM_POLL_ERROR, Error::COMM_SEND_ERROR, or Error::COMM_RECEIVE_ERROR on error
int Hypertable::IOHandler::reset_poll_interest ( )
inline

Resets poll interest by adding m_poll_interest to the polling interface for this handler.

If an error is encountered, m_error is set to the approprate error code.

Returns
Error::OK on success, or one of Error::COMM_POLL_ERROR, Error::COMM_SEND_ERROR, or Error::COMM_RECEIVE_ERROR on error

Definition at line 220 of file IOHandler.h.

void Hypertable::IOHandler::set_alias ( const InetAddr alias)
inlineprotected

Set alias address for this connection.

Parameters
aliasReference to return alias address.

Definition at line 334 of file IOHandler.h.

void Hypertable::IOHandler::set_proxy ( const String proxy)
inline

Sets the proxy name for this connection.

Parameters
proxyProxy name to set for this connection.

Definition at line 239 of file IOHandler.h.

int IOHandler::start_polling ( int  mode = PollEvent::READ)

Start polling on the handler with the poll interest specified in mode.

This method registers the poll interest, specified in mode, with the polling interface and sets m_poll_interest to mode. If an error is encountered, m_error is set to the approprate error code.

Returns
Error::OK on success, or one of Error::COMM_POLL_ERROR, Error::COMM_SEND_ERROR, or Error::COMM_RECEIVE_ERROR on error

Definition at line 91 of file IOHandler.cc.

void Hypertable::IOHandler::stop_polling ( )
inlineprotected

Stops polling by removing socket from polling interface.

Clears m_poll_interest.

Definition at line 420 of file IOHandler.h.

bool Hypertable::IOHandler::test_and_set_error ( int32_t  error)
inlineprotected

Sets m_error to error if it has not already been set.

This method checks to see if m_error is set to Error::OK and if so, it sets m_error to error and returns true. Otherwise it does nothing and returns false.

Returns
true if m_error was set to error, false otherwise.

Definition at line 303 of file IOHandler.h.

Friends And Related Function Documentation

friend class HandlerMap
friend

Definition at line 292 of file IOHandler.h.

Member Data Documentation

InetAddr Hypertable::IOHandler::m_addr
protected

Handler socket address.

Definition at line 457 of file IOHandler.h.

InetAddr Hypertable::IOHandler::m_alias
protected

Address alias for connection.

Definition at line 463 of file IOHandler.h.

bool Hypertable::IOHandler::m_decomissioned
protected

Decomissioned flag.

Calls to methods that reference this member must be mutex protected by caller.

Definition at line 483 of file IOHandler.h.

DispatchHandlerPtr Hypertable::IOHandler::m_dispatch_handler
protected

Default dispatch hander for connection.

Definition at line 469 of file IOHandler.h.

int32_t Hypertable::IOHandler::m_error
protected

Error code.

Definition at line 451 of file IOHandler.h.

uint32_t Hypertable::IOHandler::m_free_flag
protected

Free flag (for testing)

Definition at line 448 of file IOHandler.h.

InetAddr Hypertable::IOHandler::m_local_addr
protected

Local address of connection.

Definition at line 460 of file IOHandler.h.

std::mutex Hypertable::IOHandler::m_mutex
protected

Mutex for serializing concurrent access

Definition at line 440 of file IOHandler.h.

int Hypertable::IOHandler::m_poll_interest
protected

Current polling interest.

The polling interest is some bitwise combination of the flags PollEvent::READ and PollEvent::WRITE.

Definition at line 478 of file IOHandler.h.

String Hypertable::IOHandler::m_proxy
protected

Proxy name for this connection.

Definition at line 454 of file IOHandler.h.

ReactorPtr Hypertable::IOHandler::m_reactor
protected

Reactor to which this handler is assigned.

Definition at line 472 of file IOHandler.h.

size_t Hypertable::IOHandler::m_reference_count
protected

Reference count.

Calls to methods that reference this member must be mutex protected by caller.

Definition at line 445 of file IOHandler.h.

int Hypertable::IOHandler::m_sd
protected

Socket descriptor.

Definition at line 466 of file IOHandler.h.

bool m_socket_internally_created Hypertable::IOHandler::true
protected

Socket was internally created and should be closed on destroy.

Definition at line 486 of file IOHandler.h.


The documentation for this class was generated from the following files: