Skip to content
CryoCryo home
Stdlibnet::tls

stream

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

Types

TlsStream

type struct TlsStream {
    ssl:   void*;
    inner: TcpStream;

    static from_parts(ssl: void*, inner: TcpStream) -> TlsStream;
    ssl_ptr(&this) -> void*;
    raw_fd(&this) -> i32;
    negotiated_alpn(&this) -> AlpnProtocol;
}

A TlsStream owns both the SSL* and the underlying TcpStream, hence the descriptor. You obtain one from a TlsConnector or TlsAcceptor; from_parts is the constructor those use. ssl_ptr and raw_fd expose the handles for code that needs to talk to OpenSSL or the socket directly — setting a socket option, say — not for reading or writing, which would desynchronise the record layer.

Drop order is load-bearing: SSL_shutdown sends close_notify, SSL_free releases the SSL and its context reference (the socket BIO is BIO_NOCLOSE, so the descriptor survives), and finally TcpStream::drop closes it. All of that is the inherent drop on this type.

Properties

PropertyType
sslvoid*
innerTcpStream

Constructors

static from_parts(ssl: void*, inner: TcpStream) -> TlsStream;

Assemble from a completed handshake. Internal: the connector/acceptor owns the SSL_connect/SSL_accept dance and hands over the live SSL* plus the socket it's bound to.

Methods

ssl_ptr(&this) -> void*;

The live SSL*. For the async futures in net::tls::future, which re-issue SSL_connect/SSL_read/SSL_write against it directly rather than through the blocking Read/Write impls. The stream still owns it and frees it on drop.

raw_fd(&this) -> i32;

The underlying socket descriptor, so a parked async operation can register its readiness interest with a Reactor. Ownership is unchanged: this stream still closes it.

negotiated_alpn(&this) -> AlpnProtocol;

The ALPN protocol the peer agreed on, or None if ALPN wasn't offered / negotiated. Valid only after the handshake.

AlpnProtocol

type enum AlpnProtocol {
    None;
    Http11;
    H2;
}

negotiated_alpn() reports what the ALPN extension settled on: H2, Http11, or None when the connector did not offer anything or the server did not answer.

Variants
Variant
None
Http11
H2

Trait implementations

implement trait Drop for struct TlsStream
implement trait AsyncTransport for struct TlsStream
std::net::tls::future

AsyncTransport is the seam the HTTP and WebSocket layers are written against: a BufStream<TlsStream> and a BufStream<TcpStream> are the same code above this point. The impl's read_into and write_from are the TlsRead and TlsWrite futures.