Skip to content

Commit d039668

Browse files
committed
---
yaml --- r: 31665 b: refs/heads/dist-snap c: 4544c01 h: refs/heads/master i: 31663: 2e82b1e v: v3
1 parent 2f7094c commit d039668

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: bff512a90facf2b0064f13737d44c716863f644d
10+
refs/heads/dist-snap: 4544c015b3bd45b18612ede3e0c091ec3ee27e8a
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/libcore/pipes.rs

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ type packet<T: send> = {
162162
mut payload: option<T>,
163163
};
164164

165+
#[doc(hidden)]
165166
trait has_buffer {
166167
fn set_buffer(b: *libc::c_void);
167168
}
@@ -172,13 +173,15 @@ impl methods<T: send> of has_buffer for packet<T> {
172173
}
173174
}
174175

176+
#[doc(hidden)]
175177
fn mk_packet<T: send>() -> packet<T> {
176178
{
177179
header: packet_header(),
178180
mut payload: none
179181
}
180182
}
181183

184+
#[doc(hidden)]
182185
fn unibuffer<T: send>() -> ~buffer<packet<T>> {
183186
let b = ~{
184187
header: buffer_header(),
@@ -216,6 +219,7 @@ fn entangle_buffer<T: send, Tstart: send>(
216219
}
217220

218221
#[abi = "rust-intrinsic"]
222+
#[doc(hidden)]
219223
extern mod rusti {
220224
fn atomic_xchng(&dst: int, src: int) -> int;
221225
fn atomic_xchng_acq(&dst: int, src: int) -> int;
@@ -256,6 +260,7 @@ fn swap_task(&dst: *rust_task, src: *rust_task) -> *rust_task {
256260
#[doc(hidden)]
257261
type rust_task = libc::c_void;
258262

263+
#[doc(hidden)]
259264
extern mod rustrt {
260265
#[rust_stack]
261266
fn rust_get_task() -> *rust_task;
@@ -614,14 +619,17 @@ fn select2<A: send, Ab: send, B: send, Bb: send>(
614619
}
615620
}
616621

622+
#[doc(hidden)]
617623
trait selectable {
618624
pure fn header() -> *packet_header;
619625
}
620626

627+
/// Returns the index of an endpoint that is ready to receive.
621628
fn selecti<T: selectable>(endpoints: &[T]) -> uint {
622629
wait_many(endpoints.map(|p| p.header()))
623630
}
624631

632+
/// Returns 0 or 1 depending on which endpoint is ready to receive
625633
fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> {
626634
alt wait_many([a.header(), b.header()]/_) {
627635
0 => left(()),
@@ -630,8 +638,10 @@ fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> {
630638
}
631639
}
632640

633-
#[doc = "Waits on a set of endpoints. Returns a message, its index,
634-
and a list of the remaining endpoints."]
641+
/** Waits on a set of endpoints. Returns a message, its index, and a
642+
list of the remaining endpoints.
643+
644+
*/
635645
fn select<T: send, Tb: send>(+endpoints: ~[recv_packet_buffered<T, Tb>])
636646
-> (uint, option<T>, ~[recv_packet_buffered<T, Tb>])
637647
{
@@ -650,8 +660,10 @@ fn select<T: send, Tb: send>(+endpoints: ~[recv_packet_buffered<T, Tb>])
650660
(ready, result, remaining)
651661
}
652662

653-
/// The sending end of a pipe. It can be used to send exactly one
654-
/// message.
663+
/** The sending end of a pipe. It can be used to send exactly one
664+
message.
665+
666+
*/
655667
type send_packet<T: send> = send_packet_buffered<T, packet<T>>;
656668

657669
#[doc(hidden)]
@@ -778,6 +790,13 @@ fn entangle<T: send>() -> (send_packet<T>, recv_packet<T>) {
778790
(send_packet(p), recv_packet(p))
779791
}
780792

793+
/** Spawn a task to provide a service.
794+
795+
It takes an initialization function that produces a send and receive
796+
endpoint. The send endpoint is returned to the caller and the receive
797+
endpoint is passed to the new task.
798+
799+
*/
781800
fn spawn_service<T: send, Tb: send>(
782801
init: extern fn() -> (send_packet_buffered<T, Tb>,
783802
recv_packet_buffered<T, Tb>),
@@ -798,6 +817,10 @@ fn spawn_service<T: send, Tb: send>(
798817
client
799818
}
800819

820+
/** Like `spawn_service_recv`, but for protocols that start in the
821+
receive state.
822+
823+
*/
801824
fn spawn_service_recv<T: send, Tb: send>(
802825
init: extern fn() -> (recv_packet_buffered<T, Tb>,
803826
send_packet_buffered<T, Tb>),
@@ -826,33 +849,54 @@ proto! streamp {
826849
}
827850
}
828851

829-
// It'd be nice to call this send, but it'd conflict with the built in
830-
// send kind.
852+
/// A trait for things that can send multiple messages.
831853
trait channel<T: send> {
854+
// It'd be nice to call this send, but it'd conflict with the
855+
// built in send kind.
856+
857+
/// Sends a message.
832858
fn send(+x: T);
833859
}
834860

861+
/// A trait for things that can receive multiple messages.
835862
trait recv<T: send> {
863+
/// Receives a message, or fails if the connection closes.
836864
fn recv() -> T;
865+
866+
/** Receives a message if one is available, or returns `none` if
867+
the connection is closed.
868+
869+
*/
837870
fn try_recv() -> option<T>;
838-
// This should perhaps be a new trait
871+
872+
/** Returns true if a message is available or the connection is
873+
closed.
874+
875+
*/
839876
pure fn peek() -> bool;
840877
}
841878

842879
#[doc(hidden)]
843880
type chan_<T:send> = { mut endp: option<streamp::client::open<T>> };
844881

882+
/// An endpoint that can send many messages.
845883
enum chan<T:send> {
846884
chan_(chan_<T>)
847885
}
848886

849887
#[doc(hidden)]
850888
type port_<T:send> = { mut endp: option<streamp::server::open<T>> };
851889

890+
/// An endpoint that can receive many messages.
852891
enum port<T:send> {
853892
port_(port_<T>)
854893
}
855894

895+
/** Creates a `(chan, port)` pair.
896+
897+
These allow sending or receiving an unlimited number of messages.
898+
899+
*/
856900
fn stream<T:send>() -> (chan<T>, port<T>) {
857901
let (c, s) = streamp::init();
858902

@@ -970,7 +1014,7 @@ impl<T: send> of selectable for port<T> {
9701014
}
9711015
}
9721016

973-
1017+
/// A channel that can be shared between many senders.
9741018
type shared_chan<T: send> = arc::exclusive<chan<T>>;
9751019

9761020
impl chan<T: send> of channel<T> for shared_chan<T> {
@@ -984,12 +1028,16 @@ impl chan<T: send> of channel<T> for shared_chan<T> {
9841028
}
9851029
}
9861030

1031+
/// Converts a `chan` into a `shared_chan`.
9871032
fn shared_chan<T:send>(+c: chan<T>) -> shared_chan<T> {
9881033
arc::exclusive(c)
9891034
}
9901035

1036+
/// Receive a message from one of two endpoints.
9911037
trait select2<T: send, U: send> {
1038+
/// Receive a message or return `none` if a connection closes.
9921039
fn try_select() -> either<option<T>, option<U>>;
1040+
/// Receive a message or fail if a connection closes.
9931041
fn select() -> either<T, U>;
9941042
}
9951043

0 commit comments

Comments
 (0)