InspIRCd  3.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 ThreadSignalSocket

Public Member Functions

 BufferedSocket (int newfd)
void DoConnect (const std::string &ipaddr, int aport, unsigned int maxtime, const std::string &connectbindip)
virtual void OnConnected ()
void OnDataReady () CXX11_OVERRIDE=0
virtual void OnTimeout ()
- Public Member Functions inherited from StreamSocket
IOHookGetIOHook () const
void AddIOHook (IOHook *hook)
void DelIOHook ()
void DoWrite ()
void OnEventHandlerRead () CXX11_OVERRIDE
void OnEventHandlerError (int errcode) CXX11_OVERRIDE
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
SendQueueGetSendQ ()
virtual void Close ()
CullResult cull () CXX11_OVERRIDE
IOHookGetModHook (Module *mod) const
- 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

void OnEventHandlerWrite () CXX11_OVERRIDE
BufferedSocketError BeginConnect (const irc::sockets::sockaddrs &dest, const irc::sockets::sockaddrs &bind, unsigned int timeout)
BufferedSocketError BeginConnect (const std::string &ipaddr, int aport, unsigned int 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 int  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)

◆ OnConnected()

void BufferedSocket::OnConnected ( )

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

◆ OnDataReady()

void BufferedSocket::OnDataReady ( )
pure virtual

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

Implements StreamSocket.

Implemented in ThreadSignalSocket.

◆ OnEventHandlerWrite()

void BufferedSocket::OnEventHandlerWrite ( )

Called by the socket engine on a write event

Reimplemented from StreamSocket.

Reimplemented in ThreadSignalSocket.

◆ 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: