The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EventHandler Class Reference

This class is a basic I/O handler class. More...

#include <socketengine.h>

Inheritance diagram for EventHandler:

Inheritance graph
[legend]
Collaboration diagram for EventHandler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

ModuleGetIOHook ()
 Return the current hooker of IO events for this socket, or NULL.
bool AddIOHook (Module *IOHooker)
 Set a module as hooking IO events on this socket.
bool DelIOHook ()
 Remove IO hooking from a module.
int GetFd ()
 Get the current file descriptor.
void SetFd (int FD)
 Set a new file desciptor.
 EventHandler ()
 Constructor.
virtual ~EventHandler ()
 Destructor.
virtual bool Readable ()
 Override this function to indicate readability.
virtual bool Writeable ()
 Override this function to indicate writeability.
virtual void HandleEvent (EventType et, int errornum=0)=0
 Process an I/O event.

Protected Attributes

int fd
 File descriptor.
ModuleIOHook
 Pointer to the module which has hooked the given EventHandler for IO events.

Detailed Description

This class is a basic I/O handler class.

Any object which wishes to receive basic I/O events from the socketengine must derive from this class and implement the HandleEvent() method. The derived class must then be added to SocketEngine using the method SocketEngine::AddFd(), after which point the derived class will receive events to its HandleEvent() method. The derived class should also implement one of Readable() and Writeable(). In the current implementation, only Readable() is used. If this returns true, the socketengine inserts a readable socket. If it is false, the socketengine inserts a writeable socket. The derived class should never change the value this function returns without first deleting the socket from the socket engine. The only requirement beyond this for an event handler is that it must have a file descriptor. What this file descriptor is actually attached to is completely up to you.

Definition at line 61 of file socketengine.h.


Constructor & Destructor Documentation

EventHandler::EventHandler  ) 
 

Constructor.

Definition at line 44 of file socketengine.cpp.

References IOHook.

virtual EventHandler::~EventHandler  )  [inline, virtual]
 

Destructor.

Definition at line 113 of file socketengine.h.


Member Function Documentation

bool EventHandler::AddIOHook Module IOHooker  ) 
 

Set a module as hooking IO events on this socket.

Parameters:
IOHooker The module hooking IO
Returns:
True if the hook could be added, false otherwise.

Definition at line 49 of file socketengine.cpp.

References IOHook.

Referenced by CommandStartTLS::Handle(), ModuleSSLOpenSSL::OnHookUserIO(), ModuleSSLGnuTLS::OnHookUserIO(), ModuleZLib::OnRequest(), ModuleSSLOpenSSL::OnRequest(), ModuleSSLGnuTLS::OnRequest(), and SpanningTreeUtilities::ReadConfiguration().

bool EventHandler::DelIOHook  ) 
 

Remove IO hooking from a module.

Returns:
True if hooking was successfully removed, false otherwise.

Definition at line 58 of file socketengine.cpp.

References IOHook.

Referenced by ModuleSSLOpenSSL::OnCleanup(), ModuleSSLGnuTLS::OnCleanup(), ModuleZLib::OnRequest(), ModuleSSLOpenSSL::OnRequest(), and ModuleSSLGnuTLS::OnRequest().

int EventHandler::GetFd  ) 
 

Get the current file descriptor.

Returns:
The file descriptor of this handler

Definition at line 72 of file socketengine.cpp.

References fd.

Referenced by SocketEngine::Accept(), CullList::Apply(), InspIRCd::BindPorts(), SocketEngine::BoundsCheckFd(), ModuleCgiIRC::CheckIdent(), ModuleCgiIRC::CheckPass(), SocketEngine::Close(), IdentRequestSocket::Close(), SocketEngine::Connect(), ModuleSpanningTree::ConnectServer(), SocketEngine::GetSockName(), CommandStartTLS::Handle(), ModuleSpanningTree::HandleRemoteWhois(), HandshakeTimer::HandshakeTimer(), IdentRequestSocket::IdentRequestSocket(), ModuleMsSQL::ModuleMsSQL(), ModuleSQL::ModuleSQL(), ModuleSQLite3::ModuleSQLite3(), ModuleSSLOpenSSL::OnBufferFlushed(), ModuleSSLGnuTLS::OnBufferFlushed(), IdentRequestSocket::OnConnected(), ServernameResolver::OnLookupComplete(), ModuleSSLOpenSSL::OnRequest(), ModuleSSLGnuTLS::OnRequest(), ModuleSpanningTree::OnUserMessage(), ModuleSpanningTree::OnUserNotice(), ModuleIdent::OnUserRegister(), ModuleDNSBL::OnUserRegister(), CommandParser::ProcessBuffer(), SpanningTreeUtilities::ReadConfiguration(), SocketEngine::Recv(), SocketEngine::RecvFrom(), SocketEngine::Send(), SocketEngine::SendTo(), SocketEngine::Shutdown(), and UserResolver::UserResolver().

Module * EventHandler::GetIOHook  ) 
 

Return the current hooker of IO events for this socket, or NULL.

Returns:
Hooker module, if set, or NULL.

Definition at line 67 of file socketengine.cpp.

References IOHook.

Referenced by UserManager::AddUser(), CullList::Apply(), BufferedSocket::Close(), BufferedSocket::FlushWriteBuffer(), CommandStartTLS::Handle(), BufferedSocket::InternalMarkConnected(), ServerSocketListener::OnAcceptReady(), ModuleSSLOpenSSL::OnCleanup(), ModuleSSLGnuTLS::OnCleanup(), ModuleSSLOpenSSL::OnHookUserIO(), ModuleSSLGnuTLS::OnHookUserIO(), BufferedSocket::Read(), and User::Write().

virtual void EventHandler::HandleEvent EventType  et,
int  errornum = 0
[pure virtual]
 

Process an I/O event.

You MUST implement this function in your derived class, and it will be called whenever read or write events are received, depending on what your functions Readable() and Writeable() returns and wether you previously made a call to SocketEngine::WantWrite().

Parameters:
et either one of EVENT_READ for read events, and EVENT_WRITE for write events.

Implemented in IdentRequestSocket, SQLConn, DNS, BufferedSocket, FileWriter, ListenSocketBase, and User.

bool EventHandler::Readable  )  [virtual]
 

Override this function to indicate readability.

Returns:
This should return true if the function wishes to receive EVENT_READ events. Do not change what this function returns while the event handler is still added to a SocketEngine instance! If this function is unimplemented, the base class will return true.
NOTE: You cannot set both Readable() and Writeable() to true. If you wish to receive a write event for your object, you must call SocketEngine::WantWrite() instead. This will trigger your objects next EVENT_WRITE type event.

Reimplemented in BufferedSocket.

Definition at line 82 of file socketengine.cpp.

void EventHandler::SetFd int  FD  ) 
 

Set a new file desciptor.

Parameters:
FD The new file descriptor. Do not call this method without first deleting the object from the SocketEngine if you have added it to a SocketEngine instance.

Definition at line 77 of file socketengine.cpp.

References fd.

Referenced by UserManager::AddUser(), IdentRequestSocket::Close(), DNS::DNS(), IdentRequestSocket::IdentRequestSocket(), InspIRCd::InspIRCd(), ListenSocketBase::ListenSocketBase(), TreeSocket::ParseUID(), and DNS::Rehash().

bool EventHandler::Writeable  )  [virtual]
 

Override this function to indicate writeability.

Returns:
This should return true if the function wishes to receive EVENT_WRITE events. Do not change what this function returns while the event handler is still added to a SocketEngine instance! If this function is unimplemented, the base class will return false.
NOTE: You cannot set both Readable() and Writeable() to true. If you wish to receive a write event for your object, you must call SocketEngine::WantWrite() instead. This will trigger your objects next EVENT_WRITE type event.

Definition at line 87 of file socketengine.cpp.


Member Data Documentation

int EventHandler::fd [protected]
 

File descriptor.

All events which can be handled must have a file descriptor. This allows you to add events for sockets, fifo's, pipes, and various other forms of IPC.

Definition at line 71 of file socketengine.h.

Referenced by BufferedSocket::BindAddr(), BufferedSocket::BufferedSocket(), SQLConn::DoConnect(), BufferedSocket::DoConnect(), User::FlushWriteBuf(), BufferedSocket::FlushWriteBuffer(), GetFd(), ListenSocketBase::ListenSocketBase(), SetFd(), User::User(), and ListenSocketBase::~ListenSocketBase().

Module* EventHandler::IOHook [protected]
 

Pointer to the module which has hooked the given EventHandler for IO events.

Definition at line 75 of file socketengine.h.

Referenced by AddIOHook(), DelIOHook(), EventHandler(), and GetIOHook().


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