diff options
| author | Eric Reed <ereed@mozilla.com> | 2013-06-26 09:37:48 -0700 |
|---|---|---|
| committer | Eric Reed <ereed@mozilla.com> | 2013-06-26 09:37:48 -0700 |
| commit | 87ecfb74357b669308a6e337ebc766af8a03b554 (patch) | |
| tree | f0ed18885c906eea7e96d6a1141d0cbae88e1882 /src/libstd | |
| parent | d0dc6970d8b8bb0e6cc358ec169daa70d99e1d15 (diff) | |
| download | rust-87ecfb74357b669308a6e337ebc766af8a03b554.tar.gz rust-87ecfb74357b669308a6e337ebc766af8a03b554.zip | |
converted TCP interface to newtype structs
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/rt/io/net/tcp.rs | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/libstd/rt/io/net/tcp.rs b/src/libstd/rt/io/net/tcp.rs index 3607f781da3..947fade096b 100644 --- a/src/libstd/rt/io/net/tcp.rs +++ b/src/libstd/rt/io/net/tcp.rs @@ -18,15 +18,11 @@ use rt::rtio::{IoFactory, IoFactoryObject, RtioTcpStream, RtioTcpStreamObject}; use rt::local::Local; -pub struct TcpStream { - rtstream: ~RtioTcpStreamObject -} +pub struct TcpStream(~RtioTcpStreamObject); impl TcpStream { fn new(s: ~RtioTcpStreamObject) -> TcpStream { - TcpStream { - rtstream: s - } + TcpStream(s) } pub fn connect(addr: IpAddr) -> Option<TcpStream> { @@ -38,13 +34,11 @@ impl TcpStream { }; match stream { - Ok(s) => { - Some(TcpStream::new(s)) - } + Ok(s) => Some(TcpStream::new(s)), Err(ioerr) => { rtdebug!("failed to connect: %?", ioerr); io_error::cond.raise(ioerr); - return None; + None } } } @@ -52,8 +46,7 @@ impl TcpStream { impl Reader for TcpStream { fn read(&mut self, buf: &mut [u8]) -> Option<uint> { - let bytes_read = self.rtstream.read(buf); - match bytes_read { + match (**self).read(buf) { Ok(read) => Some(read), Err(ioerr) => { // EOF is indicated by returning None @@ -70,8 +63,7 @@ impl Reader for TcpStream { impl Writer for TcpStream { fn write(&mut self, buf: &[u8]) { - let res = self.rtstream.write(buf); - match res { + match (**self).write(buf) { Ok(_) => (), Err(ioerr) => { io_error::cond.raise(ioerr); @@ -82,9 +74,7 @@ impl Writer for TcpStream { fn flush(&mut self) { fail!() } } -pub struct TcpListener { - rtlistener: ~RtioTcpListenerObject, -} +pub struct TcpListener(~RtioTcpListenerObject); impl TcpListener { pub fn bind(addr: IpAddr) -> Option<TcpListener> { @@ -93,11 +83,7 @@ impl TcpListener { (*io).tcp_bind(addr) }; match listener { - Ok(l) => { - Some(TcpListener { - rtlistener: l - }) - } + Ok(l) => Some(TcpListener(l)), Err(ioerr) => { io_error::cond.raise(ioerr); return None; @@ -108,8 +94,7 @@ impl TcpListener { impl Listener<TcpStream> for TcpListener { fn accept(&mut self) -> Option<TcpStream> { - let rtstream = self.rtlistener.accept(); - match rtstream { + match (**self).accept() { Ok(s) => { Some(TcpStream::new(s)) } |
