@@ -16,31 +16,24 @@ use rt::io::{io_error, read_error, EndOfFile};
16
16
use rt:: rtio:: { RtioUdpSocketObject , RtioUdpSocket , IoFactory , IoFactoryObject } ;
17
17
use rt:: local:: Local ;
18
18
19
- pub struct UdpSocket {
20
- rtsocket : ~RtioUdpSocketObject
21
- }
19
+ pub struct UdpSocket ( ~RtioUdpSocketObject ) ;
22
20
23
21
impl UdpSocket {
24
- fn new ( s : ~RtioUdpSocketObject ) -> UdpSocket {
25
- UdpSocket { rtsocket : s }
26
- }
22
+ fn new ( s : ~RtioUdpSocketObject ) -> UdpSocket { UdpSocket ( s) }
27
23
28
24
pub fn bind ( addr : IpAddr ) -> Option < UdpSocket > {
29
- let socket = unsafe {
30
- let io = Local :: unsafe_borrow :: < IoFactoryObject > ( ) ;
31
- ( * io) . udp_bind ( addr)
32
- } ;
25
+ let socket = unsafe { ( * Local :: unsafe_borrow :: < IoFactoryObject > ( ) ) . udp_bind ( addr) } ;
33
26
match socket {
34
- Ok ( s) => { Some ( UdpSocket { rtsocket : s } ) }
27
+ Ok ( s) => Some ( UdpSocket :: new ( s ) ) ,
35
28
Err ( ioerr) => {
36
29
io_error:: cond. raise ( ioerr) ;
37
- return None ;
30
+ None
38
31
}
39
32
}
40
33
}
41
34
42
35
pub fn recvfrom ( & self , buf : & mut [ u8 ] ) -> Option < ( uint , IpAddr ) > {
43
- match ( * self . rtsocket ) . recvfrom ( buf) {
36
+ match ( * * self ) . recvfrom ( buf) {
44
37
Ok ( ( nread, src) ) => Some ( ( nread, src) ) ,
45
38
Err ( ioerr) => {
46
39
// EOF is indicated by returning None
@@ -53,34 +46,26 @@ impl UdpSocket {
53
46
}
54
47
55
48
pub fn sendto ( & self , buf : & [ u8 ] , dst : IpAddr ) {
56
- match ( * self . rtsocket ) . sendto ( buf, dst) {
49
+ match ( * * self ) . sendto ( buf, dst) {
57
50
Ok ( _) => ( ) ,
58
- Err ( ioerr) => {
59
- io_error:: cond. raise ( ioerr) ;
60
- }
51
+ Err ( ioerr) => io_error:: cond. raise ( ioerr) ,
61
52
}
62
53
}
63
54
64
- // XXX convert ~self to self eventually
65
- pub fn connect ( ~self , other : IpAddr ) -> UdpStream {
55
+ pub fn connect ( self , other : IpAddr ) -> UdpStream {
66
56
UdpStream { socket : self , connectedTo : other }
67
57
}
68
58
}
69
59
70
60
pub struct UdpStream {
71
- socket : ~ UdpSocket ,
61
+ socket : UdpSocket ,
72
62
connectedTo : IpAddr
73
63
}
74
64
75
65
impl UdpStream {
76
- pub fn as_socket < T > ( & self , f : & fn ( & UdpSocket ) -> T ) -> T {
77
- f ( self . socket )
78
- }
66
+ pub fn as_socket < T > ( & self , f : & fn ( & UdpSocket ) -> T ) -> T { f ( & self . socket ) }
79
67
80
- pub fn disconnect ( self ) -> ~UdpSocket {
81
- let UdpStream { socket : s, _ } = self ;
82
- s
83
- }
68
+ pub fn disconnect ( self ) -> UdpSocket { self . socket }
84
69
}
85
70
86
71
impl Reader for UdpStream {
0 commit comments