diff --git a/Csocket.cpp b/Csocket.cpp index 0294468a..e3d929a9 100644 --- a/Csocket.cpp +++ b/Csocket.cpp @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.83 $ +* $Revision: 1.89 $ */ #include "Csocket.h" @@ -36,6 +36,7 @@ #include #endif /* __NetBSD__ */ + #include #define CS_SRANDBUFFER 128 @@ -54,6 +55,29 @@ int GetCsockClassIdx() } #ifdef _WIN32 +static const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) +{ + if( af == AF_INET ) + { + struct sockaddr_in in; + memset(&in, 0, sizeof(in)); + in.sin_family = AF_INET; + memcpy( &in.sin_addr, src, sizeof(struct in_addr) ); + getnameinfo( (struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST ); + return dst; + } + else if( af == AF_INET6 ) + { + struct sockaddr_in6 in; + memset( &in, 0, sizeof(in) ); + in.sin6_family = AF_INET6; + memcpy( &in.sin6_addr, src, sizeof(struct in_addr6) ); + getnameinfo( (struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST ); + return dst; + } + return( NULL ); +} + static inline void set_non_blocking(int fd) { u_long iOpts = 1; @@ -157,7 +181,9 @@ static int __GetHostByName( const CS_STRING & sHostName, struct in_addr *paddr, if( h_errno != TRY_AGAIN ) { +#ifndef _WIN32 CS_DEBUG( "gethostyname: " << hstrerror( h_errno ) ); +#endif /* _WIN32 */ break; } } @@ -1143,9 +1169,19 @@ bool Csock::ConnectSSL( const CS_STRING & sBindhost ) if ( iErr != 1 ) { int sslErr = SSL_get_error( m_ssl, iErr ); - - if ( ( sslErr != SSL_ERROR_WANT_READ ) && ( sslErr != SSL_ERROR_WANT_WRITE ) ) - bPass = false; + bPass = false; + if( sslErr == SSL_ERROR_WANT_READ || sslErr == SSL_ERROR_WANT_WRITE ) + bPass = true; +#ifdef _WIN32 + else if( sslErr == SSL_ERROR_SYSCALL && iErr < 0 && GetLastError() == WSAENOTCONN ) + { + // this seems to be an issue with win32 only. I've seen it happen on slow connections + // the issue is calling this before select(), which isn't a problem on unix. Allowing this + // to pass in this case is fine because subsequent ssl transactions will occur and the handshake + // will finish. At this point, its just instantiating the handshake. + bPass = true; + } +#endif /* _WIN32 */ } else bPass = true; @@ -1566,12 +1602,12 @@ void Csock::PushBuff( const char *data, int len, bool bStartAtZero ) CS_STRING & Csock::GetInternalReadBuffer() { return( m_sbuffer ); } CS_STRING & Csock::GetInternalWriteBuffer() { return( m_sSend ); } void Csock::SetMaxBufferThreshold( u_int iThreshold ) { m_iMaxStoredBufferLength = iThreshold; } -u_int Csock::GetMaxBufferThreshold() { return( m_iMaxStoredBufferLength ); } -int Csock::GetType() { return( m_iConnType ); } +u_int Csock::GetMaxBufferThreshold() const { return( m_iMaxStoredBufferLength ); } +int Csock::GetType() const { return( m_iConnType ); } void Csock::SetType( int iType ) { m_iConnType = iType; } -const CS_STRING & Csock::GetSockName() { return( m_sSockName ); } +const CS_STRING & Csock::GetSockName() const { return( m_sSockName ); } void Csock::SetSockName( const CS_STRING & sName ) { m_sSockName = sName; } -const CS_STRING & Csock::GetHostName() { return( m_shostname ); } +const CS_STRING & Csock::GetHostName() const { return( m_shostname ); } void Csock::SetHostName( const CS_STRING & sHostname ) { m_shostname = sHostname; } unsigned long long Csock::GetStartTime() const { return( m_iStartTime ); } void Csock::ResetStartTime() { m_iStartTime = 0; } diff --git a/Csocket.h b/Csocket.h index 64a6d897..8e004d4b 100644 --- a/Csocket.h +++ b/Csocket.h @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.195 $ +* $Revision: 1.199 $ */ // note to compile with win32 need to link to winsock2, using gcc its -lws2_32 @@ -56,6 +56,8 @@ #define ECONNREFUSED WSAECONNREFUSED #define EINPROGRESS WSAEINPROGRESS #define ETIMEDOUT WSAETIMEDOUT +#define EADDRNOTAVAIL WSAEADDRNOTAVAIL +#define ECONNABORTED WSAECONNABORTED #endif /* _WIN32 */ @@ -292,6 +294,11 @@ inline void ShutdownWin32() { WSACleanup(); } +#define InitCsocket InitWin32 +#define ShutdownCsocket ShutdownWin32 +#else +#define InitCsocket (void)0 +#define ShutdownCsocket (void)0 #endif /* _WIN32 */ //! wrappers for FD_SET and such to work in templates. @@ -639,18 +646,18 @@ public: //! sets the max buffered threshold when EnableReadLine() is enabled void SetMaxBufferThreshold( u_int iThreshold ); - u_int GetMaxBufferThreshold(); + u_int GetMaxBufferThreshold() const; //! Returns the connection type from enum eConnType - int GetType(); + int GetType() const; void SetType( int iType ); //! Returns a reference to the socket name - const CS_STRING & GetSockName(); + const CS_STRING & GetSockName() const; void SetSockName( const CS_STRING & sName ); //! Returns a reference to the host name - const CS_STRING & GetHostName(); + const CS_STRING & GetHostName() const; void SetHostName( const CS_STRING & sHostname );