Linux: is there a read or recv from socket with timeout?

前端 未结 5 1350
时光说笑
时光说笑 2020-11-27 10:42

How can I try to read data from socket with timeout? I know, select, pselect, poll, has a timeout field, but using of them disables \"tcp fast-path\" in tcp reno stack.

5条回答
  •  迷失自我
    2020-11-27 11:05

    Install a handler for SIGALRM, then use alarm() or ualarm() before a regular blocking recv(). If the alarm goes off, the recv() will return an error with errno set to EINTR.

提交回复
热议问题