[][src]Module romio::tcp

Async TCP bindings.

This module contains the TCP networking types, similar to those found in std::net, but suitable for async programming via futures and async/await.

Example

#![feature(async_await, await_macro, futures_api)]
use romio::tcp::{TcpListener, TcpStream};
use futures::prelude::*;

async fn say_hello(mut stream: TcpStream) {
    await!(stream.write_all(b"Shall I hear more, or shall I speak at this?!"));
}

async fn listen() -> Result<(), Box<dyn std::error::Error + 'static>> {
    let socket_addr = "127.0.0.1:80".parse()?;
    let listener = TcpListener::bind(&socket_addr)?;
    let mut incoming = listener.incoming();

    // accept connections and process them serially
    while let Some(stream) = await!(incoming.next()) {
        await!(say_hello(stream?));
    }
    Ok(())
}

Structs

ConnectFuture

The future returned by TcpStream::connect, which will resolve to a TcpStream when the stream is connected.

Incoming

Stream returned by the TcpListener::incoming function representing the stream of sockets received from a listener.

TcpListener

A TCP socket server, listening for connections.

TcpStream

A TCP stream between a local and a remote socket.