Skip to content

Commit c5c0252

Browse files
committed
auto merge of #7908 : anasazi/rust/fix_udp_mut, r=brson
2 parents 5c999d4 + b03f1e7 commit c5c0252

File tree

4 files changed

+81
-82
lines changed

4 files changed

+81
-82
lines changed

src/libstd/rt/io/net/udp.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl UdpSocket {
3030
}
3131
}
3232

33-
pub fn recvfrom(&self, buf: &mut [u8]) -> Option<(uint, IpAddr)> {
33+
pub fn recvfrom(&mut self, buf: &mut [u8]) -> Option<(uint, IpAddr)> {
3434
match (**self).recvfrom(buf) {
3535
Ok((nread, src)) => Some((nread, src)),
3636
Err(ioerr) => {
@@ -43,7 +43,7 @@ impl UdpSocket {
4343
}
4444
}
4545

46-
pub fn sendto(&self, buf: &[u8], dst: IpAddr) {
46+
pub fn sendto(&mut self, buf: &[u8], dst: IpAddr) {
4747
match (**self).sendto(buf, dst) {
4848
Ok(_) => (),
4949
Err(ioerr) => io_error::cond.raise(ioerr),
@@ -61,16 +61,17 @@ pub struct UdpStream {
6161
}
6262

6363
impl UdpStream {
64-
pub fn as_socket<T>(&self, f: &fn(&UdpSocket) -> T) -> T { f(&self.socket) }
64+
pub fn as_socket<T>(&mut self, f: &fn(&mut UdpSocket) -> T) -> T { f(&mut self.socket) }
6565

6666
pub fn disconnect(self) -> UdpSocket { self.socket }
6767
}
6868

6969
impl Reader for UdpStream {
7070
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
71+
let peer = self.connectedTo;
7172
do self.as_socket |sock| {
7273
match sock.recvfrom(buf) {
73-
Some((_nread, src)) if src != self.connectedTo => Some(0),
74+
Some((_nread, src)) if src != peer => Some(0),
7475
Some((nread, _src)) => Some(nread),
7576
None => None,
7677
}
@@ -122,7 +123,7 @@ mod test {
122123

123124
do spawntask_immediately {
124125
match UdpSocket::bind(server_ip) {
125-
Some(server) => {
126+
Some(ref mut server) => {
126127
let mut buf = [0];
127128
match server.recvfrom(buf) {
128129
Some((nread, src)) => {
@@ -139,7 +140,7 @@ mod test {
139140

140141
do spawntask_immediately {
141142
match UdpSocket::bind(client_ip) {
142-
Some(client) => client.sendto([99], server_ip),
143+
Some(ref mut client) => client.sendto([99], server_ip),
143144
None => fail!()
144145
}
145146
}
@@ -154,7 +155,7 @@ mod test {
154155

155156
do spawntask_immediately {
156157
match UdpSocket::bind(server_ip) {
157-
Some(server) => {
158+
Some(ref mut server) => {
158159
let mut buf = [0];
159160
match server.recvfrom(buf) {
160161
Some((nread, src)) => {
@@ -171,7 +172,7 @@ mod test {
171172

172173
do spawntask_immediately {
173174
match UdpSocket::bind(client_ip) {
174-
Some(client) => client.sendto([99], server_ip),
175+
Some(ref mut client) => client.sendto([99], server_ip),
175176
None => fail!()
176177
}
177178
}

src/libstd/rt/rtio.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,37 @@ pub trait IoFactory {
5050

5151
pub trait RtioTcpListener : RtioSocket {
5252
fn accept(&mut self) -> Result<~RtioTcpStreamObject, IoError>;
53-
fn accept_simultaneously(&self);
54-
fn dont_accept_simultaneously(&self);
53+
fn accept_simultaneously(&mut self);
54+
fn dont_accept_simultaneously(&mut self);
5555
}
5656

5757
pub trait RtioTcpStream : RtioSocket {
58-
fn read(&self, buf: &mut [u8]) -> Result<uint, IoError>;
59-
fn write(&self, buf: &[u8]) -> Result<(), IoError>;
60-
fn peer_name(&self) -> IpAddr;
61-
fn control_congestion(&self);
62-
fn nodelay(&self);
63-
fn keepalive(&self, delay_in_seconds: uint);
64-
fn letdie(&self);
58+
fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError>;
59+
fn write(&mut self, buf: &[u8]) -> Result<(), IoError>;
60+
fn peer_name(&mut self) -> IpAddr;
61+
fn control_congestion(&mut self);
62+
fn nodelay(&mut self);
63+
fn keepalive(&mut self, delay_in_seconds: uint);
64+
fn letdie(&mut self);
6565
}
6666

6767
pub trait RtioSocket {
68-
fn socket_name(&self) -> IpAddr;
68+
fn socket_name(&mut self) -> IpAddr;
6969
}
7070

7171
pub trait RtioUdpSocket : RtioSocket {
72-
fn recvfrom(&self, buf: &mut [u8]) -> Result<(uint, IpAddr), IoError>;
73-
fn sendto(&self, buf: &[u8], dst: IpAddr) -> Result<(), IoError>;
72+
fn recvfrom(&mut self, buf: &mut [u8]) -> Result<(uint, IpAddr), IoError>;
73+
fn sendto(&mut self, buf: &[u8], dst: IpAddr) -> Result<(), IoError>;
7474

75-
fn join_multicast(&self, multi: IpAddr);
76-
fn leave_multicast(&self, multi: IpAddr);
75+
fn join_multicast(&mut self, multi: IpAddr);
76+
fn leave_multicast(&mut self, multi: IpAddr);
7777

78-
fn loop_multicast_locally(&self);
79-
fn dont_loop_multicast_locally(&self);
78+
fn loop_multicast_locally(&mut self);
79+
fn dont_loop_multicast_locally(&mut self);
8080

81-
fn multicast_time_to_live(&self, ttl: int);
82-
fn time_to_live(&self, ttl: int);
81+
fn multicast_time_to_live(&mut self, ttl: int);
82+
fn time_to_live(&mut self, ttl: int);
8383

84-
fn hear_broadcasts(&self);
85-
fn ignore_broadcasts(&self);
84+
fn hear_broadcasts(&mut self);
85+
fn ignore_broadcasts(&mut self);
8686
}

src/libstd/rt/uv/net.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl UdpWatcher {
359359
}
360360
}
361361

362-
pub fn bind(&self, address: IpAddr) -> Result<(), UvError> {
362+
pub fn bind(&mut self, address: IpAddr) -> Result<(), UvError> {
363363
do ip_as_uv_ip(address) |addr| {
364364
let result = unsafe {
365365
match addr {
@@ -374,10 +374,9 @@ impl UdpWatcher {
374374
}
375375
}
376376

377-
pub fn recv_start(&self, alloc: AllocCallback, cb: UdpReceiveCallback) {
377+
pub fn recv_start(&mut self, alloc: AllocCallback, cb: UdpReceiveCallback) {
378378
{
379-
let mut this = *self;
380-
let data = this.get_watcher_data();
379+
let data = self.get_watcher_data();
381380
data.alloc_cb = Some(alloc);
382381
data.udp_recv_cb = Some(cb);
383382
}
@@ -409,14 +408,13 @@ impl UdpWatcher {
409408
}
410409
}
411410

412-
pub fn recv_stop(&self) {
411+
pub fn recv_stop(&mut self) {
413412
unsafe { uvll::udp_recv_stop(self.native_handle()); }
414413
}
415414

416-
pub fn send(&self, buf: Buf, address: IpAddr, cb: UdpSendCallback) {
415+
pub fn send(&mut self, buf: Buf, address: IpAddr, cb: UdpSendCallback) {
417416
{
418-
let mut this = *self;
419-
let data = this.get_watcher_data();
417+
let data = self.get_watcher_data();
420418
assert!(data.udp_send_cb.is_none());
421419
data.udp_send_cb = Some(cb);
422420
}
@@ -620,7 +618,7 @@ mod test {
620618
fn udp_bind_close_ip4() {
621619
do run_in_bare_thread() {
622620
let mut loop_ = Loop::new();
623-
let udp_watcher = { UdpWatcher::new(&mut loop_) };
621+
let mut udp_watcher = { UdpWatcher::new(&mut loop_) };
624622
let addr = next_test_ip4();
625623
udp_watcher.bind(addr);
626624
udp_watcher.close(||());
@@ -633,7 +631,7 @@ mod test {
633631
fn udp_bind_close_ip6() {
634632
do run_in_bare_thread() {
635633
let mut loop_ = Loop::new();
636-
let udp_watcher = { UdpWatcher::new(&mut loop_) };
634+
let mut udp_watcher = { UdpWatcher::new(&mut loop_) };
637635
let addr = next_test_ip6();
638636
udp_watcher.bind(addr);
639637
udp_watcher.close(||());
@@ -798,15 +796,15 @@ mod test {
798796
let server_addr = next_test_ip4();
799797
let client_addr = next_test_ip4();
800798
801-
let server = UdpWatcher::new(&loop_);
799+
let mut server = UdpWatcher::new(&loop_);
802800
assert!(server.bind(server_addr).is_ok());
803801
804802
rtdebug!("starting read");
805803
let alloc: AllocCallback = |size| {
806804
vec_to_uv_buf(vec::from_elem(size, 0u8))
807805
};
808806
809-
do server.recv_start(alloc) |server, nread, buf, src, flags, status| {
807+
do server.recv_start(alloc) |mut server, nread, buf, src, flags, status| {
810808
server.recv_stop();
811809
rtdebug!("i'm reading!");
812810
assert!(status.is_none());
@@ -830,7 +828,7 @@ mod test {
830828
831829
do Thread::start {
832830
let mut loop_ = Loop::new();
833-
let client = UdpWatcher::new(&loop_);
831+
let mut client = UdpWatcher::new(&loop_);
834832
assert!(client.bind(client_addr).is_ok());
835833
let msg = ~[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
836834
let buf = slice_to_uv_buf(msg);
@@ -857,15 +855,15 @@ mod test {
857855
let server_addr = next_test_ip6();
858856
let client_addr = next_test_ip6();
859857
860-
let server = UdpWatcher::new(&loop_);
858+
let mut server = UdpWatcher::new(&loop_);
861859
assert!(server.bind(server_addr).is_ok());
862860
863861
rtdebug!("starting read");
864862
let alloc: AllocCallback = |size| {
865863
vec_to_uv_buf(vec::from_elem(size, 0u8))
866864
};
867865
868-
do server.recv_start(alloc) |server, nread, buf, src, flags, status| {
866+
do server.recv_start(alloc) |mut server, nread, buf, src, flags, status| {
869867
server.recv_stop();
870868
rtdebug!("i'm reading!");
871869
assert!(status.is_none());
@@ -889,7 +887,7 @@ mod test {
889887
890888
do Thread::start {
891889
let mut loop_ = Loop::new();
892-
let client = UdpWatcher::new(&loop_);
890+
let mut client = UdpWatcher::new(&loop_);
893891
assert!(client.bind(client_addr).is_ok());
894892
let msg = ~[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
895893
let buf = slice_to_uv_buf(msg);

0 commit comments

Comments
 (0)