diff --git a/src/io.rs b/src/io.rs index 6928c435f..cda22a47f 100644 --- a/src/io.rs +++ b/src/io.rs @@ -69,6 +69,12 @@ impl TryWrite for T { } } +pub trait TryAccept { + type Output; + + fn accept(&self) -> Result>; +} + /* * * ===== Helpers ===== diff --git a/src/lib.rs b/src/lib.rs index 72c490828..d369c1f52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,6 +122,7 @@ pub use io::{ TryRead, TryWrite, Evented, + TryAccept, }; pub use net::{ tcp, diff --git a/src/net/tcp.rs b/src/net/tcp.rs index f08bc8464..335083d87 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -1,4 +1,4 @@ -use {io, sys, Evented, EventSet, PollOpt, Selector, Token}; +use {io, sys, Evented, EventSet, PollOpt, Selector, Token, TryAccept}; use std::io::{Read, Write}; use std::net::SocketAddr; @@ -261,6 +261,14 @@ impl Evented for TcpListener { } } +impl TryAccept for TcpListener { + type Output = TcpStream; + + fn accept(&self) -> io::Result> { + TcpListener::accept(self) + } +} + /* * * ===== UNIX ext ===== diff --git a/src/net/unix.rs b/src/net/unix.rs index ef17f0b46..48c6bd335 100644 --- a/src/net/unix.rs +++ b/src/net/unix.rs @@ -1,4 +1,4 @@ -use {io, sys, Evented, EventSet, Io, PollOpt, Selector, Token}; +use {io, sys, Evented, EventSet, Io, PollOpt, Selector, Token, TryAccept}; use std::io::{Read, Write}; use std::path::Path; @@ -161,6 +161,14 @@ impl Evented for UnixListener { } } +impl TryAccept for UnixListener { + type Output = UnixStream; + + fn accept(&self) -> io::Result> { + UnixListener::accept(self) + } +} + impl From for UnixListener { fn from(sys: sys::UnixSocket) -> UnixListener { UnixListener { sys: sys } diff --git a/src/sys/unix/tcp.rs b/src/sys/unix/tcp.rs index 4947ab332..a015c9128 100644 --- a/src/sys/unix/tcp.rs +++ b/src/sys/unix/tcp.rs @@ -1,4 +1,4 @@ -use {io, Evented, EventSet, Io, PollOpt, Selector, Token}; +use {io, Evented, EventSet, Io, PollOpt, Selector, Token, TryAccept}; use sys::unix::{net, nix, Socket}; use std::io::{Read, Write}; use std::net::SocketAddr; @@ -123,6 +123,14 @@ impl Evented for TcpSocket { } } +impl TryAccept for TcpSocket { + type Output = TcpSocket; + + fn accept(&self) -> io::Result> { + TcpSocket::accept(self) + } +} + impl Socket for TcpSocket { } diff --git a/src/sys/unix/uds.rs b/src/sys/unix/uds.rs index 4a5456da3..3bf11446a 100644 --- a/src/sys/unix/uds.rs +++ b/src/sys/unix/uds.rs @@ -1,4 +1,4 @@ -use {io, Evented, EventSet, Io, PollOpt, Selector, Token}; +use {io, Evented, EventSet, Io, PollOpt, Selector, Token, TryAccept}; use sys::unix::{net, nix, Socket}; use std::io::{Read, Write}; use std::path::Path; @@ -77,6 +77,14 @@ impl Evented for UnixSocket { } } +impl TryAccept for UnixSocket { + type Output = UnixSocket; + + fn accept(&self) -> io::Result> { + UnixSocket::accept(self) + } +} + impl Socket for UnixSocket { }