mirror of
https://github.com/znc/znc.git
synced 2026-05-05 13:02:31 +02:00
Update to latest Csocket
This fixes some trailing whitespaces and space/tab mixups I found. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@958 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
85
Csocket.cpp
85
Csocket.cpp
@@ -28,7 +28,7 @@
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* $Revision: 1.65 $
|
||||
* $Revision: 1.66 $
|
||||
*/
|
||||
|
||||
#include "Csocket.h"
|
||||
@@ -177,7 +177,7 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA
|
||||
csSockAddr.SetIPv6( false );
|
||||
if( __GetHostByName( sHostname, csSockAddr.GetAddr(), 3 ) == 0 )
|
||||
return( 0 );
|
||||
|
||||
|
||||
#else /* HAVE_IPV6 */
|
||||
struct addrinfo *res = NULL;
|
||||
struct addrinfo hints;
|
||||
@@ -231,11 +231,11 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA
|
||||
// pick a random canidate to make this work
|
||||
struct random_data cRandData;
|
||||
char chState[CS_SRANDBUFFER];
|
||||
int32_t iNumber = 0;
|
||||
int32_t iNumber = 0;
|
||||
if( initstate_r( (u_int)millitime(), chState, CS_SRANDBUFFER, &cRandData ) == 0 && random_r( &cRandData, &iNumber ) == 0 )
|
||||
{
|
||||
iNumber %= (int)vHostCanidates.size();
|
||||
pUseAddr = vHostCanidates[iNumber];
|
||||
iNumber %= (int)vHostCanidates.size();
|
||||
pUseAddr = vHostCanidates[iNumber];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -274,17 +274,17 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA
|
||||
}
|
||||
|
||||
#ifdef ___DO_THREADS
|
||||
CSMutex::CSMutex()
|
||||
CSMutex::CSMutex()
|
||||
{
|
||||
pthread_mutexattr_init( &m_mattrib );
|
||||
if ( pthread_mutexattr_settype( &m_mattrib, PTHREAD_MUTEX_FAST_NP ) != 0 )
|
||||
throw CS_STRING( "ERROR: pthread_mutexattr_settype failed!" );
|
||||
|
||||
|
||||
if ( pthread_mutex_init( &m_mutex, &m_mattrib ) != 0 )
|
||||
throw CS_STRING( "ERROR: pthread_mutex_init failed!" );
|
||||
}
|
||||
|
||||
CSMutex::~CSMutex()
|
||||
CSMutex::~CSMutex()
|
||||
{
|
||||
pthread_mutexattr_destroy( &m_mattrib );
|
||||
pthread_mutex_destroy( &m_mutex );
|
||||
@@ -327,7 +327,7 @@ bool CSThread::start()
|
||||
}
|
||||
|
||||
return( true );
|
||||
}
|
||||
}
|
||||
|
||||
void CSThread::wait()
|
||||
{
|
||||
@@ -349,7 +349,7 @@ void *CSThread::start_thread( void *args )
|
||||
curThread->lock();
|
||||
curThread->SetStatus( CSThread::FINISHED );
|
||||
curThread->unlock();
|
||||
pthread_exit( NULL );
|
||||
pthread_exit( NULL );
|
||||
}
|
||||
|
||||
void CDNSResolver::Lookup( const CS_STRING & sHostname )
|
||||
@@ -629,46 +629,46 @@ void Csock::Copy( const Csock & cCopy )
|
||||
m_iTcount = cCopy.m_iTcount;
|
||||
m_iLastCheckTimeoutTime = cCopy.m_iLastCheckTimeoutTime;
|
||||
m_iport = cCopy.m_iport;
|
||||
m_iRemotePort = cCopy.m_iRemotePort;
|
||||
m_iRemotePort = cCopy.m_iRemotePort;
|
||||
m_iLocalPort = cCopy.m_iLocalPort;
|
||||
m_iReadSock = cCopy.m_iReadSock;
|
||||
m_iWriteSock = cCopy.m_iWriteSock;
|
||||
m_itimeout = cCopy.m_iWriteSock;
|
||||
m_iConnType = cCopy.m_iConnType;
|
||||
m_itimeout = cCopy.m_iWriteSock;
|
||||
m_iConnType = cCopy.m_iConnType;
|
||||
m_iMethod = cCopy.m_iMethod;
|
||||
m_bssl = cCopy.m_bssl;
|
||||
m_bIsConnected = cCopy.m_bIsConnected;
|
||||
m_bBLOCK = cCopy.m_bBLOCK;
|
||||
m_bFullsslAccept = cCopy.m_bFullsslAccept;
|
||||
m_bsslEstablished = cCopy.m_bsslEstablished;
|
||||
m_bEnableReadLine = cCopy.m_bEnableReadLine;
|
||||
m_bRequireClientCert = cCopy.m_bRequireClientCert;
|
||||
m_bPauseRead = cCopy.m_bPauseRead;
|
||||
m_bEnableReadLine = cCopy.m_bEnableReadLine;
|
||||
m_bRequireClientCert = cCopy.m_bRequireClientCert;
|
||||
m_bPauseRead = cCopy.m_bPauseRead;
|
||||
m_shostname = cCopy.m_shostname;
|
||||
m_sbuffer = cCopy.m_sbuffer;
|
||||
m_sSockName = cCopy.m_sSockName;
|
||||
m_sPemFile = cCopy.m_sPemFile;
|
||||
m_sCipherType = cCopy.m_sCipherType;
|
||||
m_sParentName = cCopy.m_sParentName;
|
||||
m_sbuffer = cCopy.m_sbuffer;
|
||||
m_sSockName = cCopy.m_sSockName;
|
||||
m_sPemFile = cCopy.m_sPemFile;
|
||||
m_sCipherType = cCopy.m_sCipherType;
|
||||
m_sParentName = cCopy.m_sParentName;
|
||||
m_sSend = cCopy.m_sSend;
|
||||
m_sSSLBuffer = cCopy.m_sSSLBuffer;
|
||||
m_sPemPass = cCopy.m_sPemPass;
|
||||
m_sLocalIP = cCopy.m_sLocalIP;
|
||||
m_sRemoteIP = cCopy.m_sRemoteIP;
|
||||
m_sSSLBuffer = cCopy.m_sSSLBuffer;
|
||||
m_sPemPass = cCopy.m_sPemPass;
|
||||
m_sLocalIP = cCopy.m_sLocalIP;
|
||||
m_sRemoteIP = cCopy.m_sRemoteIP;
|
||||
m_eCloseType = cCopy.m_eCloseType;
|
||||
|
||||
m_iMaxMilliSeconds = cCopy.m_iMaxMilliSeconds;
|
||||
m_iLastSendTime = cCopy.m_iLastSendTime;
|
||||
m_iBytesRead = cCopy.m_iBytesRead;
|
||||
m_iBytesWritten = cCopy.m_iBytesWritten;
|
||||
m_iStartTime = cCopy.m_iStartTime;
|
||||
m_iLastSendTime = cCopy.m_iLastSendTime;
|
||||
m_iBytesRead = cCopy.m_iBytesRead;
|
||||
m_iBytesWritten = cCopy.m_iBytesWritten;
|
||||
m_iStartTime = cCopy.m_iStartTime;
|
||||
m_iMaxBytes = cCopy.m_iMaxBytes;
|
||||
m_iLastSend = cCopy.m_iLastSend;
|
||||
m_iMaxStoredBufferLength = cCopy.m_iMaxStoredBufferLength;
|
||||
m_iTimeoutType = cCopy.m_iTimeoutType;
|
||||
m_iLastSend = cCopy.m_iLastSend;
|
||||
m_iMaxStoredBufferLength = cCopy.m_iMaxStoredBufferLength;
|
||||
m_iTimeoutType = cCopy.m_iTimeoutType;
|
||||
|
||||
m_address = cCopy.m_address;
|
||||
m_bindhost = cCopy.m_bindhost;
|
||||
m_bindhost = cCopy.m_bindhost;
|
||||
m_bIsIPv6 = cCopy.m_bIsIPv6;
|
||||
|
||||
#ifdef HAVE_LIBSSL
|
||||
@@ -695,7 +695,7 @@ void Csock::Copy( const Csock & cCopy )
|
||||
m_eConState = cCopy.m_eConState;
|
||||
m_sBindHost = cCopy.m_sBindHost;
|
||||
m_iCurBindCount = cCopy.m_iCurBindCount;
|
||||
m_iDNSTryCount = cCopy.m_iDNSTryCount;
|
||||
m_iDNSTryCount = cCopy.m_iDNSTryCount;
|
||||
|
||||
#ifdef ___DO_THREADS
|
||||
if( m_pResolver )
|
||||
@@ -974,7 +974,6 @@ int Csock::Accept( CS_STRING & sHost, u_short & iRPort )
|
||||
}
|
||||
#endif /* HAVE_IPV6 */
|
||||
|
||||
|
||||
if ( iSock != -1 )
|
||||
{
|
||||
// Make it close-on-exec
|
||||
@@ -1507,7 +1506,7 @@ CS_STRING Csock::GetLocalIP()
|
||||
char straddr[INET6_ADDRSTRLEN];
|
||||
struct sockaddr_in6 mLocalAddr;
|
||||
socklen_t mLocalLen = sizeof( mLocalAddr );
|
||||
if ( ( getsockname( iSock, (struct sockaddr *) &mLocalAddr, &mLocalLen ) == 0 )
|
||||
if ( ( getsockname( iSock, (struct sockaddr *) &mLocalAddr, &mLocalLen ) == 0 )
|
||||
&& ( inet_ntop( AF_INET6, &mLocalAddr.sin6_addr, straddr, sizeof(straddr) ) ) )
|
||||
{
|
||||
m_sLocalIP = straddr;
|
||||
@@ -1544,7 +1543,7 @@ CS_STRING Csock::GetRemoteIP()
|
||||
char straddr[INET6_ADDRSTRLEN];
|
||||
struct sockaddr_in6 mRemoteAddr;
|
||||
socklen_t mRemoteLen = sizeof( mRemoteAddr );
|
||||
if ( ( getpeername( iSock, (struct sockaddr *) &mRemoteAddr, &mRemoteLen ) == 0 )
|
||||
if ( ( getpeername( iSock, (struct sockaddr *) &mRemoteAddr, &mRemoteLen ) == 0 )
|
||||
&& ( inet_ntop( AF_INET6, &mRemoteAddr.sin6_addr, straddr, sizeof(straddr) ) ) )
|
||||
{
|
||||
m_sRemoteIP = straddr;
|
||||
@@ -1604,7 +1603,7 @@ bool Csock::CheckTimeout( time_t iNow )
|
||||
// this is weird, but its possible if someone changes a clock and it went back in time, this essentially has to reset the last check
|
||||
// the worst case scenario is the timeout is about to it and the clock changes, it would then cause
|
||||
// this to pass over the last half the time
|
||||
m_iLastCheckTimeoutTime = iNow;
|
||||
m_iLastCheckTimeoutTime = iNow;
|
||||
}
|
||||
|
||||
if ( m_itimeout > 0 )
|
||||
@@ -1759,7 +1758,7 @@ u_short Csock::GetLocalPort()
|
||||
u_short Csock::GetPort() { return( m_iport ); }
|
||||
void Csock::SetPort( u_short iPort ) { m_iport = iPort; }
|
||||
void Csock::Close( ECloseType eCloseType )
|
||||
{
|
||||
{
|
||||
m_eCloseType = eCloseType;
|
||||
}
|
||||
void Csock::BlockIO( bool bBLOCK ) { m_bBLOCK = bBLOCK; }
|
||||
@@ -2058,7 +2057,7 @@ int Csock::DNSLookup( EDNSLType eDNSLType )
|
||||
m_pResolverLookup( ( eDNSLType == DNS_VHOST ) ? m_sBindHost : m_shostname );
|
||||
m_iDNSTryCount++;
|
||||
}
|
||||
|
||||
|
||||
if ( m_pResolverIsCompleted() )
|
||||
{
|
||||
m_iDNSTryCount = 0;
|
||||
@@ -2097,7 +2096,7 @@ int Csock::DNSLookup( EDNSLType eDNSLType )
|
||||
|
||||
if ( m_eConState != CST_OK )
|
||||
m_eConState = ( ( eDNSLType == DNS_VHOST ) ? CST_BINDVHOST : CST_VHOSTDNS );
|
||||
|
||||
|
||||
if( !CreateSocksFD() )
|
||||
return( ETIMEDOUT );
|
||||
|
||||
@@ -2107,7 +2106,7 @@ int Csock::DNSLookup( EDNSLType eDNSLType )
|
||||
return( ETIMEDOUT );
|
||||
}
|
||||
return( EAGAIN );
|
||||
|
||||
|
||||
#else
|
||||
int iRet = ETIMEDOUT;
|
||||
if ( eDNSLType == DNS_VHOST )
|
||||
@@ -2131,7 +2130,7 @@ int Csock::DNSLookup( EDNSLType eDNSLType )
|
||||
|
||||
if( !CreateSocksFD() )
|
||||
iRet = ETIMEDOUT;
|
||||
|
||||
|
||||
if ( iRet == 0 )
|
||||
{
|
||||
if ( m_eConState != CST_OK )
|
||||
|
||||
60
Csocket.h
60
Csocket.h
@@ -28,7 +28,7 @@
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* $Revision: 1.181 $
|
||||
* $Revision: 1.182 $
|
||||
*/
|
||||
|
||||
// note to compile with win32 need to link to winsock2, using gcc its -lws2_32
|
||||
@@ -137,9 +137,9 @@ private:
|
||||
class CSSockAddr
|
||||
{
|
||||
public:
|
||||
CSSockAddr()
|
||||
{
|
||||
m_bIsIPv6 = false;
|
||||
CSSockAddr()
|
||||
{
|
||||
m_bIsIPv6 = false;
|
||||
memset( (struct sockaddr_in *)&m_saddr, '\0', sizeof( m_saddr ) );
|
||||
#ifdef HAVE_IPV6
|
||||
memset( (struct sockaddr_in6 *)&m_saddr6, '\0', sizeof( m_saddr6 ) );
|
||||
@@ -181,8 +181,8 @@ public:
|
||||
m_saddr.sin_port = htons( iPort );
|
||||
}
|
||||
|
||||
void SetIPv6( bool b )
|
||||
{
|
||||
void SetIPv6( bool b )
|
||||
{
|
||||
#ifndef HAVE_IPV6
|
||||
if( b )
|
||||
{
|
||||
@@ -191,7 +191,7 @@ public:
|
||||
return;
|
||||
}
|
||||
#endif /* HAVE_IPV6 */
|
||||
m_bIsIPv6 = b;
|
||||
m_bIsIPv6 = b;
|
||||
SinFamily();
|
||||
}
|
||||
bool GetIPv6() const { return( m_bIsIPv6 ); }
|
||||
@@ -234,7 +234,7 @@ Csock *GetCsockFromCTX( X509_STORE_CTX *pCTX );
|
||||
#define ___DO_THREADS
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef PTHREAD_MUTEX_FAST_NP
|
||||
#ifndef PTHREAD_MUTEX_FAST_NP
|
||||
#define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_NORMAL
|
||||
#endif /* PTHREAD_MUTEX_FAST_NP */
|
||||
|
||||
@@ -249,7 +249,6 @@ public:
|
||||
private:
|
||||
pthread_mutex_t m_mutex;
|
||||
pthread_mutexattr_t m_mattrib;
|
||||
|
||||
};
|
||||
|
||||
class CSThread
|
||||
@@ -257,7 +256,7 @@ class CSThread
|
||||
public:
|
||||
CSThread() { m_eStatus = WAITING; }
|
||||
virtual ~CSThread() {}
|
||||
|
||||
|
||||
enum EStatus
|
||||
{
|
||||
WAITING = 1,
|
||||
@@ -479,12 +478,12 @@ public:
|
||||
* @brief 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
|
||||
* the whole point of this function is to allow this class to go away without shutting down
|
||||
*/
|
||||
virtual void Dereference();
|
||||
//! use this to copy a sock from one to the other, override it if you have special needs in the event of a copy
|
||||
virtual void Copy( const Csock & cCopy );
|
||||
|
||||
|
||||
enum ETConn
|
||||
{
|
||||
OUTBOUND = 0, //!< outbound connection
|
||||
@@ -931,11 +930,11 @@ public:
|
||||
|
||||
|
||||
//! return how long it has been (in seconds) since the last read or successful write
|
||||
int GetTimeSinceLastDataTransaction( time_t iNow = 0 )
|
||||
{
|
||||
int GetTimeSinceLastDataTransaction( time_t iNow = 0 )
|
||||
{
|
||||
if( m_iLastCheckTimeoutTime == 0 )
|
||||
return( 0 );
|
||||
return( ( iNow > 0 ? iNow : time( NULL ) ) - m_iLastCheckTimeoutTime );
|
||||
return( ( iNow > 0 ? iNow : time( NULL ) ) - m_iLastCheckTimeoutTime );
|
||||
}
|
||||
time_t GetLastCheckTimeout() { return( m_iLastCheckTimeoutTime ); }
|
||||
|
||||
@@ -954,7 +953,7 @@ public:
|
||||
{
|
||||
if( m_iReadSock != -1 )
|
||||
return( true );
|
||||
|
||||
|
||||
m_iReadSock = m_iWriteSock = SOCKET();
|
||||
if ( m_iReadSock == -1 )
|
||||
return( false );
|
||||
@@ -967,13 +966,13 @@ public:
|
||||
|
||||
const CS_STRING & GetBindHost() const { return( m_sBindHost ); }
|
||||
void SetBindHost( const CS_STRING & sBindHost ) { m_sBindHost = sBindHost; }
|
||||
|
||||
|
||||
enum EDNSLType
|
||||
{
|
||||
DNS_VHOST,
|
||||
DNS_DEST
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* nonblocking dns lookup (when -pthread is set to compile)
|
||||
* @return 0 for success, EAGAIN to check back again (same arguments as before), ETIMEDOUT on failure
|
||||
@@ -982,11 +981,11 @@ public:
|
||||
|
||||
//! this is only used on outbound connections, listeners bind in a different spot
|
||||
bool SetupVHost();
|
||||
|
||||
|
||||
bool GetIPv6() const { return( m_bIsIPv6 ); }
|
||||
void SetIPv6( bool b )
|
||||
{
|
||||
m_bIsIPv6 = b;
|
||||
void SetIPv6( bool b )
|
||||
{
|
||||
m_bIsIPv6 = b;
|
||||
m_address.SetIPv6( b );
|
||||
m_bindhost.SetIPv6( b );
|
||||
}
|
||||
@@ -1065,7 +1064,7 @@ public:
|
||||
* @param iPort port to connect to
|
||||
* @param iTimeout connection timeout
|
||||
*/
|
||||
CSConnection( const CS_STRING & sHostname, u_short iPort, int iTimeout = 60 )
|
||||
CSConnection( const CS_STRING & sHostname, u_short iPort, int iTimeout = 60 )
|
||||
{
|
||||
m_sHostname = sHostname;
|
||||
m_iPort = iPort;
|
||||
@@ -1149,7 +1148,7 @@ public:
|
||||
* @param iPort port to listen on. Set to 0 to listen on a random port
|
||||
* @param sBindHost host to bind to
|
||||
*/
|
||||
CSListener( u_short iPort, const CS_STRING & sBindHost = "" )
|
||||
CSListener( u_short iPort, const CS_STRING & sBindHost = "" )
|
||||
{
|
||||
m_iPort = iPort;
|
||||
m_sBindHost = sBindHost;
|
||||
@@ -1492,7 +1491,7 @@ public:
|
||||
|
||||
if ( iLen <= 0 )
|
||||
iLen = CS_BLOCKSIZE;
|
||||
|
||||
|
||||
CSCharBuffer cBuff( iLen );
|
||||
|
||||
int bytes = pcSock->Read( cBuff(), iLen );
|
||||
@@ -1587,14 +1586,14 @@ public:
|
||||
* - by itself. I've tried to mitigate that as much as possible by not having it change the select if the previous call to select
|
||||
* - was not a timeout. Anyways .... Caveat Emptor.
|
||||
* - Sample useage is cFoo.DynamicSelectLoop( 500000, 5000000 ); which basically says min of 500ms and max of 5s
|
||||
*
|
||||
*
|
||||
* @param iLowerBounds the lower bounds to use in MICROSECONDS
|
||||
* @param iUpperBounds the upper bounds to use in MICROSECONDS
|
||||
* @param iMaxResolution the maximum time to calculate overall in seconds
|
||||
*/
|
||||
void DynamicSelectLoop( u_long iLowerBounds, u_long iUpperBounds, time_t iMaxResolution = 3600 )
|
||||
{
|
||||
SetSelectTimeout( iLowerBounds );
|
||||
SetSelectTimeout( iLowerBounds );
|
||||
if( m_errno == SELECT_TIMEOUT )
|
||||
{ // only do this if the previous call to select was a timeout
|
||||
time_t iNow = time( NULL );
|
||||
@@ -1808,7 +1807,7 @@ public:
|
||||
(*this)[iOrginalSockIdx] = (T *)pNewSock;
|
||||
return( true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief swaps out a sock with a copy of the original sock
|
||||
* @param pNewSock the new sock to change out with. (this should be constructed by you with the default ctor)
|
||||
@@ -2139,7 +2138,7 @@ private:
|
||||
iTimeoutInSeconds = 0;
|
||||
else
|
||||
iTimeoutInSeconds -= iDiff;
|
||||
|
||||
|
||||
iMinTimeout = std::min( iMinTimeout, iTimeoutInSeconds );
|
||||
}
|
||||
|
||||
@@ -2183,9 +2182,6 @@ private:
|
||||
|
||||
////////
|
||||
// Connection State Functions
|
||||
|
||||
|
||||
|
||||
|
||||
///////////
|
||||
// members
|
||||
|
||||
Reference in New Issue
Block a user