diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 963be25b69f..ce72a6edca9 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -162,6 +162,7 @@ fn set_buffer(b: ~buffer) unsafe { mut payload: option, }; +#[doc(hidden)] trait has_buffer { fn set_buffer(b: *libc::c_void); } @@ -172,6 +173,7 @@ fn set_buffer(b: *libc::c_void) { } } +#[doc(hidden)] fn mk_packet() -> packet { { header: packet_header(), @@ -179,6 +181,7 @@ fn mk_packet() -> packet { } } +#[doc(hidden)] fn unibuffer() -> ~buffer> { let b = ~{ header: buffer_header(), @@ -216,6 +219,7 @@ fn entangle_buffer( } #[abi = "rust-intrinsic"] +#[doc(hidden)] extern mod rusti { fn atomic_xchng(&dst: int, src: int) -> int; fn atomic_xchng_acq(&dst: int, src: int) -> int; @@ -256,6 +260,7 @@ fn swap_task(&dst: *rust_task, src: *rust_task) -> *rust_task { #[doc(hidden)] type rust_task = libc::c_void; +#[doc(hidden)] extern mod rustrt { #[rust_stack] fn rust_get_task() -> *rust_task; @@ -614,14 +619,17 @@ fn select2( } } +#[doc(hidden)] trait selectable { pure fn header() -> *packet_header; } +/// Returns the index of an endpoint that is ready to receive. fn selecti(endpoints: &[T]) -> uint { wait_many(endpoints.map(|p| p.header())) } +/// Returns 0 or 1 depending on which endpoint is ready to receive fn select2i(a: A, b: B) -> either<(), ()> { alt wait_many([a.header(), b.header()]/_) { 0 => left(()), @@ -630,8 +638,10 @@ fn select2i(a: A, b: B) -> either<(), ()> { } } -#[doc = "Waits on a set of endpoints. Returns a message, its index, - and a list of the remaining endpoints."] +/** Waits on a set of endpoints. Returns a message, its index, and a + list of the remaining endpoints. + +*/ fn select(+endpoints: ~[recv_packet_buffered]) -> (uint, option, ~[recv_packet_buffered]) { @@ -650,8 +660,10 @@ fn select(+endpoints: ~[recv_packet_buffered]) (ready, result, remaining) } -/// The sending end of a pipe. It can be used to send exactly one -/// message. +/** The sending end of a pipe. It can be used to send exactly one +message. + +*/ type send_packet = send_packet_buffered>; #[doc(hidden)] @@ -778,6 +790,13 @@ fn entangle() -> (send_packet, recv_packet) { (send_packet(p), recv_packet(p)) } +/** Spawn a task to provide a service. + +It takes an initialization function that produces a send and receive +endpoint. The send endpoint is returned to the caller and the receive +endpoint is passed to the new task. + +*/ fn spawn_service( init: extern fn() -> (send_packet_buffered, recv_packet_buffered), @@ -798,6 +817,10 @@ fn spawn_service( client } +/** Like `spawn_service_recv`, but for protocols that start in the +receive state. + +*/ fn spawn_service_recv( init: extern fn() -> (recv_packet_buffered, send_packet_buffered), @@ -826,22 +849,37 @@ fn spawn_service_recv( } } -// It'd be nice to call this send, but it'd conflict with the built in -// send kind. +/// A trait for things that can send multiple messages. trait channel { + // It'd be nice to call this send, but it'd conflict with the + // built in send kind. + + /// Sends a message. fn send(+x: T); } +/// A trait for things that can receive multiple messages. trait recv { + /// Receives a message, or fails if the connection closes. fn recv() -> T; + + /** Receives a message if one is available, or returns `none` if + the connection is closed. + + */ fn try_recv() -> option; - // This should perhaps be a new trait + + /** Returns true if a message is available or the connection is + closed. + + */ pure fn peek() -> bool; } #[doc(hidden)] type chan_ = { mut endp: option> }; +/// An endpoint that can send many messages. enum chan { chan_(chan_) } @@ -849,10 +887,16 @@ enum chan { #[doc(hidden)] type port_ = { mut endp: option> }; +/// An endpoint that can receive many messages. enum port { port_(port_) } +/** Creates a `(chan, port)` pair. + +These allow sending or receiving an unlimited number of messages. + +*/ fn stream() -> (chan, port) { let (c, s) = streamp::init(); @@ -970,7 +1014,7 @@ impl of selectable for port { } } - +/// A channel that can be shared between many senders. type shared_chan = arc::exclusive>; impl chan of channel for shared_chan { @@ -984,12 +1028,16 @@ fn send(+x: T) { } } +/// Converts a `chan` into a `shared_chan`. fn shared_chan(+c: chan) -> shared_chan { arc::exclusive(c) } +/// Receive a message from one of two endpoints. trait select2 { + /// Receive a message or return `none` if a connection closes. fn try_select() -> either, option>; + /// Receive a message or fail if a connection closes. fn select() -> either; }