UDP sockets use of select()

笑着哭i 提交于 2019-12-01 14:55:37

On some systems (Linux in particular), a select call modifies the timeout to show how much time is left. So in your case, if it waits 3 seconds for a packet, timeout will be reduced to 1.15 seconds, and after a total of 4.15 seconds, timeout will be 0, so later calls to select will immediately return with nready == 0.

If you want to wait again after sending an ack, you need to reset the timeout to non-zero.

One has to reset the fd_set rset before every call to select. The select call expects a bit set of field descriptors to monitor and overwrites with a bit set of field descriptors with notifications to read.

for( i=0; ;i++){
    do {
        rset = allset;
        nready=select( (maxfd +1), &rset, NULL, NULL,  &timeout); 
    } while ((nready<0) & (errno==EINTR)); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!