[rust-dev] TCP Socket Non-blocking IO

Jack Moffitt jack at metajack.im
Thu Mar 21 19:32:25 PDT 2013

> In principle the right pattern for this might be two tasks with the same
> socket? I don't know if rust's socket abstraction would like that or not.

I thought some more about this and I think some kind of non-blocking
read will be necessary. The Erlang way I mentioned must do this in the
library, as it sends each incoming packet as a message to the process
that owns the socket. A similar abstraction could be done in rust, but
would only really make sense if you can do periodic reads on the
socket to see if there is new data, or have the socket notify you.

One idea is to hand the socket functions a channel to send
notifications on, and then you can just peek() on the port to see if
data is ready. Another lower level idea would just be to allow a
read(0) which returns any data that is available.

Actually, reading the docs a bit closer, it looks like read_start()
may do what you want. It returns a port which you can peek(). That may
work. Alternatively, you might try calling read() with a timeout of 1,
which isn't ideal, but will probably tide you over.


More information about the Rust-dev mailing list