Skip to content

Commit 20423fe

Browse files
committed
---
yaml --- r: 93597 b: refs/heads/try c: 8e719bd h: refs/heads/master i: 93595: 5a53493 v: v3
1 parent e9c9c6a commit 20423fe

37 files changed

+5675
-3632
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
5-
refs/heads/try: b5e602ac563422e13a18be9f79100f96359d582a
5+
refs/heads/try: 8e719bdfb5e32db67bcd62700bd6f14f597dcb89
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/mk/rt.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ LIBUV_MAKEFILE_$(1) := $$(CFG_BUILD_DIR)$$(RT_OUTPUT_DIR_$(1))/libuv/Makefile
207207

208208
$$(LIBUV_MAKEFILE_$(1)): $$(LIBUV_DEPS)
209209
(cd $(S)src/libuv/ && \
210-
$$(CFG_PYTHON) ./gyp_uv.py -f make -Dtarget_arch=$$(LIBUV_ARCH_$(1)) \
210+
$$(CFG_PYTHON) ./gyp_uv -f make -Dtarget_arch=$$(LIBUV_ARCH_$(1)) \
211211
-D ninja \
212212
-DOS=$$(LIBUV_OSTYPE_$(1)) \
213213
-Goutput_dir=$$(@D) --generator-output $$(@D))
@@ -218,7 +218,7 @@ $$(LIBUV_MAKEFILE_$(1)): $$(LIBUV_DEPS)
218218
ifdef CFG_WINDOWSY_$(1)
219219
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
220220
$$(Q)$$(MAKE) -C $$(S)src/libuv -f Makefile.mingw \
221-
CC="$$(CC) $$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
221+
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
222222
AR="$$(AR_$(1))" \
223223
V=$$(VERBOSE)
224224
$$(Q)cp $$(S)src/libuv/libuv.a $$@

branches/try/src/libextra/getopts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ pub struct Matches {
142142
}
143143

144144
/// The type returned when the command line does not conform to the
145-
/// expected format. Pass this value to <fail_str> to get an error message.
145+
/// expected format. Call the `to_err_msg` method to retrieve the
146+
/// error as a string.
146147
#[deriving(Clone, Eq, ToStr)]
147148
#[allow(missing_doc)]
148149
pub enum Fail_ {

branches/try/src/librustuv/addrinfo.rs

Lines changed: 133 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,41 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use ai = std::rt::io::net::addrinfo;
12-
use std::libc::c_int;
11+
use std::cast::transmute;
12+
use std::cell::Cell;
13+
use std::libc::{c_int, c_void};
1314
use std::ptr::null;
14-
use std::rt::BlockedTask;
15-
use std::rt::local::Local;
16-
use std::rt::sched::Scheduler;
15+
use ai = std::rt::io::net::addrinfo;
1716

18-
use net;
19-
use super::{Loop, UvError, Request, wait_until_woken_after};
2017
use uvll;
18+
use uvll::UV_GETADDRINFO;
19+
use super::{Loop, UvError, NativeHandle, status_to_maybe_uv_error};
20+
use net;
2121

22-
struct Addrinfo {
23-
handle: *uvll::addrinfo,
24-
}
22+
type GetAddrInfoCallback = ~fn(GetAddrInfoRequest, &net::UvAddrInfo, Option<UvError>);
2523

26-
struct Ctx {
27-
slot: Option<BlockedTask>,
28-
status: c_int,
29-
addrinfo: Option<Addrinfo>,
30-
}
24+
pub struct GetAddrInfoRequest(*uvll::uv_getaddrinfo_t);
3125

32-
pub struct GetAddrInfoRequest;
26+
pub struct RequestData {
27+
priv getaddrinfo_cb: Option<GetAddrInfoCallback>,
28+
}
3329

3430
impl GetAddrInfoRequest {
35-
pub fn run(loop_: &Loop, node: Option<&str>, service: Option<&str>,
36-
hints: Option<ai::Hint>) -> Result<~[ai::Info], UvError> {
31+
pub fn new() -> GetAddrInfoRequest {
32+
let req = unsafe { uvll::malloc_req(UV_GETADDRINFO) };
33+
assert!(req.is_not_null());
34+
let mut req: GetAddrInfoRequest = NativeHandle::from_native_handle(req);
35+
req.install_req_data();
36+
return req;
37+
}
38+
39+
pub fn getaddrinfo(&mut self, loop_: &Loop, node: Option<&str>,
40+
service: Option<&str>, hints: Option<ai::Hint>,
41+
cb: GetAddrInfoCallback) {
42+
3743
assert!(node.is_some() || service.is_some());
38-
let (_c_node, c_node_ptr) = match node {
44+
45+
let (c_node, c_node_ptr) = match node {
3946
Some(n) => {
4047
let c_node = n.to_c_str();
4148
let c_node_ptr = c_node.with_ref(|r| r);
@@ -44,7 +51,7 @@ impl GetAddrInfoRequest {
4451
None => (None, null())
4552
};
4653

47-
let (_c_service, c_service_ptr) = match service {
54+
let (c_service, c_service_ptr) = match service {
4855
Some(s) => {
4956
let c_service = s.to_c_str();
5057
let c_service_ptr = c_service.with_ref(|r| r);
@@ -53,13 +60,37 @@ impl GetAddrInfoRequest {
5360
None => (None, null())
5461
};
5562

63+
let cb = Cell::new(cb);
64+
let wrapper_cb: GetAddrInfoCallback = |req, addrinfo, err| {
65+
// Capture some heap values that need to stay alive for the
66+
// getaddrinfo call
67+
let _ = &c_node;
68+
let _ = &c_service;
69+
70+
let cb = cb.take();
71+
cb(req, addrinfo, err)
72+
};
73+
5674
let hint = hints.map(|hint| {
5775
let mut flags = 0;
5876
do each_ai_flag |cval, aival| {
5977
if hint.flags & (aival as uint) != 0 {
6078
flags |= cval as i32;
6179
}
6280
}
81+
/* XXX: do we really want to support these?
82+
let socktype = match hint.socktype {
83+
Some(ai::Stream) => uvll::rust_SOCK_STREAM(),
84+
Some(ai::Datagram) => uvll::rust_SOCK_DGRAM(),
85+
Some(ai::Raw) => uvll::rust_SOCK_RAW(),
86+
None => 0,
87+
};
88+
let protocol = match hint.protocol {
89+
Some(ai::UDP) => uvll::rust_IPPROTO_UDP(),
90+
Some(ai::TCP) => uvll::rust_IPPROTO_TCP(),
91+
_ => 0,
92+
};
93+
*/
6394
let socktype = 0;
6495
let protocol = 0;
6596

@@ -75,48 +106,66 @@ impl GetAddrInfoRequest {
75106
}
76107
});
77108
let hint_ptr = hint.as_ref().map_default(null(), |x| x as *uvll::addrinfo);
78-
let mut req = Request::new(uvll::UV_GETADDRINFO);
79-
80-
return match unsafe {
81-
uvll::uv_getaddrinfo(loop_.handle, req.handle,
82-
getaddrinfo_cb, c_node_ptr, c_service_ptr,
83-
hint_ptr)
84-
} {
85-
0 => {
86-
req.defuse(); // uv callback now owns this request
87-
let mut cx = Ctx { slot: None, status: 0, addrinfo: None };
88-
89-
do wait_until_woken_after(&mut cx.slot) {
90-
req.set_data(&cx);
91-
}
92109

93-
match cx.status {
94-
0 => Ok(accum_addrinfo(cx.addrinfo.get_ref())),
95-
n => Err(UvError(n))
96-
}
110+
self.get_req_data().getaddrinfo_cb = Some(wrapper_cb);
111+
112+
unsafe {
113+
assert!(0 == uvll::getaddrinfo(loop_.native_handle(),
114+
self.native_handle(),
115+
getaddrinfo_cb,
116+
c_node_ptr,
117+
c_service_ptr,
118+
hint_ptr));
119+
}
120+
121+
extern "C" fn getaddrinfo_cb(req: *uvll::uv_getaddrinfo_t,
122+
status: c_int,
123+
res: *uvll::addrinfo) {
124+
let mut req: GetAddrInfoRequest = NativeHandle::from_native_handle(req);
125+
let err = status_to_maybe_uv_error(status);
126+
let addrinfo = net::UvAddrInfo(res);
127+
let data = req.get_req_data();
128+
(*data.getaddrinfo_cb.get_ref())(req, &addrinfo, err);
129+
unsafe {
130+
uvll::freeaddrinfo(res);
97131
}
98-
n => Err(UvError(n))
99-
};
132+
}
133+
}
100134

135+
fn get_loop(&self) -> Loop {
136+
unsafe {
137+
Loop {
138+
handle: uvll::get_loop_from_fs_req(self.native_handle())
139+
}
140+
}
141+
}
101142

102-
extern fn getaddrinfo_cb(req: *uvll::uv_getaddrinfo_t,
103-
status: c_int,
104-
res: *uvll::addrinfo) {
105-
let req = Request::wrap(req);
106-
assert!(status != uvll::ECANCELED);
107-
let cx: &mut Ctx = unsafe { req.get_data() };
108-
cx.status = status;
109-
cx.addrinfo = Some(Addrinfo { handle: res });
143+
fn install_req_data(&mut self) {
144+
let req = self.native_handle() as *uvll::uv_getaddrinfo_t;
145+
let data = ~RequestData {
146+
getaddrinfo_cb: None
147+
};
148+
unsafe {
149+
let data = transmute::<~RequestData, *c_void>(data);
150+
uvll::set_data_for_req(req, data);
151+
}
152+
}
110153

111-
let sched: ~Scheduler = Local::take();
112-
sched.resume_blocked_task_immediately(cx.slot.take_unwrap());
154+
fn get_req_data<'r>(&'r mut self) -> &'r mut RequestData {
155+
unsafe {
156+
let data = uvll::get_data_for_req(self.native_handle());
157+
let data = transmute::<&*c_void, &mut ~RequestData>(&data);
158+
return &mut **data;
113159
}
114160
}
115-
}
116161

117-
impl Drop for Addrinfo {
118-
fn drop(&mut self) {
119-
unsafe { uvll::uv_freeaddrinfo(self.handle) }
162+
fn delete(self) {
163+
unsafe {
164+
let data = uvll::get_data_for_req(self.native_handle());
165+
let _data = transmute::<*c_void, ~RequestData>(data);
166+
uvll::set_data_for_req(self.native_handle(), null::<()>());
167+
uvll::free_req(self.native_handle());
168+
}
120169
}
121170
}
122171

@@ -135,13 +184,15 @@ fn each_ai_flag(_f: &fn(c_int, ai::Flag)) {
135184
}
136185

137186
// Traverse the addrinfo linked list, producing a vector of Rust socket addresses
138-
pub fn accum_addrinfo(addr: &Addrinfo) -> ~[ai::Info] {
187+
pub fn accum_addrinfo(addr: &net::UvAddrInfo) -> ~[ai::Info] {
139188
unsafe {
140-
let mut addr = addr.handle;
189+
let &net::UvAddrInfo(addr) = addr;
190+
let mut addr = addr;
141191

142192
let mut addrs = ~[];
143193
loop {
144-
let rustaddr = net::sockaddr_to_socket_addr((*addr).ai_addr);
194+
let uvaddr = net::sockaddr_to_UvSocketAddr((*addr).ai_addr);
195+
let rustaddr = net::uv_socket_addr_to_socket_addr(uvaddr);
145196

146197
let mut flags = 0;
147198
do each_ai_flag |cval, aival| {
@@ -184,27 +235,39 @@ pub fn accum_addrinfo(addr: &Addrinfo) -> ~[ai::Info] {
184235
}
185236
}
186237

238+
impl NativeHandle<*uvll::uv_getaddrinfo_t> for GetAddrInfoRequest {
239+
fn from_native_handle(handle: *uvll::uv_getaddrinfo_t) -> GetAddrInfoRequest {
240+
GetAddrInfoRequest(handle)
241+
}
242+
fn native_handle(&self) -> *uvll::uv_getaddrinfo_t {
243+
match self { &GetAddrInfoRequest(ptr) => ptr }
244+
}
245+
}
246+
187247
#[cfg(test)]
188248
mod test {
249+
use Loop;
189250
use std::rt::io::net::ip::{SocketAddr, Ipv4Addr};
190251
use super::*;
191-
use super::super::local_loop;
192252

193253
#[test]
194254
fn getaddrinfo_test() {
195-
match GetAddrInfoRequest::run(local_loop(), Some("localhost"), None, None) {
196-
Ok(infos) => {
197-
let mut found_local = false;
198-
let local_addr = &SocketAddr {
199-
ip: Ipv4Addr(127, 0, 0, 1),
200-
port: 0
201-
};
202-
for addr in infos.iter() {
203-
found_local = found_local || addr.address == *local_addr;
204-
}
205-
assert!(found_local);
255+
let mut loop_ = Loop::new();
256+
let mut req = GetAddrInfoRequest::new();
257+
do req.getaddrinfo(&loop_, Some("localhost"), None, None) |_, addrinfo, _| {
258+
let sockaddrs = accum_addrinfo(addrinfo);
259+
let mut found_local = false;
260+
let local_addr = &SocketAddr {
261+
ip: Ipv4Addr(127, 0, 0, 1),
262+
port: 0
263+
};
264+
for addr in sockaddrs.iter() {
265+
found_local = found_local || addr.address == *local_addr;
206266
}
207-
Err(e) => fail!("{:?}", e),
267+
assert!(found_local);
208268
}
269+
loop_.run();
270+
loop_.close();
271+
req.delete();
209272
}
210273
}

0 commit comments

Comments
 (0)