@@ -124,7 +124,7 @@ impl IoFactory for UvIoFactory {
124
124
rtdebug ! ( "connect: in connect callback" ) ;
125
125
let maybe_stream = if status. is_none ( ) {
126
126
rtdebug ! ( "status is none" ) ;
127
- Ok ( ~UvTcpStream ( stream_watcher) )
127
+ Ok ( ~UvTcpStream { watcher : stream_watcher } )
128
128
} else {
129
129
rtdebug ! ( "status is some" ) ;
130
130
// XXX: Wait for close
@@ -148,7 +148,7 @@ impl IoFactory for UvIoFactory {
148
148
fn tcp_bind ( & mut self , addr : IpAddr ) -> Result < ~RtioTcpListenerObject , IoError > {
149
149
let mut watcher = TcpWatcher :: new ( self . uv_loop ( ) ) ;
150
150
match watcher. bind ( addr) {
151
- Ok ( _) => Ok ( ~UvTcpListener ( watcher) ) ,
151
+ Ok ( _) => Ok ( ~UvTcpListener { watcher : watcher } ) ,
152
152
Err ( uverr) => {
153
153
// XXX: Should we wait until close completes?
154
154
watcher. as_stream ( ) . close ( ||( ) ) ;
@@ -158,23 +158,19 @@ impl IoFactory for UvIoFactory {
158
158
}
159
159
}
160
160
161
- pub struct UvTcpListener ( TcpWatcher ) ;
161
+ // FIXME #6090: Prefer newtype structs but Drop doesn't work
162
+ pub struct UvTcpListener {
163
+ watcher : TcpWatcher
164
+ }
162
165
163
166
impl UvTcpListener {
164
- fn watcher ( & self ) -> TcpWatcher {
165
- match self { & UvTcpListener ( w) => w }
166
- }
167
-
168
- fn close ( & self ) {
169
- // XXX: Need to wait until close finishes before returning
170
- self . watcher ( ) . as_stream ( ) . close ( ||( ) ) ;
171
- }
167
+ fn watcher ( & self ) -> TcpWatcher { self . watcher }
172
168
}
173
169
174
170
impl Drop for UvTcpListener {
175
171
fn finalize ( & self ) {
176
- // XXX: Again, this never gets called. Use .close() instead
177
- // self.watcher().as_stream().close(||());
172
+ // XXX: Need to wait until close finishes before returning
173
+ self . watcher ( ) . as_stream ( ) . close ( ||( ) ) ;
178
174
}
179
175
}
180
176
@@ -200,7 +196,7 @@ impl RtioTcpListener for UvTcpListener {
200
196
let client_tcp_watcher = TcpWatcher :: new ( & mut loop_) . as_stream ( ) ;
201
197
// XXX: Needs to be surfaced in interface
202
198
server_stream_watcher. accept ( client_tcp_watcher) ;
203
- Ok ( ~UvTcpStream :: new ( client_tcp_watcher) )
199
+ Ok ( ~UvTcpStream { watcher : client_tcp_watcher } )
204
200
} else {
205
201
Err ( standard_error ( OtherIoError ) )
206
202
} ;
@@ -219,28 +215,19 @@ impl RtioTcpListener for UvTcpListener {
219
215
}
220
216
}
221
217
222
- pub struct UvTcpStream ( StreamWatcher ) ;
218
+ // FIXME #6090: Prefer newtype structs but Drop doesn't work
219
+ pub struct UvTcpStream {
220
+ watcher : StreamWatcher
221
+ }
223
222
224
223
impl UvTcpStream {
225
- fn new ( watcher : StreamWatcher ) -> UvTcpStream {
226
- UvTcpStream ( watcher)
227
- }
228
-
229
- fn watcher ( & self ) -> StreamWatcher {
230
- match self { & UvTcpStream ( w) => w }
231
- }
232
-
233
- // XXX: finalize isn't working for ~UvStream???
234
- fn close ( & self ) {
235
- // XXX: Need to wait until this finishes before returning
236
- self . watcher ( ) . close ( ||( ) ) ;
237
- }
224
+ fn watcher ( & self ) -> StreamWatcher { self . watcher }
238
225
}
239
226
240
227
impl Drop for UvTcpStream {
241
228
fn finalize ( & self ) {
242
229
rtdebug ! ( "closing stream" ) ;
243
- // self.watcher().close(||());
230
+ self . watcher ( ) . close ( ||( ) ) ;
244
231
}
245
232
}
246
233
@@ -354,8 +341,6 @@ fn test_simple_tcp_server_and_client() {
354
341
rtdebug ! ( "%u" , buf[ i] as uint) ;
355
342
assert ! ( buf[ i] == i as u8 ) ;
356
343
}
357
- stream. close( ) ;
358
- listener. close( ) ;
359
344
}
360
345
}
361
346
@@ -364,7 +349,6 @@ fn test_simple_tcp_server_and_client() {
364
349
let io = local_sched:: unsafe_borrow_io ( ) ;
365
350
let mut stream = ( * io) . tcp_connect ( addr) . unwrap ( ) ;
366
351
stream. write ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) ;
367
- stream. close ( ) ;
368
352
}
369
353
}
370
354
}
@@ -408,9 +392,6 @@ fn test_read_and_block() {
408
392
409
393
// Make sure we had multiple reads
410
394
assert ! ( reads > 1 ) ;
411
-
412
- stream. close ( ) ;
413
- listener. close ( ) ;
414
395
}
415
396
416
397
do spawntask_immediately {
@@ -421,7 +402,6 @@ fn test_read_and_block() {
421
402
stream. write ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) ;
422
403
stream. write ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) ;
423
404
stream. write ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) ;
424
- stream. close ( ) ;
425
405
}
426
406
}
427
407
@@ -445,8 +425,6 @@ fn test_read_read_read() {
445
425
stream. write ( buf) ;
446
426
total_bytes_written += buf. len ( ) ;
447
427
}
448
- stream. close ( ) ;
449
- listener. close ( ) ;
450
428
}
451
429
}
452
430
@@ -465,7 +443,6 @@ fn test_read_read_read() {
465
443
}
466
444
}
467
445
rtdebug ! ( "read %u bytes total" , total_bytes_read as uint) ;
468
- stream. close ( ) ;
469
446
}
470
447
}
471
448
}
0 commit comments