ZNC
trunk
|
Basic socket class. More...
#include <Csocket.h>
Public Types | |
enum | ETConn { OUTBOUND = 0 , LISTENER = 1 , INBOUND = 2 } |
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 { TLS = 0 , SSL23 = TLS , SSL2 = 2 , SSL3 = 3 , TLS1 = 4 , TLS11 = 5 , TLS12 = 6 } |
enum | EDisableProtocol { EDP_None = 0 , EDP_SSLv2 = 1 , EDP_SSLv3 = 2 , EDP_TLSv1 = 4 , EDP_TLSv1_1 = 8 , EDP_TLSv1_2 = 16 , EDP_SSL = (EDP_SSLv2|EDP_SSLv3) } |
enum | ECONState { CST_START = 0 , CST_DNS = CST_START , CST_BINDVHOST = 1 , CST_DESTDNS = 2 , CST_CONNECT = 3 , CST_CONNECTSSL = 4 , CST_OK = 5 } |
enum | ECloseType { CLT_DONT = 0 , CLT_NOW = 1 , CLT_AFTERWRITE = 2 , CLT_DEREFERENCE = 3 } |
enum | { TMO_READ = 1 , TMO_WRITE = 2 , TMO_ACCEPT = 4 , TMO_ALL = TMO_READ|TMO_WRITE|TMO_ACCEPT } |
this timeout isn't just connection timeout, but also timeout on NOT recieving data, to disable this set it to 0 then the normal TCP timeout will apply (basically TCP will kill a dead connection) Set the timeout, set to 0 to never timeout More... | |
enum | EDNSLType { DNS_VHOST , DNS_DEST } |
Public Member Functions | |
Csock (int iTimeout=60) | |
default constructor, sets a timeout of 60 seconds More... | |
Csock (const CS_STRING &sHostname, uint16_t uPort, int itimeout=60) | |
Advanced constructor, for creating a simple connection. More... | |
virtual Csock * | GetSockObj (const CS_STRING &sHostname, uint16_t iPort) |
override this for accept sockets More... | |
virtual | ~Csock () |
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 More... | |
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 More... | |
Csock & | operator<< (const CS_STRING &s) |
Csock & | operator<< (std::ostream &(*io)(std::ostream &)) |
Csock & | operator<< (int32_t i) |
Csock & | operator<< (uint32_t i) |
Csock & | operator<< (int64_t i) |
Csock & | operator<< (uint64_t i) |
Csock & | operator<< (float i) |
Csock & | operator<< (double i) |
virtual bool | Connect () |
Create the connection, this is used by the socket manager, and shouldn't be called directly by the user. More... | |
virtual bool | ConnectUnix (const CS_STRING &sPath) |
Connect to a UNIX socket. More... | |
virtual bool | ListenUnix (const CS_STRING &sBindFile, int iMaxConns=SOMAXCONN, uint32_t iTimeout=0) |
Listens for connections on an UNIX socket. More... | |
virtual bool | Listen (uint16_t iPort, int iMaxConns=SOMAXCONN, const CS_STRING &sBindHost="", uint32_t iTimeout=0, bool bDetach=false) |
Listens for connections. More... | |
virtual cs_sock_t | Accept (CS_STRING &sHost, uint16_t &iRPort) |
Accept an inbound connection, this is used internally. More... | |
virtual bool | AcceptSSL () |
Accept an inbound SSL connection, this is used internally and called after Accept. More... | |
virtual bool | SSLClientSetup () |
This sets up the SSL Client, this is used internally. More... | |
virtual bool | SSLServerSetup () |
This sets up the SSL Server, this is used internally. More... | |
virtual bool | ConnectSSL () |
Create the SSL connection. More... | |
bool | StartTLS () |
start a TLS connection on an existing plain connection More... | |
virtual bool | Write (const char *data, size_t len) |
Write data to the socket. More... | |
virtual bool | Write (const CS_STRING &sData) |
Write a text string to the socket. More... | |
virtual cs_ssize_t | Read (char *data, size_t len) |
Read from the socket Just pass in a pointer, big enough to hold len bytes. More... | |
CS_STRING | GetLocalIP () const |
CS_STRING | GetRemoteIP () const |
virtual bool | IsConnected () const |
Tells you if the socket is connected. More... | |
virtual void | SetIsConnected (bool b) |
Sets the sock, telling it its connected (internal use only) More... | |
cs_sock_t & | GetRSock () |
returns a reference to the sock More... | |
const cs_sock_t & | GetRSock () const |
void | SetRSock (cs_sock_t iSock) |
cs_sock_t & | GetWSock () |
const cs_sock_t & | GetWSock () const |
void | SetWSock (cs_sock_t iSock) |
void | SetSock (cs_sock_t iSock) |
cs_sock_t & | GetSock () |
const cs_sock_t & | GetSock () const |
void | CallSockError (int iErrno, const CS_STRING &sDescription="") |
calls SockError, if sDescription is not set, then strerror is used to pull out a default description More... | |
virtual void | ResetTimer () |
resets the time counter, this is virtual in the event you need an event on the timer being Reset More... | |
void | PauseRead () |
will pause/unpause reading on this socket More... | |
void | UnPauseRead () |
bool | IsReadPaused () const |
void | SetTimeout (int iTimeout, uint32_t iTimeoutType=TMO_ALL) |
Currently this uses the same value for all timeouts, and iTimeoutType merely states which event will be checked for timeouts. More... | |
void | SetTimeoutType (uint32_t iTimeoutType) |
int | GetTimeout () const |
uint32_t | GetTimeoutType () const |
virtual bool | CheckTimeout (time_t iNow) |
returns true if the socket has timed out More... | |
virtual void | PushBuff (const char *data, size_t len, bool bStartAtZero=false) |
pushes data up on the buffer, if a line is ready it calls the ReadLine event More... | |
CS_STRING & | GetInternalReadBuffer () |
This gives access to the internal read buffer, if your not going to use ReadLine(), then you may want to clear this out (if its binary data and not many '\n') More... | |
CS_STRING & | GetInternalWriteBuffer () |
This gives access to the internal write buffer. More... | |
void | SetMaxBufferThreshold (uint32_t iThreshold) |
sets the max buffered threshold when EnableReadLine() is enabled More... | |
uint32_t | GetMaxBufferThreshold () const |
int | GetType () const |
Returns the connection type from enum eConnType. More... | |
void | SetType (int iType) |
const CS_STRING & | GetSockName () const |
Returns a reference to the socket name. More... | |
void | SetSockName (const CS_STRING &sName) |
const CS_STRING & | GetHostName () const |
Returns a reference to the host name. More... | |
void | SetHostName (const CS_STRING &sHostname) |
uint64_t | GetStartTime () const |
Gets the starting time of this socket. More... | |
void | ResetStartTime () |
Resets the start time. More... | |
uint64_t | GetBytesRead () const |
Gets the amount of data read during the existence of the socket. More... | |
void | ResetBytesRead () |
uint64_t | GetBytesWritten () const |
Gets the amount of data written during the existence of the socket. More... | |
void | ResetBytesWritten () |
double | GetAvgRead (uint64_t iSample=1000) const |
Get Avg Read Speed in sample milliseconds (default is 1000 milliseconds or 1 second) More... | |
double | GetAvgWrite (uint64_t iSample=1000) const |
Get Avg Write Speed in sample milliseconds (default is 1000 milliseconds or 1 second) More... | |
uint16_t | GetRemotePort () const |
Returns the remote port. More... | |
uint16_t | GetLocalPort () const |
Returns the local port. More... | |
uint16_t | GetPort () const |
Returns the port. More... | |
void | SetPort (uint16_t iPort) |
void | Close (ECloseType eCloseType=CLT_NOW) |
just mark us as closed, the parent can pick it up More... | |
ECloseType | GetCloseType () const |
returns int of type to close More... | |
bool | IsClosed () const |
void | NonBlockingIO () |
Use this to change your fd's to blocking or none blocking. More... | |
bool | GetSSL () const |
Return true if this socket is using ssl. Note this does not mean the SSL state is finished, but simply that its configured to use ssl. More... | |
void | SetSSL (bool b) |
void | DisableSSLProtocols (u_int uDisableOpts) |
bitwise setter, More... | |
void | DisableSSLCompression () |
allow disabling compression More... | |
void | FollowSSLCipherServerPreference () |
select the ciphers in server-preferred order More... | |
void | SetCipher (const CS_STRING &sCipher) |
Set the cipher type ( openssl cipher [to see ciphers available] ) More... | |
const CS_STRING & | GetCipher () const |
void | SetDHParamLocation (const CS_STRING &sDHParamFile) |
Set the pem file location. More... | |
const CS_STRING & | GetDHParamLocation () const |
void | SetKeyLocation (const CS_STRING &sKeyFile) |
const CS_STRING & | GetKeyLocation () const |
void | SetPemLocation (const CS_STRING &sPemFile) |
const CS_STRING & | GetPemLocation () const |
void | SetPemPass (const CS_STRING &sPassword) |
const CS_STRING & | GetPemPass () const |
void | SetSSLMethod (int iMethod) |
Set the SSL method type. More... | |
int | GetSSLMethod () const |
void | SetSSLObject (SSL *ssl, bool bDeleteExisting=false) |
SSL * | GetSSLObject () const |
void | SetCTXObject (SSL_CTX *sslCtx, bool bDeleteExisting=false) |
SSL_SESSION * | GetSSLSession () const |
void | SetCertVerifyCB (FPCertVerifyCB pFP) |
setting this to NULL will allow the default openssl verification process kick in More... | |
bool | HasWriteBuffer () const |
Get the send buffer. More... | |
void | ClearWriteBuffer () |
bool | SslIsEstablished () const |
is SSL_accept finished ? is the ssl properly finished (from write no error) More... | |
bool | ConnectInetd (bool bIsSSL=false, const CS_STRING &sHostname="") |
Use this to bind this socket to inetd. More... | |
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. More... | |
X509 * | GetX509 () const |
Get the peer's X509 cert. More... | |
CS_STRING | GetPeerPubKey () const |
Returns the peer's public key. More... | |
long | GetPeerFingerprint (CS_STRING &sFP) const |
Returns the peer's certificate finger print. More... | |
uint32_t | GetRequireClientCertFlags () const |
void | SetRequiresClientCert (bool bRequiresCert) |
legacy, deprecated More... | |
void | SetRequireClientCertFlags (uint32_t iRequireClientCertFlags) |
bitwise flags, 0 means don't require cert, SSL_VERIFY_PEER verifies peers, SSL_VERIFY_FAIL_IF_NO_PEER_CERT will cause the connection to fail if no cert More... | |
virtual void | SetParentSockName (const CS_STRING &sParentName) |
Set The INBOUND Parent sockname. More... | |
const CS_STRING & | GetParentSockName () const |
virtual void | SetRate (uint32_t iBytes, uint64_t iMilliseconds) |
sets the rate at which we can send data More... | |
uint32_t | GetRateBytes () const |
uint64_t | GetRateTime () const |
virtual void | Connected () |
Connected event. More... | |
virtual void | Disconnected () |
Disconnected event. More... | |
virtual void | Timeout () |
Sock Timed out event. More... | |
virtual void | ReadData (const char *data, size_t len) |
Ready to read data event. More... | |
virtual void | ReadLine (const CS_STRING &sLine) |
Ready to Read a full line event. More... | |
void | EnableReadLine () |
set the value of m_bEnableReadLine to true, we don't want to store a buffer for ReadLine, unless we want it More... | |
void | DisableReadLine () |
bool | HasReadLine () const |
returns the value of m_bEnableReadLine, if ReadLine is enabled More... | |
virtual void | ReachedMaxBuffer () |
This WARNING event is called when your buffer for readline exceeds the warning threshold and triggers this event. More... | |
virtual void | SockError (int iErrno, const CS_STRING &sDescription) |
A sock error occured event. More... | |
virtual bool | ConnectionFrom (const CS_STRING &sHost, uint16_t iPort) |
Incoming Connection Event return false and the connection will fail default returns true. More... | |
virtual void | Listening (const CS_STRING &sBindIP, uint16_t uPort) |
called when type is LISTENER and the listening port is up and running More... | |
virtual void | ConnectionRefused () |
Connection Refused Event. More... | |
virtual void | ReadPaused () |
This gets called every iteration of CSocketManager::Select() if the socket is ReadPaused. More... | |
virtual void | SSLFinishSetup (SSL *pSSL) |
Gets called immediatly after the m_ssl member is setup and initialized, useful if you need to assign anything to this ssl session via SSL_set_ex_data. More... | |
virtual bool | SNIConfigureServer (const CS_STRING &sHostname, CS_STRING &sPemFile, CS_STRING &sPemPass) |
gets called when a SNI request is sent, and used to configure a SNI session More... | |
virtual bool | SNIConfigureClient (CS_STRING &sHostname) |
called to configure the SNI client More... | |
SSL_CTX * | SetupServerCTX () |
creates a new SSL_CTX based on the setup of this sock More... | |
virtual void | SSLHandShakeFinished () |
called once the SSL handshake is complete, this is triggered via SSL_CB_HANDSHAKE_DONE in SSL_set_info_callback() More... | |
virtual int | VerifyPeerCertificate (int iPreVerify, X509_STORE_CTX *pStoreCTX) |
this is hooked in via SSL_set_verify, and be default it just returns 1 meaning success More... | |
time_t | GetTimeSinceLastDataTransaction (time_t iNow=0) const |
return how long it has been (in seconds) since the last read or successful write More... | |
time_t | GetLastCheckTimeout () const |
time_t | GetNextCheckTimeout (time_t iNow=0) const |
Returns the time when CheckTimeout() should be called next. More... | |
virtual int | GetPending () const |
return the data imediatly ready for read More... | |
ECONState | GetConState () const |
returns the current connection state More... | |
void | SetConState (ECONState eState) |
sets the connection state to eState More... | |
bool | CreateSocksFD () |
grabs fd's for the sockets More... | |
void | CloseSocksFD () |
puts the socks back to the state they were prior to calling CreateSocksFD More... | |
const CS_STRING & | GetBindHost () const |
void | SetBindHost (const CS_STRING &sBindHost) |
int | DNSLookup (EDNSLType eDNSLType) |
dns lookup More... | |
bool | SetupVHost () |
this is only used on outbound connections, listeners bind in a different spot More... | |
bool | GetIPv6 () const |
void | SetIPv6 (bool b) |
void | SetAFRequire (CSSockAddr::EAFRequire iAFRequire) |
bool | AllowWrite (uint64_t &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 More... | |
void | SetSkipConnect (bool b) |
virtual int | GetAddrInfo (const CS_STRING &sHostname, CSSockAddr &csSockAddr) |
override this call with your own DNS lookup method if you have one. More... | |
virtual int | ConvertAddress (const struct sockaddr_storage *pAddr, socklen_t iAddrLen, CS_STRING &sIP, uint16_t *piPort) const |
retrieve name info (numeric only) for a given sockaddr_storage More... | |
int | GetMaxConns () const |
returns the number of max pending connections when type is LISTENER More... | |
void | SetEncoding (const CS_STRING &sEncoding) |
CS_STRING | GetEncoding () const |
virtual void | IcuExtToUCallback (UConverterToUnicodeArgs *toArgs, const char *codeUnits, int32_t length, UConverterCallbackReason reason, UErrorCode *err) |
virtual void | IcuExtFromUCallback (UConverterFromUnicodeArgs *fromArgs, const UChar *codeUnits, int32_t length, UChar32 codePoint, UConverterCallbackReason reason, UErrorCode *err) |
void | CleanupCrons () |
void | CleanupFDMonitors () |
const std::vector< CCron * > & | GetCrons () const |
returns a const reference to the crons associated to this socket More... | |
virtual void | Cron () |
This has a garbage collecter, and is used internall to call the jobs. More... | |
virtual void | AddCron (CCron *pcCron) |
insert a newly created cron More... | |
virtual void | DelCron (const CS_STRING &sName, bool bDeleteAll=true, bool bCaseSensitive=true) |
deletes a cron by name More... | |
virtual void | DelCron (uint32_t iPos) |
delete cron by idx More... | |
virtual void | DelCronByAddr (CCron *pcCron) |
delete cron by address More... | |
void | CheckFDs (const std::map< cs_sock_t, short > &miiReadyFds) |
void | AssignFDs (std::map< cs_sock_t, short > &miiReadyFds, struct timeval *tvtimeout) |
void | MonitorFD (CSMonitorFD *pMonitorFD) |
add an FD set to monitor More... | |
Protected Attributes | |
std::vector< CCron * > | m_vcCrons |
std::vector< CSMonitorFD * > | m_vcMonitorFD |
Basic socket class.
The most basic level socket class. You can use this class directly for quick things or use the socket manager.
anonymous enum |
enum Csock::ECloseType |
Enumerator | |
---|---|
CLT_DONT | don't close DER |
CLT_NOW | close immediatly |
CLT_AFTERWRITE | close after finishing writing the buffer |
CLT_DEREFERENCE | used after copy in Csock::Dereference() to cleanup a sock thats being shutdown |
enum Csock::ECONState |
enum Csock::EDNSLType |
enum Csock::EFRead |
enum Csock::EFSelect |
enum Csock::ESSLMethod |
enum Csock::ETConn |
Csock::Csock | ( | int | iTimeout = 60 | ) |
default constructor, sets a timeout of 60 seconds
Csock::Csock | ( | const CS_STRING & | sHostname, |
uint16_t | uPort, | ||
int | itimeout = 60 |
||
) |
Advanced constructor, for creating a simple connection.
sHostname | the hostname your are connecting to |
uPort | the port you are connecting to |
itimeout | how long to wait before ditching the connection, default is 60 seconds |
|
virtual |
Accept an inbound connection, this is used internally.
|
virtual |
Accept an inbound SSL connection, this is used internally and called after Accept.
|
virtualinherited |
insert a newly created cron
bool Csock::AllowWrite | ( | uint64_t & | 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
|
inherited |
void Csock::CallSockError | ( | int | iErrno, |
const CS_STRING & | sDescription = "" |
||
) |
calls SockError, if sDescription is not set, then strerror is used to pull out a default description
iErrno | the errno to send |
sDescription | the description of the error that occurred |
|
inherited |
|
virtual |
returns true if the socket has timed out
|
inherited |
|
inherited |
void Csock::ClearWriteBuffer | ( | ) |
void Csock::Close | ( | ECloseType | eCloseType = CLT_NOW | ) |
just mark us as closed, the parent can pick it up
Referenced by CExecSock::Kill().
void Csock::CloseSocksFD | ( | ) |
puts the socks back to the state they were prior to calling CreateSocksFD
|
virtual |
Create the connection, this is used by the socket manager, and shouldn't be called directly by the user.
Reimplemented in CSocket.
|
inlinevirtual |
bool Csock::ConnectFD | ( | int | iReadFD, |
int | iWriteFD, | ||
const CS_STRING & | sName, | ||
bool | bIsSSL = false , |
||
ETConn | eDirection = INBOUND |
||
) |
Tie this guy to an existing real file descriptor.
Referenced by CExecSock::Execute().
bool Csock::ConnectInetd | ( | bool | bIsSSL = false , |
const CS_STRING & | sHostname = "" |
||
) |
Use this to bind this socket to inetd.
|
inlinevirtual |
Incoming Connection Event return false and the connection will fail default returns true.
|
inlinevirtual |
|
virtual |
Create the SSL connection.
This is used by the socket manager, and shouldn't be called directly by the user.
|
virtual |
Connect to a UNIX socket.
sPath | the path to the UNIX socket. |
|
virtual |
retrieve name info (numeric only) for a given sockaddr_storage
pAddr | the sockaddr_storage |
iAddrLen | the length |
sIP | filled with the IP from getnameinfo |
piPort | if not null, filled with the port |
In the event you want to do additional work before or after getnameinfo is called, you can override this and do just that. One example is in the event that an ipv6 ip is a mapped ipv4 mapped, you can check like so.
|
virtual |
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 Csock::CreateSocksFD | ( | ) |
grabs fd's for the sockets
|
virtualinherited |
This has a garbage collecter, and is used internall to call the jobs.
|
virtualinherited |
deletes a cron by name
sName | the name of the cron |
bDeleteAll | delete all crons that match sName |
bCaseSensitive | use strcmp or strcasecmp |
|
virtualinherited |
delete cron by idx
|
virtualinherited |
delete cron by address
|
virtual |
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 Csock::DisableReadLine | ( | ) |
|
inline |
allow disabling compression
|
inline |
bitwise setter,
|
inlinevirtual |
int Csock::DNSLookup | ( | EDNSLType | eDNSLType | ) |
dns lookup
void Csock::EnableReadLine | ( | ) |
set the value of m_bEnableReadLine to true, we don't want to store a buffer for ReadLine, unless we want it
|
inline |
select the ciphers in server-preferred order
|
virtual |
override this call with your own DNS lookup method if you have one.
By default this function is blocking
sHostname | the hostname to resolve |
csSockAddr | the destination sock address info |
double Csock::GetAvgRead | ( | uint64_t | iSample = 1000 | ) | const |
Get Avg Read Speed in sample milliseconds (default is 1000 milliseconds or 1 second)
double Csock::GetAvgWrite | ( | uint64_t | iSample = 1000 | ) | const |
Get Avg Write Speed in sample milliseconds (default is 1000 milliseconds or 1 second)
|
inline |
uint64_t Csock::GetBytesRead | ( | ) | const |
Gets the amount of data read during the existence of the socket.
uint64_t Csock::GetBytesWritten | ( | ) | const |
Gets the amount of data written during the existence of the socket.
const CS_STRING& Csock::GetCipher | ( | ) | const |
|
inline |
returns int of type to close
|
inline |
returns the current connection state
|
inlineinherited |
returns a const reference to the crons associated to this socket
const CS_STRING& Csock::GetDHParamLocation | ( | ) | const |
|
inline |
const CS_STRING& Csock::GetHostName | ( | ) | const |
Returns a reference to the host name.
CS_STRING& Csock::GetInternalReadBuffer | ( | ) |
This gives access to the internal read buffer, if your not going to use ReadLine(), then you may want to clear this out (if its binary data and not many '\n')
CS_STRING& Csock::GetInternalWriteBuffer | ( | ) |
This gives access to the internal write buffer.
If you want to check if the send queue fills up, check here.
|
inline |
const CS_STRING& Csock::GetKeyLocation | ( | ) | const |
|
inline |
CS_STRING Csock::GetLocalIP | ( | ) | const |
uint16_t Csock::GetLocalPort | ( | ) | const |
Returns the local port.
uint32_t Csock::GetMaxBufferThreshold | ( | ) | const |
|
inline |
returns the number of max pending connections when type is LISTENER
time_t Csock::GetNextCheckTimeout | ( | time_t | iNow = 0 | ) | const |
Returns the time when CheckTimeout() should be called next.
const CS_STRING& Csock::GetParentSockName | ( | ) | const |
long Csock::GetPeerFingerprint | ( | CS_STRING & | sFP | ) | const |
Returns the peer's certificate finger print.
CS_STRING Csock::GetPeerPubKey | ( | ) | const |
Returns the peer's public key.
const CS_STRING& Csock::GetPemLocation | ( | ) | const |
const CS_STRING& Csock::GetPemPass | ( | ) | const |
|
virtual |
return the data imediatly ready for read
uint16_t Csock::GetPort | ( | ) | const |
Returns the port.
uint32_t Csock::GetRateBytes | ( | ) | const |
uint64_t Csock::GetRateTime | ( | ) | const |
CS_STRING Csock::GetRemoteIP | ( | ) | const |
Referenced by CZNCSock::GetRemoteIP().
uint16_t Csock::GetRemotePort | ( | ) | const |
Returns the remote port.
uint32_t Csock::GetRequireClientCertFlags | ( | ) | const |
cs_sock_t& Csock::GetRSock | ( | ) |
returns a reference to the sock
Referenced by CExecSock::~CExecSock().
const cs_sock_t& Csock::GetRSock | ( | ) | const |
cs_sock_t& Csock::GetSock | ( | ) |
const cs_sock_t& Csock::GetSock | ( | ) | const |
const CS_STRING& Csock::GetSockName | ( | ) | const |
Returns a reference to the socket name.
override this for accept sockets
bool Csock::GetSSL | ( | ) | const |
Return true if this socket is using ssl. Note this does not mean the SSL state is finished, but simply that its configured to use ssl.
int Csock::GetSSLMethod | ( | ) | const |
SSL* Csock::GetSSLObject | ( | ) | const |
SSL_SESSION* Csock::GetSSLSession | ( | ) | const |
uint64_t Csock::GetStartTime | ( | ) | const |
Gets the starting time of this socket.
int Csock::GetTimeout | ( | ) | const |
uint32_t Csock::GetTimeoutType | ( | ) | const |
time_t Csock::GetTimeSinceLastDataTransaction | ( | time_t | iNow = 0 | ) | const |
return how long it has been (in seconds) since the last read or successful write
int Csock::GetType | ( | ) | const |
Returns the connection type from enum eConnType.
cs_sock_t& Csock::GetWSock | ( | ) |
Referenced by CExecSock::~CExecSock().
const cs_sock_t& Csock::GetWSock | ( | ) | const |
X509* Csock::GetX509 | ( | ) | const |
Get the peer's X509 cert.
it is up to you, the caller to call X509_free() on this object
|
inline |
returns the value of m_bEnableReadLine, if ReadLine is enabled
bool Csock::HasWriteBuffer | ( | ) | const |
Get the send buffer.
|
virtual |
Reimplemented in CIRCSocket.
|
virtual |
Reimplemented in CIRCSocket.
|
inline |
|
virtual |
Tells you if the socket is connected.
bool Csock::IsReadPaused | ( | ) | const |
|
virtual |
Listens for connections.
iPort | the port to listen on |
iMaxConns | the maximum amount of pending connections to allow |
sBindHost | the vhost on which to listen |
iTimeout | if no connections come in by this timeout, the listener is closed |
bDetach | don't block waiting for port to come up, instead detach and return immediately |
|
inlinevirtual |
called when type is LISTENER and the listening port is up and running
sBindIP | the IP that is being bound to. Empty if no bind restriction |
uPort | the listening port |
|
virtual |
Listens for connections on an UNIX socket.
sBindFile | the socket on which to listen |
iMaxConns | the maximum amount of pending connections to allow |
iTimeout | if no connections come in by this timeout, the listener is closed |
|
inlineinherited |
add an FD set to monitor
void Csock::NonBlockingIO | ( | ) |
Use this to change your fd's to blocking or none blocking.
Csock& Csock::operator<< | ( | double | i | ) |
Csock& Csock::operator<< | ( | float | i | ) |
Csock& Csock::operator<< | ( | int32_t | i | ) |
Csock& Csock::operator<< | ( | int64_t | i | ) |
Csock& Csock::operator<< | ( | std::ostream &(*)(std::ostream &) | io | ) |
Csock& Csock::operator<< | ( | uint32_t | i | ) |
Csock& Csock::operator<< | ( | uint64_t | i | ) |
void Csock::PauseRead | ( | ) |
will pause/unpause reading on this socket
|
virtual |
pushes data up on the buffer, if a line is ready it calls the ReadLine event
|
virtual |
This WARNING event is called when your buffer for readline exceeds the warning threshold and triggers this event.
Either Override it and do nothing, or SetMaxBufferThreshold() This event will only get called if m_bEnableReadLine is enabled
Reimplemented in CSocket, CIncomingConnection, CIRCSock, and CClient.
|
virtual |
Read from the socket Just pass in a pointer, big enough to hold len bytes.
data | the buffer to read into |
len | the size of the buffer |
|
inlinevirtual |
Ready to read data event.
Reimplemented in CHTTPSock.
|
inlinevirtual |
Ready to Read a full line event.
If encoding is provided, this is guaranteed to be UTF-8
|
inlinevirtual |
This gets called every iteration of CSocketManager::Select() if the socket is ReadPaused.
void Csock::ResetBytesRead | ( | ) |
void Csock::ResetBytesWritten | ( | ) |
void Csock::ResetStartTime | ( | ) |
Resets the start time.
|
virtual |
resets the time counter, this is virtual in the event you need an event on the timer being Reset
|
inline |
|
inline |
|
inline |
setting this to NULL will allow the default openssl verification process kick in
void Csock::SetCipher | ( | const CS_STRING & | sCipher | ) |
Set the cipher type ( openssl cipher [to see ciphers available] )
|
inline |
sets the connection state to eState
void Csock::SetCTXObject | ( | SSL_CTX * | sslCtx, |
bool | bDeleteExisting = false |
||
) |
void Csock::SetDHParamLocation | ( | const CS_STRING & | sDHParamFile | ) |
Set the pem file location.
void Csock::SetEncoding | ( | const CS_STRING & | sEncoding | ) |
void Csock::SetHostName | ( | const CS_STRING & | sHostname | ) |
|
inline |
|
virtual |
Sets the sock, telling it its connected (internal use only)
void Csock::SetKeyLocation | ( | const CS_STRING & | sKeyFile | ) |
void Csock::SetMaxBufferThreshold | ( | uint32_t | iThreshold | ) |
sets the max buffered threshold when EnableReadLine() is enabled
|
virtual |
Set The INBOUND Parent sockname.
void Csock::SetPemLocation | ( | const CS_STRING & | sPemFile | ) |
void Csock::SetPemPass | ( | const CS_STRING & | sPassword | ) |
void Csock::SetPort | ( | uint16_t | iPort | ) |
|
virtual |
sets the rate at which we can send data
iBytes | the amount of bytes we can write |
iMilliseconds | the amount of time we have to rate to iBytes |
|
inline |
bitwise flags, 0 means don't require cert, SSL_VERIFY_PEER verifies peers, SSL_VERIFY_FAIL_IF_NO_PEER_CERT will cause the connection to fail if no cert
void Csock::SetRequiresClientCert | ( | bool | bRequiresCert | ) |
legacy, deprecated
void Csock::SetRSock | ( | cs_sock_t | iSock | ) |
Referenced by CExecSock::~CExecSock().
|
inline |
void Csock::SetSock | ( | cs_sock_t | iSock | ) |
void Csock::SetSockName | ( | const CS_STRING & | sName | ) |
void Csock::SetSSL | ( | bool | b | ) |
void Csock::SetSSLMethod | ( | int | iMethod | ) |
Set the SSL method type.
void Csock::SetSSLObject | ( | SSL * | ssl, |
bool | bDeleteExisting = false |
||
) |
void Csock::SetTimeout | ( | int | iTimeout, |
uint32_t | iTimeoutType = TMO_ALL |
||
) |
Currently this uses the same value for all timeouts, and iTimeoutType merely states which event will be checked for timeouts.
void Csock::SetTimeoutType | ( | uint32_t | iTimeoutType | ) |
void Csock::SetType | ( | int | iType | ) |
SSL_CTX* Csock::SetupServerCTX | ( | ) |
creates a new SSL_CTX based on the setup of this sock
bool Csock::SetupVHost | ( | ) |
this is only used on outbound connections, listeners bind in a different spot
void Csock::SetWSock | ( | cs_sock_t | iSock | ) |
Referenced by CExecSock::~CExecSock().
|
virtual |
called to configure the SNI client
sHostname,the | hostname to configure SNI with, you can fill this with GetHostname() if its a valid hostname and not an OP |
|
inlinevirtual |
gets called when a SNI request is sent, and used to configure a SNI session
sHostname | the hostname sent from the client |
sPemFile | fill this with the location to the pemfile |
sPemPass | fill this with the pemfile password if there is one |
|
inlinevirtual |
A sock error occured event.
|
virtual |
This sets up the SSL Client, this is used internally.
|
inlinevirtual |
Gets called immediatly after the m_ssl member is setup and initialized, useful if you need to assign anything to this ssl session via SSL_set_ex_data.
|
inlinevirtual |
called once the SSL handshake is complete, this is triggered via SSL_CB_HANDSHAKE_DONE in SSL_set_info_callback()
This is a spot where you can look at the finished peer certifificate ... IE
X509 * pCert = GetX509(); char szName[256]; memset( szName, '\0', 256 ); X509_NAME_get_text_by_NID ( X509_get_subject_name( pCert ), NID_commonName, szName, 255 ); cerr << "Name! " << szName << endl; X509_free( pCert );
Reimplemented in CZNCSock.
bool Csock::SslIsEstablished | ( | ) | const |
is SSL_accept finished ? is the ssl properly finished (from write no error)
|
virtual |
This sets up the SSL Server, this is used internally.
bool Csock::StartTLS | ( | ) |
start a TLS connection on an existing plain connection
|
inlinevirtual |
void Csock::UnPauseRead | ( | ) |
|
inlinevirtual |
this is hooked in via SSL_set_verify, and be default it just returns 1 meaning success
iPreVerify | the pre-verification status as determined by openssl internally |
pStoreCTX | the X509_STORE_CTX containing the certificate |
This may get called multiple times, for example with a chain certificate which is fairly typical with certificates from godaddy, freessl, etc. Additionally, openssl does not do any host verification, they leave that up to the you. One easy way to deal with this is to wait for SSLHandShakeFinished() and examine the peer certificate
Reimplemented in CZNCSock.
|
virtual |
Write data to the socket.
If not all of the data is sent, it will be stored on an internal buffer, and tried again with next call to Write if the socket is blocking, it will send everything, its ok to check ernno after this (nothing else is processed)
data | the data to send |
len | the length of data |
|
virtual |
Write a text string to the socket.
Encoding is used, if set
sData | the string to send; if encoding is provided, sData should be UTF-8 and will be encoded |
|
protectedinherited |
|
protectedinherited |