[−][src]Struct fibers::net::TcpListener
A structure representing a socket server.
Examples
// See also: fibers/examples/tcp_example.rs use fibers::{Executor, InPlaceExecutor, Spawn}; use fibers::net::{TcpListener, TcpStream}; use fibers::sync::oneshot; use futures::{Future, Stream}; let mut executor = InPlaceExecutor::new().unwrap(); let (addr_tx, addr_rx) = oneshot::channel(); // Spawns TCP listener executor.spawn(TcpListener::bind("127.0.0.1:0".parse().unwrap()) .and_then(|listener| { let addr = listener.local_addr().unwrap(); println!("# Start listening: {}", addr); addr_tx.send(addr).unwrap(); listener.incoming() .for_each(move |(_client, addr)| { println!("# Accepted: {}", addr); Ok(()) }) }) .map_err(|e| panic!("{:?}", e))); // Spawns TCP client let mut monitor = executor.spawn_monitor(addr_rx.map_err(|e| panic!("{:?}", e)) .and_then(|server_addr| { TcpStream::connect(server_addr).and_then(move |_stream| { println!("# Connected: {}", server_addr); Ok(()) }) })); // Runs until the TCP client exits while monitor.poll().unwrap().is_not_ready() { executor.run_once().unwrap(); } println!("# Succeeded");
Methods
impl TcpListener
[src]
pub fn bind(addr: SocketAddr) -> TcpListenerBind
[src]
Makes a future to create a new TcpListener
which will be bound to the specified address.
pub fn incoming(self) -> Incoming
[src]
Makes a stream of the connections which will be accepted by this listener.
pub fn local_addr(&self) -> Result<SocketAddr>
[src]
Returns the local socket address of this listener.
pub fn take_error(&self) -> Result<Option<Error>>
[src]
Get the value of the SO_ERROR
option on this socket.
This will retrieve the stored error in the underlying socket, clearing the field in the process. This can be useful for checking errors between calls.
pub fn with_inner<F, T>(&self, f: F) -> T where
F: FnOnce(&MioTcpListener) -> T,
[src]
F: FnOnce(&MioTcpListener) -> T,
Calls f
with the reference to the inner socket.
Trait Implementations
Auto Trait Implementations
impl Send for TcpListener
impl !Sync for TcpListener
impl Unpin for TcpListener
impl UnwindSafe for TcpListener
impl RefUnwindSafe for TcpListener
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,