19
19
// modified in hopefully straightforward ways.
20
20
mod pingpong {
21
21
use core:: pipes:: * ;
22
+ use core:: ptr;
22
23
23
- type packets = {
24
- // This is probably a resolve bug, I forgot to export packet,
25
- // but since I didn't import pipes::*, it worked anyway.
24
+ pub type packets = {
26
25
ping : Packet < ping > ,
27
26
pong : Packet < pong > ,
28
27
} ;
29
28
30
- fn init ( ) -> ( client:: ping , server:: ping ) {
29
+ pub fn init ( ) -> ( client:: ping , server:: ping ) {
31
30
let buffer = ~{
32
31
header: BufferHeader ( ) ,
33
32
data : {
@@ -44,44 +43,48 @@ mod pingpong {
44
43
pub enum ping = server:: pong;
45
44
pub enum pong = client:: ping;
46
45
pub mod client {
46
+ use core:: ptr;
47
+
47
48
pub fn ping ( +pipe : ping ) -> pong {
48
49
{
49
50
let b = pipe. reuse_buffer ( ) ;
50
51
let s = SendPacketBuffered ( ptr:: addr_of ( & ( b. buffer . data . pong ) ) ) ;
51
52
let c = RecvPacketBuffered ( ptr:: addr_of ( & ( b. buffer . data . pong ) ) ) ;
52
- let message = pingpong:: ping ( move s) ;
53
- pipes:: send ( move pipe, move message) ;
53
+ let message = :: pingpong:: ping ( move s) ;
54
+ :: pipes:: send ( move pipe, move message) ;
54
55
move c
55
56
}
56
57
}
57
- pub type ping = pipes:: SendPacketBuffered < pingpong:: ping ,
58
- pingpong:: packets > ;
59
- pub type pong = pipes:: RecvPacketBuffered < pingpong:: pong ,
60
- pingpong:: packets > ;
58
+ pub type ping = pipes:: SendPacketBuffered < :: pingpong:: ping ,
59
+ :: pingpong:: packets > ;
60
+ pub type pong = pipes:: RecvPacketBuffered < :: pingpong:: pong ,
61
+ :: pingpong:: packets > ;
61
62
}
62
63
pub mod server {
63
- pub type ping = pipes:: RecvPacketBuffered < pingpong:: ping ,
64
- pingpong:: packets > ;
64
+ use core:: ptr;
65
+
66
+ pub type ping = pipes:: RecvPacketBuffered < :: pingpong:: ping ,
67
+ :: pingpong:: packets > ;
65
68
pub fn pong ( +pipe : pong ) -> ping {
66
69
{
67
70
let b = pipe. reuse_buffer ( ) ;
68
71
let s = SendPacketBuffered ( ptr:: addr_of ( & ( b. buffer . data . ping ) ) ) ;
69
72
let c = RecvPacketBuffered ( ptr:: addr_of ( & ( b. buffer . data . ping ) ) ) ;
70
- let message = pingpong:: pong ( move s) ;
71
- pipes:: send ( move pipe, move message) ;
73
+ let message = :: pingpong:: pong ( move s) ;
74
+ :: pipes:: send ( move pipe, move message) ;
72
75
move c
73
76
}
74
77
}
75
- pub type pong = pipes:: SendPacketBuffered < pingpong:: pong ,
76
- pingpong:: packets > ;
78
+ pub type pong = pipes:: SendPacketBuffered < :: pingpong:: pong ,
79
+ :: pingpong:: packets > ;
77
80
}
78
81
}
79
82
80
83
mod test {
81
84
use pipes:: recv;
82
85
use pingpong:: { ping, pong} ;
83
86
84
- pub fn client ( -chan : pingpong:: client:: ping ) {
87
+ pub fn client ( -chan : :: pingpong:: client:: ping ) {
85
88
use pingpong:: client;
86
89
87
90
let chan = client:: ping ( move chan) ; return ;
@@ -90,7 +93,7 @@ mod test {
90
93
log ( error, "Received pong" ) ;
91
94
}
92
95
93
- pub fn server ( -chan : pingpong:: server:: ping ) {
96
+ pub fn server ( -chan : :: pingpong:: server:: ping ) {
94
97
use pingpong:: server;
95
98
96
99
let ping( chan) = recv ( move chan) ; return ;
@@ -101,7 +104,7 @@ mod test {
101
104
}
102
105
103
106
fn main ( ) {
104
- let ( client_, server_) = pingpong:: init ( ) ;
107
+ let ( client_, server_) = :: pingpong:: init ( ) ;
105
108
let client_ = ~mut Some ( move client_) ;
106
109
let server_ = ~mut Some ( move server_) ;
107
110
do task:: spawn |move client_| {
0 commit comments