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
| Property | Type |
|---|---|
ssl | void* |
inner | TcpStream |
Constructors
static from_parts(ssl: void*, inner: TcpStream) -> TlsStream;
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*;
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;
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;
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.
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct TlsStream {
ssl: void*;
inner: TcpStream;
}TlsStream.ssl: void*TlsStream.inner: TcpStreamtype struct TcpStream {
fd: i32;
}static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static TlsStream::from_parts(ssl: void*, inner: TcpStream) -> TlsStreamAssemble 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.
(parameter) ssl: void*(parameter) inner: TcpStreamtype struct TlsStream {
ssl: void*;
inner: TcpStream;
}TlsStream::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.
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
TlsStream::raw_fd(&this) -> i32The underlying socket descriptor, so a parked async operation can register its readiness interest with a Reactor. Ownership is unchanged: this stream still closes it.
TlsStream::negotiated_alpn(&this) -> AlpnProtocolThe ALPN protocol the peer agreed on, or None if ALPN wasn't offered / negotiated. Valid only after the handshake.
type enum AlpnProtocol {
None;
Http11;
H2;
}Application-layer protocol negotiated during the handshake (ALPN).
std::net::tls::streamtype enum Name {
Unit,
Payload(T),
Named { x: i32 },
}An algebraic data type. Variants may be bare or carry a tuple or struct payload, and a match on an enum must cover every variant. Name::Variant names a variant; methods are added with implement enum Name { ... }.
type enum AlpnProtocol {
None;
Http11;
H2;
}Application-layer protocol negotiated during the handshake (ALPN).
AlpnProtocol::NoneAlpnProtocol::Http11AlpnProtocol::H2import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
static TlsStream::from_parts(ssl: void*, inner: TcpStream) -> TlsStreamAssemble 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.
TlsStream::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.
TlsStream::raw_fd(&this) -> i32The underlying socket descriptor, so a parked async operation can register its readiness interest with a Reactor. Ownership is unchanged: this stream still closes it.
TcpStream::drop(mut &this) -> voidvia trait Drop
Close both halves. Ownership obligation: every TcpStream must have drop called before going out of scope.
TlsStream::drop(mut &this) -> voidvia trait Drop
Tear down the connection: close_notify goes out and the SSL is freed here, and the socket is closed by its field after this returns.
TlsStream.ssl: void*TlsStream.inner: TcpStreamnamespace std::net::tls::future;Async TLS: the futures that drive OpenSSL on a NON-BLOCKING socket.
module pagetype trait Read {
read(mut &this, buffer: u8*, length: u64) -> Result<u64, IoError>;
read_all(mut &this, buffer: u8*, length: u64) -> Result<u64, IoError>;
read_byte(mut &this) -> Result<Option<u8>, IoError>;
read_char(mut &this) -> Result<Option<u32>, IoError>;
read_until(mut &this, delimiter: u8, out: mut &Array<u8>) -> Result<u64, IoError>;
read_exact(mut &this, buffer: u8*, length: u64) -> Result<(), IoError>;
read_to_end(mut &this, out: mut &Array<u8>) -> Result<u64, IoError>;
read_to_string(mut &this, out: mut &String) -> Result<u64, IoError>;
read_line(mut &this, out: mut &String) -> Result<u64, IoError>;
}type trait Write {
write_some(mut &this, bytes: Slice<u8>) -> Result<u64, IoError>;
flush(mut &this) -> Result<(), IoError>;
write<T>(mut &this, data: T) -> Result<(), IoError>;
}type struct Reactor {
mtx: [u8;
40];
buckets: [Registration*;
64];
poll_h: i64;
kick_h: i64;
aux_h: i64;
shutdown: Atomic<u8>;
thread: u64;
timers: Timer*;
// … 1 more
}The I/O readiness driver for one Executor. Heap-allocated: worker threads and parked futures hold raw pointers to it, and the backend hands the OS interior addresses, so it must not move.
TlsStream::negotiated_alpn(&this) -> AlpnProtocolThe ALPN protocol the peer agreed on, or None if ALPN wasn't offered / negotiated. Valid only after the handshake.
AlpnProtocol::NoneAlpnProtocol::H2AlpnProtocol::Http11implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referenceimplement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencetype trait AsyncTransport {
async read_into(mut &this, buf: Array<u8>) -> Transfer;
async write_from(mut &this, buf: Array<u8>) -> Transfer;
}One raw, unbuffered async byte channel: what BufStream<S> needs of a transport, and nothing more.
type struct BufStream<S> {
inner: S;
rbuf: Array<u8>;
rpos: u64;
scratch: Array<u8>;
wbuf: Array<u8>;
}async TlsStream::read_into(mut &this, buf: Array<u8>) -> Transfervia trait AsyncTransport
std::net::tls::futureasync TlsStream::write_from(mut &this, buf: Array<u8>) -> Transfervia trait AsyncTransport
std::net::tls::future