Skip to content

Commit

Permalink
std: Stop using oldcomm
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Jan 30, 2013
1 parent 87acde8 commit da4b376
Show file tree
Hide file tree
Showing 8 changed files with 429 additions and 449 deletions.
1 change: 0 additions & 1 deletion src/libstd/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ mod tests {
use arc::*;
use arc;

use core::oldcomm::*;
use core::option::{Some, None};
use core::option;
use core::pipes;
Expand Down
1 change: 0 additions & 1 deletion src/libstd/c_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#[forbid(deprecated_mode)];

use core::libc;
use core::oldcomm;
use core::option;
use core::prelude::*;
use core::ptr;
Expand Down
71 changes: 36 additions & 35 deletions src/libstd/net_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#[forbid(deprecated_mode)];

use core::libc;
use core::oldcomm;
use core::prelude::*;
use core::pipes::{stream, SharedChan};
use core::ptr;
use core::result;
use core::str;
Expand Down Expand Up @@ -113,40 +113,40 @@ enum IpGetAddrErr {
* A `result<~[ip_addr], ip_get_addr_err>` instance that will contain
* a vector of `ip_addr` results, in the case of success, or an error
* object in the case of failure
*/
*/
pub fn get_addr(node: &str, iotask: &iotask)
-> result::Result<~[IpAddr], IpGetAddrErr> {
do oldcomm::listen |output_ch| {
do str::as_buf(node) |node_ptr, len| {
unsafe {
log(debug, fmt!("slice len %?", len));
let handle = create_uv_getaddrinfo_t();
let handle_ptr = ptr::addr_of(&handle);
let handle_data = GetAddrData {
output_ch: output_ch
};
let handle_data_ptr = ptr::addr_of(&handle_data);
do interact(iotask) |loop_ptr| {
unsafe {
let result = uv_getaddrinfo(
loop_ptr,
handle_ptr,
get_addr_cb,
node_ptr,
ptr::null(),
ptr::null());
match result {
0i32 => {
-> result::Result<~[IpAddr], IpGetAddrErr> {
let (output_po, output_ch) = stream();
let output_ch = SharedChan(output_ch);
do str::as_buf(node) |node_ptr, len| {
unsafe {
log(debug, fmt!("slice len %?", len));
let handle = create_uv_getaddrinfo_t();
let handle_ptr = ptr::addr_of(&handle);
let handle_data = GetAddrData {
output_ch: output_ch.clone()
};
let handle_data_ptr = ptr::addr_of(&handle_data);
do interact(iotask) |loop_ptr| {
unsafe {
let result = uv_getaddrinfo(
loop_ptr,
handle_ptr,
get_addr_cb,
node_ptr,
ptr::null(),
ptr::null());
match result {
0i32 => {
set_data_for_req(handle_ptr, handle_data_ptr);
}
_ => {
}
_ => {
output_ch.send(result::Err(GetAddrUnknownError));
}
}
}
};
output_ch.recv()
}
}
};
output_po.recv()
}
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ pub mod v6 {
}

struct GetAddrData {
output_ch: oldcomm::Chan<result::Result<~[IpAddr],IpGetAddrErr>>
output_ch: SharedChan<result::Result<~[IpAddr],IpGetAddrErr>>
}

extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
Expand All @@ -309,6 +309,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
log(debug, ~"in get_addr_cb");
let handle_data = get_data_for_req(handle) as
*GetAddrData;
let output_ch = (*handle_data).output_ch.clone();
if status == 0i32 {
if res != (ptr::null::<addrinfo>()) {
let mut out_vec = ~[];
Expand All @@ -326,7 +327,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
else {
log(debug, ~"curr_addr is not of family AF_INET or "+
~"AF_INET6. Error.");
(*handle_data).output_ch.send(
output_ch.send(
result::Err(GetAddrUnknownError));
break;
};
Expand All @@ -344,17 +345,17 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
}
log(debug, fmt!("successful process addrinfo result, len: %?",
vec::len(out_vec)));
(*handle_data).output_ch.send(result::Ok(move out_vec));
output_ch.send(result::Ok(move out_vec));
}
else {
log(debug, ~"addrinfo pointer is NULL");
(*handle_data).output_ch.send(
output_ch.send(
result::Err(GetAddrUnknownError));
}
}
else {
log(debug, ~"status != 0 error in get_addr_cb");
(*handle_data).output_ch.send(
output_ch.send(
result::Err(GetAddrUnknownError));
}
if res != (ptr::null::<addrinfo>()) {
Expand Down
Loading

1 comment on commit da4b376

@graydon
Copy link
Contributor

Choose a reason for hiding this comment

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

\o/

Please sign in to comment.