InspIRCd  2.0
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
BufferedSocket Class Referenceabstract

#include <inspsocket.h>

Inheritance diagram for BufferedSocket:
StreamSocket EventHandler classbase

Public Member Functions

 BufferedSocket (int newfd)
void DoConnect (const std::string &ipaddr, int aport, unsigned long maxtime, const std::string &connectbindip)
virtual void OnConnected ()
virtual void OnDataReady ()=0
virtual void OnTimeout ()
- Public Member Functions inherited from StreamSocket
ModuleGetIOHook ()
void AddIOHook (Module *m)
void DelIOHook ()
virtual void HandleEvent (EventType et, int errornum=0)
virtual void DoRead ()
void SetError (const std::string &err)
const std::string & getError () const
virtual void OnError (BufferedSocketError e)=0
void WriteData (const std::string &data)
bool GetNextLine (std::string &line, char delim='\n')
size_t getSendQSize () const
virtual void Close ()
virtual CullResult cull ()
- Public Member Functions inherited from EventHandler
int GetFd () const
int GetEventMask () const
void SetFd (int FD)
 EventHandler ()
virtual ~EventHandler ()

Public Attributes

BufferedSocketState state

Protected Member Functions

virtual void DoWrite ()
BufferedSocketError BeginConnect (const irc::sockets::sockaddrs &dest, const irc::sockets::sockaddrs &bind, unsigned long timeout)
BufferedSocketError BeginConnect (const std::string &ipaddr, int aport, unsigned long maxtime, const std::string &connectbindip)

Additional Inherited Members

- Protected Attributes inherited from StreamSocket
std::string recvq
- Protected Attributes inherited from EventHandler
int fd

Detailed Description

BufferedSocket is an extendable socket class which modules can use for TCP socket support. It is fully integrated into InspIRCds socket loop and attaches its sockets to the core's instance of the SocketEngine class, meaning that all use is fully asynchronous.

To use BufferedSocket, you must inherit a class from it.

Constructor & Destructor Documentation

◆ BufferedSocket()

BufferedSocket::BufferedSocket ( int  newfd)

This constructor is used to associate an existing connecting with an BufferedSocket class. The given file descriptor must be valid, and when initialized, the BufferedSocket will be placed in CONNECTED state.

Member Function Documentation

◆ DoConnect()

void BufferedSocket::DoConnect ( const std::string &  ipaddr,
int  aport,
unsigned long  maxtime,
const std::string &  connectbindip 

Begin connection to the given address This will create a socket, register with socket engine, and start the asynchronous connection process. If an error is detected at this point (such as out of file descriptors), OnError will be called; otherwise, the state will become CONNECTING.

ipaddrAddress to connect to
aportPort to connect on
maxtimeTime to wait for connection
connectbindipAddress to bind to (if NULL, no bind will be done)

◆ DoWrite()

void BufferedSocket::DoWrite ( )

Dispatched from HandleEvent

Reimplemented from StreamSocket.

◆ OnConnected()

void BufferedSocket::OnConnected ( )

This method is called when an outbound connection on your socket is completed.

◆ OnDataReady()

virtual void BufferedSocket::OnDataReady ( )
pure virtual

When there is data waiting to be read on a socket, the OnDataReady() method is called.

Implements StreamSocket.

◆ OnTimeout()

void BufferedSocket::OnTimeout ( )

When an outbound connection fails, and the attempt times out, you will receive this event. The method will trigger once maxtime seconds are reached (as given in the constructor) just before the socket's descriptor is closed. A failed DNS lookup may cause this event if the DNS server is not responding, as well as a failed connect() call, because DNS lookups are nonblocking as implemented by this class.

Member Data Documentation

◆ state

BufferedSocketState BufferedSocket::state

The state for this socket, either listening, connecting, connected or error.

◆ Timeout

SocketTimeout* BufferedSocket::Timeout

Timeout object or NULL

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