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

前端 未结 5 1355
时光说笑
时光说笑 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条回答
  •  萌比男神i
    2020-11-27 11:03

    // works also after bind operation for WINDOWS

    DWORD timeout = timeout_in_seconds * 1000;
    setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof timeout);
    

提交回复
热议问题