@@ -162,6 +162,7 @@ type packet<T: send> = {
162
162
mut payload : option < T > ,
163
163
} ;
164
164
165
+ #[ doc( hidden) ]
165
166
trait has_buffer {
166
167
fn set_buffer ( b : * libc:: c_void ) ;
167
168
}
@@ -172,13 +173,15 @@ impl methods<T: send> of has_buffer for packet<T> {
172
173
}
173
174
}
174
175
176
+ #[ doc( hidden) ]
175
177
fn mk_packet < T : send > ( ) -> packet < T > {
176
178
{
177
179
header: packet_header ( ) ,
178
180
mut payload: none
179
181
}
180
182
}
181
183
184
+ #[ doc( hidden) ]
182
185
fn unibuffer < T : send > ( ) -> ~buffer < packet < T > > {
183
186
let b = ~{
184
187
header: buffer_header ( ) ,
@@ -216,6 +219,7 @@ fn entangle_buffer<T: send, Tstart: send>(
216
219
}
217
220
218
221
#[ abi = "rust-intrinsic" ]
222
+ #[ doc( hidden) ]
219
223
extern mod rusti {
220
224
fn atomic_xchng ( & dst: int , src : int ) -> int ;
221
225
fn atomic_xchng_acq ( & dst: int , src : int ) -> int ;
@@ -256,6 +260,7 @@ fn swap_task(&dst: *rust_task, src: *rust_task) -> *rust_task {
256
260
#[ doc( hidden) ]
257
261
type rust_task = libc:: c_void ;
258
262
263
+ #[ doc( hidden) ]
259
264
extern mod rustrt {
260
265
#[ rust_stack]
261
266
fn rust_get_task ( ) -> * rust_task ;
@@ -614,14 +619,17 @@ fn select2<A: send, Ab: send, B: send, Bb: send>(
614
619
}
615
620
}
616
621
622
+ #[ doc( hidden) ]
617
623
trait selectable {
618
624
pure fn header ( ) -> * packet_header ;
619
625
}
620
626
627
+ /// Returns the index of an endpoint that is ready to receive.
621
628
fn selecti < T : selectable > ( endpoints : & [ T ] ) -> uint {
622
629
wait_many ( endpoints. map ( |p| p. header ( ) ) )
623
630
}
624
631
632
+ /// Returns 0 or 1 depending on which endpoint is ready to receive
625
633
fn select2i < A : selectable , B : selectable > ( a : A , b : B ) -> either < ( ) , ( ) > {
626
634
alt wait_many ( [ a. header ( ) , b. header ( ) ] /_) {
627
635
0 => left ( ( ) ) ,
@@ -630,8 +638,10 @@ fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> {
630
638
}
631
639
}
632
640
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
+ */
635
645
fn select < T : send , Tb : send > ( +endpoints : ~[ recv_packet_buffered < T , Tb > ] )
636
646
-> ( uint , option < T > , ~[ recv_packet_buffered < T , Tb > ] )
637
647
{
@@ -650,8 +660,10 @@ fn select<T: send, Tb: send>(+endpoints: ~[recv_packet_buffered<T, Tb>])
650
660
( ready, result, remaining)
651
661
}
652
662
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
+ */
655
667
type send_packet < T : send > = send_packet_buffered < T , packet < T > > ;
656
668
657
669
#[ doc( hidden) ]
@@ -778,6 +790,13 @@ fn entangle<T: send>() -> (send_packet<T>, recv_packet<T>) {
778
790
( send_packet ( p) , recv_packet ( p) )
779
791
}
780
792
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
+ */
781
800
fn spawn_service < T : send , Tb : send > (
782
801
init : extern fn ( ) -> ( send_packet_buffered < T , Tb > ,
783
802
recv_packet_buffered < T , Tb > ) ,
@@ -798,6 +817,10 @@ fn spawn_service<T: send, Tb: send>(
798
817
client
799
818
}
800
819
820
+ /** Like `spawn_service_recv`, but for protocols that start in the
821
+ receive state.
822
+
823
+ */
801
824
fn spawn_service_recv < T : send , Tb : send > (
802
825
init : extern fn ( ) -> ( recv_packet_buffered < T , Tb > ,
803
826
send_packet_buffered < T , Tb > ) ,
@@ -826,33 +849,54 @@ proto! streamp {
826
849
}
827
850
}
828
851
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.
831
853
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.
832
858
fn send ( +x : T ) ;
833
859
}
834
860
861
+ /// A trait for things that can receive multiple messages.
835
862
trait recv < T : send > {
863
+ /// Receives a message, or fails if the connection closes.
836
864
fn recv ( ) -> T ;
865
+
866
+ /** Receives a message if one is available, or returns `none` if
867
+ the connection is closed.
868
+
869
+ */
837
870
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
+ */
839
876
pure fn peek ( ) -> bool ;
840
877
}
841
878
842
879
#[ doc( hidden) ]
843
880
type chan_ < T : send > = { mut endp : option < streamp:: client:: open < T > > } ;
844
881
882
+ /// An endpoint that can send many messages.
845
883
enum chan < T : send > {
846
884
chan_( chan_ < T > )
847
885
}
848
886
849
887
#[ doc( hidden) ]
850
888
type port_ < T : send > = { mut endp : option < streamp:: server:: open < T > > } ;
851
889
890
+ /// An endpoint that can receive many messages.
852
891
enum port < T : send > {
853
892
port_( port_ < T > )
854
893
}
855
894
895
+ /** Creates a `(chan, port)` pair.
896
+
897
+ These allow sending or receiving an unlimited number of messages.
898
+
899
+ */
856
900
fn stream < T : send > ( ) -> ( chan < T > , port < T > ) {
857
901
let ( c, s) = streamp:: init ( ) ;
858
902
@@ -970,7 +1014,7 @@ impl<T: send> of selectable for port<T> {
970
1014
}
971
1015
}
972
1016
973
-
1017
+ /// A channel that can be shared between many senders.
974
1018
type shared_chan < T : send > = arc:: exclusive < chan < T > > ;
975
1019
976
1020
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> {
984
1028
}
985
1029
}
986
1030
1031
+ /// Converts a `chan` into a `shared_chan`.
987
1032
fn shared_chan < T : send > ( +c : chan < T > ) -> shared_chan < T > {
988
1033
arc:: exclusive ( c)
989
1034
}
990
1035
1036
+ /// Receive a message from one of two endpoints.
991
1037
trait select2 < T : send , U : send > {
1038
+ /// Receive a message or return `none` if a connection closes.
992
1039
fn try_select ( ) -> either < option < T > , option < U > > ;
1040
+ /// Receive a message or fail if a connection closes.
993
1041
fn select ( ) -> either < T , U > ;
994
1042
}
995
1043
0 commit comments