全部博文(372)
2012年(372)
分类: 嵌入式
2012-03-18 19:41:48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 |
int connect_timeo(int sockfd, const SA *saptr, socklen_t salen, int nsec){
Sigfunc *sigfunc;
int n;
sigfunc = Signal(SIGALRM, connect_alarm);
if(alarm(nsec) != 0)
err_msg("Alarm has already been set!");
if( ( n = connect(sockfd, saptr, salen)) < 0){ //如果超过nsec秒数,会被中断产生EINTR
close(sockfd); //关闭此套接字,防止三次握手继续进行
if(errno == EINTR) //慢系统调用产生中断信号
errno = ETIMEDOUT;
}
alarm(0);
Signal(SIGALRM, sigfunc);
return n;
}
static void connect_alarm(int signo){
return;
} |