Stream::attach
pub fn attach(int ptr, int read, int write, int shutdown, int free) -> Result<Stream, IoError> Import
Source: use io::{Stream}; compiler/src/builtin_docs/io.hy Installs package IO hooks on this stream in place and returns the same stream.
ptr is the package’s session pointer and read, write,
shutdown and free are C function pointers (as int, usually
looked up through dload). After attach, read / write on the
stream go through those hooks, close (or a GC drop) calls shutdown
then free, and the socket keeps its descriptor. This is how the
coil-tls package turns a TCP stream into a TLS stream.
Returns Err(IoError::InvalidInput) when ptr is 0 or the stream is
already attached, and Err(IoError::AlreadyClosed) on a closed stream.
A program that reaches attach compiles only with --allow-attach.
Called on a Stream value as value.attach(…).
Parameters#
| Name | Type |
|---|---|
ptr | int |
read | int |
write | int |
shutdown | int |
free | int |
Returns#
Result<Stream, IoError>
Examples#
use io::net::tcp::{connect};
let s = connect("example.com", 443)?;
// session, rd, wr, sd, fr: a session pointer and C hooks from a dload'ed library
let tls = s.attach(session, rd, wr, sd, fr)?;
See also#
intio::attachio::closeStream: An open file, socket or standard stream.Stream::park: Waits until this stream’s descriptor is ready.Stream::fd: Returns the OS file descriptor (socket handle on Windows) of this stream.