mirror of
https://github.com/znc/znc.git
synced 2026-08-03 23:43:42 +02:00
bring csocket changes up to date with win32 fixes provided by DGandalf, also forgot to implement ares_timeout
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1708 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
+27
-5
@@ -28,7 +28,7 @@
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* $Revision: 1.115 $
|
||||
* $Revision: 1.117 $
|
||||
*/
|
||||
|
||||
#include "Csocket.h"
|
||||
@@ -78,6 +78,30 @@ static const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && (!defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600))
|
||||
//! thanks to KiNgMaR @ #znc for this wrapper
|
||||
static int inet_pton( int af, const char *src, void *dst )
|
||||
{
|
||||
sockaddr_storage aAddress;
|
||||
int iAddrLen = sizeof( sockaddr_storage );
|
||||
memset( &aAddress, 0, iAddrLen );
|
||||
char *pTmp = strdup( src );
|
||||
aAddress.ss_family = af; // this is important:
|
||||
// The function fails if the sin_family member of the SOCKADDR_IN structure is not set to AF_INET or AF_INET6.
|
||||
int iRet = WSAStringToAddressA( pTmp, af, NULL, (sockaddr *)&aAddress, &iAddrLen );
|
||||
free( pTmp );
|
||||
if( iRet == 0 )
|
||||
{
|
||||
if( af == AF_INET6 )
|
||||
memcpy(dst, &((sockaddr_in6 *)&aAddress)->sin6_addr, sizeof(in6_addr));
|
||||
else
|
||||
memcpy(dst, &((sockaddr_in *)&aAddress)->sin_addr, sizeof(in_addr));
|
||||
return( 1 );
|
||||
}
|
||||
return( -1 );
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void set_non_blocking(cs_sock_t fd)
|
||||
{
|
||||
u_long iOpts = 1;
|
||||
@@ -1049,7 +1073,7 @@ bool Csock::SSLClientSetup()
|
||||
CS_DEBUG( "ERROR: sockfd larger than OpenSSL can handle" );
|
||||
return( false );
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
#endif /* _WIN64 */
|
||||
|
||||
switch( m_iMethod )
|
||||
{
|
||||
@@ -1143,7 +1167,7 @@ bool Csock::SSLServerSetup()
|
||||
CS_DEBUG( "ERROR: sockfd larger than OpenSSL can handle" );
|
||||
return( false );
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
#endif /* _WIN64 */
|
||||
|
||||
|
||||
switch( m_iMethod )
|
||||
@@ -2079,7 +2103,6 @@ int Csock::GetPending()
|
||||
|
||||
int Csock::GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr )
|
||||
{
|
||||
#ifndef _WIN32
|
||||
#ifdef HAVE_IPV6
|
||||
if( csSockAddr.GetAFRequire() != AF_INET && inet_pton( AF_INET6, sHostname.c_str(), csSockAddr.GetAddr6() ) > 0 )
|
||||
{
|
||||
@@ -2094,7 +2117,6 @@ int Csock::GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr )
|
||||
#endif /* HAVE_IPV6 */
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef HAVE_C_ARES
|
||||
if( GetType() != LISTENER )
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* $Revision: 1.216 $
|
||||
* $Revision: 1.219 $
|
||||
*/
|
||||
|
||||
// note to compile with win32 need to link to winsock2, using gcc its -lws2_32
|
||||
@@ -1894,6 +1894,8 @@ private:
|
||||
if( pChannel )
|
||||
{
|
||||
ares_fds( pChannel, &rfds, &wfds );
|
||||
// let ares drop the timeout if it has something timing out sooner then whats in tv currently
|
||||
ares_timeout( pChannel, &tv, &tv );
|
||||
bHasWriteable = true;
|
||||
}
|
||||
#endif /* HAVE_C_ARES */
|
||||
@@ -2029,15 +2031,7 @@ private:
|
||||
#ifdef HAVE_C_ARES
|
||||
ares_channel pChannel = pcSock->GetAresChannel();
|
||||
if( pChannel )
|
||||
{
|
||||
int iAresFD;
|
||||
ares_getsock( pChannel, &iAresFD, 1 );
|
||||
// only process the channels that are actually set in the read/write set
|
||||
// this should effectively be the same as finding the max timeout amongst ares fd's
|
||||
// as this fd is either ready or its not
|
||||
if( TFD_ISSET( iAresFD, &rfds ) || TFD_ISSET( iAresFD, &wfds ) )
|
||||
ares_process( pChannel, &rfds, &wfds );
|
||||
}
|
||||
ares_process( pChannel, &rfds, &wfds );
|
||||
#endif /* HAVE_C_ARES */
|
||||
|
||||
if ( pcSock->GetConState() != T::CST_OK )
|
||||
|
||||
Reference in New Issue
Block a user