Set a timeout on socket_read

前端 未结 4 1926
忘掉有多难
忘掉有多难 2021-01-01 17:08

I was wondering how can I set a timeout on a socket_read call? The first time it calls socket_read, it waits till data is sent, and if no data is s

4条回答
  •  臣服心动
    2021-01-01 17:49

    I did a socket_listen and then I made a manual timeout with time()+2 and a while loop with nonblock set and socket_read() inside. Seems to be working ok. Any alternatives?

    UPDATE: I found that setting the socket as nonblocking and then using socket_listen provided the timeout I needed.

提交回复
热议问题