summary refs log tree commit diff
path: root/src/libstd/rt/rtio.rs
diff options
context:
space:
mode:
authorEric Reed <ecreed@cs.washington.edu>2013-08-27 10:01:17 -0700
committerEric Reed <ecreed@cs.washington.edu>2013-06-23 00:03:11 -0700
commit58b2ff9f564833f5f4fa077a5708c139738dad8e (patch)
tree04561298feb219db737a5b382059092fa03552f9 /src/libstd/rt/rtio.rs
parentefb8924f8848f39811a8e69db182effb465ad3cf (diff)
downloadrust-58b2ff9f564833f5f4fa077a5708c139738dad8e.tar.gz
rust-58b2ff9f564833f5f4fa077a5708c139738dad8e.zip
Split out starting a listener from accepting incoming connections.
The Listener trait takes two type parameters, the type of connection and the type of Acceptor,
and specifies only one method, listen, which consumes the listener and produces an Acceptor.

The Acceptor trait takes one type parameter, the type of connection, and defines two methods.
The accept() method waits for an incoming connection attempt and returns the result.
The incoming() method creates an iterator over incoming connections and is a default method.

Example:

let listener = TcpListener.bind(addr); // Bind to a socket
let acceptor = listener.listen(); // Start the listener
for stream in acceptor.incoming() {
    // Process incoming connections forever (or until you break out of the loop)
}
Diffstat (limited to 'src/libstd/rt/rtio.rs')
-rw-r--r--src/libstd/rt/rtio.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs
index 1788b7a04e3..6f1b33d1e21 100644
--- a/src/libstd/rt/rtio.rs
+++ b/src/libstd/rt/rtio.rs
@@ -26,6 +26,7 @@ pub type EventLoopObject = uvio::UvEventLoop;
 pub type RemoteCallbackObject = uvio::UvRemoteCallback;
 pub type IoFactoryObject = uvio::UvIoFactory;
 pub type RtioTcpStreamObject = uvio::UvTcpStream;
+pub type RtioTcpAcceptorObject = uvio::UvTcpAcceptor;
 pub type RtioTcpListenerObject = uvio::UvTcpListener;
 pub type RtioUdpSocketObject = uvio::UvUdpSocket;
 pub type RtioTimerObject = uvio::UvTimer;
@@ -75,6 +76,10 @@ pub trait IoFactory {
 }
 
 pub trait RtioTcpListener : RtioSocket {
+    fn listen(self) -> Result<~RtioTcpAcceptorObject, IoError>;
+}
+
+pub trait RtioTcpAcceptor : RtioSocket {
     fn accept(&mut self) -> Result<~RtioTcpStreamObject, IoError>;
     fn accept_simultaneously(&mut self) -> Result<(), IoError>;
     fn dont_accept_simultaneously(&mut self) -> Result<(), IoError>;