53 #include <netinet/in.h> 54 #include <arpa/inet.h> 55 #include <sys/socket.h> 56 #include <sys/ioctl.h> 58 #include <sys/select.h> 66 #include <sys/timeb.h> 69 #define strcasecmp _stricmp 70 #define suseconds_t long 76 #define ECONNREFUSED WSAECONNREFUSED 77 #define EINPROGRESS WSAEINPROGRESS 78 #define ETIMEDOUT WSAETIMEDOUT 79 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 80 #define ECONNABORTED WSAECONNABORTED 81 #define ENETUNREACH WSAENETUNREACH 91 # include <unicode/ucnv.h> 101 #include <openssl/ssl.h> 102 #include <openssl/err.h> 103 #include <openssl/rand.h> 120 # ifdef _HAS_CSTRING_ 121 # define CS_STRING Cstring 123 # define CS_STRING std::string 129 # define CS_DEBUG( f ) std::cerr << __FILE__ << ":" << __LINE__ << " " << f << std::endl 131 # define CS_DEBUG(f) (void)0 141 # define PERROR( f ) __Perror( f, __FILE__, __LINE__ ) 143 # define PERROR( f ) (void)0 154 #define CS_INVALID_SOCK INVALID_SOCKET 158 #define CS_INVALID_SOCK -1 163 #define HAVE_UNIX_SOCKET 166 #ifdef CSOCK_USE_POLL 170 #ifdef HAVE_UNIX_SOCKET 174 #ifndef _NO_CSOCKET_NS // some people may not want to use a namespace 189 m_pBuffer = (
char * )malloc( iSize );
212 memset( (
struct sockaddr_in * ) &m_saddr,
'\0',
sizeof( m_saddr ) );
214 memset( (
struct sockaddr_in6 * ) &m_saddr6,
'\0',
sizeof( m_saddr6 ) );
216 m_iAFRequire = RAF_ANY;
225 RAF_INET6 = AF_INET6,
231 void SinPort( uint16_t iPort );
232 void SetIPv6(
bool b );
237 in_addr *
GetAddr() {
return( &( m_saddr.sin_addr ) ); }
241 in6_addr *
GetAddr6() {
return( &( m_saddr6.sin6_addr ) ); }
251 sockaddr_in6 m_saddr6;
253 EAFRequire m_iAFRequire;
297 struct addrinfo * m_pAddrRes;
298 struct addrinfo m_cHints;
319 template <
class T>
inline void CS_Delete( T * & p ) {
if( p ) {
delete p; p = NULL; } }
331 void SSLErrors(
const char *filename, uint32_t iLineNum );
355 return( WSAGetLastError() );
369 FD_SET( iSock,
set );
374 return( FD_ISSET( iSock,
set ) != 0 );
379 FD_CLR( iSock,
set );
399 void run( timeval & tNow );
405 void StartMaxCycles(
double dTimeSequence, uint32_t iMaxCycles );
406 void StartMaxCycles(
const timeval& tTimeSequence, uint32_t iMaxCycles );
409 void Start(
double dTimeSequence );
410 void Start(
const timeval& TimeSequence );
424 timeval GetInterval()
const;
425 uint32_t GetMaxCycles()
const;
426 uint32_t GetCyclesLeft()
const;
429 bool isValid()
const;
440 virtual void RunJob();
447 bool m_bActive, m_bPause;
448 timeval m_tTimeSequence;
449 uint32_t m_iMaxCycles, m_iCycles;
469 virtual bool GatherFDsForSelect( std::map< cs_sock_t, short > & miiReadyFds,
long & iTimeoutMS );
476 virtual bool FDsThatTriggered(
const std::map< cs_sock_t, short > & miiReadyFds ) {
return(
true ); }
483 virtual bool CheckFDs(
const std::map< cs_sock_t, short > & miiReadyFds );
490 void Add(
cs_sock_t iFD,
short iMonitorEvents ) { m_miiMonitorFDs[iFD] = iMonitorEvents; }
515 void CleanupFDMonitors();
518 const std::vector<CCron *> &
GetCrons()
const {
return( m_vcCrons ); }
523 virtual void AddCron(
CCron * pcCron );
530 virtual void DelCron(
const CS_STRING & sName,
bool bDeleteAll =
true,
bool bCaseSensitive =
true );
532 virtual void DelCron( uint32_t iPos );
534 virtual void DelCronByAddr(
CCron * pcCron );
536 void CheckFDs(
const std::map< cs_sock_t, short > & miiReadyFds );
537 void AssignFDs( std::map< cs_sock_t, short > & miiReadyFds,
struct timeval * tvtimeout );
567 Csock(
int iTimeout = 60 );
574 Csock(
const CS_STRING & sHostname, uint16_t uPort,
int itimeout = 60 );
577 virtual Csock *GetSockObj(
const CS_STRING & sHostname, uint16_t iPort );
587 virtual void Dereference();
589 virtual void Copy(
const Csock & cCopy );
603 READ_CONNREFUSED = -3,
634 EDP_SSL = (EDP_SSLv2|EDP_SSLv3)
657 Csock & operator<<( std::ostream & ( *io )( std::ostream & ) );
658 Csock & operator<<( int32_t i );
659 Csock & operator<<( uint32_t i );
660 Csock & operator<<( int64_t i );
661 Csock & operator<<( uint64_t i );
662 Csock & operator<<(
float i );
663 Csock & operator<<(
double i );
669 virtual bool Connect();
671 #ifdef HAVE_UNIX_SOCKET 676 virtual bool ConnectUnix(
const CS_STRING & sPath );
684 virtual bool ListenUnix(
const CS_STRING & sBindFile,
int iMaxConns = SOMAXCONN, uint32_t iTimeout = 0 );
695 virtual bool Listen( uint16_t iPort,
int iMaxConns = SOMAXCONN,
const CS_STRING & sBindHost =
"", uint32_t iTimeout = 0,
bool bDetach =
false );
701 virtual bool AcceptSSL();
704 virtual bool SSLClientSetup();
707 virtual bool SSLServerSetup();
715 virtual bool ConnectSSL();
730 virtual bool Write(
const char *data,
size_t len );
740 virtual bool Write(
const CS_STRING & sData );
757 virtual cs_ssize_t Read(
char *data,
size_t len );
762 virtual bool IsConnected()
const;
764 virtual void SetIsConnected(
bool b );
783 void CallSockError(
int iErrno,
const CS_STRING & sDescription =
"" );
785 virtual void ResetTimer();
790 bool IsReadPaused()
const;
802 TMO_ALL = TMO_READ|TMO_WRITE|TMO_ACCEPT
807 void SetTimeout(
int iTimeout, uint32_t iTimeoutType = TMO_ALL );
808 void SetTimeoutType( uint32_t iTimeoutType );
809 int GetTimeout()
const;
810 uint32_t GetTimeoutType()
const;
813 virtual bool CheckTimeout( time_t iNow );
819 virtual void PushBuff(
const char *data,
size_t len,
bool bStartAtZero =
false );
831 void SetMaxBufferThreshold( uint32_t iThreshold );
832 uint32_t GetMaxBufferThreshold()
const;
836 void SetType(
int iType );
840 void SetSockName(
const CS_STRING & sName );
844 void SetHostName(
const CS_STRING & sHostname );
848 uint64_t GetStartTime()
const;
850 void ResetStartTime();
853 uint64_t GetBytesRead()
const;
854 void ResetBytesRead();
857 uint64_t GetBytesWritten()
const;
858 void ResetBytesWritten();
861 double GetAvgRead( uint64_t iSample = 1000 )
const;
864 double GetAvgWrite( uint64_t iSample = 1000 )
const;
867 uint16_t GetRemotePort()
const;
870 uint16_t GetLocalPort()
const;
873 uint16_t GetPort()
const;
874 void SetPort( uint16_t iPort );
877 void Close( ECloseType eCloseType = CLT_NOW );
880 bool IsClosed()
const {
return( GetCloseType() != CLT_DONT ); }
883 void NonBlockingIO();
887 void SetSSL(
bool b );
890 void DisableSSLProtocols( u_int uDisableOpts ) { m_uDisableProtocols = uDisableOpts; }
897 void SetCipher(
const CS_STRING & sCipher );
901 void SetDHParamLocation(
const CS_STRING & sDHParamFile );
902 const CS_STRING & GetDHParamLocation()
const;
903 void SetKeyLocation(
const CS_STRING & sKeyFile );
904 const CS_STRING & GetKeyLocation()
const;
905 void SetPemLocation(
const CS_STRING & sPemFile );
906 const CS_STRING & GetPemLocation()
const;
907 void SetPemPass(
const CS_STRING & sPassword );
911 void SetSSLMethod(
int iMethod );
912 int GetSSLMethod()
const;
914 void SetSSLObject( SSL *ssl,
bool bDeleteExisting =
false );
915 SSL * GetSSLObject()
const;
916 void SetCTXObject( SSL_CTX *sslCtx,
bool bDeleteExisting =
false );
917 SSL_SESSION * GetSSLSession()
const;
924 bool HasWriteBuffer()
const;
925 void ClearWriteBuffer();
929 bool SslIsEstablished()
const;
932 bool ConnectInetd(
bool bIsSSL =
false,
const CS_STRING & sHostname =
"" );
935 bool ConnectFD(
int iReadFD,
int iWriteFD,
const CS_STRING & sName,
bool bIsSSL =
false, ETConn eDirection = INBOUND );
939 X509 *GetX509()
const;
945 long GetPeerFingerprint(
CS_STRING & sFP )
const;
947 uint32_t GetRequireClientCertFlags()
const;
949 void SetRequiresClientCert(
bool bRequiresCert );
955 virtual void SetParentSockName(
const CS_STRING & sParentName );
956 const CS_STRING & GetParentSockName()
const;
963 virtual void SetRate( uint32_t iBytes, uint64_t iMilliseconds );
965 uint32_t GetRateBytes()
const;
966 uint64_t GetRateTime()
const;
983 virtual void ReadData(
const char *data,
size_t len ) {}
990 void EnableReadLine();
991 void DisableReadLine();
1000 virtual void ReachedMaxBuffer();
1048 virtual bool SNIConfigureClient(
CS_STRING & sHostname );
1050 SSL_CTX * SetupServerCTX();
1082 time_t GetTimeSinceLastDataTransaction( time_t iNow = 0 )
const;
1087 time_t GetNextCheckTimeout( time_t iNow = 0 )
const;
1090 virtual int GetPending()
const;
1100 bool CreateSocksFD();
1103 void CloseSocksFD();
1118 int DNSLookup( EDNSLType eDNSLType );
1127 m_address.SetIPv6( b );
1128 m_bindhost.SetIPv6( b );
1133 m_address.SetAFRequire( iAFRequire );
1134 m_bindhost.SetAFRequire( iAFRequire );
1138 bool AllowWrite( uint64_t & iNOW )
const;
1163 virtual int ConvertAddress(
const struct sockaddr_storage * pAddr, socklen_t iAddrLen,
CS_STRING & sIP, uint16_t * piPort )
const;
1166 CSSockAddr * GetCurrentAddr()
const {
return( m_pCurrAddr ); }
1167 void SetAresFinished(
int status ) { m_pCurrAddr = NULL; m_iARESStatus = status; }
1168 ares_channel GetAresChannel()
const {
return( m_pARESChannel ); }
1175 void SetEncoding(
const CS_STRING & sEncoding );
1177 virtual void IcuExtToUCallback(
1178 UConverterToUnicodeArgs* toArgs,
1179 const char* codeUnits,
1181 UConverterCallbackReason reason,
1183 virtual void IcuExtFromUCallback(
1184 UConverterFromUnicodeArgs* fromArgs,
1185 const UChar* codeUnits,
1188 UConverterCallbackReason reason,
1196 void ShrinkSendBuff();
1197 void IncBuffPos(
size_t uBytes );
1203 int m_iTimeout, m_iConnType, m_iMethod, m_iTcount, m_iMaxConns;
1204 bool m_bUseSSL, m_bIsConnected;
1205 bool m_bsslEstablished, m_bEnableReadLine, m_bPauseRead;
1206 CS_STRING m_shostname, m_sbuffer, m_sSockName, m_sDHParamFile, m_sKeyFile, m_sPemFile, m_sCipherType, m_sParentName;
1208 ECloseType m_eCloseType;
1211 mutable uint16_t m_iRemotePort, m_iLocalPort;
1212 mutable CS_STRING m_sLocalIP, m_sRemoteIP;
1214 uint64_t m_iMaxMilliSeconds, m_iLastSendTime, m_iBytesRead, m_iBytesWritten, m_iStartTime;
1215 uint32_t m_iMaxBytes, m_iMaxStoredBufferLength, m_iTimeoutType;
1216 size_t m_iLastSend, m_uSendBufferPos;
1219 bool m_bIsIPv6, m_bSkipConnect;
1220 time_t m_iLastCheckTimeoutTime;
1225 SSL_CTX * m_ssl_ctx;
1226 uint32_t m_iRequireClientCertFlags;
1227 u_int m_uDisableProtocols;
1228 bool m_bNoSSLCompression;
1229 bool m_bSSLCipherServerPreference;
1235 bool ConfigureCTXOptions( SSL_CTX * pCTX );
1240 cs_sock_t CreateSocket(
bool bListen =
false,
bool bUnix =
false );
1241 void Init(
const CS_STRING & sHostname, uint16_t uPort,
int iTimeout = 60 );
1244 ECONState m_eConState;
1246 uint32_t m_iCurBindCount, m_iDNSTryCount;
1249 ares_channel m_pARESChannel;
1255 UConverter* m_cnvInt;
1256 UConverter* m_cnvExt;
1277 m_sHostname = sHostname;
1279 m_iTimeout = iTimeout;
1320 void SetCipher(
const CS_STRING & s ) { m_sCipher = s; }
1365 m_sBindHost = sBindHost;
1367 m_iMaxConns = SOMAXCONN;
1370 m_bDetach = bDetach;
1373 m_iRequireCertFlags = 0;
1397 void SetPort( uint16_t iPort ) { m_iPort = iPort; }
1412 void SetCipher(
const CS_STRING & s ) { m_sCipher = s; }
1423 void SetRequiresClientCert(
bool b ) { m_iRequireCertFlags = ( b ? SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0 ); }
1433 uint32_t m_iTimeout;
1437 CS_STRING m_sDHParamLocation, m_sKeyLocation, m_sPemLocation, m_sPemPass, m_sCipher;
1438 uint32_t m_iRequireCertFlags;
1480 virtual void clear();
1481 virtual void Cleanup();
1483 virtual Csock * GetSockObj(
const CS_STRING & sHostname, uint16_t uPort,
int iTimeout = 60 );
1489 SELECT_TIMEOUT = -2,
1490 SELECT_TRYAGAIN = -3
1509 virtual bool Listen(
const CSListener & cListen,
Csock * pcSock = NULL, uint16_t * piRandPort = NULL );
1513 bool HasFDs()
const;
1520 virtual void Loop();
1537 void DynamicSelectLoop( uint64_t iLowerBounds, uint64_t iUpperBounds, time_t iMaxResolution = 3600 );
1543 virtual void AddSock(
Csock * pcSock,
const CS_STRING & sSockName );
1546 virtual Csock * FindSockByRemotePort( uint16_t iPort );
1549 virtual Csock * FindSockByLocalPort( uint16_t iPort );
1557 virtual std::vector<Csock *> FindSocksByName(
const CS_STRING & sName );
1560 virtual std::vector<Csock *> FindSocksByRemoteHost(
const CS_STRING & sHostname );
1575 virtual void DelSockByAddr(
Csock * pcSock );
1582 virtual void DelSock(
size_t iPos );
1590 virtual bool SwapSockByIdx(
Csock * pNewSock,
size_t iOrginalSockIdx );
1598 virtual bool SwapSockByAddr(
Csock * pNewSock,
Csock * pOrigSock );
1601 uint64_t GetBytesRead()
const;
1604 uint64_t GetBytesWritten()
const;
1613 void FDSetCheck(
cs_sock_t iFd, std::map< cs_sock_t, short > & miiReadyFds, ECheckType eType );
1614 bool FDHasCheck(
cs_sock_t iFd, std::map< cs_sock_t, short > & miiReadyFds, ECheckType eType );
1618 virtual int Select( std::map< cs_sock_t, short > & miiReadyFds,
struct timeval *tvtimeout );
1627 void Select( std::map<Csock *, EMessages> & mpeSocks );
1629 timeval GetDynamicSleepTime(
const timeval& tNow,
const timeval& tMaxResolution )
const;
1632 virtual void SelectSock( std::map<Csock *, EMessages> & mpeSocks, EMessages eErrno,
Csock * pcSock );
1640 uint64_t m_iCallTimeouts;
1641 uint64_t m_iBytesRead;
1642 uint64_t m_iBytesWritten;
1643 uint64_t m_iSelectWait;
1661 return(
new T( sHostname, uPort, iTimeout ) );
1665 #ifndef _NO_CSOCKET_NS void CSAdjustTVTimeout(struct timeval &tv, long iTimeoutMS)
adjusts tv with a new timeout if iTimeoutMS is smaller
void SetRequireClientCertFlags(unsigned int iRequireCertFlags)
bitwise flags, 0 means don't require cert, SSL_VERIFY_PEER verifies peers, SSL_VERIFY_FAIL_IF_NO_PEER...
Definition: Csocket.h:1425
uint32_t GetTimeout() const
Definition: Csocket.h:1385
void SSLErrors(const char *filename, uint32_t iLineNum)
bool IsEnabled() const
Definition: Csocket.h:496
const CS_STRING & GetPemPass() const
Definition: Csocket.h:1301
int GetErrno() const
return the last known error as set by this class
Definition: Csocket.h:1563
virtual ~CCron()
Definition: Csocket.h:396
simple class to share common code to both TSockManager and Csock
Definition: Csocket.h:508
bool GetIsSSL() const
Definition: Csocket.h:1293
void MonitorFD(CSMonitorFD *pMonitorFD)
add an FD set to monitor
Definition: Csocket.h:540
ssize_t cs_ssize_t
Definition: Csocket.h:157
Ease of use templated socket manager.
Definition: Csocket.h:1654
#define CS_EXPORT
Definition: Csocket.h:136
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1290
Definition: Csocket.h:223
virtual void SSLHandShakeFinished()
called once the SSL handshake is complete, this is triggered via SSL_CB_HANDSHAKE_DONE in SSL_set_inf...
Definition: Csocket.h:1065
virtual void ReadPaused()
This gets called every iteration of CSocketManager::Select() if the socket is ReadPaused.
Definition: Csocket.h:1027
void SetIPv6(bool b)
Definition: Csocket.h:1124
void SetBindHost(const CS_STRING &s)
sets the hostname to bind to (vhost support)
Definition: Csocket.h:1309
void SetBindHost(const CS_STRING &sBindHost)
sets the host to bind to
Definition: Csocket.h:1401
Definition: Csocket.h:1339
CSCharBuffer(size_t iSize)
Definition: Csocket.h:187
Csock * GetCsockFromCTX(X509_STORE_CTX *pCTX)
returns the sock object associated to the particular context. returns NULL on failure or if not avail...
void ShutdownCsocket()
Shutdown and release global allocated memory.
virtual void SockError(int iErrno, const CS_STRING &sDescription)
A sock error occured event.
Definition: Csocket.h:1004
void SetTimeout(uint32_t i)
sets the listen timeout. The listener class will close after timeout has been reached if not 0 ...
Definition: Csocket.h:1407
this function is a wrapper around getaddrinfo (for ipv6)
Definition: Csocket.h:274
const std::vector< CCron * > & GetCrons() const
returns a const reference to the crons associated to this socket
Definition: Csocket.h:518
CS_STRING m_sSockName
Definition: Csocket.h:1329
ESSLMethod
Definition: Csocket.h:615
virtual T * GetSockObj(const CS_STRING &sHostname, uint16_t uPort, int iTimeout=60)
Definition: Csocket.h:1659
void Add(cs_sock_t iFD, short iMonitorEvents)
adds a file descriptor to be monitored
Definition: Csocket.h:490
int(* FPCertVerifyCB)(int, X509_STORE_CTX *)
Definition: Csocket.h:549
void SetConState(ECONState eState)
sets the connection state to eState
Definition: Csocket.h:1097
bool TFD_ISSET(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:372
void SetAFRequire(EAFRequire iWhich)
Definition: Csocket.h:244
virtual ~CSSockAddr()
Definition: Csocket.h:218
void Remove(cs_sock_t iFD)
removes this fd from monitoring
Definition: Csocket.h:492
ETConn
Definition: Csocket.h:591
bool m_bEnabled
Definition: Csocket.h:500
bool m_bRunOnNextCall
if set to true, RunJob() gets called on next invocation of run() despite the timeout ...
Definition: Csocket.h:443
void SetTimeout(int i)
sets the connection timeout
Definition: Csocket.h:1313
Definition: Csocket.h:1443
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1105
virtual bool FDsThatTriggered(const std::map< cs_sock_t, short > &miiReadyFds)
called when there are fd's belonging to this class that have triggered
Definition: Csocket.h:476
char * operator()()
Definition: Csocket.h:195
const CS_STRING & GetPemPass() const
Definition: Csocket.h:1392
const CS_STRING & GetPemLocation() const
Definition: Csocket.h:1391
ECONState GetConState() const
returns the current connection state
Definition: Csocket.h:1095
CSSockAddr::EAFRequire GetAFRequire() const
Definition: Csocket.h:1386
EFRead
Definition: Csocket.h:598
Ease of use self deleting char * class.
Definition: Csocket.h:184
EFSelect
Definition: Csocket.h:607
bool GetIsSSL() const
Definition: Csocket.h:1383
virtual void Connected()
Connected event.
Definition: Csocket.h:971
ECONState
Definition: Csocket.h:637
const CS_STRING & GetHostname() const
Definition: Csocket.h:1288
virtual ~CSMonitorFD()
Definition: Csocket.h:461
Definition: Csocket.h:325
CSSockAddr::EAFRequire GetAFRequire() const
Definition: Csocket.h:1294
void SetDetach(bool b)
Definition: Csocket.h:1378
CSSockAddr::EAFRequire m_iAFrequire
Definition: Csocket.h:1333
void SetPemLocation(const CS_STRING &s)
set the location of the pemfile
Definition: Csocket.h:1415
this lookup is for the vhost bind
Definition: Csocket.h:1110
void SetSockName(const CS_STRING &s)
sets the name of the socket, used for reference, ie in FindSockByName()
Definition: Csocket.h:1307
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 ...
Definition: Csocket.h:1077
void CS_Delete(T *&p)
Definition: Csocket.h:319
virtual void SSLFinishSetup(SSL *pSSL)
Gets called immediatly after the m_ssl member is setup and initialized, useful if you need to assign ...
Definition: Csocket.h:1034
bool HasReadLine() const
returns the value of m_bEnableReadLine, if ReadLine is enabled
Definition: Csocket.h:993
void SetSelectTimeout(uint64_t iTimeout)
Set the Select Timeout in MICROSECONDS ( 1000 == 1 millisecond ) Setting this to 0 will cause no time...
Definition: Csocket.h:1569
ECloseType
Definition: Csocket.h:648
in_addr * GetAddr()
Definition: Csocket.h:237
options for creating a connection
Definition: Csocket.h:1267
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
sets the AF family type required
Definition: Csocket.h:1317
Basic socket class.
Definition: Csocket.h:563
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
sets the AF family type required
Definition: Csocket.h:1409
bool GetDetach() const
Definition: Csocket.h:1379
void DisableSSLCompression()
allow disabling compression
Definition: Csocket.h:893
virtual void Timeout()
Sock Timed out event.
Definition: Csocket.h:979
virtual ~CSListener()
Definition: Csocket.h:1376
const CS_STRING & GetKeyLocation() const
Definition: Csocket.h:1390
bool m_bIsSSL
Definition: Csocket.h:1332
ECompType
Definition: Csocket.h:322
#define CS_STRING
Definition: Csocket.h:123
socklen_t GetSockAddrLen6()
Definition: Csocket.h:239
void SetPort(uint16_t iPort)
sets the port to listen on. Set to 0 to listen on a random port
Definition: Csocket.h:1397
bool GetIPv6() const
Definition: Csocket.h:233
void SetMaxConns(int i)
set max connections as called by accept()
Definition: Csocket.h:1405
virtual ~CSConnection()
Definition: Csocket.h:1286
CSMonitorFD()
Definition: Csocket.h:460
const CS_STRING & GetCipher() const
Definition: Csocket.h:1388
CSConnection(const CS_STRING &sHostname, uint16_t iPort, int iTimeout=60)
Definition: Csocket.h:1275
uint16_t m_iPort
Definition: Csocket.h:1330
void SetPemPass(const CS_STRING &s)
set the pemfile pass
Definition: Csocket.h:1325
virtual ~TSocketManager()
Definition: Csocket.h:1658
int cs_sock_t
Definition: Csocket.h:156
const CS_STRING & GetKeyLocation() const
Definition: Csocket.h:1299
const uint32_t CS_BLOCKSIZE
Definition: Csocket.h:318
void SetKeyLocation(const CS_STRING &s)
set the location of the keyfile
Definition: Csocket.h:1417
bool GetIPv6() const
Definition: Csocket.h:1123
options container to create a listener
Definition: Csocket.h:1354
bool InitCsocket()
This does all the csocket initialized inclusing InitSSL() and win32 specific initializations, only needs to be called once.
CSSSListener(uint16_t iPort, const CS_STRING &sBindHost="")
Definition: Csocket.h:1446
virtual bool ConnectionFrom(const CS_STRING &sHost, uint16_t iPort)
Incoming Connection Event return false and the connection will fail default returns true...
Definition: Csocket.h:1010
EDisableProtocol
Definition: Csocket.h:626
ECloseType GetCloseType() const
returns int of type to close
Definition: Csocket.h:879
int GetMaxConns() const
returns the number of max pending connections when type is LISTENER
Definition: Csocket.h:1172
void SetSkipConnect(bool b)
Definition: Csocket.h:1141
std::vector< CSMonitorFD * > m_vcMonitorFD
Definition: Csocket.h:544
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1382
this is the main cron job class
Definition: Csocket.h:392
void SetHostname(const CS_STRING &s)
sets the hostname to connect to
Definition: Csocket.h:1305
EAFRequire GetAFRequire() const
Definition: Csocket.h:245
CS_STRING GetEncoding() const
Definition: Csocket.h:1176
void SetPemPass(const CS_STRING &s)
set the pemfile pass
Definition: Csocket.h:1421
const CS_STRING & GetDHParamLocation() const
Definition: Csocket.h:1300
virtual void Listening(const CS_STRING &sBindIP, uint16_t uPort)
called when type is LISTENER and the listening port is up and running
Definition: Csocket.h:1017
void SetSockName(const CS_STRING &sSockName)
sets the sock name for later reference (ie FindSockByName)
Definition: Csocket.h:1399
virtual void ReadData(const char *data, size_t len)
Ready to read data event.
Definition: Csocket.h:983
socklen_t GetSockAddrLen()
Definition: Csocket.h:235
int CS_GetAddrInfo(const CS_STRING &sHostname, Csock *pSock, CSSockAddr &csSockAddr)
backwards compatible wrapper around CGetAddrInfo and gethostbyname
virtual void ReadLine(const CS_STRING &sLine)
Ready to Read a full line event.
Definition: Csocket.h:988
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
Definition: Csocket.h:1042
virtual void Disconnected()
Disconnected event.
Definition: Csocket.h:975
int GetTimeout() const
Definition: Csocket.h:1292
sockaddr_in6 * GetSockAddr6()
Definition: Csocket.h:240
void SetPort(uint16_t i)
sets the port to connect to
Definition: Csocket.h:1311
timeval GetNextRun() const
returns the timestamp of the next estimated run time. Note that it may not run at this EXACT time...
Definition: Csocket.h:435
sockaddr wrapper.
Definition: Csocket.h:206
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
Definition: Csocket.h:1131
void __Perror(const CS_STRING &s, const char *pszFile, uint32_t iLineNo)
CSSSLConnection(const CS_STRING &sHostname, uint16_t iPort, int iTimeout=60)
Definition: Csocket.h:1342
CSockCommon()
Definition: Csocket.h:511
uint64_t GetSelectTimeout() const
Get the Select Timeout in MICROSECONDS ( 1000 == 1 millisecond )
Definition: Csocket.h:1566
CSSockAddr()
Definition: Csocket.h:209
EDNSLType
Definition: Csocket.h:1108
const CS_STRING & GetDHParamLocation() const
Definition: Csocket.h:1389
TSocketManager()
Definition: Csocket.h:1657
CSListener(uint16_t iPort, const CS_STRING &sBindHost="", bool bDetach=false)
Definition: Csocket.h:1362
void TFD_ZERO(fd_set *set)
wrappers for FD_SET and such to work in templates.
Definition: Csocket.h:362
EAFRequire
Definition: Csocket.h:221
void SetDHParamLocation(const CS_STRING &s)
set the location of the dhparamfile
Definition: Csocket.h:1419
uint16_t GetPort() const
Definition: Csocket.h:1380
void SetBindHost(const CS_STRING &sBindHost)
Definition: Csocket.h:1106
int GetMaxConns() const
Definition: Csocket.h:1384
void SetRequireClientCertFlags(uint32_t iRequireClientCertFlags)
bitwise flags, 0 means don't require cert, SSL_VERIFY_PEER verifies peers, SSL_VERIFY_FAIL_IF_NO_PEER...
Definition: Csocket.h:951
const CS_STRING & GetPemLocation() const
Definition: Csocket.h:1298
void FollowSSLCipherServerPreference()
select the ciphers in server-preferred order
Definition: Csocket.h:895
void SetCertVerifyCB(FPCertVerifyCB pFP)
setting this to NULL will allow the default openssl verification process kick in
Definition: Csocket.h:920
uint32_t GetRequireClientCertFlags() const
Definition: Csocket.h:1393
time_t GetLastCheckTimeout() const
Definition: Csocket.h:1084
int m_iTimeout
Definition: Csocket.h:1331
in6_addr * GetAddr6()
Definition: Csocket.h:241
void SetIsSSL(bool b)
set to true to enable SSL
Definition: Csocket.h:1315
const CS_STRING & GetSockName() const
Definition: Csocket.h:1289
void TFD_SET(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:367
virtual void ConnectionRefused()
Connection Refused Event.
Definition: Csocket.h:1023
Best class to use to interact with the sockets.
Definition: Csocket.h:1475
void DisableMonitor()
causes this monitor to be removed
Definition: Csocket.h:494
int GetCsockSSLIdx()
This returns the [ex_]data index position for SSL objects only.
std::map< cs_sock_t, short > m_miiMonitorFDs
Definition: Csocket.h:499
void SetPemLocation(const CS_STRING &s)
set the location of the pemfile
Definition: Csocket.h:1323
ECheckType
this is a strict wrapper around C-api select(). Added in the event you need to do special work here ...
Definition: Csocket.h:1607
CS_STRING m_sPemPass
Definition: Csocket.h:1335
std::vector< CCron * > m_vcCrons
Definition: Csocket.h:543
int GetSockError()
Definition: Csocket.h:352
const CS_STRING & GetSockName() const
Definition: Csocket.h:1381
uint16_t GetPort() const
Definition: Csocket.h:1291
Class to tie sockets to for monitoring by Csocket at either the Csock or TSockManager.
Definition: Csocket.h:457
EMessages
Definition: Csocket.h:1485
Definition: Csocket.h:324
bool IsClosed() const
Definition: Csocket.h:880
~CSCharBuffer()
Definition: Csocket.h:191
bool InitSSL(ECompType eCompressionType=CT_NONE)
You HAVE to call this in order to use the SSL library, calling InitCsocket() also calls this so unles...
const CS_STRING & GetCipher() const
Definition: Csocket.h:1297
void TFD_CLR(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:377
void SetRequiresClientCert(bool b)
set to true if require a client certificate (deprecated
Definition: Csocket.h:1423
void SetIsSSL(bool b)
set to true to enable SSL
Definition: Csocket.h:1403
sockaddr_in * GetSockAddr()
Definition: Csocket.h:236