Skip to content

Commit

Permalink
Missed the methods of UdpWatcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Reed committed Jul 19, 2013
1 parent 968f7f5 commit b03f1e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
30 changes: 14 additions & 16 deletions src/libstd/rt/uv/net.rs
Expand Up @@ -359,7 +359,7 @@ impl UdpWatcher {
}
}

pub fn bind(&self, address: IpAddr) -> Result<(), UvError> {
pub fn bind(&mut self, address: IpAddr) -> Result<(), UvError> {
do ip_as_uv_ip(address) |addr| {
let result = unsafe {
match addr {
Expand All @@ -374,10 +374,9 @@ impl UdpWatcher {
}
}

pub fn recv_start(&self, alloc: AllocCallback, cb: UdpReceiveCallback) {
pub fn recv_start(&mut self, alloc: AllocCallback, cb: UdpReceiveCallback) {
{
let mut this = *self;
let data = this.get_watcher_data();
let data = self.get_watcher_data();
data.alloc_cb = Some(alloc);
data.udp_recv_cb = Some(cb);
}
Expand Down Expand Up @@ -409,14 +408,13 @@ impl UdpWatcher {
}
}

pub fn recv_stop(&self) {
pub fn recv_stop(&mut self) {
unsafe { uvll::udp_recv_stop(self.native_handle()); }
}

pub fn send(&self, buf: Buf, address: IpAddr, cb: UdpSendCallback) {
pub fn send(&mut self, buf: Buf, address: IpAddr, cb: UdpSendCallback) {
{
let mut this = *self;
let data = this.get_watcher_data();
let data = self.get_watcher_data();
assert!(data.udp_send_cb.is_none());
data.udp_send_cb = Some(cb);
}
Expand Down Expand Up @@ -620,7 +618,7 @@ mod test {
fn udp_bind_close_ip4() {
do run_in_bare_thread() {
let mut loop_ = Loop::new();
let udp_watcher = { UdpWatcher::new(&mut loop_) };
let mut udp_watcher = { UdpWatcher::new(&mut loop_) };
let addr = next_test_ip4();
udp_watcher.bind(addr);
udp_watcher.close(||());
Expand All @@ -633,7 +631,7 @@ mod test {
fn udp_bind_close_ip6() {
do run_in_bare_thread() {
let mut loop_ = Loop::new();
let udp_watcher = { UdpWatcher::new(&mut loop_) };
let mut udp_watcher = { UdpWatcher::new(&mut loop_) };
let addr = next_test_ip6();
udp_watcher.bind(addr);
udp_watcher.close(||());
Expand Down Expand Up @@ -798,15 +796,15 @@ mod test {
let server_addr = next_test_ip4();
let client_addr = next_test_ip4();

let server = UdpWatcher::new(&loop_);
let mut server = UdpWatcher::new(&loop_);
assert!(server.bind(server_addr).is_ok());

rtdebug!("starting read");
let alloc: AllocCallback = |size| {
vec_to_uv_buf(vec::from_elem(size, 0u8))
};

do server.recv_start(alloc) |server, nread, buf, src, flags, status| {
do server.recv_start(alloc) |mut server, nread, buf, src, flags, status| {
server.recv_stop();
rtdebug!("i'm reading!");
assert!(status.is_none());
Expand All @@ -830,7 +828,7 @@ mod test {

do Thread::start {
let mut loop_ = Loop::new();
let client = UdpWatcher::new(&loop_);
let mut client = UdpWatcher::new(&loop_);
assert!(client.bind(client_addr).is_ok());
let msg = ~[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let buf = slice_to_uv_buf(msg);
Expand All @@ -857,15 +855,15 @@ mod test {
let server_addr = next_test_ip6();
let client_addr = next_test_ip6();

let server = UdpWatcher::new(&loop_);
let mut server = UdpWatcher::new(&loop_);
assert!(server.bind(server_addr).is_ok());

rtdebug!("starting read");
let alloc: AllocCallback = |size| {
vec_to_uv_buf(vec::from_elem(size, 0u8))
};

do server.recv_start(alloc) |server, nread, buf, src, flags, status| {
do server.recv_start(alloc) |mut server, nread, buf, src, flags, status| {
server.recv_stop();
rtdebug!("i'm reading!");
assert!(status.is_none());
Expand All @@ -889,7 +887,7 @@ mod test {

do Thread::start {
let mut loop_ = Loop::new();
let client = UdpWatcher::new(&loop_);
let mut client = UdpWatcher::new(&loop_);
assert!(client.bind(client_addr).is_ok());
let msg = ~[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let buf = slice_to_uv_buf(msg);
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/rt/uv/uvio.rs
Expand Up @@ -264,7 +264,7 @@ impl IoFactory for UvIoFactory {
}

fn udp_bind(&mut self, addr: IpAddr) -> Result<~RtioUdpSocketObject, IoError> {
let /*mut*/ watcher = UdpWatcher::new(self.uv_loop());
let mut watcher = UdpWatcher::new(self.uv_loop());
match watcher.bind(addr) {
Ok(_) => Ok(~UvUdpSocket(watcher)),
Err(uverr) => {
Expand Down Expand Up @@ -497,7 +497,7 @@ impl RtioUdpSocket for UvUdpSocket {
assert!(!sched.in_task_context());
let task_cell = Cell::new(task);
let alloc: AllocCallback = |_| unsafe { slice_to_uv_buf(*buf_ptr) };
do self.recv_start(alloc) |watcher, nread, _buf, addr, flags, status| {
do self.recv_start(alloc) |mut watcher, nread, _buf, addr, flags, status| {
let _ = flags; // XXX add handling for partials?

watcher.recv_stop();
Expand Down

5 comments on commit b03f1e7

@bors
Copy link
Contributor

@bors bors commented on b03f1e7 Jul 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at anasazi@b03f1e7

@bors
Copy link
Contributor

@bors bors commented on b03f1e7 Jul 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging anasazi/rust/fix_udp_mut = b03f1e7 into auto

@bors
Copy link
Contributor

@bors bors commented on b03f1e7 Jul 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anasazi/rust/fix_udp_mut = b03f1e7 merged ok, testing candidate = c5c0252

@bors
Copy link
Contributor

@bors bors commented on b03f1e7 Jul 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c5c0252

Please sign in to comment.