0
votes

Is there a way to use a client socket in a non blocking way.

For example, if I create a socket for a client to connect on a server and that I do recursive recv on that socket, the last call of Unix.recv will block when no data is send and if the connection is not closed by the server.

In C, you can specify flags for both :

  • socket() and use the SOCK_NONBLOCK flag ORed with the socket type
  • or receiv() with the MSG_DONTWAIT flags.

I have looked here :

But I could not find any informations on this.

1
'Recursive recv()' doesn't mean anything. - user207421
Yes, you are right, sorry, I wanted to say when you call recv in a recursive function until all the data are read. Maybe I should have say multiple call to recv until all the data are read. - cedlemo
Have you looked at Lwt (ocsigen.org/lwt/2.5.2/manual)? It provides lots of tools for non-blocking operations. For example, Lwt_unix.recv (ocsigen.org/lwt/2.5.2/api/Lwt_unix#VALrecv) is a non-blocking equivalent to Unix.recv. - hcarty
@hcarty, no I have not looked at Lwt for this particular matter, but yes I will. - cedlemo

1 Answers