diff options
| author | bors <bors@rust-lang.org> | 2014-03-13 21:06:34 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-13 21:06:34 -0700 |
| commit | 4443fb3cfa945cf7cb791cf8f2ec81b7faf25132 (patch) | |
| tree | c8f6ce3665e52cee6b0bff3a55aa0116a61af1c6 /src/libstd | |
| parent | 98fa0f89b1cd406594bedc5803a1b6db53990a15 (diff) | |
| parent | a63deeb3d32fc21f36d484d62a3ea1d3d0c82500 (diff) | |
| download | rust-4443fb3cfa945cf7cb791cf8f2ec81b7faf25132.tar.gz rust-4443fb3cfa945cf7cb791cf8f2ec81b7faf25132.zip | |
auto merge of #12855 : alexcrichton/rust/shutdown, r=brson
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.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/net/tcp.rs | 18 | ||||
| -rw-r--r-- | src/libstd/libc.rs | 18 | ||||
| -rw-r--r-- | src/libstd/rt/rtio.rs | 1 |
3 files changed, 37 insertions, 0 deletions
diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index edadbc7873a..7b1dd114d34 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -710,5 +710,23 @@ mod test { rx.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])); + }) } diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs index c602c2fc27f..cfa4a2deb2f 100644 --- a/src/libstd/libc.rs +++ b/src/libstd/libc.rs @@ -1611,6 +1611,10 @@ pub mod consts { pub static SO_KEEPALIVE: c_int = 8; pub static SO_BROADCAST: c_int = 32; pub static SO_REUSEADDR: c_int = 4; + + pub static SHUT_RD: c_int = 0; + pub static SHUT_WR: c_int = 1; + pub static SHUT_RDWR: c_int = 2; } pub mod extra { use libc::types::os::arch::c95::c_int; @@ -2391,6 +2395,10 @@ pub mod consts { pub static SO_KEEPALIVE: c_int = 9; pub static SO_BROADCAST: c_int = 6; pub static SO_REUSEADDR: c_int = 2; + + pub static SHUT_RD: c_int = 0; + pub static SHUT_WR: c_int = 1; + pub static SHUT_RDWR: c_int = 2; } #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")] @@ -2842,6 +2850,10 @@ pub mod consts { pub static SO_KEEPALIVE: c_int = 0x0008; pub static SO_BROADCAST: c_int = 0x0020; pub static SO_REUSEADDR: c_int = 0x0004; + + pub static SHUT_RD: c_int = 0; + pub static SHUT_WR: c_int = 1; + pub static SHUT_RDWR: c_int = 2; } pub mod extra { use libc::types::os::arch::c95::c_int; @@ -3221,6 +3233,10 @@ pub mod consts { pub static SO_KEEPALIVE: c_int = 0x0008; pub static SO_BROADCAST: c_int = 0x0020; pub static SO_REUSEADDR: c_int = 0x0004; + + pub static SHUT_RD: c_int = 0; + pub static SHUT_WR: c_int = 1; + pub static SHUT_RDWR: c_int = 2; } pub mod extra { use libc::types::os::arch::c95::c_int; @@ -3918,6 +3934,7 @@ pub mod funcs { pub fn sendto(socket: c_int, buf: *c_void, len: size_t, flags: c_int, addr: *sockaddr, addrlen: socklen_t) -> ssize_t; + pub fn shutdown(socket: c_int, how: c_int) -> c_int; } } @@ -3954,6 +3971,7 @@ pub mod funcs { pub fn sendto(socket: SOCKET, buf: *c_void, len: c_int, flags: c_int, addr: *sockaddr, addrlen: c_int) -> c_int; + pub fn shutdown(socket: SOCKET, how: c_int) -> c_int; } } diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index cd557f01834..60933aeb38b 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -206,6 +206,7 @@ pub trait RtioTcpStream : RtioSocket { fn keepalive(&mut self, delay_in_seconds: uint) -> Result<(), IoError>; fn letdie(&mut self) -> Result<(), IoError>; fn clone(&self) -> ~RtioTcpStream; + fn close_write(&mut self) -> Result<(), IoError>; } pub trait RtioSocket { |
