From 08b3048c438efd661380bdc18d2ee2f91184d9a4 Mon Sep 17 00:00:00 2001 From: Jeff Olson Date: Mon, 30 Apr 2012 15:10:08 -0700 Subject: [PATCH] std: misc cleanup for uv::ll * tweaked the layout of sockaddr_in6 struct in anticipation of future use * changed several uv:ll fn signatures to use generics and be more flexible with ptr types they get passed * add uv_err_data and a help fn to return it.. packages up err_name and err_msg info from uv_get_last_error() stuff.. --- src/libstd/uv_ll.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 31d36430aec..e33c37739f3 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -250,7 +250,7 @@ enum uv_handle_type { #[cfg(target_os = "win32")] type sockaddr_in6 = { a0: *u8, a1: *u8, - a2: *u8, a3: *u8 + a2: *u8, a3: (u8, u8, u8, u8) }; mod uv_ll_struct_stubgen { @@ -777,12 +777,13 @@ unsafe fn set_data_for_uv_handle(handle: *T, rustrt::rust_uv_set_data_for_uv_handle(handle as *libc::c_void, data as *libc::c_void); } -unsafe fn get_data_for_req(req: *libc::c_void) -> *libc::c_void { - ret rustrt::rust_uv_get_data_for_req(req); +unsafe fn get_data_for_req(req: *T) -> *libc::c_void { + ret rustrt::rust_uv_get_data_for_req(req as *libc::c_void); } -unsafe fn set_data_for_req(req: *libc::c_void, - data: *libc::c_void) { - rustrt::rust_uv_set_data_for_req(req, data); +unsafe fn set_data_for_req(req: *T, + data: *U) { + rustrt::rust_uv_set_data_for_req(req as *libc::c_void, + data as *libc::c_void); } unsafe fn get_base_from_buf(buf: uv_buf_t) -> *u8 { ret rustrt::rust_uv_get_base_from_buf(buf); @@ -807,6 +808,19 @@ unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> str { err_name, err_msg); } +unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data { + let err = last_error(uv_loop); + let err_ptr = ptr::addr_of(err); + let err_name = str::unsafe::from_c_str(err_name(err_ptr)); + let err_msg = str::unsafe::from_c_str(strerror(err_ptr)); + { err_name: err_name, err_msg: err_msg } +} + +type uv_err_data = { + err_name: str, + err_msg: str +}; + #[cfg(test)] mod test { enum tcp_read_data {