From a63deeb3d32fc21f36d484d62a3ea1d3d0c82500 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 12 Mar 2014 17:04:34 -0700 Subject: io: Bind to shutdown() for TCP streams This is something that is plausibly useful, and is provided by libuv. This is not currently surfaced as part of the `TcpStream` type, but it may possibly appear in the future. For now only the raw functionality is provided through the Rtio objects. --- src/libstd/io/net/tcp.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/libstd/io') diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 53129f3df9b..95be3add0db 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -751,5 +751,23 @@ mod test { p.recv(); }) + + iotest!(fn shutdown_smoke() { + use rt::rtio::RtioTcpStream; + + let addr = next_test_ip4(); + let a = TcpListener::bind(addr).unwrap().listen(); + spawn(proc() { + let mut a = a; + let mut c = a.accept().unwrap(); + assert_eq!(c.read_to_end(), Ok(~[])); + c.write([1]).unwrap(); + }); + + let mut s = TcpStream::connect(addr).unwrap(); + assert!(s.obj.close_write().is_ok()); + assert!(s.write([1]).is_err()); + assert_eq!(s.read_to_end(), Ok(~[1])); + }) } -- cgit 1.4.1-3-g733a5