Logo Search packages:      
Sourcecode: znc version File versions  Download package

Csock Class Reference

#include <Csocket.h>

Inheritance diagram for Csock:

CExecSock

List of all members.


Detailed Description

Basic Socket Class The most basic level socket class You can use this class directly for quick things or use the socket manager.

See also:
TSocketManager
Author:
Jim Hull <imaginos@imaginos.net>

Definition at line 458 of file Csocket.h.


Public Types

enum  { TMO_READ = 1, TMO_WRITE = 2, TMO_ACCEPT = 4, TMO_ALL = TMO_READ|TMO_WRITE|TMO_ACCEPT }
enum  ECloseType { CLT_DONT = 0, CLT_NOW = 1, CLT_AFTERWRITE = 2 }
enum  ECONState {
  CST_START = 0, CST_DNS = CST_START, CST_VHOSTDNS = 1, CST_BINDVHOST = 2,
  CST_CONNECT = 3, CST_OK = 4
}
enum  EDNSLType { DNS_VHOST, DNS_DEST }
enum  EFRead {
  READ_EOF = 0, READ_ERR = -1, READ_EAGAIN = -2, READ_CONNREFUSED = -3,
  READ_TIMEDOUT = -4
}
enum  EFSelect { SEL_OK = 0, SEL_TIMEOUT = -1, SEL_EAGAIN = -2, SEL_ERR = -3 }
enum  ESSLMethod { SSL23 = 0, SSL2 = 2, SSL3 = 3, TLS1 = 4 }
enum  ETConn { OUTBOUND = 0, LISTENER = 1, INBOUND = 2 }

Public Member Functions

virtual int Accept (CS_STRING &sHost, u_short &iRPort)
 Accept an inbound connection, this is used internally.
virtual bool AcceptSSL ()
 Accept an inbound SSL connection, this is used internally and called after Accept.
virtual void AddCron (CCron *pcCron)
 insert a newly created cron
bool AllowWrite (unsigned long long &iNOW) const
 returns true if this socket can write its data, primarily used with rate shaping, initialize iNOW to 0 and it sets it on the first call
void BlockIO (bool bBLOCK)
 Set rather to NON Blocking IO on this socket, default is true.
virtual bool CheckTimeout (time_t iNow)
 returns true if the socket has timed out
void ClearWriteBuffer ()
void Close (ECloseType eCloseType=CLT_NOW)
 just mark us as closed, the parent can pick it up
virtual bool Connect (const CS_STRING &sBindHost="", bool bSkipSetup=false)
virtual void Connected ()
bool ConnectFD (int iReadFD, int iWriteFD, const CS_STRING &sName, bool bIsSSL=false, ETConn eDirection=INBOUND)
 Tie this guy to an existing real file descriptor.
bool ConnectInetd (bool bIsSSL=false, const CS_STRING &sHostname="")
 Use this to bind this socket to inetd.
virtual bool ConnectionFrom (const CS_STRING &sHost, u_short iPort)
virtual void ConnectionRefused ()
virtual bool ConnectSSL (const CS_STRING &sBindhost="")
virtual void Copy (const Csock &cCopy)
 use this to copy a sock from one to the other, override it if you have special needs in the event of a copy
bool CreateSocksFD ()
 grabs fd's for the sockets
virtual void Cron ()
 This has a garbage collecter, and is used internall to call the jobs.
 Csock (const CS_STRING &sHostname, u_short iport, int itimeout=60)
 Csock (int itimeout=60)
 default constructor, sets a timeout of 60 seconds
virtual void DelCron (u_int iPos)
 delete cron by idx
virtual void DelCron (const CS_STRING &sName, bool bDeleteAll=true, bool bCaseSensitive=true)
 deletes a cron by name
virtual void DelCronByAddr (CCron *pcCron)
 delete cron by address
virtual void Dereference ()
 in the event you pass this class to Copy(), you MUST call this function or on the original Csock other wise bad side effects will happen (double deletes, weird sock closures, etc) if you call this function and have not handled the internal pointers, other bad things can happend (memory leaks, fd leaks, etc) the whole point of this function is to allow this class to go away without shutting down
void DisableReadLine ()
virtual void Disconnected ()
int DNSLookup (EDNSLType eDNSLType)
void EnableReadLine ()
 set the value of m_bEnableReadLine to true, we don't want to store a buffer for ReadLine, unless we want it
bool FullSSLAccept ()
 is SSL_accept finished ?
double GetAvgRead (unsigned long long iSample=1000)
 Get Avg Read Speed in sample milliseconds (default is 1000 milliseconds or 1 second).
double GetAvgWrite (unsigned long long iSample=1000)
 Get Avg Write Speed in sample milliseconds (default is 1000 milliseconds or 1 second).
const CS_STRING & GetBindHost () const
unsigned long long GetBytesRead () const
 Gets the amount of data read during the existence of the socket.
unsigned long long GetBytesWritten () const
 Gets the amount of data written during the existence of the socket.
ECloseType GetCloseType ()
 returns int of type to close
ECONState GetConState () const
 returns the current connection state
const std::vector< CCron * > & GetCrons () const
 returns a const reference to the crons associated to this socket
const CS_STRING & GetHostName ()
 Returns a reference to the host name.
CS_STRING & GetInternalBuffer ()
bool GetIPv6 () const
time_t GetLastCheckTimeout ()
CS_STRING GetLocalIP ()
u_short GetLocalPort ()
 Returns the local port.
u_int GetMaxBufferThreshold ()
const CS_STRING & GetParentSockName ()
virtual int GetPending ()
 return the data imediatly ready for read
u_short GetPort ()
 Returns the port.
u_int GetRateBytes ()
unsigned long long GetRateTime ()
CS_STRING GetRemoteIP ()
u_short GetRemotePort ()
 Returns the remote port.
int & GetRSock ()
 returns a reference to the sock
int & GetSock ()
const CS_STRING & GetSockName ()
 Returns a reference to the socket name.
virtual CsockGetSockObj (const CS_STRING &sHostname, u_short iPort)
 override this for accept sockets
bool GetSSL ()
 if this connection type is ssl or not
unsigned long long GetStartTime () const
 Gets the starting time of this socket.
int GetTimeout () const
u_int GetTimeoutType () const
int GetTimeSinceLastDataTransaction (time_t iNow=0)
 return how long it has been (in seconds) since the last read or successful write
int GetType ()
 Returns the connection type from enum eConnType.
const CS_STRING & GetWriteBuffer ()
 Get the send buffer.
int & GetWSock ()
bool HasReadLine () const
 returns the value of m_bEnableReadLine, if ReadLine is enabled
bool IsClosed ()
virtual bool IsConnected ()
 Tells you if the socket is connected.
bool IsReadPaused ()
virtual bool Listen (u_short iPort, int iMaxConns=SOMAXCONN, const CS_STRING &sBindHost="", u_int iTimeout=0)
void NonBlockingIO ()
 Use this to change your fd's to blocking or none blocking.
Csockoperator<< (double i)
Csockoperator<< (float i)
Csockoperator<< (unsigned long long i)
Csockoperator<< (unsigned long i)
Csockoperator<< (long i)
Csockoperator<< (unsigned int i)
Csockoperator<< (int i)
Csockoperator<< (std::ostream &(*io)(std::ostream &))
Csockoperator<< (const CS_STRING &s)
void PauseRead ()
 will pause/unpause reading on this socket
virtual void PushBuff (const char *data, int len, bool bStartAtZero=false)
virtual void ReachedMaxBuffer ()
virtual int Read (char *data, int len)
virtual void ReadData (const char *data, int len)
virtual void ReadLine (const CS_STRING &sLine)
virtual void ReadPaused ()
virtual int ReadSelect ()
void ResetBytesRead ()
void ResetBytesWritten ()
void ResetStartTime ()
 Resets the start time.
void ResetTimer ()
 resets the time counter
void SetAFRequire (CSSockAddr::EAFRequire iAFRequire)
void SetBindHost (const CS_STRING &sBindHost)
void SetConState (ECONState eState)
 sets the connection state to eState
void SetHostName (const CS_STRING &sHostname)
void SetIPv6 (bool b)
virtual void SetIsConnected (bool b)
 Sets the sock, telling it its connected (internal use only).
void SetMaxBufferThreshold (u_int iThreshold)
 sets the max buffered threshold when EnableReadLine() is enabled
virtual void SetParentSockName (const CS_STRING &sParentName)
 Get the peer's X509 cert.
void SetPort (u_short iPort)
virtual void SetRate (u_int iBytes, unsigned long long iMilliseconds)
void SetRSock (int iSock)
void SetSock (int iSock)
void SetSockName (const CS_STRING &sName)
void SetSSL (bool b)
void SetTimeout (int iTimeout, u_int iTimeoutType=TMO_ALL)
void SetTimeoutType (u_int iTimeoutType)
void SetType (int iType)
bool SetupVHost ()
 this is only used on outbound connections, listeners bind in a different spot
void SetWSock (int iSock)
virtual void SockError (int iErrno)
virtual bool SSLClientSetup ()
 This sets up the SSL Client, this is used internally.
bool SslIsEstablished ()
 is the ssl properly finished (from write no error)
virtual bool SSLServerSetup ()
 This sets up the SSL Server, this is used internally.
virtual void Timeout ()
void UnPauseRead ()
virtual bool Write (const CS_STRING &sData)
virtual bool Write (const char *data, int len)
virtual int WriteSelect ()

Private Member Functions

 Csock (const Csock &cCopy)
 making private for safety
void Init (const CS_STRING &sHostname, u_short iport, int itimeout=60)
int SOCKET (bool bListen=false)
 Create the socket.

Private Attributes

CSSockAddr m_address
bool m_bBLOCK
bool m_bEnableReadLine
bool m_bFullsslAccept
CSSockAddr m_bindhost
bool m_bIsConnected
bool m_bIsIPv6
bool m_bPauseRead
bool m_bRequireClientCert
bool m_bssl
bool m_bsslEstablished
ECloseType m_eCloseType
ECONState m_eConState
unsigned long long m_iBytesRead
unsigned long long m_iBytesWritten
int m_iConnType
u_int m_iCurBindCount
u_int m_iDNSTryCount
time_t m_iLastCheckTimeoutTime
unsigned int m_iLastSend
unsigned long long m_iLastSendTime
u_short m_iLocalPort
unsigned int m_iMaxBytes
unsigned long long m_iMaxMilliSeconds
unsigned int m_iMaxStoredBufferLength
int m_iMethod
u_short m_iport
int m_iReadSock
u_short m_iRemotePort
unsigned long long m_iStartTime
int m_iTcount
int m_itimeout
unsigned int m_iTimeoutType
int m_iWriteSock
CS_STRING m_sBindHost
CS_STRING m_sbuffer
CS_STRING m_sCipherType
CS_STRING m_shostname
CS_STRING m_sLocalIP
CS_STRING m_sParentName
CS_STRING m_sPemFile
CS_STRING m_sPemPass
CS_STRING m_sRemoteIP
CS_STRING m_sSend
CS_STRING m_sSockName
CS_STRING m_sSSLBuffer
std::vector< CCron * > m_vcCrons

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

Generated by  Doxygen 1.6.0   Back to index