有关select函数的问题
我在收包程序中,使用select函数来判断是否接受超时,结果,当网络不通时(ping不通,我发送的也是icmp请求报文),select函数也是返回的正值。
代码如下:
…………………………
send:
/* start the ping's going ... */
apmlog_send_icmp_pkt(pthd_para);
/* listen for replies */
while (1) {
FD_ZERO(&readfds);
FD_SET(pthd_para->pingsock, &readfds);
maxfdp = pthd_para->pingsock + 1;
timeout.tv_sec = PINGINTERVAL; /* 2s的阻塞时延 */
timeout.tv_usec = 0;
slc_ret = select(maxfdp, &readfds, NULL, NULL, &timeout);
printf("select func ret is %d\n", slc_ret);
if (slc_ret <= 0) {
switch (ret) {
case 0:
printf("ping [%s] timeout, [%d] packets transmitted!\n", pthd_para->ping_addr,
pthd_para->ntransmitted);
break;
default:
printf("select: error unknow!\n");
break;
}
//FD_CLR(pthd_para->pingsock, &readfds);
if (pthd_para->ntimes > pthd_para->ntransmitted) {
goto send;
} else {
break;
}
}
……………………………………
我给一个ping不通的ip发包,其测试结果:
select func ret is 1
这是怎么回事呢?ping不通,没有reply包返回,ret应该是为0啊!