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.