Method in io · Stream compiler

Stream::attach

pub fn attach(int ptr, int read, int write, int shutdown, int free) -> Result<Stream, IoError>
Import
use io::{Stream};
Source: 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#

NameType
ptrint
readint
writeint
shutdownint
freeint

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#

↑ ↓ navigate ↵ open