Hi rust-dev@,

We participated in an informal "try a new language" session and decided to
try out Rust. The goal of session was to implement a simple TCP proxy.

Our approach was to accept an incoming connection, then open an outgoing
connection, and finally to spawn two tasks, each doing a blocking read on
either end and then writing the read data to the other end.

At first, we tried to implement this with rust 0.9 but failed due to lack
of clone() in TcpStream. Fortunately, it looks like clone() is present in
master.

However, we still couldn't implement this correctly in master. The problem
is that when one task noticed that the outgoing socket closed, it would
finish. However, there was no way for it to notify the other task to do the
same, as that other task was potentially blocking on the incoming socket.

In other languages, we'd close the incoming socket and the other task would
get an end-of-stream. But, we couldn't close the socket directly in Rust,
since a socket is only closed when the TcpStream object is destroyed.

If there's a better way to do this in Rust, let us know.

However, this mail is mainly an FYI that either close() support in
TcpStream or some other way to implement the functionality described above
seems important.

I've also attached our program in case anyone is curious!

Cheers,
Peter

Attachment: proxy.rs
Description: Binary data

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to