UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2002-07-27 12:06 AM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: 6.2 - How can I put a timeout on connect()?

static int sTimeout = 0; 

static void AlarmHandler(int sig) 
{ 
  sTimeout = 1; 
} 

. 
. 
. 
   signal(SIGALRM, AlarmHandler); 
   sTimeout = 0; 
   alarm(CONNECT_TIMEOUT); 

   if ( connect(sock, (struct sockaddr *) &server, sizeof(server)) ) 
   { 
      if ( sTimeout ) 
         perror("timeout connecting stream socket"); 
      else 
         perror("connecting stream socket"); 
      exit(1); 
   } 

   sTimeout = 0; 
   alarm(CONNECT_TIMEOUT); 
. 
. 
.

Offline

Board footer

Powered by FluxBB