Generic communication channels for things that can be represented as, or transformed to and from, byte vectors.

The FlatPort and FlatChan types implement the generic channel and port interface for arbitrary types and transport strategies. It can particularly be used to send and recieve serializable types over I/O streams.

FlatPort and FlatChan implement the same comm traits as pipe-based ports and channels.

Example

This example sends boxed integers across tasks using serialization.

let (port, chan) = serial::pipe_stream();

do task::spawn |move chan| {
    for int::range(0, 10) |i| {
        chan.send(@i)
    }
}

for int::range(0, 10) |i| {
    assert @i == port.recv()
}

Safety Note

Flat pipes created from io::Readers and io::Writers share the same blocking properties as the underlying stream. Since some implementations block the scheduler thread, so will their pipes.

Const CONTINUE

[u8 * 4]

Struct FlatChan

pub struct FlatChan <T, F: Flattener<T>, C: ByteChan>{
    flattener: F,
    byte_chan: C,
}

A FlatChan, consisting of a Flattener that converts values to byte vectors, and a ByteChan that transmits the bytes.

Create using the constructors in the serial and pod modules.

Struct FlatPort

pub struct FlatPort <T, U: Unflattener<T>, P: BytePort>{
    unflattener: U,
    byte_port: P,
}

A FlatPort, consisting of a BytePort that recieves byte vectors, and an Unflattener that converts the bytes to a value.

Create using the constructors in the serial and pod modules.

Interface ByteChan

ByteChans are a simple interface for sending bytes

Method send

fn send(val: ~[u8])

Interface BytePort

BytePorts are a simple interface for receiving a specified number

Method try_recv

fn try_recv(count: uint) -> Option<~[u8]>

Interface Flattener

Flatteners present a value as a byte vector

Method flatten

fn flatten(val: T) -> ~[u8]

Interface Unflattener

Unflatteners convert a byte vector to a value

Method unflatten

fn unflatten(buf: ~[u8]) -> T

Implementation of GenericPort<T> for FlatPort<T, U, P>

Method recv

fn recv() -> T

Method try_recv

fn try_recv() -> Option<T>

Implementation of GenericChan<T> for FlatChan<T, F, C>

Method send

fn send(val: T)

Implementation for FlatPort<T, U, P>

Method new

fn new(u: U, p: P) -> FlatPort<T, U, P>

Implementation for FlatChan<T, F, C>

Method new

fn new(f: F, c: C) -> FlatChan<T, F, C>