Here's how I time-out WSAAsyncGetHostByName().
Can you telnet to the server Mr Gates ?
If you like home-made ??? cooking ???,
here's how I time-out WSAAsyncGetHostByName():
[ Note: code is from X.CPP, taken out of context.
X.CPP is in ??? www.Cotse.NET/users/jeffrelf/Games.ZIP ??? ]
#include <Winsock2.H>
#define Tics ( QueryPerformanceCounter( ( DubInt * ) & _Tics ), _Tics )
#define Secs ( _Secs = Tics / Secnd_Dub )
typedef wchar_t * LnP ;
__int64 _Tics, Secnd ; double _Secs, Secnd_Dub, Due, Started ;
.........
QueryPerformanceFrequency( ( DubInt * ) & Secnd );
Secnd_Dub = Secnd ;
.........
#define Patience( Seconds ) ( Due = Secs + Seconds, Started = _Secs )
int Getting( int TheGirl ) { blah blah blah ..... handle events.
enum { No_Protocol, Modem, SNTP, POP3, IMAP, SMTP_AUTH, NNTP };
LnP Protocol_Nam []
= { L"No_Protocol", L"Modem", L"SNTP", L"POP3"
, L"IMAP", L"SMTP_AUTH", L"NNTP " };
struct ServT { LnP Nick ; int Protocol ;
LnP Name, User, Pass ; int Port ; ulong IP ; };
typedef ServT * SrP ;
SrP Serv ; LnP SrvNam ;
struct sockaddr_in Host_IP ;
int Service () { int rv ;
if ( ! WinSock ) { WSADATA X;
WinSock = WSAStartup( 0x0202, & X ) >= 0 ;
if ( ! WinSock ) { Sh ( L"No Winsock 2.2" ); return 0 ; } };
Port = Serv->Port ; Protocol = Serv->Protocol ; SrvNam = Serv->Name ;
if ( ! Serv->IP ) { // if ( Protocol == IMAP )
char _SrvNam [ 200 ]; wcstombs( _SrvNam, SrvNam, 200 );
HANDLE DNS ; char Buff_DNS [ MAXGETHOSTSTRUCT ]; Patience( 10 );
DNS = WSAAsyncGetHostByName (
Win, WM_USER + 1, _SrvNam, Buff_DNS, sizeof Buff_DNS );
while ( Secs < Due && ! Getting ( WM_USER + 1 ) );
if ( WM != WM_USER + 1 || P_C2 [ 1 ] ) {
int rv = P_C2 [ 1 ] - WSABASEERR ;
Sh (
L"Didn't get an IP address for: ??? %S ???. WsaBaseErr + %d"
, _SrvNam, rv );
return 0 ; }
Serv->IP = * ( ulong * )
* ( ( hostent * ) Buff_DNS ) -> h_addr_list ; }
Host_IP.sin_addr.S_un.S_addr = Serv->IP ;
Host_IP.sin_family = AF_INET ;
Host_IP.sin_port = htons( Port );
if ( Connected >= 0 ) closesocket( Connected );
Connected = socket(
AF_INET, Protocol == SNTP ? SOCK_DGRAM : SOCK_STREAM, 0 );
WSAAsyncSelect( Connected, Win, WM_USER + 2
, FD_CONNECT | FD_READ | FD_WRITE );
if ( Protocol == IMAP || Protocol == POP3
|| Protocol == SMTP_AUTH || Protocol == NNTP ) {
rv = connect (
Connected, ( struct sockaddr * ) & Host_IP
, sizeof Host_IP );
if ( rv && WSAGetLastError() != WSAEWOULDBLOCK )
closesocket( Connected ), Connected = -1 ;
else if ( Protocol != SNTP ) { Patience( 9 );
while (
Secs < Due
&& ! ( Getting ( WM_USER + 2 ) && * P_C2 == FD_CONNECT ) );
if ( WM != WM_USER + 2 || P_C2 [ 1 ] ) { rv = WSAGetLastError();
closesocket( Connected ), Connected = -1 ;
Sh ( L"FD_CONNECT to %s:%d, WinSock_Error_Code: %d."
, SrvNam, Port, rv ); return 0 ; } } }
if ( Connected < 0 ) { rv = WSAGetLastError();
Sh ( L"... No Socket, WinSock_Error_Code: %d.", rv ); return 0 ; }
if ( Protocol == SNTP ) return 1 ;
if ( Ask ( aLine, 0, 0 ) ) { Close; return 0 ; }
// if ( Protocol == IMAP ) *Ln.PP
if ( Protocol == POP3
&& ( Ask( aLine, 0, L"User %s", Serv->User )
|| Ask( aLine, 0, L"Pass %s", Serv->Pass ) ) ) {
Close; return 0 ; }
rv = Protocol == NNTP && Serv->Pass
&& ( Ask ( aLine, 0, L"AuthInfo User %s", Serv->User )
|| Ask ( aLine, 0, L"AuthInfo Pass %s", Serv->Pass ) );
return ! rv ; }