Help using Select in TCP Client I'm using select if I get an "errno==EINTR" on my return calling "connect".
It appears not working. I'm still getting a signal interrupt from my alarm
timeout, thusly call my function "catch_int" at bottom example.
Is this correct what I am doing when trying to connect and get
"errno==EINTR"?
Thank you,
JT
/* start alarm */
alarm_flag = 0;
alarm(conn_timeout);
/* try to connect */
conn_retval=connect(sock_id, (void *)&pin, sizeof(pin));
/* turn off alarm if it did not go off */
alarm(0);
if( alarm_flag == 1 )
{
if (errno == EINTR) /*pause until connection established*/
{
fd_set writefd;
do
{
FD_ZERO(&writefd);
FD_SET(sock_id,&writefd);
errno=0;
ret=select(sock_id+1,NULL,&writefd,NULL,NULL); /*wait forever*/
}while((ret<0 && errno==EINTR) || ret<1);
}
void catch_int(int sig_num){
if(errno!=EINTR)
{
errlog(0,"WARNING: caught exception handler - Ctrl-C");
keep_going = 0;
kill(getpid(),SIGKILL);
}
}
static void alarm_function(int signo) {
alarm_flag = 1;
} |