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> 64 #include <sys/timeb.h> 69 #define ECONNREFUSED WSAECONNREFUSED 70 #define EINPROGRESS WSAEINPROGRESS 71 #define ETIMEDOUT WSAETIMEDOUT 72 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 73 #define ECONNABORTED WSAECONNABORTED 74 #define ENETUNREACH WSAENETUNREACH 84 # include <unicode/ucnv.h> 94 #include <openssl/ssl.h> 95 #include <openssl/err.h> 96 #include <openssl/rand.h> 113 # ifdef _HAS_CSTRING_ 114 # define CS_STRING Cstring 116 # define CS_STRING std::string 122 # define CS_DEBUG( f ) std::cerr << __FILE__ << ":" << __LINE__ << " " << f << std::endl 124 # define CS_DEBUG(f) (void)0 134 # define PERROR( f ) __Perror( f, __FILE__, __LINE__ ) 136 # define PERROR( f ) (void)0 147 #define CS_INVALID_SOCK INVALID_SOCKET 151 #define CS_INVALID_SOCK -1 154 #ifdef CSOCK_USE_POLL 158 #ifndef _NO_CSOCKET_NS // some people may not want to use a namespace 173 m_pBuffer = (
char * )malloc( iSize );
196 memset( (
struct sockaddr_in * ) &m_saddr,
'\0',
sizeof( m_saddr ) );
198 memset( (
struct sockaddr_in6 * ) &m_saddr6,
'\0',
sizeof( m_saddr6 ) );
200 m_iAFRequire = RAF_ANY;
209 RAF_INET6 = AF_INET6,
215 void SinPort( uint16_t iPort );
216 void SetIPv6(
bool b );
221 in_addr *
GetAddr() {
return( &( m_saddr.sin_addr ) ); }
225 in6_addr *
GetAddr6() {
return( &( m_saddr6.sin6_addr ) ); }
235 sockaddr_in6 m_saddr6;
281 struct addrinfo * m_pAddrRes;
282 struct addrinfo m_cHints;
303 template <
class T>
inline void CS_Delete( T * & p ) {
if( p ) {
delete p; p = NULL; } }
315 void SSLErrors(
const char *filename, uint32_t iLineNum );
339 return( WSAGetLastError() );
353 FD_SET( iSock,
set );
358 return( FD_ISSET( iSock,
set ) != 0 );
363 FD_CLR( iSock,
set );
384 void run( timeval & tNow );
390 void StartMaxCycles(
double dTimeSequence, uint32_t iMaxCycles );
391 void StartMaxCycles(
const timeval& tTimeSequence, uint32_t iMaxCycles );
394 void Start(
double dTimeSequence );
395 void Start(
const timeval& TimeSequence );
409 timeval GetInterval()
const;
410 uint32_t GetMaxCycles()
const;
411 uint32_t GetCyclesLeft()
const;
414 bool isValid()
const;
425 virtual void RunJob();
432 bool m_bActive, m_bPause;
433 timeval m_tTimeSequence;
434 uint32_t m_iMaxCycles, m_iCycles;
454 virtual bool GatherFDsForSelect( std::map< cs_sock_t, short > & miiReadyFds,
long & iTimeoutMS );
461 virtual bool FDsThatTriggered(
const std::map< cs_sock_t, short > & miiReadyFds ) {
return(
true ); }
468 virtual bool CheckFDs(
const std::map< cs_sock_t, short > & miiReadyFds );
475 void Add(
cs_sock_t iFD,
short iMonitorEvents ) { m_miiMonitorFDs[iFD] = iMonitorEvents; }
500 void CleanupFDMonitors();
503 const std::vector<CCron *> &
GetCrons()
const {
return( m_vcCrons ); }
508 virtual void AddCron(
CCron * pcCron );
515 virtual void DelCron(
const CS_STRING & sName,
bool bDeleteAll =
true,
bool bCaseSensitive =
true );
517 virtual void DelCron( uint32_t iPos );
519 virtual void DelCronByAddr(
CCron * pcCron );
521 void CheckFDs(
const std::map< cs_sock_t, short > & miiReadyFds );
522 void AssignFDs( std::map< cs_sock_t, short > & miiReadyFds,
struct timeval * tvtimeout );
552 Csock(
int iTimeout = 60 );
559 Csock(
const CS_STRING & sHostname, uint16_t uPort,
int itimeout = 60 );
562 virtual Csock *GetSockObj(
const CS_STRING & sHostname, uint16_t iPort );
572 virtual void Dereference();
574 virtual void Copy(
const Csock & cCopy );
588 READ_CONNREFUSED = -3,
619 EDP_SSL = (EDP_SSLv2|EDP_SSLv3)
642 Csock & operator<<( std::ostream & ( *io )( std::ostream & ) );
643 Csock & operator<<( int32_t i );
644 Csock & operator<<( uint32_t i );
645 Csock & operator<<( int64_t i );
646 Csock & operator<<( uint64_t i );
647 Csock & operator<<(
float i );
648 Csock & operator<<(
double i );
654 virtual bool Connect();
664 virtual bool Listen( uint16_t iPort,
int iMaxConns = SOMAXCONN,
const CS_STRING & sBindHost =
"", uint32_t iTimeout = 0,
bool bDetach =
false );
670 virtual bool AcceptSSL();
673 virtual bool SSLClientSetup();
676 virtual bool SSLServerSetup();
684 virtual bool ConnectSSL();
699 virtual bool Write(
const char *data,
size_t len );
709 virtual bool Write(
const CS_STRING & sData );
726 virtual cs_ssize_t Read(
char *data,
size_t len );
731 virtual bool IsConnected()
const;
733 virtual void SetIsConnected(
bool b );
752 void CallSockError(
int iErrno,
const CS_STRING & sDescription =
"" );
754 virtual void ResetTimer();
759 bool IsReadPaused()
const;
771 TMO_ALL = TMO_READ|TMO_WRITE|TMO_ACCEPT
776 void SetTimeout(
int iTimeout, uint32_t iTimeoutType = TMO_ALL );
777 void SetTimeoutType( uint32_t iTimeoutType );
778 int GetTimeout()
const;
779 uint32_t GetTimeoutType()
const;
782 virtual bool CheckTimeout( time_t iNow );
788 virtual void PushBuff(
const char *data,
size_t len,
bool bStartAtZero =
false );
800 void SetMaxBufferThreshold( uint32_t iThreshold );
801 uint32_t GetMaxBufferThreshold()
const;
805 void SetType(
int iType );
809 void SetSockName(
const CS_STRING & sName );
813 void SetHostName(
const CS_STRING & sHostname );
817 uint64_t GetStartTime()
const;
819 void ResetStartTime();
822 uint64_t GetBytesRead()
const;
823 void ResetBytesRead();
826 uint64_t GetBytesWritten()
const;
827 void ResetBytesWritten();
830 double GetAvgRead( uint64_t iSample = 1000 )
const;
833 double GetAvgWrite( uint64_t iSample = 1000 )
const;
836 uint16_t GetRemotePort()
const;
839 uint16_t GetLocalPort()
const;
842 uint16_t GetPort()
const;
843 void SetPort( uint16_t iPort );
846 void Close(
ECloseType eCloseType = CLT_NOW );
849 bool IsClosed()
const {
return( GetCloseType() != CLT_DONT ); }
852 void NonBlockingIO();
856 void SetSSL(
bool b );
859 void DisableSSLProtocols( u_int uDisableOpts ) { m_uDisableProtocols = uDisableOpts; }
866 void SetCipher(
const CS_STRING & sCipher );
870 void SetDHParamLocation(
const CS_STRING & sDHParamFile );
871 const CS_STRING & GetDHParamLocation()
const;
872 void SetKeyLocation(
const CS_STRING & sKeyFile );
873 const CS_STRING & GetKeyLocation()
const;
874 void SetPemLocation(
const CS_STRING & sPemFile );
875 const CS_STRING & GetPemLocation()
const;
876 void SetPemPass(
const CS_STRING & sPassword );
880 void SetSSLMethod(
int iMethod );
881 int GetSSLMethod()
const;
883 void SetSSLObject( SSL *ssl,
bool bDeleteExisting =
false );
884 SSL * GetSSLObject()
const;
885 void SetCTXObject( SSL_CTX *sslCtx,
bool bDeleteExisting =
false );
886 SSL_SESSION * GetSSLSession()
const;
893 bool HasWriteBuffer()
const;
894 void ClearWriteBuffer();
898 bool SslIsEstablished()
const;
901 bool ConnectInetd(
bool bIsSSL =
false,
const CS_STRING & sHostname =
"" );
904 bool ConnectFD(
int iReadFD,
int iWriteFD,
const CS_STRING & sName,
bool bIsSSL =
false,
ETConn eDirection = INBOUND );
908 X509 *GetX509()
const;
914 long GetPeerFingerprint(
CS_STRING & sFP )
const;
916 uint32_t GetRequireClientCertFlags()
const;
918 void SetRequiresClientCert(
bool bRequiresCert );
924 virtual void SetParentSockName(
const CS_STRING & sParentName );
925 const CS_STRING & GetParentSockName()
const;
932 virtual void SetRate( uint32_t iBytes, uint64_t iMilliseconds );
934 uint32_t GetRateBytes()
const;
935 uint64_t GetRateTime()
const;
952 virtual void ReadData(
const char *data,
size_t len ) {}
959 void EnableReadLine();
960 void DisableReadLine();
969 virtual void ReachedMaxBuffer();
1017 virtual bool SNIConfigureClient(
CS_STRING & sHostname );
1019 SSL_CTX * SetupServerCTX();
1051 time_t GetTimeSinceLastDataTransaction( time_t iNow = 0 )
const;
1056 time_t GetNextCheckTimeout( time_t iNow = 0 )
const;
1059 virtual int GetPending()
const;
1069 bool CreateSocksFD();
1072 void CloseSocksFD();
1096 m_address.SetIPv6( b );
1097 m_bindhost.SetIPv6( b );
1102 m_address.SetAFRequire( iAFRequire );
1103 m_bindhost.SetAFRequire( iAFRequire );
1107 bool AllowWrite( uint64_t & iNOW )
const;
1132 virtual int ConvertAddress(
const struct sockaddr_storage * pAddr, socklen_t iAddrLen,
CS_STRING & sIP, uint16_t * piPort )
const;
1135 CSSockAddr * GetCurrentAddr()
const {
return( m_pCurrAddr ); }
1136 void SetAresFinished(
int status ) { m_pCurrAddr = NULL; m_iARESStatus = status; }
1137 ares_channel GetAresChannel()
const {
return( m_pARESChannel ); }
1144 void SetEncoding(
const CS_STRING & sEncoding );
1146 virtual void IcuExtToUCallback(
1147 UConverterToUnicodeArgs* toArgs,
1148 const char* codeUnits,
1150 UConverterCallbackReason reason,
1152 virtual void IcuExtFromUCallback(
1153 UConverterFromUnicodeArgs* fromArgs,
1154 const UChar* codeUnits,
1157 UConverterCallbackReason reason,
1165 void ShrinkSendBuff();
1166 void IncBuffPos(
size_t uBytes );
1172 int m_iTimeout, m_iConnType, m_iMethod, m_iTcount, m_iMaxConns;
1173 bool m_bUseSSL, m_bIsConnected;
1174 bool m_bsslEstablished, m_bEnableReadLine, m_bPauseRead;
1175 CS_STRING m_shostname, m_sbuffer, m_sSockName, m_sDHParamFile, m_sKeyFile, m_sPemFile, m_sCipherType, m_sParentName;
1180 mutable uint16_t m_iRemotePort, m_iLocalPort;
1181 mutable CS_STRING m_sLocalIP, m_sRemoteIP;
1183 uint64_t m_iMaxMilliSeconds, m_iLastSendTime, m_iBytesRead, m_iBytesWritten, m_iStartTime;
1184 uint32_t m_iMaxBytes, m_iMaxStoredBufferLength, m_iTimeoutType;
1185 size_t m_iLastSend, m_uSendBufferPos;
1188 bool m_bIsIPv6, m_bSkipConnect;
1189 time_t m_iLastCheckTimeoutTime;
1194 SSL_CTX * m_ssl_ctx;
1195 uint32_t m_iRequireClientCertFlags;
1196 u_int m_uDisableProtocols;
1197 bool m_bNoSSLCompression;
1198 bool m_bSSLCipherServerPreference;
1204 bool ConfigureCTXOptions( SSL_CTX * pCTX );
1209 cs_sock_t CreateSocket(
bool bListen =
false );
1210 void Init(
const CS_STRING & sHostname, uint16_t uPort,
int iTimeout = 60 );
1215 uint32_t m_iCurBindCount, m_iDNSTryCount;
1218 ares_channel m_pARESChannel;
1224 UConverter* m_cnvInt;
1225 UConverter* m_cnvIntStrict;
1226 UConverter* m_cnvExt;
1247 m_sHostname = sHostname;
1249 m_iTimeout = iTimeout;
1290 void SetCipher(
const CS_STRING & s ) { m_sCipher = s; }
1335 m_sBindHost = sBindHost;
1337 m_iMaxConns = SOMAXCONN;
1340 m_bDetach = bDetach;
1343 m_iRequireCertFlags = 0;
1367 void SetPort( uint16_t iPort ) { m_iPort = iPort; }
1382 void SetCipher(
const CS_STRING & s ) { m_sCipher = s; }
1393 void SetRequiresClientCert(
bool b ) { m_iRequireCertFlags = ( b ? SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0 ); }
1403 uint32_t m_iTimeout;
1407 CS_STRING m_sDHParamLocation, m_sKeyLocation, m_sPemLocation, m_sPemPass, m_sCipher;
1408 uint32_t m_iRequireCertFlags;
1450 virtual void clear();
1451 virtual void Cleanup();
1453 virtual Csock * GetSockObj(
const CS_STRING & sHostname, uint16_t uPort,
int iTimeout = 60 );
1459 SELECT_TIMEOUT = -2,
1460 SELECT_TRYAGAIN = -3
1479 virtual bool Listen(
const CSListener & cListen,
Csock * pcSock = NULL, uint16_t * piRandPort = NULL );
1483 bool HasFDs()
const;
1490 virtual void Loop();
1507 void DynamicSelectLoop( uint64_t iLowerBounds, uint64_t iUpperBounds, time_t iMaxResolution = 3600 );
1513 virtual void AddSock(
Csock * pcSock,
const CS_STRING & sSockName );
1516 virtual Csock * FindSockByRemotePort( uint16_t iPort );
1519 virtual Csock * FindSockByLocalPort( uint16_t iPort );
1527 virtual std::vector<Csock *> FindSocksByName(
const CS_STRING & sName );
1530 virtual std::vector<Csock *> FindSocksByRemoteHost(
const CS_STRING & sHostname );
1545 virtual void DelSockByAddr(
Csock * pcSock );
1552 virtual void DelSock(
size_t iPos );
1560 virtual bool SwapSockByIdx(
Csock * pNewSock,
size_t iOrginalSockIdx );
1568 virtual bool SwapSockByAddr(
Csock * pNewSock,
Csock * pOrigSock );
1571 uint64_t GetBytesRead()
const;
1574 uint64_t GetBytesWritten()
const;
1583 void FDSetCheck(
cs_sock_t iFd, std::map< cs_sock_t, short > & miiReadyFds,
ECheckType eType );
1584 bool FDHasCheck(
cs_sock_t iFd, std::map< cs_sock_t, short > & miiReadyFds,
ECheckType eType );
1588 virtual int Select( std::map< cs_sock_t, short > & miiReadyFds,
struct timeval *tvtimeout );
1597 void Select( std::map<Csock *, EMessages> & mpeSocks );
1599 timeval GetDynamicSleepTime(
const timeval& tNow,
const timeval& tMaxResolution )
const;
1602 virtual void SelectSock( std::map<Csock *, EMessages> & mpeSocks,
EMessages eErrno,
Csock * pcSock );
1610 uint64_t m_iCallTimeouts;
1611 uint64_t m_iBytesRead;
1612 uint64_t m_iBytesWritten;
1613 uint64_t m_iSelectWait;
1631 return(
new T( sHostname, uPort, iTimeout ) );
1635 #ifndef _NO_CSOCKET_NS void CSAdjustTVTimeout(struct timeval &tv, long iTimeoutMS)
adjusts tv with a new timeout if iTimeoutMS is smaller
const CS_STRING & GetDHParamLocation() const
Definition: Csocket.h:1270
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:1395
void SSLErrors(const char *filename, uint32_t iLineNum)
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1260
ECloseType GetCloseType() const
returns int of type to close
Definition: Csocket.h:848
virtual ~CCron()
Definition: Csocket.h:381
simple class to share common code to both TSockManager and Csock
Definition: Csocket.h:493
void MonitorFD(CSMonitorFD *pMonitorFD)
add an FD set to monitor
Definition: Csocket.h:525
ssize_t cs_ssize_t
Definition: Csocket.h:150
Ease of use templated socket manager.
Definition: Csocket.h:1624
#define CS_EXPORT
Definition: Csocket.h:129
Definition: Csocket.h:207
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:1034
virtual void ReadPaused()
This gets called every iteration of CSocketManager::Select() if the socket is ReadPaused.
Definition: Csocket.h:996
void SetIPv6(bool b)
Definition: Csocket.h:1093
void SetBindHost(const CS_STRING &s)
sets the hostname to bind to (vhost support)
Definition: Csocket.h:1279
void SetBindHost(const CS_STRING &sBindHost)
sets the host to bind to
Definition: Csocket.h:1371
Definition: Csocket.h:1309
CSCharBuffer(size_t iSize)
Definition: Csocket.h:171
Csock * GetCsockFromCTX(X509_STORE_CTX *pCTX)
returns the sock object associated to the particular context. returns NULL on failure or if not avail...
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1074
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:973
const CS_STRING & GetSockName() const
Definition: Csocket.h:1351
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:1377
this function is a wrapper around getaddrinfo (for ipv6)
Definition: Csocket.h:258
CS_STRING GetEncoding() const
Definition: Csocket.h:1145
CS_STRING m_sSockName
Definition: Csocket.h:1299
const CS_STRING & GetDHParamLocation() const
Definition: Csocket.h:1359
ESSLMethod
Definition: Csocket.h:600
virtual T * GetSockObj(const CS_STRING &sHostname, uint16_t uPort, int iTimeout=60)
Definition: Csocket.h:1629
void Add(cs_sock_t iFD, short iMonitorEvents)
adds a file descriptor to be monitored
Definition: Csocket.h:475
int(* FPCertVerifyCB)(int, X509_STORE_CTX *)
Definition: Csocket.h:534
bool GetIPv6() const
Definition: Csocket.h:1092
void SetConState(ECONState eState)
sets the connection state to eState
Definition: Csocket.h:1066
EAFRequire GetAFRequire() const
Definition: Csocket.h:229
bool TFD_ISSET(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:356
void SetAFRequire(EAFRequire iWhich)
Definition: Csocket.h:228
virtual ~CSSockAddr()
Definition: Csocket.h:202
CSSockAddr::EAFRequire GetAFRequire() const
Definition: Csocket.h:1356
void Remove(cs_sock_t iFD)
removes this fd from monitoring
Definition: Csocket.h:477
time_t GetLastCheckTimeout() const
Definition: Csocket.h:1053
const CS_STRING & GetPemLocation() const
Definition: Csocket.h:1268
ETConn
Definition: Csocket.h:576
bool m_bEnabled
Definition: Csocket.h:485
bool m_bRunOnNextCall
if set to true, RunJob() gets called on next invocation of run() despite the timeout ...
Definition: Csocket.h:428
void SetTimeout(int i)
sets the connection timeout
Definition: Csocket.h:1283
uint16_t GetPort() const
Definition: Csocket.h:1350
Definition: Csocket.h:1413
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:461
char * operator()()
Definition: Csocket.h:179
EFRead
Definition: Csocket.h:583
Ease of use self deleting char * class.
Definition: Csocket.h:168
EFSelect
Definition: Csocket.h:592
virtual void Connected()
Connected event.
Definition: Csocket.h:940
ECONState
Definition: Csocket.h:622
uint64_t GetSelectTimeout() const
Get the Select Timeout in MICROSECONDS ( 1000 == 1 millisecond )
Definition: Csocket.h:1536
const CS_STRING & GetCipher() const
Definition: Csocket.h:1267
uint32_t GetTimeout() const
Definition: Csocket.h:1355
virtual ~CSMonitorFD()
Definition: Csocket.h:446
Definition: Csocket.h:309
void SetDetach(bool b)
Definition: Csocket.h:1348
CSSockAddr::EAFRequire m_iAFrequire
Definition: Csocket.h:1303
void SetPemLocation(const CS_STRING &s)
set the location of the pemfile
Definition: Csocket.h:1385
this lookup is for the vhost bind
Definition: Csocket.h:1079
void SetSockName(const CS_STRING &s)
sets the name of the socket, used for reference, ie in FindSockByName()
Definition: Csocket.h:1277
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:1046
void CS_Delete(T *&p)
Definition: Csocket.h:303
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:1003
const CS_STRING & GetHostname() const
Definition: Csocket.h:1258
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:1539
bool GetIPv6() const
Definition: Csocket.h:217
int GetMaxConns() const
Definition: Csocket.h:1354
ECloseType
Definition: Csocket.h:633
in_addr * GetAddr()
Definition: Csocket.h:221
const CS_STRING & GetBindHost() const
Definition: Csocket.h:1352
options for creating a connection
Definition: Csocket.h:1237
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
sets the AF family type required
Definition: Csocket.h:1287
CSSockAddr::EAFRequire GetAFRequire() const
Definition: Csocket.h:1264
Basic socket class.
Definition: Csocket.h:548
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
sets the AF family type required
Definition: Csocket.h:1379
void DisableSSLCompression()
allow disabling compression
Definition: Csocket.h:862
const CS_STRING & GetPemPass() const
Definition: Csocket.h:1362
virtual void Timeout()
Sock Timed out event.
Definition: Csocket.h:948
virtual ~CSListener()
Definition: Csocket.h:1346
bool m_bIsSSL
Definition: Csocket.h:1302
const CS_STRING & GetCipher() const
Definition: Csocket.h:1358
int GetErrno() const
return the last known error as set by this class
Definition: Csocket.h:1533
ECompType
Definition: Csocket.h:306
#define CS_STRING
Definition: Csocket.h:116
socklen_t GetSockAddrLen6()
Definition: Csocket.h:223
void SetPort(uint16_t iPort)
sets the port to listen on. Set to 0 to listen on a random port
Definition: Csocket.h:1367
void SetMaxConns(int i)
set max connections as called by accept()
Definition: Csocket.h:1375
virtual ~CSConnection()
Definition: Csocket.h:1256
CSMonitorFD()
Definition: Csocket.h:445
uint16_t GetPort() const
Definition: Csocket.h:1261
CSConnection(const CS_STRING &sHostname, uint16_t iPort, int iTimeout=60)
Definition: Csocket.h:1245
uint16_t m_iPort
Definition: Csocket.h:1300
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:420
void SetPemPass(const CS_STRING &s)
set the pemfile pass
Definition: Csocket.h:1295
int GetTimeout() const
Definition: Csocket.h:1262
virtual ~TSocketManager()
Definition: Csocket.h:1628
int cs_sock_t
Definition: Csocket.h:149
const uint32_t CS_BLOCKSIZE
Definition: Csocket.h:302
void SetKeyLocation(const CS_STRING &s)
set the location of the keyfile
Definition: Csocket.h:1387
options container to create a listener
Definition: Csocket.h:1324
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:1416
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:979
const CS_STRING & GetPemLocation() const
Definition: Csocket.h:1361
EDisableProtocol
Definition: Csocket.h:611
void SetSkipConnect(bool b)
Definition: Csocket.h:1110
std::vector< CSMonitorFD * > m_vcMonitorFD
Definition: Csocket.h:529
bool IsClosed() const
Definition: Csocket.h:849
const CS_STRING & GetKeyLocation() const
Definition: Csocket.h:1269
const CS_STRING & GetKeyLocation() const
Definition: Csocket.h:1360
this is the main cron job class
Definition: Csocket.h:377
bool IsEnabled() const
Definition: Csocket.h:481
ECONState GetConState() const
returns the current connection state
Definition: Csocket.h:1064
void SetHostname(const CS_STRING &s)
sets the hostname to connect to
Definition: Csocket.h:1275
void SetPemPass(const CS_STRING &s)
set the pemfile pass
Definition: Csocket.h:1391
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:986
void SetSockName(const CS_STRING &sSockName)
sets the sock name for later reference (ie FindSockByName)
Definition: Csocket.h:1369
virtual void ReadData(const char *data, size_t len)
Ready to read data event.
Definition: Csocket.h:952
socklen_t GetSockAddrLen()
Definition: Csocket.h:219
virtual void ReadLine(const CS_STRING &sLine)
Ready to Read a full line event.
Definition: Csocket.h:957
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:1011
virtual void Disconnected()
Disconnected event.
Definition: Csocket.h:944
sockaddr_in6 * GetSockAddr6()
Definition: Csocket.h:224
void SetPort(uint16_t i)
sets the port to connect to
Definition: Csocket.h:1281
sockaddr wrapper.
Definition: Csocket.h:190
void SetAFRequire(CSSockAddr::EAFRequire iAFRequire)
Definition: Csocket.h:1100
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:1312
bool HasReadLine() const
returns the value of m_bEnableReadLine, if ReadLine is enabled
Definition: Csocket.h:962
int GetAddrInfo(const CS_STRING &sHostname, Csock *pSock, CSSockAddr &csSockAddr)
backwards compatible wrapper around CGetAddrInfo and gethostbyname
CSockCommon()
Definition: Csocket.h:496
CSSockAddr()
Definition: Csocket.h:193
EDNSLType
Definition: Csocket.h:1077
const CS_STRING & GetPemPass() const
Definition: Csocket.h:1271
TSocketManager()
Definition: Csocket.h:1627
CSListener(uint16_t iPort, const CS_STRING &sBindHost="", bool bDetach=false)
Definition: Csocket.h:1332
void TFD_ZERO(fd_set *set)
wrappers for FD_SET and such to work in templates.
Definition: Csocket.h:346
bool GetIsSSL() const
Definition: Csocket.h:1263
bool GetDetach() const
Definition: Csocket.h:1349
EAFRequire
Definition: Csocket.h:205
void SetDHParamLocation(const CS_STRING &s)
set the location of the dhparamfile
Definition: Csocket.h:1389
void SetBindHost(const CS_STRING &sBindHost)
Definition: Csocket.h:1075
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:920
void FollowSSLCipherServerPreference()
select the ciphers in server-preferred order
Definition: Csocket.h:864
void SetCertVerifyCB(FPCertVerifyCB pFP)
setting this to NULL will allow the default openssl verification process kick in
Definition: Csocket.h:889
int m_iTimeout
Definition: Csocket.h:1301
const CS_STRING & GetSockName() const
Definition: Csocket.h:1259
in6_addr * GetAddr6()
Definition: Csocket.h:225
void SetIsSSL(bool b)
set to true to enable SSL
Definition: Csocket.h:1285
void TFD_SET(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:351
virtual void ConnectionRefused()
Connection Refused Event.
Definition: Csocket.h:992
Best class to use to interact with the sockets.
Definition: Csocket.h:1445
bool GetIsSSL() const
Definition: Csocket.h:1353
void DisableMonitor()
causes this monitor to be removed
Definition: Csocket.h:479
int GetMaxConns() const
returns the number of max pending connections when type is LISTENER
Definition: Csocket.h:1141
int GetCsockSSLIdx()
This returns the [ex_]data index position for SSL objects only.
std::map< cs_sock_t, short > m_miiMonitorFDs
Definition: Csocket.h:484
void SetPemLocation(const CS_STRING &s)
set the location of the pemfile
Definition: Csocket.h:1293
ECheckType
this is a strict wrapper around C-api select(). Added in the event you need to do special work here ...
Definition: Csocket.h:1577
CS_STRING m_sPemPass
Definition: Csocket.h:1305
std::vector< CCron * > m_vcCrons
Definition: Csocket.h:528
int GetSockError()
Definition: Csocket.h:336
Class to tie sockets to for monitoring by Csocket at either the Csock or TSockManager.
Definition: Csocket.h:442
EMessages
Definition: Csocket.h:1455
Definition: Csocket.h:308
~CSCharBuffer()
Definition: Csocket.h:175
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...
void TFD_CLR(cs_sock_t iSock, fd_set *set)
Definition: Csocket.h:361
void SetRequiresClientCert(bool b)
set to true if require a client certificate (deprecated
Definition: Csocket.h:1393
void SetIsSSL(bool b)
set to true to enable SSL
Definition: Csocket.h:1373
uint32_t GetRequireClientCertFlags() const
Definition: Csocket.h:1363
sockaddr_in * GetSockAddr()
Definition: Csocket.h:220
const std::vector< CCron * > & GetCrons() const
returns a const reference to the crons associated to this socket
Definition: Csocket.h:503