InspIRCd
2.0
|
#include <inspsocket.h>
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 () |
![]() | |
Module * | GetIOHook () |
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 () |
![]() | |
int | GetFd () const |
int | GetEventMask () const |
void | SetFd (int FD) |
EventHandler () | |
virtual | ~EventHandler () |
Public Attributes | |
SocketTimeout * | Timeout |
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 | |
![]() | |
std::string | recvq |
![]() | |
int | fd |
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.
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.
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.
ipaddr | Address to connect to |
aport | Port to connect on |
maxtime | Time to wait for connection |
connectbindip | Address to bind to (if NULL, no bind will be done) |
|
protectedvirtual |
Dispatched from HandleEvent
Reimplemented from StreamSocket.
|
virtual |
This method is called when an outbound connection on your socket is completed.
|
pure virtual |
When there is data waiting to be read on a socket, the OnDataReady() method is called.
Implements StreamSocket.
|
virtual |
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.
BufferedSocketState BufferedSocket::state |
The state for this socket, either listening, connecting, connected or error.
SocketTimeout* BufferedSocket::Timeout |
Timeout object or NULL