diff --git a/Csocket.cpp b/Csocket.cpp index 78f395b2..c8c89b5b 100644 --- a/Csocket.cpp +++ b/Csocket.cpp @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.131 $ +* $Revision: 1.134 $ */ #include "Csocket.h" @@ -721,7 +721,7 @@ void Csock::Copy( const Csock & cCopy ) #endif /* HAVE_LIBSSL */ - if( m_vcCrons.size() ) + if( !m_vcCrons.empty() ) { for( u_long a = 0; a < m_vcCrons.size(); a++ ) { @@ -966,11 +966,15 @@ bool Csock::Listen( u_short iPort, int iMaxConns, const CS_STRING & sBindHost, u return( false ); #ifdef HAVE_IPV6 -#ifdef IPV6_V6ONLY - // per RFC3493#5.3 - const int on = ( m_address.GetAFRequire() == CSSockAddr::RAF_INET6 ? 1 : 0 ); - if( setsockopt( m_iReadSock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&on, sizeof( on ) ) != 0 ) - PERROR( "IPV6_V6ONLY" ); +// there's no IPPROTO_IPV6 below Win XP. - KiNgMaR +#if (!defined(_WIN32) && defined(IPV6_V6ONLY)) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0501) + if( GetIPv6() ) + { + // per RFC3493#5.3 + const int on = ( m_address.GetAFRequire() == CSSockAddr::RAF_INET6 ? 1 : 0 ); + if( setsockopt( m_iReadSock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&on, sizeof( on ) ) != 0 ) + PERROR( "IPV6_V6ONLY" ); + } #endif /* IPV6_V6ONLY */ #endif /* HAVE_IPV6 */ @@ -1475,9 +1479,9 @@ bool Csock::Write( const char *data, size_t len ) } #endif /* HAVE_LIBSSL */ #ifdef _WIN32 - ssize_t bytes = send( m_iWriteSock, m_sSend.data(), iBytesToSend, 0 ); + cs_ssize_t bytes = send( m_iWriteSock, m_sSend.data(), iBytesToSend, 0 ); #else - ssize_t bytes = write( m_iWriteSock, m_sSend.data(), iBytesToSend ); + cs_ssize_t bytes = write( m_iWriteSock, m_sSend.data(), iBytesToSend ); #endif /* _WIN32 */ if ( ( bytes == -1 ) && ( GetSockError() == ECONNREFUSED ) ) @@ -1511,9 +1515,9 @@ bool Csock::Write( const CS_STRING & sData ) return( Write( sData.c_str(), sData.length() ) ); } -ssize_t Csock::Read( char *data, size_t len ) +cs_ssize_t Csock::Read( char *data, size_t len ) { - ssize_t bytes = 0; + cs_ssize_t bytes = 0; if ( ( IsReadPaused() ) && ( SslIsEstablished() ) ) return( READ_EAGAIN ); // allow the handshake to complete first diff --git a/Csocket.h b/Csocket.h index fddfa872..2799005e 100644 --- a/Csocket.h +++ b/Csocket.h @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.223 $ +* $Revision: 1.227 $ */ // note to compile with win32 need to link to winsock2, using gcc its -lws2_32 @@ -119,12 +119,19 @@ #ifdef _WIN32 typedef SOCKET cs_sock_t; +#ifdef _WIN64 +typedef signed __int64 cs_ssize_t; +#else +typedef signed int cs_ssize_t; +#endif /* _WIN64 */ #define CS_INVALID_SOCK INVALID_SOCKET #else typedef int cs_sock_t; +typedef ssize_t cs_ssize_t; #define CS_INVALID_SOCK -1 #endif /* _WIN32 */ + #ifndef _NO_CSOCKET_NS // some people may not want to use a namespace namespace Csocket { @@ -588,7 +595,7 @@ public: * Returns READ_TIMEDOUT for a connection that timed out at the TCP level * Otherwise returns the bytes read into data */ - virtual ssize_t Read( char *data, size_t len ); + virtual cs_ssize_t Read( char *data, size_t len ); CS_STRING GetLocalIP(); CS_STRING GetRemoteIP(); @@ -1347,6 +1354,12 @@ public: pcSock->SetIPv6( true ); #endif /* HAVE_IPV6 */ } +#ifdef HAVE_IPV6 + else + { + pcSock->SetIPv6( true ); + } +#endif /* HAVE_IPV6 */ #ifdef HAVE_LIBSSL pcSock->SetSSL( cListen.GetIsSSL() ); if( ( cListen.GetIsSSL() ) && ( !cListen.GetPemLocation().empty() ) ) @@ -1488,7 +1501,7 @@ public: CSCharBuffer cBuff( iLen ); - ssize_t bytes = pcSock->Read( cBuff(), iLen ); + cs_ssize_t bytes = pcSock->Read( cBuff(), iLen ); if ( ( bytes != T::READ_TIMEDOUT ) && ( bytes != T::READ_CONNREFUSED ) && ( !pcSock->IsConnected() ) ) @@ -1949,7 +1962,7 @@ private: { pcSock->Close(); } - if( pcSock->GetWriteBuffer().size() ) + if( !pcSock->GetWriteBuffer().empty() ) { // this means we need to write again, not everything got knocked out TFD_SET( iWSock, &wfds ); bHasWriteable = true;