@@ -14,7 +14,7 @@ export exit;
14
14
15
15
import libc:: c_void;
16
16
import ptr:: addr_of;
17
- import comm:: { port, chan, methods} ;
17
+ import comm:: { port, chan, methods, listen } ;
18
18
import ll = uv_ll;
19
19
20
20
#[ doc = "
@@ -31,9 +31,6 @@ fn spawn_iotask(-builder: task::builder) -> iotask {
31
31
32
32
import task:: { set_opts, get_opts, single_threaded, run} ;
33
33
34
- let iotask_po = port :: < iotask > ( ) ;
35
- let iotask_ch = iotask_po. chan ( ) ;
36
-
37
34
set_opts ( builder, {
38
35
sched: some ( {
39
36
mode: single_threaded,
@@ -42,13 +39,16 @@ fn spawn_iotask(-builder: task::builder) -> iotask {
42
39
with get_opts ( builder)
43
40
} ) ;
44
41
45
- run ( builder) { ||
46
- #debug ( "entering libuv task" ) ;
47
- run_loop ( iotask_ch) ;
48
- #debug ( "libuv task exiting" ) ;
49
- } ;
42
+ listen { |iotask_ch|
43
+
44
+ run ( copy ( builder) ) { ||
45
+ #debug ( "entering libuv task" ) ;
46
+ run_loop ( iotask_ch) ;
47
+ #debug ( "libuv task exiting" ) ;
48
+ } ;
50
49
51
- iotask_po. recv ( )
50
+ iotask_ch. recv ( )
51
+ }
52
52
}
53
53
54
54
@@ -102,27 +102,29 @@ enum iotask_msg {
102
102
Run the loop and begin handling messages
103
103
" ]
104
104
fn run_loop ( iotask_ch : chan < iotask > ) unsafe {
105
- let msg_po = port :: < iotask_msg > ( ) ;
105
+
106
106
let loop_ptr = ll:: loop_new ( ) ;
107
+
107
108
// set up the special async handle we'll use to allow multi-task
108
109
// communication with this loop
109
110
let async = ll:: async_t ( ) ;
110
111
let async_handle = addr_of ( async ) ;
112
+
111
113
// associate the async handle with the loop
112
114
ll:: async_init ( loop_ptr, async_handle, wake_up_cb) ;
113
115
114
116
// initialize our loop data and store it in the loop
115
117
let data: iotask_loop_data = {
116
118
async_handle: async_handle,
117
- msg_po_ptr : addr_of ( msg_po )
119
+ msg_po : port ( )
118
120
} ;
119
121
ll:: set_data_for_uv_handle ( async_handle, addr_of ( data) ) ;
120
122
121
123
// Send out a handle through which folks can talk to us
122
124
// while we dwell in the I/O loop
123
125
let iotask = iotask_ ( {
124
126
async_handle: async_handle,
125
- op_chan: msg_po. chan ( )
127
+ op_chan: data . msg_po . chan ( )
126
128
} ) ;
127
129
iotask_ch. send ( iotask) ;
128
130
@@ -136,7 +138,7 @@ fn run_loop(iotask_ch: chan<iotask>) unsafe {
136
138
// data that lives for the lifetime of the high-evel oo
137
139
type iotask_loop_data = {
138
140
async_handle : * ll:: uv_async_t ,
139
- msg_po_ptr : * port < iotask_msg >
141
+ msg_po : port < iotask_msg >
140
142
} ;
141
143
142
144
fn send_msg ( iotask : iotask ,
@@ -145,21 +147,19 @@ fn send_msg(iotask: iotask,
145
147
ll:: async_send ( iotask. async_handle ) ;
146
148
}
147
149
148
- // this will be invoked by a call to uv::hl::interact() with
149
- // the high_level_loop corresponding to this async_handle. We
150
- // simply check if the loop is active and, if so, invoke the
151
- // user-supplied on_wake callback that is stored in the loop's
152
- // data member
150
+ #[ doc ="Dispatch all pending messages" ]
153
151
crust fn wake_up_cb ( async_handle : * ll:: uv_async_t ,
154
152
status : int ) unsafe {
153
+
155
154
log ( debug, #fmt ( "wake_up_cb crust.. handle: %? status: %?" ,
156
155
async_handle, status) ) ;
156
+
157
157
let loop_ptr = ll:: get_loop_for_uv_handle ( async_handle) ;
158
158
let data = ll:: get_data_for_uv_handle ( async_handle) as * iotask_loop_data ;
159
- let msg_po = * ( ( * data) . msg_po_ptr ) ;
159
+ let msg_po = ( * data) . msg_po ;
160
+
160
161
while msg_po. peek ( ) {
161
- let msg = msg_po. recv ( ) ;
162
- alt msg {
162
+ alt msg_po. recv ( ) {
163
163
interaction ( cb) {
164
164
cb ( loop_ptr) ;
165
165
}
@@ -172,7 +172,6 @@ crust fn wake_up_cb(async_handle: *ll::uv_async_t,
172
172
173
173
fn begin_teardown ( data : * iotask_loop_data ) unsafe {
174
174
log ( debug, "iotask begin_teardown() called, close async_handle" ) ;
175
- // call user-suppled before_tear_down cb
176
175
let async_handle = ( * data) . async_handle ;
177
176
ll:: close ( async_handle as * c_void , tear_down_close_cb) ;
178
177
}
0 commit comments