[][src]Struct tls_async::TlsAcceptor

pub struct TlsAcceptor { /* fields omitted */ }

A builder for server-side TLS connections.

Examples

#![feature(async_await, await_macro, futures_api)]
use futures::StreamExt;
use futures::io::AsyncRead;
use tls_async::{Identity, TlsAcceptor, TlsStream};
use std::fs::File;
use std::io::{Read};
use romio::{TcpListener, TcpStream};
use std::sync::Arc;
use std::thread;

let mut file = File::open("identity.pfx").unwrap();
let mut identity = vec![];
file.read_to_end(&mut identity).unwrap();
let identity = Identity::from_pkcs12(&identity, "hunter2").unwrap();

let mut listener = TcpListener::bind(&"0.0.0.0:8443".parse().unwrap()).unwrap();
let acceptor = TlsAcceptor::new(identity).unwrap();
let acceptor = Arc::new(acceptor);

fn handle_client<S: AsyncRead>(stream: S) {
    // ...
}

let mut incoming = listener.incoming();
for stream in await!(incoming.next()) {
    match stream {
        Ok(stream) => {
            let acceptor = acceptor.clone();
            let stream = await!(acceptor.accept(stream)).unwrap();
            handle_client(stream);
        }
        Err(e) => { /* connection failed */ }
    }
}

Methods

impl TlsAcceptor[src]

pub fn new(identity: Identity) -> Result<TlsAcceptor, Error>[src]

Creates a acceptor with default settings.

The identity acts as the server's private key/certificate chain.

pub fn builder(identity: Identity) -> TlsAcceptorBuilder[src]

Returns a new builder for a TlsAcceptor.

The identity acts as the server's private key/certificate chain.

pub fn accept<S>(&self, stream: S) -> PendingTlsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

Accepts a new client connection with the provided stream.

This function will internally call TlsAcceptor::accept to connect the stream and returns a future representing the resolution of the connection operation. The returned future will resolve to either TlsStream<S> or Error depending if it's successful or not.

This is typically used after a new socket has been accepted from a TcpListener. That socket is then passed to this function to perform the server half of accepting a client connection.

Trait Implementations

impl Clone for TlsAcceptor[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl From<TlsAcceptor> for TlsAcceptor[src]

Auto Trait Implementations

impl Send for TlsAcceptor

impl Sync for TlsAcceptor

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]