Skip to content
CryoCryo home
Stdlibnet::tls

future

import std::net::tls::future; · source

The TLS counterparts of TcpConnect, TcpRead, and TcpWrite, with the same ownership handshake: the stream (and, for a read or write, the buffer) goes in through start and comes back out through take_stream / take_buf on the TlsIo outcome. TlsHandshake completes with the stream itself once the handshake is done, or the error that ended it.

They differ from their TCP counterparts in one respect. OpenSSL may need to write to make progress on a read (a renegotiation, a close_notify) or vice versa, so each remembers which direction it last armed with the reactor and re-registers for whichever SSL_get_error asks for — SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE — rather than assuming a read always waits on readability.

Dropping any of these mid-operation releases its registration.

Types

TlsHandshake

type struct TlsHandshake {
    tls:       TlsStream;
    is_client: boolean;
    verify:    boolean;
    rt:        Reactor*;
    armed:     u32;

    static start(tls: TlsStream, is_client: boolean, verify: boolean) -> TlsHandshake;
}

Drives SSL_connect or SSL_accept to completion, re-arming for whichever direction OpenSSL asks for, and completes with the stream. Dropping it closes the half-established connection.

Properties

PropertyType
tlsTlsStream
is_clientboolean
verifyboolean
rtReactor*
armedu32

Constructors

static start(tls: TlsStream, is_client: boolean, verify: boolean) -> TlsHandshake;

Begin a handshake on tls, which this future owns until it completes.

TlsRead

type struct TlsRead {
    tls:   TlsStream;
    buf:   Array<u8>;
    rt:    Reactor*;
    armed: u32;

    static start(tls: TlsStream, buf: Array<u8>) -> TlsRead;
}

One SSL_read into buf. A TlsRead that completes with 0 bytes saw close_notify, the TLS equivalent of EOF.

Properties

PropertyType
tlsTlsStream
bufArray<u8>
rtReactor*
armedu32

Constructors

static start(tls: TlsStream, buf: Array<u8>) -> TlsRead;

Begin a read on tls, filling buf — both owned by this future until it completes.

TlsWrite

type struct TlsWrite {
    tls:   TlsStream;
    buf:   Array<u8>;
    rt:    Reactor*;
    armed: u32;

    static start(tls: TlsStream, buf: Array<u8>) -> TlsWrite;
}

One SSL_write from buf, completing with the bytes accepted.

Properties

PropertyType
tlsTlsStream
bufArray<u8>
rtReactor*
armedu32

Constructors

static start(tls: TlsStream, buf: Array<u8>) -> TlsWrite;

Begin a write of every byte in buf on tls — both owned by this future until it completes.

TlsIo

type struct TlsIo {
    tls:    TlsStream;
    buf:    Array<u8>;
    result: Result<u64, IoError>;

    take_stream(mut &this) -> TlsStream;
    take_buf(mut &this) -> Array<u8>;
    outcome(&this) -> Result<u64, IoError>;
}

The outcome of a read or write: the stream and buffer back through take_stream / take_buf, and outcome() for the count or the error.

Properties

PropertyType
tlsTlsStream
bufArray<u8>
resultResult<u64, IoError>

Methods

take_stream(mut &this) -> TlsStream;

Take the stream back. Calling it twice yields a closed placeholder the second time — the outcome holds the stream exactly once.

take_buf(mut &this) -> Array<u8>;

Take the buffer back. After a read it holds exactly the bytes that arrived; after a write it is untouched, so a caller with a short write still has the bytes it has not sent yet.

outcome(&this) -> Result<u64, IoError>;

How many bytes moved, or why none did.

Trait implementations

TlsHandshake

implement trait Future for struct TlsHandshake
implement trait Drop for struct TlsHandshake

TlsRead

implement trait Future for struct TlsRead
implement trait Drop for struct TlsRead

TlsWrite

implement trait Future for struct TlsWrite
implement trait Drop for struct TlsWrite