1
Fork 0

Upgrade libuv to the current master (again)

This is a reopening of the libuv-upgrade part of #8645. Hopefully this won't
cause random segfaults all over the place. The windows regression in testing
should also be fixed (it shouldn't build the whole compiler twice).

A notable difference from before is that gyp is now a git submodule instead of
always git-cloned at make time. This allows bundling for releases more easily.

Closes #8850
This commit is contained in:
Alex Crichton 2013-08-18 17:11:45 -07:00
parent d39cec65b0
commit b4c36c2d1b
17 changed files with 116 additions and 148 deletions

5
.gitmodules vendored
View file

@ -4,5 +4,8 @@
branch = master branch = master
[submodule "src/libuv"] [submodule "src/libuv"]
path = src/libuv path = src/libuv
url = https://github.com/brson/libuv.git url = https://github.com/alexcrichton/libuv.git
branch = master branch = master
[submodule "src/gyp"]
path = src/gyp
url = https://git.chromium.org/external/gyp.git

View file

@ -12,7 +12,7 @@ PKG_ICO = $(S)src/etc/pkg/rust-logo.ico
PKG_EXE = $(PKG_DIR)-install.exe PKG_EXE = $(PKG_DIR)-install.exe
endif endif
PKG_GITMODULES := $(S)src/libuv $(S)src/llvm PKG_GITMODULES := $(S)src/libuv $(S)src/llvm $(S)src/gyp
PKG_FILES := \ PKG_FILES := \
$(S)COPYRIGHT \ $(S)COPYRIGHT \

View file

@ -170,16 +170,28 @@ LIBUV_DEPS := $$(wildcard \
$$(S)src/libuv/*/*/*/*) $$(S)src/libuv/*/*/*/*)
endif endif
LIBUV_MAKEFILE_$(1)_$(2) := $$(CFG_BUILD_DIR)$$(RT_BUILD_DIR_$(1)_$(2))/libuv/Makefile
LIBUV_NO_LOAD = run-benchmarks.target.mk run-tests.target.mk \
uv_dtrace_header.target.mk uv_dtrace_provider.target.mk
export PYTHONPATH := $(PYTHONPATH):$$(S)src/gyp/pylib
$$(LIBUV_MAKEFILE_$(1)_$(2)):
(cd $(S)src/libuv/ && \
./gyp_uv -f make -Dtarget_arch=$$(LIBUV_ARCH_$(1)) -D ninja \
-Goutput_dir=$$(@D) --generator-output $$(@D))
# XXX: Shouldn't need platform-specific conditions here # XXX: Shouldn't need platform-specific conditions here
ifdef CFG_WINDOWSY_$(1) ifdef CFG_WINDOWSY_$(1)
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \ $$(Q)$$(MAKE) -C $$(S)src/libuv -f Makefile.mingw \
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \ CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
OS=mingw \ AR="$$(AR_$(1))" \
V=$$(VERBOSE) V=$$(VERBOSE)
$$(Q)cp $$(S)src/libuv/libuv.a $$@
else ifeq ($(OSTYPE_$(1)), linux-androideabi) else ifeq ($(OSTYPE_$(1)), linux-androideabi)
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1)_$(2))
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \ $$(Q)$$(MAKE) -C $$(@D) \
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \ CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \ LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
CC="$$(CC_$(1))" \ CC="$$(CC_$(1))" \
@ -187,19 +199,22 @@ $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
LINK="$$(CXX_$(1))" \ LINK="$$(CXX_$(1))" \
AR="$$(AR_$(1))" \ AR="$$(AR_$(1))" \
PLATFORM=android \ PLATFORM=android \
BUILDTYPE=Release \
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
host=android OS=linux \ host=android OS=linux \
builddir="." \
BUILDTYPE=Release \
NO_LOAD="$$(LIBUV_NO_LOAD)" \
V=$$(VERBOSE) V=$$(VERBOSE)
else else
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1)_$(2))
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \ $$(Q)$$(MAKE) -C $$(@D) \
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \ CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \ LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
CC="$$(CC_$(1))" \ CC="$$(CC_$(1))" \
CXX="$$(CXX_$(1))" \ CXX="$$(CXX_$(1))" \
AR="$$(AR_$(1))" \ AR="$$(AR_$(1))" \
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \ builddir="." \
BUILDTYPE=Release \
NO_LOAD="$$(LIBUV_NO_LOAD)" \
V=$$(VERBOSE) V=$$(VERBOSE)
endif endif

1
src/gyp Submodule

@ -0,0 +1 @@
Subproject commit f407f09c94e00d2d570e8e42114e3f6848b2deb2

View file

@ -182,7 +182,7 @@ mod test {
do run_in_newsched_task { do run_in_newsched_task {
let mut called = false; let mut called = false;
do io_error::cond.trap(|e| { do io_error::cond.trap(|e| {
assert!(e.kind == ConnectionRefused); assert_eq!(e.kind, ConnectionRefused);
called = true; called = true;
}).inside { }).inside {
let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 };

View file

@ -17,7 +17,7 @@ use ptr::null;
use rt::uv::uvll; use rt::uv::uvll;
use rt::uv::uvll::UV_GETADDRINFO; use rt::uv::uvll::UV_GETADDRINFO;
use rt::uv::{Loop, UvError, NativeHandle}; use rt::uv::{Loop, UvError, NativeHandle};
use rt::uv::status_to_maybe_uv_error_with_loop; use rt::uv::status_to_maybe_uv_error;
use rt::uv::net::UvAddrInfo; use rt::uv::net::UvAddrInfo;
type GetAddrInfoCallback = ~fn(GetAddrInfoRequest, &UvAddrInfo, Option<UvError>); type GetAddrInfoCallback = ~fn(GetAddrInfoRequest, &UvAddrInfo, Option<UvError>);
@ -90,8 +90,7 @@ impl GetAddrInfoRequest {
status: c_int, status: c_int,
res: *uvll::addrinfo) { res: *uvll::addrinfo) {
let mut req: GetAddrInfoRequest = NativeHandle::from_native_handle(req); let mut req: GetAddrInfoRequest = NativeHandle::from_native_handle(req);
let loop_ = req.get_loop(); let err = status_to_maybe_uv_error(status);
let err = status_to_maybe_uv_error_with_loop(loop_.native_handle(), status);
let addrinfo = UvAddrInfo(res); let addrinfo = UvAddrInfo(res);
let data = req.get_req_data(); let data = req.get_req_data();
(*data.getaddrinfo_cb.get_ref())(req, &addrinfo, err); (*data.getaddrinfo_cb.get_ref())(req, &addrinfo, err);

View file

@ -34,7 +34,7 @@ impl AsyncWatcher {
extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) { extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle); let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
let status = status_to_maybe_uv_error(watcher, status); let status = status_to_maybe_uv_error(status);
let data = watcher.get_watcher_data(); let data = watcher.get_watcher_data();
let cb = data.async_cb.get_ref(); let cb = data.async_cb.get_ref();
(*cb)(watcher, status); (*cb)(watcher, status);

View file

@ -12,7 +12,7 @@ use prelude::*;
use ptr::null; use ptr::null;
use libc::c_void; use libc::c_void;
use rt::uv::{Request, NativeHandle, Loop, FsCallback, Buf, use rt::uv::{Request, NativeHandle, Loop, FsCallback, Buf,
status_to_maybe_uv_error_with_loop, UvError}; status_to_maybe_uv_error, UvError};
use rt::uv::uvll; use rt::uv::uvll;
use rt::uv::uvll::*; use rt::uv::uvll::*;
use super::super::io::support::PathLike; use super::super::io::support::PathLike;
@ -62,7 +62,7 @@ impl FsRequest {
pub fn open_sync<P: PathLike>(loop_: &Loop, path: &P, flags: int, mode: int) pub fn open_sync<P: PathLike>(loop_: &Loop, path: &P, flags: int, mode: int)
-> Result<int, UvError> { -> Result<int, UvError> {
let result = FsRequest::open_common(loop_, path, flags, mode, None); let result = FsRequest::open_common(loop_, path, flags, mode, None);
sync_cleanup(loop_, result) sync_cleanup(result)
} }
fn unlink_common<P: PathLike>(loop_: &Loop, path: &P, cb: Option<FsCallback>) -> int { fn unlink_common<P: PathLike>(loop_: &Loop, path: &P, cb: Option<FsCallback>) -> int {
@ -83,11 +83,11 @@ impl FsRequest {
} }
pub fn unlink<P: PathLike>(loop_: &Loop, path: &P, cb: FsCallback) { pub fn unlink<P: PathLike>(loop_: &Loop, path: &P, cb: FsCallback) {
let result = FsRequest::unlink_common(loop_, path, Some(cb)); let result = FsRequest::unlink_common(loop_, path, Some(cb));
sync_cleanup(loop_, result); sync_cleanup(result);
} }
pub fn unlink_sync<P: PathLike>(loop_: &Loop, path: &P) -> Result<int, UvError> { pub fn unlink_sync<P: PathLike>(loop_: &Loop, path: &P) -> Result<int, UvError> {
let result = FsRequest::unlink_common(loop_, path, None); let result = FsRequest::unlink_common(loop_, path, None);
sync_cleanup(loop_, result) sync_cleanup(result)
} }
pub fn install_req_data(&self, cb: Option<FsCallback>) { pub fn install_req_data(&self, cb: Option<FsCallback>) {
@ -140,9 +140,9 @@ impl NativeHandle<*uvll::uv_fs_t> for FsRequest {
} }
} }
fn sync_cleanup(loop_: &Loop, result: int) fn sync_cleanup(result: int)
-> Result<int, UvError> { -> Result<int, UvError> {
match status_to_maybe_uv_error_with_loop(loop_.native_handle(), result as i32) { match status_to_maybe_uv_error(result as i32) {
Some(err) => Err(err), Some(err) => Err(err),
None => Ok(result) None => Ok(result)
} }
@ -186,7 +186,7 @@ impl FileDescriptor {
pub fn write_sync(&mut self, loop_: &Loop, buf: Buf, offset: i64) pub fn write_sync(&mut self, loop_: &Loop, buf: Buf, offset: i64)
-> Result<int, UvError> { -> Result<int, UvError> {
let result = self.write_common(loop_, buf, offset, None); let result = self.write_common(loop_, buf, offset, None);
sync_cleanup(loop_, result) sync_cleanup(result)
} }
fn read_common(&mut self, loop_: &Loop, buf: Buf, fn read_common(&mut self, loop_: &Loop, buf: Buf,
@ -214,7 +214,7 @@ impl FileDescriptor {
pub fn read_sync(&mut self, loop_: &Loop, buf: Buf, offset: i64) pub fn read_sync(&mut self, loop_: &Loop, buf: Buf, offset: i64)
-> Result<int, UvError> { -> Result<int, UvError> {
let result = self.read_common(loop_, buf, offset, None); let result = self.read_common(loop_, buf, offset, None);
sync_cleanup(loop_, result) sync_cleanup(result)
} }
fn close_common(self, loop_: &Loop, cb: Option<FsCallback>) -> int { fn close_common(self, loop_: &Loop, cb: Option<FsCallback>) -> int {
@ -236,12 +236,11 @@ impl FileDescriptor {
} }
pub fn close_sync(self, loop_: &Loop) -> Result<int, UvError> { pub fn close_sync(self, loop_: &Loop) -> Result<int, UvError> {
let result = self.close_common(loop_, None); let result = self.close_common(loop_, None);
sync_cleanup(loop_, result) sync_cleanup(result)
} }
} }
extern fn compl_cb(req: *uv_fs_t) { extern fn compl_cb(req: *uv_fs_t) {
let mut req: FsRequest = NativeHandle::from_native_handle(req); let mut req: FsRequest = NativeHandle::from_native_handle(req);
let loop_ = req.get_loop();
// pull the user cb out of the req data // pull the user cb out of the req data
let cb = { let cb = {
let data = req.get_req_data(); let data = req.get_req_data();
@ -252,8 +251,7 @@ extern fn compl_cb(req: *uv_fs_t) {
// in uv_fs_open calls, the result will be the fd in the // in uv_fs_open calls, the result will be the fd in the
// case of success, otherwise it's -1 indicating an error // case of success, otherwise it's -1 indicating an error
let result = req.get_result(); let result = req.get_result();
let status = status_to_maybe_uv_error_with_loop( let status = status_to_maybe_uv_error(result);
loop_.native_handle(), result);
// we have a req and status, call the user cb.. // we have a req and status, call the user cb..
// only giving the user a ref to the FsRequest, as we // only giving the user a ref to the FsRequest, as we
// have to clean it up, afterwards (and they aren't really // have to clean it up, afterwards (and they aren't really

View file

@ -43,7 +43,7 @@ impl IdleWatcher {
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle); let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
let data = idle_watcher.get_watcher_data(); let data = idle_watcher.get_watcher_data();
let cb: &IdleCallback = data.idle_cb.get_ref(); let cb: &IdleCallback = data.idle_cb.get_ref();
let status = status_to_maybe_uv_error(idle_watcher, status); let status = status_to_maybe_uv_error(status);
(*cb)(idle_watcher, status); (*cb)(idle_watcher, status);
} }
} }
@ -57,7 +57,7 @@ impl IdleWatcher {
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle); let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
let data = idle_watcher.get_watcher_data(); let data = idle_watcher.get_watcher_data();
let cb: &IdleCallback = data.idle_cb.get_ref(); let cb: &IdleCallback = data.idle_cb.get_ref();
let status = status_to_maybe_uv_error(idle_watcher, status); let status = status_to_maybe_uv_error(status);
(*cb)(idle_watcher, status); (*cb)(idle_watcher, status);
} }
} }

View file

@ -204,12 +204,12 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
// XXX: Need to define the error constants like EOF so they can be // XXX: Need to define the error constants like EOF so they can be
// compared to the UvError type // compared to the UvError type
pub struct UvError(uvll::uv_err_t); pub struct UvError(c_int);
impl UvError { impl UvError {
pub fn name(&self) -> ~str { pub fn name(&self) -> ~str {
unsafe { unsafe {
let inner = match self { &UvError(ref a) => a }; let inner = match self { &UvError(a) => a };
let name_str = uvll::err_name(inner); let name_str = uvll::err_name(inner);
assert!(name_str.is_not_null()); assert!(name_str.is_not_null());
from_c_str(name_str) from_c_str(name_str)
@ -218,7 +218,7 @@ impl UvError {
pub fn desc(&self) -> ~str { pub fn desc(&self) -> ~str {
unsafe { unsafe {
let inner = match self { &UvError(ref a) => a }; let inner = match self { &UvError(a) => a };
let desc_str = uvll::strerror(inner); let desc_str = uvll::strerror(inner);
assert!(desc_str.is_not_null()); assert!(desc_str.is_not_null());
from_c_str(desc_str) from_c_str(desc_str)
@ -226,7 +226,7 @@ impl UvError {
} }
pub fn is_eof(&self) -> bool { pub fn is_eof(&self) -> bool {
self.code == uvll::EOF **self == uvll::EOF
} }
} }
@ -238,18 +238,10 @@ impl ToStr for UvError {
#[test] #[test]
fn error_smoke_test() { fn error_smoke_test() {
let err = uvll::uv_err_t { code: 1, sys_errno_: 1 }; let err: UvError = UvError(uvll::EOF);
let err: UvError = UvError(err);
assert_eq!(err.to_str(), ~"EOF: end of file"); assert_eq!(err.to_str(), ~"EOF: end of file");
} }
pub fn last_uv_error<H, W: Watcher + NativeHandle<*H>>(watcher: &W) -> UvError {
unsafe {
let loop_ = watcher.event_loop();
UvError(uvll::last_error(loop_.native_handle()))
}
}
pub fn uv_error_to_io_error(uverr: UvError) -> IoError { pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
unsafe { unsafe {
// Importing error constants // Importing error constants
@ -257,10 +249,10 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
use rt::io::*; use rt::io::*;
// uv error descriptions are static // uv error descriptions are static
let c_desc = uvll::strerror(&*uverr); let c_desc = uvll::strerror(*uverr);
let desc = str::raw::c_str_to_static_slice(c_desc); let desc = str::raw::c_str_to_static_slice(c_desc);
let kind = match uverr.code { let kind = match *uverr {
UNKNOWN => OtherIoError, UNKNOWN => OtherIoError,
OK => OtherIoError, OK => OtherIoError,
EOF => EndOfFile, EOF => EndOfFile,
@ -268,8 +260,8 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
ECONNREFUSED => ConnectionRefused, ECONNREFUSED => ConnectionRefused,
ECONNRESET => ConnectionReset, ECONNRESET => ConnectionReset,
EPIPE => BrokenPipe, EPIPE => BrokenPipe,
_ => { err => {
rtdebug!("uverr.code %u", uverr.code as uint); rtdebug!("uverr.code %d", err as int);
// XXX: Need to map remaining uv error types // XXX: Need to map remaining uv error types
OtherIoError OtherIoError
} }
@ -284,30 +276,12 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
} }
/// Given a uv handle, convert a callback status to a UvError /// Given a uv handle, convert a callback status to a UvError
pub fn status_to_maybe_uv_error_with_loop( pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
loop_: *uvll::uv_loop_t, {
status: c_int) -> Option<UvError> { if status >= 0 {
if status != -1 {
None None
} else { } else {
unsafe { Some(UvError(status))
rtdebug!("loop: %x", loop_ as uint);
let err = uvll::last_error(loop_);
Some(UvError(err))
}
}
}
/// Given a uv handle, convert a callback status to a UvError
pub fn status_to_maybe_uv_error<T, U: Watcher + NativeHandle<*T>>(handle: U,
status: c_int) -> Option<UvError> {
if status != -1 {
None
} else {
unsafe {
rtdebug!("handle: %x", handle.native_handle() as uint);
let loop_ = uvll::get_loop_for_uv_handle(handle.native_handle());
status_to_maybe_uv_error_with_loop(loop_, status)
}
} }
} }

View file

@ -16,7 +16,6 @@ use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback
use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle, NullCallback, use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle, NullCallback,
status_to_maybe_uv_error}; status_to_maybe_uv_error};
use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr}; use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr};
use rt::uv::last_uv_error;
use vec; use vec;
use str; use str;
use from_str::{FromStr}; use from_str::{FromStr};
@ -161,7 +160,7 @@ impl StreamWatcher {
rtdebug!("buf len: %d", buf.len as int); rtdebug!("buf len: %d", buf.len as int);
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(stream); let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(stream);
let cb = stream_watcher.get_watcher_data().read_cb.get_ref(); let cb = stream_watcher.get_watcher_data().read_cb.get_ref();
let status = status_to_maybe_uv_error(stream_watcher, nread as c_int); let status = status_to_maybe_uv_error(nread as c_int);
(*cb)(stream_watcher, nread as int, buf, status); (*cb)(stream_watcher, nread as int, buf, status);
} }
} }
@ -191,7 +190,7 @@ impl StreamWatcher {
let mut stream_watcher = write_request.stream(); let mut stream_watcher = write_request.stream();
write_request.delete(); write_request.delete();
let cb = stream_watcher.get_watcher_data().write_cb.take_unwrap(); let cb = stream_watcher.get_watcher_data().write_cb.take_unwrap();
let status = status_to_maybe_uv_error(stream_watcher, status); let status = status_to_maybe_uv_error(status);
cb(stream_watcher, status); cb(stream_watcher, status);
} }
} }
@ -256,7 +255,7 @@ impl TcpWatcher {
}; };
match result { match result {
0 => Ok(()), 0 => Ok(()),
_ => Err(last_uv_error(self)), _ => Err(UvError(result)),
} }
} }
} }
@ -284,7 +283,7 @@ impl TcpWatcher {
let mut stream_watcher = connect_request.stream(); let mut stream_watcher = connect_request.stream();
connect_request.delete(); connect_request.delete();
let cb = stream_watcher.get_watcher_data().connect_cb.take_unwrap(); let cb = stream_watcher.get_watcher_data().connect_cb.take_unwrap();
let status = status_to_maybe_uv_error(stream_watcher, status); let status = status_to_maybe_uv_error(status);
cb(stream_watcher, status); cb(stream_watcher, status);
} }
} }
@ -307,7 +306,7 @@ impl TcpWatcher {
rtdebug!("connection_cb"); rtdebug!("connection_cb");
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(handle); let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(handle);
let cb = stream_watcher.get_watcher_data().connect_cb.get_ref(); let cb = stream_watcher.get_watcher_data().connect_cb.get_ref();
let status = status_to_maybe_uv_error(stream_watcher, status); let status = status_to_maybe_uv_error(status);
(*cb)(stream_watcher, status); (*cb)(stream_watcher, status);
} }
} }
@ -351,7 +350,7 @@ impl UdpWatcher {
}; };
match result { match result {
0 => Ok(()), 0 => Ok(()),
_ => Err(last_uv_error(self)), _ => Err(UvError(result)),
} }
} }
} }
@ -384,7 +383,7 @@ impl UdpWatcher {
rtdebug!("buf len: %d", buf.len as int); rtdebug!("buf len: %d", buf.len as int);
let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle); let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle);
let cb = udp_watcher.get_watcher_data().udp_recv_cb.get_ref(); let cb = udp_watcher.get_watcher_data().udp_recv_cb.get_ref();
let status = status_to_maybe_uv_error(udp_watcher, nread as c_int); let status = status_to_maybe_uv_error(nread as c_int);
let addr = uv_socket_addr_to_socket_addr(sockaddr_to_UvSocketAddr(addr)); let addr = uv_socket_addr_to_socket_addr(sockaddr_to_UvSocketAddr(addr));
(*cb)(udp_watcher, nread as int, buf, addr, flags as uint, status); (*cb)(udp_watcher, nread as int, buf, addr, flags as uint, status);
} }
@ -419,7 +418,7 @@ impl UdpWatcher {
let mut udp_watcher = send_request.handle(); let mut udp_watcher = send_request.handle();
send_request.delete(); send_request.delete();
let cb = udp_watcher.get_watcher_data().udp_send_cb.take_unwrap(); let cb = udp_watcher.get_watcher_data().udp_send_cb.take_unwrap();
let status = status_to_maybe_uv_error(udp_watcher, status); let status = status_to_maybe_uv_error(status);
cb(udp_watcher, status); cb(udp_watcher, status);
} }
} }

View file

@ -43,7 +43,7 @@ impl TimerWatcher {
let mut watcher: TimerWatcher = NativeHandle::from_native_handle(handle); let mut watcher: TimerWatcher = NativeHandle::from_native_handle(handle);
let data = watcher.get_watcher_data(); let data = watcher.get_watcher_data();
let cb = data.timer_cb.get_ref(); let cb = data.timer_cb.get_ref();
let status = status_to_maybe_uv_error(watcher, status); let status = status_to_maybe_uv_error(status);
(*cb)(watcher, status); (*cb)(watcher, status);
} }
} }

View file

@ -154,7 +154,7 @@ fn socket_name<T, U: Watcher + NativeHandle<*T>>(sk: SocketNameKind,
}; };
if r != 0 { if r != 0 {
let status = status_to_maybe_uv_error(handle, r); let status = status_to_maybe_uv_error(r);
return Err(uv_error_to_io_error(status.unwrap())); return Err(uv_error_to_io_error(status.unwrap()));
} }
@ -728,7 +728,7 @@ impl RtioTcpAcceptor for UvTcpAcceptor {
uvll::tcp_simultaneous_accepts(self_.listener.watcher.native_handle(), 1 as c_int) uvll::tcp_simultaneous_accepts(self_.listener.watcher.native_handle(), 1 as c_int)
}; };
match status_to_maybe_uv_error(self_.listener.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -741,7 +741,7 @@ impl RtioTcpAcceptor for UvTcpAcceptor {
uvll::tcp_simultaneous_accepts(self_.listener.watcher.native_handle(), 0 as c_int) uvll::tcp_simultaneous_accepts(self_.listener.watcher.native_handle(), 0 as c_int)
}; };
match status_to_maybe_uv_error(self_.listener.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -862,7 +862,7 @@ impl RtioTcpStream for UvTcpStream {
do self.home_for_io |self_| { do self.home_for_io |self_| {
let r = unsafe { uvll::tcp_nodelay(self_.watcher.native_handle(), 0 as c_int) }; let r = unsafe { uvll::tcp_nodelay(self_.watcher.native_handle(), 0 as c_int) };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -873,7 +873,7 @@ impl RtioTcpStream for UvTcpStream {
do self.home_for_io |self_| { do self.home_for_io |self_| {
let r = unsafe { uvll::tcp_nodelay(self_.watcher.native_handle(), 1 as c_int) }; let r = unsafe { uvll::tcp_nodelay(self_.watcher.native_handle(), 1 as c_int) };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -887,7 +887,7 @@ impl RtioTcpStream for UvTcpStream {
delay_in_seconds as c_uint) delay_in_seconds as c_uint)
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -900,7 +900,7 @@ impl RtioTcpStream for UvTcpStream {
uvll::tcp_keepalive(self_.watcher.native_handle(), 0 as c_int, 0 as c_uint) uvll::tcp_keepalive(self_.watcher.native_handle(), 0 as c_int, 0 as c_uint)
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -1012,7 +1012,7 @@ impl RtioUdpSocket for UvUdpSocket {
} }
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -1028,7 +1028,7 @@ impl RtioUdpSocket for UvUdpSocket {
} }
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -1042,7 +1042,7 @@ impl RtioUdpSocket for UvUdpSocket {
uvll::udp_set_multicast_loop(self_.watcher.native_handle(), 1 as c_int) uvll::udp_set_multicast_loop(self_.watcher.native_handle(), 1 as c_int)
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -1056,7 +1056,7 @@ impl RtioUdpSocket for UvUdpSocket {
uvll::udp_set_multicast_loop(self_.watcher.native_handle(), 0 as c_int) uvll::udp_set_multicast_loop(self_.watcher.native_handle(), 0 as c_int)
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -1070,7 +1070,7 @@ impl RtioUdpSocket for UvUdpSocket {
uvll::udp_set_multicast_ttl(self_.watcher.native_handle(), ttl as c_int) uvll::udp_set_multicast_ttl(self_.watcher.native_handle(), ttl as c_int)
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -1084,7 +1084,7 @@ impl RtioUdpSocket for UvUdpSocket {
uvll::udp_set_ttl(self_.watcher.native_handle(), ttl as c_int) uvll::udp_set_ttl(self_.watcher.native_handle(), ttl as c_int)
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -1098,7 +1098,7 @@ impl RtioUdpSocket for UvUdpSocket {
uvll::udp_set_broadcast(self_.watcher.native_handle(), 1 as c_int) uvll::udp_set_broadcast(self_.watcher.native_handle(), 1 as c_int)
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }
@ -1112,7 +1112,7 @@ impl RtioUdpSocket for UvUdpSocket {
uvll::udp_set_broadcast(self_.watcher.native_handle(), 0 as c_int) uvll::udp_set_broadcast(self_.watcher.native_handle(), 0 as c_int)
}; };
match status_to_maybe_uv_error(self_.watcher, r) { match status_to_maybe_uv_error(r) {
Some(err) => Err(uv_error_to_io_error(err)), Some(err) => Err(uv_error_to_io_error(err)),
None => Ok(()) None => Ok(())
} }

View file

@ -37,21 +37,34 @@ use libc::{malloc, free};
use libc; use libc;
use prelude::*; use prelude::*;
use ptr; use ptr;
use str;
use vec; use vec;
pub static UNKNOWN: c_int = -1; pub use self::errors::*;
pub static OK: c_int = 0;
pub static EOF: c_int = 1;
pub static EADDRINFO: c_int = 2;
pub static EACCES: c_int = 3;
pub static ECONNREFUSED: c_int = 12;
pub static ECONNRESET: c_int = 13;
pub static EPIPE: c_int = 36;
pub struct uv_err_t { pub static OK: c_int = 0;
code: c_int, pub static EOF: c_int = -4095;
sys_errno_: c_int pub static UNKNOWN: c_int = -4094;
// uv-errno.h redefines error codes for windows, but not for unix...
#[cfg(windows)]
pub mod errors {
use libc::c_int;
pub static EACCES: c_int = -4093;
pub static ECONNREFUSED: c_int = -4079;
pub static ECONNRESET: c_int = -4078;
pub static EPIPE: c_int = -4048;
}
#[cfg(not(windows))]
pub mod errors {
use libc;
use libc::c_int;
pub static EACCES: c_int = -libc::EACCES;
pub static ECONNREFUSED: c_int = -libc::ECONNREFUSED;
pub static ECONNRESET: c_int = -libc::ECONNRESET;
pub static EPIPE: c_int = -libc::EPIPE;
} }
pub struct uv_buf_t { pub struct uv_buf_t {
@ -537,20 +550,12 @@ pub unsafe fn read_stop(stream: *uv_stream_t) -> c_int {
return rust_uv_read_stop(stream as *c_void); return rust_uv_read_stop(stream as *c_void);
} }
pub unsafe fn last_error(loop_handle: *c_void) -> uv_err_t { pub unsafe fn strerror(err: c_int) -> *c_char {
#[fixed_stack_segment]; #[inline(never)]; #[fixed_stack_segment]; #[inline(never)];
return rust_uv_last_error(loop_handle);
}
pub unsafe fn strerror(err: *uv_err_t) -> *c_char {
#[fixed_stack_segment]; #[inline(never)];
return rust_uv_strerror(err); return rust_uv_strerror(err);
} }
pub unsafe fn err_name(err: *uv_err_t) -> *c_char { pub unsafe fn err_name(err: c_int) -> *c_char {
#[fixed_stack_segment]; #[inline(never)]; #[fixed_stack_segment]; #[inline(never)];
return rust_uv_err_name(err); return rust_uv_err_name(err);
} }
@ -787,23 +792,6 @@ pub unsafe fn freeaddrinfo(ai: *addrinfo) {
rust_uv_freeaddrinfo(ai); rust_uv_freeaddrinfo(ai);
} }
pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str {
let err = last_error(uv_loop);
let err_ptr = ptr::to_unsafe_ptr(&err);
let err_name = str::raw::from_c_str(err_name(err_ptr));
let err_msg = str::raw::from_c_str(strerror(err_ptr));
return fmt!("LIBUV ERROR: name: %s msg: %s",
err_name, err_msg);
}
pub unsafe fn get_last_err_data(uv_loop: *c_void) -> uv_err_data {
let err = last_error(uv_loop);
let err_ptr = ptr::to_unsafe_ptr(&err);
let err_name = str::raw::from_c_str(err_name(err_ptr));
let err_msg = str::raw::from_c_str(strerror(err_ptr));
uv_err_data { err_name: err_name, err_msg: err_msg }
}
pub struct uv_err_data { pub struct uv_err_data {
err_name: ~str, err_name: ~str,
err_msg: ~str, err_msg: ~str,
@ -835,9 +823,8 @@ extern {
cb: uv_async_cb) -> c_int; cb: uv_async_cb) -> c_int;
fn rust_uv_tcp_init(loop_handle: *c_void, handle_ptr: *uv_tcp_t) -> c_int; fn rust_uv_tcp_init(loop_handle: *c_void, handle_ptr: *uv_tcp_t) -> c_int;
fn rust_uv_buf_init(out_buf: *uv_buf_t, base: *u8, len: size_t); fn rust_uv_buf_init(out_buf: *uv_buf_t, base: *u8, len: size_t);
fn rust_uv_last_error(loop_handle: *c_void) -> uv_err_t; fn rust_uv_strerror(err: c_int) -> *c_char;
fn rust_uv_strerror(err: *uv_err_t) -> *c_char; fn rust_uv_err_name(err: c_int) -> *c_char;
fn rust_uv_err_name(err: *uv_err_t) -> *c_char;
fn rust_uv_ip4_addrp(ip: *u8, port: c_int) -> *sockaddr_in; fn rust_uv_ip4_addrp(ip: *u8, port: c_int) -> *sockaddr_in;
fn rust_uv_ip6_addrp(ip: *u8, port: c_int) -> *sockaddr_in6; fn rust_uv_ip6_addrp(ip: *u8, port: c_int) -> *sockaddr_in6;
fn rust_uv_free_ip4_addr(addr: *sockaddr_in); fn rust_uv_free_ip4_addr(addr: *sockaddr_in);

@ -1 +1 @@
Subproject commit dfae9c3e958dc086d9c0ab068cd76d196c95a433 Subproject commit d88cf5652a1afb23939da0bae86c70ec521b9921

View file

@ -329,20 +329,13 @@ rust_uv_get_len_from_buf(uv_buf_t buf) {
return buf.len; return buf.len;
} }
extern "C" uv_err_t
rust_uv_last_error(uv_loop_t* loop) {
return uv_last_error(loop);
}
extern "C" const char* extern "C" const char*
rust_uv_strerror(uv_err_t* err_ptr) { rust_uv_strerror(int err) {
uv_err_t err = *err_ptr;
return uv_strerror(err); return uv_strerror(err);
} }
extern "C" const char* extern "C" const char*
rust_uv_err_name(uv_err_t* err_ptr) { rust_uv_err_name(int err) {
uv_err_t err = *err_ptr;
return uv_err_name(err); return uv_err_name(err);
} }

View file

@ -47,7 +47,6 @@ rust_uv_timer_start
rust_uv_timer_stop rust_uv_timer_stop
rust_uv_tcp_init rust_uv_tcp_init
rust_uv_buf_init rust_uv_buf_init
rust_uv_last_error
rust_uv_strerror rust_uv_strerror
rust_uv_err_name rust_uv_err_name
rust_uv_ip4_addr rust_uv_ip4_addr