@@ -100,8 +100,6 @@ impl UdpSocket {
100
100
///
101
101
/// Note that this call does not perform any actual network communication,
102
102
/// because UDP is a datagram protocol.
103
- #[ deprecated = "`UdpStream` has been deprecated" ]
104
- #[ allow( deprecated) ]
105
103
pub fn connect ( self , other : SocketAddr ) -> UdpStream {
106
104
UdpStream {
107
105
socket : self ,
@@ -207,14 +205,6 @@ impl Clone for UdpSocket {
207
205
208
206
/// A type that allows convenient usage of a UDP stream connected to one
209
207
/// address via the `Reader` and `Writer` traits.
210
- ///
211
- /// # Note
212
- ///
213
- /// This structure has been deprecated because `Reader` is a stream-oriented API but UDP
214
- /// is a packet-oriented protocol. Every `Reader` method will read a whole packet and
215
- /// throw all superfluous bytes away so that they are no longer available for further
216
- /// method calls.
217
- #[ deprecated]
218
208
pub struct UdpStream {
219
209
socket : UdpSocket ,
220
210
connected_to : SocketAddr
@@ -235,15 +225,13 @@ impl UdpStream {
235
225
}
236
226
237
227
impl Reader for UdpStream {
238
- /// Returns the next non-empty message from the specified address.
239
228
fn read ( & mut self , buf : & mut [ u8 ] ) -> IoResult < uint > {
240
229
let peer = self . connected_to ;
241
230
self . as_socket ( |sock| {
242
- loop {
243
- let ( nread, src) = try!( sock. recv_from ( buf) ) ;
244
- if nread > 0 && src == peer {
245
- return Ok ( nread) ;
246
- }
231
+ match sock. recv_from ( buf) {
232
+ Ok ( ( _nread, src) ) if src != peer => Ok ( 0 ) ,
233
+ Ok ( ( nread, _src) ) => Ok ( nread) ,
234
+ Err ( e) => Err ( e) ,
247
235
}
248
236
} )
249
237
}
@@ -346,28 +334,22 @@ mod test {
346
334
}
347
335
348
336
#[ test]
349
- #[ allow( deprecated) ]
350
337
fn stream_smoke_test_ip4 ( ) {
351
338
let server_ip = next_test_ip4 ( ) ;
352
339
let client_ip = next_test_ip4 ( ) ;
353
- let dummy_ip = next_test_ip4 ( ) ;
354
340
let ( tx1, rx1) = channel ( ) ;
355
341
let ( tx2, rx2) = channel ( ) ;
356
342
357
343
spawn ( proc ( ) {
358
- let send_as = |ip, val : & [ u8 ] | {
359
- match UdpSocket :: bind ( ip) {
360
- Ok ( client) => {
361
- let client = box client;
362
- let mut stream = client. connect ( server_ip) ;
363
- stream. write ( val) . unwrap ( ) ;
364
- }
365
- Err ( ..) => fail ! ( )
344
+ match UdpSocket :: bind ( client_ip) {
345
+ Ok ( client) => {
346
+ let client = box client;
347
+ let mut stream = client. connect ( server_ip) ;
348
+ rx1. recv ( ) ;
349
+ stream. write ( [ 99 ] ) . unwrap ( ) ;
366
350
}
367
- } ;
368
- rx1. recv ( ) ;
369
- send_as ( dummy_ip, [ 98 ] ) ;
370
- send_as ( client_ip, [ 99 ] ) ;
351
+ Err ( ..) => fail ! ( )
352
+ }
371
353
tx2. send ( ( ) ) ;
372
354
} ) ;
373
355
@@ -382,7 +364,7 @@ mod test {
382
364
assert_eq ! ( nread, 1 ) ;
383
365
assert_eq ! ( buf[ 0 ] , 99 ) ;
384
366
}
385
- Err ( ..) => fail ! ( ) ,
367
+ Err ( ..) => fail ! ( )
386
368
}
387
369
}
388
370
Err ( ..) => fail ! ( )
@@ -391,7 +373,6 @@ mod test {
391
373
}
392
374
393
375
#[ test]
394
- #[ allow( deprecated) ]
395
376
fn stream_smoke_test_ip6 ( ) {
396
377
let server_ip = next_test_ip6 ( ) ;
397
378
let client_ip = next_test_ip6 ( ) ;
0 commit comments