InspIRCd  4.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 Cullable insp::uncopiable

Public Member Functions

 BufferedSocket (int newfd)
void DoConnect (const irc::sockets::sockaddrs &dest, const irc::sockets::sockaddrs &bind, unsigned long maxtime)
virtual void OnConnected ()
void OnDataReady () override=0
virtual void OnTimeout ()
- Public Member Functions inherited from StreamSocket
 StreamSocket (Type sstype=SS_UNKNOWN)
IOHookGetIOHook () const
void AddIOHook (IOHook *hook)
void DelIOHook ()
void DoWrite ()
void OnEventHandlerRead () override
void OnEventHandlerError (int errcode) override
void SetError (const std::string &err)
const std::string & GetError () const
virtual void OnError (BufferedSocketError e)=0
virtual bool OnSetLocalEndPoint (const irc::sockets::sockaddrs &ep)
virtual bool OnSetRemoteEndPoint (const irc::sockets::sockaddrs &ep)
void WriteData (const std::string &data)
size_t GetSendQSize () const
SendQueueGetSendQ ()
virtual void Close ()
void Close (bool writeblock)
Cullable::Result Cull () override
IOHookGetModHook (Module *mod) const
IOHookGetLastHook () const
- Public Member Functions inherited from EventHandler
int GetFd () const
bool HasFd () const
int GetEventMask () const
void SetFd (int FD)
 EventHandler ()
- Public Member Functions inherited from Cullable
virtual ~Cullable ()

Public Attributes

BufferedSocketState state
- Public Attributes inherited from StreamSocket
const Type type

Protected Member Functions

void OnEventHandlerWrite () override
BufferedSocketError BeginConnect (const irc::sockets::sockaddrs &dest, const irc::sockets::sockaddrs &bind, unsigned long timeout)
- Protected Member Functions inherited from Cullable
 Cullable ()

Additional Inherited Members

- Public Types inherited from StreamSocket
enum  Type { SS_UNKNOWN , SS_USER }
- 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 irc::sockets::sockaddrs dest,
const irc::sockets::sockaddrs bind,
unsigned long  maxtime 

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.

destRemote endpoint to connect to.
bindLocal endpoint to connect from.
maxtimeTime to wait for connection

◆ OnConnected()

void BufferedSocket::OnConnected ( )

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

◆ OnDataReady()

void BufferedSocket::OnDataReady ( )
overridepure virtual

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

Implements StreamSocket.

◆ OnEventHandlerWrite()

void BufferedSocket::OnEventHandlerWrite ( )

Called by the socket engine when a write event happens.

Reimplemented from 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: