File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,30 @@ pub struct TcpStream {
49
49
impl TcpStream {
50
50
/// Create a new TCP stream and issue a non-blocking connect to the
51
51
/// specified address.
52
+ ///
53
+ /// # Notes
54
+ ///
55
+ /// The returned `TcpStream` may not be connected (and thus usable), unlike
56
+ /// the API found in `std::net::TcpStream`. Because Mio issues a
57
+ /// *non-blocking* connect it will not block the thread and instead return
58
+ /// an unconnected `TcpStream`.
59
+ ///
60
+ /// Ensuring the returned stream is connected is surprisingly complex when
61
+ /// considering cross-platform support. Doing this properly should follow
62
+ /// the steps below, an example implementation can be found
63
+ /// [here](https://github.com/Thomasdezeeuw/heph/blob/0c4f1ab3eaf08bea1d65776528bfd6114c9f8374/src/net/tcp/stream.rs#L560-L622).
64
+ ///
65
+ /// 1. Call `TcpStream::connect`
66
+ /// 2. Register the returned stream with at least [read interest].
67
+ /// 3. Wait for a (readable) event.
68
+ /// 4. Check `TcpStream::peer_addr`. If it returns `libc::EINPROGRESS` or
69
+ /// `ErrorKind::NotConnected` it means the stream is not yet connected,
70
+ /// go back to step 3. If it returns an address it means the stream is
71
+ /// connected, go to step 5. If another error is returned something
72
+ /// whent wrong.
73
+ /// 5. Now the stream can be used.
74
+ ///
75
+ /// [read interest]: Interest::READABLE
52
76
pub fn connect ( addr : SocketAddr ) -> io:: Result < TcpStream > {
53
77
let socket = new_for_addr ( addr) ?;
54
78
#[ cfg( unix) ]
You can’t perform that action at this time.
0 commit comments