From 30c885ea52458b361bb8f215c17c384743e6851a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 3 Nov 2013 10:39:39 -0800 Subject: [PATCH] uv: Remove lots of uv/C++ wrappers --- src/librustuv/addrinfo.rs | 14 +- src/librustuv/async.rs | 4 +- src/librustuv/file.rs | 111 +++++-- src/librustuv/idle.rs | 8 +- src/librustuv/lib.rs | 24 +- src/librustuv/net.rs | 28 +- src/librustuv/pipe.rs | 8 +- src/librustuv/process.rs | 4 +- src/librustuv/signal.rs | 8 +- src/librustuv/timer.rs | 6 +- src/librustuv/tty.rs | 10 +- src/librustuv/uvio.rs | 46 ++- src/librustuv/uvll.rs | 642 +++++++++----------------------------- src/rt/rust_uv.cpp | 352 --------------------- 14 files changed, 310 insertions(+), 955 deletions(-) diff --git a/src/librustuv/addrinfo.rs b/src/librustuv/addrinfo.rs index 09736749997..77e70acca8d 100644 --- a/src/librustuv/addrinfo.rs +++ b/src/librustuv/addrinfo.rs @@ -110,12 +110,12 @@ impl GetAddrInfoRequest { self.get_req_data().getaddrinfo_cb = Some(wrapper_cb); unsafe { - assert!(0 == uvll::getaddrinfo(loop_.native_handle(), - self.native_handle(), - getaddrinfo_cb, - c_node_ptr, - c_service_ptr, - hint_ptr)); + assert!(0 == uvll::uv_getaddrinfo(loop_.native_handle(), + self.native_handle(), + getaddrinfo_cb, + c_node_ptr, + c_service_ptr, + hint_ptr)); } extern "C" fn getaddrinfo_cb(req: *uvll::uv_getaddrinfo_t, @@ -127,7 +127,7 @@ impl GetAddrInfoRequest { let data = req.get_req_data(); (*data.getaddrinfo_cb.get_ref())(req, &addrinfo, err); unsafe { - uvll::freeaddrinfo(res); + uvll::uv_freeaddrinfo(res); } } } diff --git a/src/librustuv/async.rs b/src/librustuv/async.rs index 4a1858ee036..79e57db1bf5 100644 --- a/src/librustuv/async.rs +++ b/src/librustuv/async.rs @@ -26,7 +26,7 @@ impl AsyncWatcher { watcher.install_watcher_data(); let data = watcher.get_watcher_data(); data.async_cb = Some(cb); - assert_eq!(0, uvll::async_init(loop_.native_handle(), handle, async_cb)); + assert_eq!(0, uvll::uv_async_init(loop_.native_handle(), handle, async_cb)); return watcher; } @@ -42,7 +42,7 @@ impl AsyncWatcher { pub fn send(&mut self) { unsafe { let handle = self.native_handle(); - uvll::async_send(handle); + uvll::uv_async_send(handle); } } } diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs index 8c9302e1238..e3fe6c95baf 100644 --- a/src/librustuv/file.rs +++ b/src/librustuv/file.rs @@ -42,8 +42,9 @@ impl FsRequest { me.req_boilerplate(Some(cb)) }; let ret = path.with_ref(|p| unsafe { - uvll::fs_open(loop_.native_handle(), - self.native_handle(), p, flags, mode, complete_cb_ptr) + uvll::uv_fs_open(loop_.native_handle(), + self.native_handle(), p, flags as c_int, + mode as c_int, complete_cb_ptr) }); assert_eq!(ret, 0); } @@ -52,8 +53,9 @@ impl FsRequest { flags: int, mode: int) -> Result { let complete_cb_ptr = self.req_boilerplate(None); let result = path.with_ref(|p| unsafe { - uvll::fs_open(loop_.native_handle(), - self.native_handle(), p, flags, mode, complete_cb_ptr) + uvll::uv_fs_open(loop_.native_handle(), + self.native_handle(), p, flags as c_int, + mode as c_int, complete_cb_ptr) }); self.sync_cleanup(result) } @@ -61,8 +63,8 @@ impl FsRequest { pub fn unlink(mut self, loop_: &Loop, path: &CString, cb: FsCallback) { let complete_cb_ptr = self.req_boilerplate(Some(cb)); let ret = path.with_ref(|p| unsafe { - uvll::fs_unlink(loop_.native_handle(), - self.native_handle(), p, complete_cb_ptr) + uvll::uv_fs_unlink(loop_.native_handle(), + self.native_handle(), p, complete_cb_ptr) }); assert_eq!(ret, 0); } @@ -71,8 +73,8 @@ impl FsRequest { -> Result { let complete_cb_ptr = self.req_boilerplate(None); let result = path.with_ref(|p| unsafe { - uvll::fs_unlink(loop_.native_handle(), - self.native_handle(), p, complete_cb_ptr) + uvll::uv_fs_unlink(loop_.native_handle(), + self.native_handle(), p, complete_cb_ptr) }); self.sync_cleanup(result) } @@ -89,8 +91,8 @@ impl FsRequest { pub fn stat(mut self, loop_: &Loop, path: &CString, cb: FsCallback) { let complete_cb_ptr = self.req_boilerplate(Some(cb)); let ret = path.with_ref(|p| unsafe { - uvll::fs_stat(loop_.native_handle(), - self.native_handle(), p, complete_cb_ptr) + uvll::uv_fs_stat(loop_.native_handle(), + self.native_handle(), p, complete_cb_ptr) }); assert_eq!(ret, 0); } @@ -101,9 +103,9 @@ impl FsRequest { let base_ptr = buf.base as *c_void; let len = buf.len as uint; let ret = unsafe { - uvll::fs_write(loop_.native_handle(), self.native_handle(), - fd, base_ptr, - len, offset, complete_cb_ptr) + uvll::uv_fs_write(loop_.native_handle(), self.native_handle(), + fd, base_ptr, + len as c_uint, offset, complete_cb_ptr) }; assert_eq!(ret, 0); } @@ -113,9 +115,9 @@ impl FsRequest { let base_ptr = buf.base as *c_void; let len = buf.len as uint; let result = unsafe { - uvll::fs_write(loop_.native_handle(), self.native_handle(), - fd, base_ptr, - len, offset, complete_cb_ptr) + uvll::uv_fs_write(loop_.native_handle(), self.native_handle(), + fd, base_ptr, + len as c_uint, offset, complete_cb_ptr) }; self.sync_cleanup(result) } @@ -126,9 +128,9 @@ impl FsRequest { let buf_ptr = buf.base as *c_void; let len = buf.len as uint; let ret = unsafe { - uvll::fs_read(loop_.native_handle(), self.native_handle(), - fd, buf_ptr, - len, offset, complete_cb_ptr) + uvll::uv_fs_read(loop_.native_handle(), self.native_handle(), + fd, buf_ptr, + len as c_uint, offset, complete_cb_ptr) }; assert_eq!(ret, 0); } @@ -138,30 +140,44 @@ impl FsRequest { let buf_ptr = buf.base as *c_void; let len = buf.len as uint; let result = unsafe { - uvll::fs_read(loop_.native_handle(), self.native_handle(), - fd, buf_ptr, - len, offset, complete_cb_ptr) + uvll::uv_fs_read(loop_.native_handle(), self.native_handle(), + fd, buf_ptr, + len as c_uint, offset, complete_cb_ptr) }; self.sync_cleanup(result) } +<<<<<<< HEAD pub fn close(mut self, loop_: &Loop, fd: c_int, cb: FsCallback) { let complete_cb_ptr = self.req_boilerplate(Some(cb)); assert_eq!(unsafe { uvll::fs_close(loop_.native_handle(), self.native_handle(), fd, complete_cb_ptr) }, 0); +======= + pub fn close(self, loop_: &Loop, fd: c_int, cb: FsCallback) { + let complete_cb_ptr = { + let mut me = self; + me.req_boilerplate(Some(cb)) + }; + let ret = unsafe { + uvll::uv_fs_close(loop_.native_handle(), self.native_handle(), + fd, complete_cb_ptr) + }; + assert_eq!(ret, 0); +>>>>>>> 1850d26... Remove lots of uv/C++ wrappers } pub fn close_sync(mut self, loop_: &Loop, fd: c_int) -> Result { let complete_cb_ptr = self.req_boilerplate(None); let result = unsafe { - uvll::fs_close(loop_.native_handle(), self.native_handle(), - fd, complete_cb_ptr) + uvll::uv_fs_close(loop_.native_handle(), self.native_handle(), + fd, complete_cb_ptr) }; self.sync_cleanup(result) } +<<<<<<< HEAD pub fn mkdir(mut self, loop_: &Loop, path: &CString, mode: c_int, cb: FsCallback) { let complete_cb_ptr = self.req_boilerplate(Some(cb)); @@ -198,10 +214,36 @@ impl FsRequest { uvll::fs_chmod(loop_.native_handle(), self.native_handle(), p, mode, complete_cb_ptr) }), 0); +======= + pub fn mkdir(self, loop_: &Loop, path: &CString, mode: int, cb: FsCallback) { + let complete_cb_ptr = { + let mut me = self; + me.req_boilerplate(Some(cb)) + }; + let ret = path.with_ref(|p| unsafe { + uvll::uv_fs_mkdir(loop_.native_handle(), + self.native_handle(), p, + mode as c_int, complete_cb_ptr) + }); + assert_eq!(ret, 0); + } + + pub fn rmdir(self, loop_: &Loop, path: &CString, cb: FsCallback) { + let complete_cb_ptr = { + let mut me = self; + me.req_boilerplate(Some(cb)) + }; + let ret = path.with_ref(|p| unsafe { + uvll::uv_fs_rmdir(loop_.native_handle(), + self.native_handle(), p, complete_cb_ptr) + }); + assert_eq!(ret, 0); +>>>>>>> 1850d26... Remove lots of uv/C++ wrappers } pub fn readdir(mut self, loop_: &Loop, path: &CString, flags: c_int, cb: FsCallback) { +<<<<<<< HEAD let complete_cb_ptr = self.req_boilerplate(Some(cb)); assert_eq!(path.with_ref(|p| unsafe { uvll::fs_readdir(loop_.native_handle(), @@ -276,6 +318,17 @@ impl FsRequest { uvll::uv_fs_fdatasync(loop_.native_handle(), self.native_handle(), fd, complete_cb_ptr) }, 0); +======= + let complete_cb_ptr = { + let mut me = self; + me.req_boilerplate(Some(cb)) + }; + let ret = path.with_ref(|p| unsafe { + uvll::uv_fs_readdir(loop_.native_handle(), + self.native_handle(), p, flags, complete_cb_ptr) + }); + assert_eq!(ret, 0); +>>>>>>> 1850d26... Remove lots of uv/C++ wrappers } // accessors/utility funcs @@ -287,12 +340,10 @@ impl FsRequest { None => Ok(result) } } - fn req_boilerplate(&mut self, cb: Option) -> *u8 { + fn req_boilerplate(&mut self, cb: Option) -> uvll::uv_fs_cb { let result = match cb { - Some(_) => { - compl_cb as *u8 - }, - None => 0 as *u8 + Some(_) => compl_cb, + None => 0 as uvll::uv_fs_cb }; self.install_req_data(cb); result @@ -365,7 +416,7 @@ impl FsRequest { let data = uvll::get_data_for_req(self.native_handle()); let _data = transmute::<*c_void, ~RequestData>(data); uvll::set_data_for_req(self.native_handle(), null::<()>()); - uvll::fs_req_cleanup(self.native_handle()); + uvll::uv_fs_req_cleanup(self.native_handle()); free_req(self.native_handle() as *c_void) } } diff --git a/src/librustuv/idle.rs b/src/librustuv/idle.rs index 4f606b5f01f..7c9b0ff461c 100644 --- a/src/librustuv/idle.rs +++ b/src/librustuv/idle.rs @@ -21,7 +21,7 @@ impl IdleWatcher { unsafe { let handle = uvll::malloc_handle(uvll::UV_IDLE); assert!(handle.is_not_null()); - assert_eq!(uvll::idle_init(loop_.native_handle(), handle), 0); + assert_eq!(uvll::uv_idle_init(loop_.native_handle(), handle), 0); let mut watcher: IdleWatcher = NativeHandle::from_native_handle(handle); watcher.install_watcher_data(); return watcher @@ -35,14 +35,14 @@ impl IdleWatcher { } unsafe { - assert_eq!(uvll::idle_start(self.native_handle(), idle_cb), 0) + assert_eq!(uvll::uv_idle_start(self.native_handle(), idle_cb), 0) } } pub fn restart(&mut self) { unsafe { assert!(self.get_watcher_data().idle_cb.is_some()); - assert_eq!(uvll::idle_start(self.native_handle(), idle_cb), 0) + assert_eq!(uvll::uv_idle_start(self.native_handle(), idle_cb), 0) } } @@ -52,7 +52,7 @@ impl IdleWatcher { // free unsafe { - assert_eq!(uvll::idle_stop(self.native_handle()), 0); + assert_eq!(uvll::uv_idle_stop(self.native_handle()), 0); } } } diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index f0a607ae35f..64aea4f0174 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -49,7 +49,7 @@ use std::str::raw::from_c_str; use std::vec; use std::ptr; use std::str; -use std::libc::{c_void, c_int, size_t, malloc, free}; +use std::libc::{c_void, c_int, size_t, malloc, free, c_char, c_uint}; use std::cast::transmute; use std::ptr::null; use std::unstable::finally::Finally; @@ -127,11 +127,11 @@ impl Loop { } pub fn run(&mut self) { - unsafe { uvll::run(self.native_handle()) }; + unsafe { uvll::uv_run(self.native_handle(), uvll::RUN_DEFAULT) }; } pub fn close(&mut self) { - unsafe { uvll::loop_delete(self.native_handle()) }; + unsafe { uvll::uv_loop_delete(self.native_handle()) }; } } @@ -240,7 +240,9 @@ impl> WatcherInterop for W { data.close_cb = Some(cb); } - unsafe { uvll::close(self.native_handle(), close_cb); } + unsafe { + uvll::uv_close(self.native_handle() as *uvll::uv_handle_t, close_cb); + } extern fn close_cb(handle: *uvll::uv_handle_t) { let mut h: Handle = NativeHandle::from_native_handle(handle); @@ -251,7 +253,9 @@ impl> WatcherInterop for W { } fn close_async(self) { - unsafe { uvll::close(self.native_handle(), close_cb); } + unsafe { + uvll::uv_close(self.native_handle() as *uvll::uv_handle_t, close_cb); + } extern fn close_cb(handle: *uvll::uv_handle_t) { let mut h: Handle = NativeHandle::from_native_handle(handle); @@ -270,7 +274,7 @@ impl UvError { pub fn name(&self) -> ~str { unsafe { let inner = match self { &UvError(a) => a }; - let name_str = uvll::err_name(inner); + let name_str = uvll::uv_err_name(inner); assert!(name_str.is_not_null()); from_c_str(name_str) } @@ -279,7 +283,7 @@ impl UvError { pub fn desc(&self) -> ~str { unsafe { let inner = match self { &UvError(a) => a }; - let desc_str = uvll::strerror(inner); + let desc_str = uvll::uv_strerror(inner); assert!(desc_str.is_not_null()); from_c_str(desc_str) } @@ -309,7 +313,7 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError { use std::rt::io::*; // uv error descriptions are static - let c_desc = uvll::strerror(*uverr); + let c_desc = uvll::uv_strerror(*uverr); let desc = str::raw::c_str_to_static_slice(c_desc); let kind = match *uverr { @@ -360,7 +364,7 @@ pub fn empty_buf() -> Buf { /// Borrow a slice to a Buf pub fn slice_to_uv_buf(v: &[u8]) -> Buf { let data = vec::raw::to_ptr(v); - unsafe { uvll::buf_init(data, v.len()) } + unsafe { uvll::uv_buf_init(data as *c_char, v.len() as c_uint) } } // XXX: Do these conversions without copying @@ -376,7 +380,7 @@ pub fn vec_to_uv_buf(v: ~[u8]) -> Buf { let data = data as *mut u8; ptr::copy_memory(data, b, l) } - uvll::buf_init(data, v.len()) + uvll::uv_buf_init(data as *c_char, v.len() as c_uint) } } diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index 0aaa931c947..e9f3f2bba4c 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::libc::{size_t, ssize_t, c_int, c_void, c_uint}; +use std::libc::{size_t, ssize_t, c_int, c_void, c_uint, c_char}; use std::vec; use std::str; use std::rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr}; @@ -70,8 +70,10 @@ fn uv_socket_addr_as_socket_addr(addr: UvSocketAddr, f: &fn(SocketAddr) -> T) unsafe { let buf_ptr = vec::raw::to_ptr(buf); match addr { - UvIpv4SocketAddr(addr) => uvll::ip4_name(addr, buf_ptr, ip_size as size_t), - UvIpv6SocketAddr(addr) => uvll::ip6_name(addr, buf_ptr, ip_size as size_t), + UvIpv4SocketAddr(addr) => + uvll::uv_ip4_name(addr, buf_ptr as *c_char, ip_size as size_t), + UvIpv6SocketAddr(addr) => + uvll::uv_ip6_name(addr, buf_ptr as *c_char, ip_size as size_t), } }; buf @@ -119,7 +121,7 @@ impl Watcher for StreamWatcher { } impl StreamWatcher { pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) { unsafe { - match uvll::read_start(self.native_handle(), alloc_cb, read_cb) { + match uvll::uv_read_start(self.native_handle(), alloc_cb, read_cb) { 0 => { let data = self.get_watcher_data(); data.alloc_cb = Some(alloc); @@ -152,14 +154,14 @@ impl StreamWatcher { // but read_stop may be called from inside one of them and we // would end up freeing the in-use environment let handle = self.native_handle(); - unsafe { assert_eq!(uvll::read_stop(handle), 0); } + unsafe { assert_eq!(uvll::uv_read_stop(handle), 0); } } pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) { let req = WriteRequest::new(); return unsafe { - match uvll::write(req.native_handle(), self.native_handle(), - [buf], write_cb) { + match uvll::uv_write(req.native_handle(), self.native_handle(), + [buf], write_cb) { 0 => { let data = self.get_watcher_data(); assert!(data.write_cb.is_none()); @@ -192,7 +194,7 @@ impl StreamWatcher { return unsafe { static BACKLOG: c_int = 128; // XXX should be configurable - match uvll::listen(self.native_handle(), BACKLOG, connection_cb) { + match uvll::uv_listen(self.native_handle(), BACKLOG, connection_cb) { 0 => Ok(()), n => Err(UvError(n)) } @@ -210,7 +212,7 @@ impl StreamWatcher { pub fn accept(&mut self, stream: StreamWatcher) { let self_handle = self.native_handle() as *c_void; let stream_handle = stream.native_handle() as *c_void; - assert_eq!(0, unsafe { uvll::accept(self_handle, stream_handle) } ); + assert_eq!(0, unsafe { uvll::uv_accept(self_handle, stream_handle) } ); } } @@ -231,7 +233,7 @@ impl TcpWatcher { unsafe { let handle = malloc_handle(UV_TCP); assert!(handle.is_not_null()); - assert_eq!(0, uvll::tcp_init(loop_.native_handle(), handle)); + assert_eq!(0, uvll::uv_tcp_init(loop_.native_handle(), handle)); let mut watcher: TcpWatcher = NativeHandle::from_native_handle(handle); watcher.install_watcher_data(); return watcher; @@ -304,7 +306,7 @@ impl UdpWatcher { unsafe { let handle = malloc_handle(UV_UDP); assert!(handle.is_not_null()); - assert_eq!(0, uvll::udp_init(loop_.native_handle(), handle)); + assert_eq!(0, uvll::uv_udp_init(loop_.native_handle(), handle)); let mut watcher: UdpWatcher = NativeHandle::from_native_handle(handle); watcher.install_watcher_data(); return watcher; @@ -333,7 +335,7 @@ impl UdpWatcher { data.udp_recv_cb = Some(cb); } - unsafe { uvll::udp_recv_start(self.native_handle(), alloc_cb, recv_cb); } + unsafe { uvll::uv_udp_recv_start(self.native_handle(), alloc_cb, recv_cb); } extern fn alloc_cb(handle: *uvll::uv_udp_t, suggested_size: size_t) -> Buf { let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle); @@ -361,7 +363,7 @@ impl UdpWatcher { } pub fn recv_stop(&mut self) { - unsafe { uvll::udp_recv_stop(self.native_handle()); } + unsafe { uvll::uv_udp_recv_stop(self.native_handle()); } } pub fn send(&mut self, buf: Buf, address: SocketAddr, cb: UdpSendCallback) { diff --git a/src/librustuv/pipe.rs b/src/librustuv/pipe.rs index b453da0cc9e..0b65c55636d 100644 --- a/src/librustuv/pipe.rs +++ b/src/librustuv/pipe.rs @@ -26,7 +26,7 @@ impl Pipe { let handle = uvll::malloc_handle(uvll::UV_NAMED_PIPE); assert!(handle.is_not_null()); let ipc = ipc as libc::c_int; - assert_eq!(uvll::pipe_init(loop_.native_handle(), handle, ipc), 0); + assert_eq!(uvll::uv_pipe_init(loop_.native_handle(), handle, ipc), 0); let mut ret: Pipe = NativeHandle::from_native_handle(handle); ret.install_watcher_data(); @@ -40,7 +40,7 @@ impl Pipe { #[fixed_stack_segment] #[inline(never)] pub fn open(&mut self, file: libc::c_int) -> Result<(), UvError> { - match unsafe { uvll::pipe_open(self.native_handle(), file) } { + match unsafe { uvll::uv_pipe_open(self.native_handle(), file) } { 0 => Ok(()), n => Err(UvError(n)) } @@ -49,7 +49,7 @@ impl Pipe { #[fixed_stack_segment] #[inline(never)] pub fn bind(&mut self, name: &CString) -> Result<(), UvError> { do name.with_ref |name| { - match unsafe { uvll::pipe_bind(self.native_handle(), name) } { + match unsafe { uvll::uv_pipe_bind(self.native_handle(), name) } { 0 => Ok(()), n => Err(UvError(n)) } @@ -68,7 +68,7 @@ impl Pipe { let name = do name.with_ref |p| { p }; unsafe { - uvll::pipe_connect(connect.native_handle(), + uvll::uv_pipe_connect(connect.native_handle(), self.native_handle(), name, connect_cb) diff --git a/src/librustuv/process.rs b/src/librustuv/process.rs index 2d746e329f4..ce281b656d3 100644 --- a/src/librustuv/process.rs +++ b/src/librustuv/process.rs @@ -94,7 +94,7 @@ impl Process { }; match unsafe { - uvll::spawn(loop_.native_handle(), **self, options) + uvll::uv_spawn(loop_.native_handle(), **self, options) } { 0 => { (*self).get_watcher_data().exit_cb = Some(exit_cb.take()); @@ -111,7 +111,7 @@ impl Process { /// This is a wrapper around `uv_process_kill` pub fn kill(&self, signum: int) -> Result<(), UvError> { match unsafe { - uvll::process_kill(self.native_handle(), signum as libc::c_int) + uvll::uv_process_kill(self.native_handle(), signum as libc::c_int) } { 0 => Ok(()), err => Err(UvError(err)) diff --git a/src/librustuv/signal.rs b/src/librustuv/signal.rs index 3fcf449959d..d5774b5aaab 100644 --- a/src/librustuv/signal.rs +++ b/src/librustuv/signal.rs @@ -24,7 +24,7 @@ impl SignalWatcher { unsafe { let handle = uvll::malloc_handle(uvll::UV_SIGNAL); assert!(handle.is_not_null()); - assert!(0 == uvll::signal_init(loop_.native_handle(), handle)); + assert!(0 == uvll::uv_signal_init(loop_.native_handle(), handle)); let mut watcher: SignalWatcher = NativeHandle::from_native_handle(handle); watcher.install_watcher_data(); return watcher; @@ -35,8 +35,8 @@ impl SignalWatcher { -> Result<(), UvError> { return unsafe { - match uvll::signal_start(self.native_handle(), signal_cb, - signum as c_int) { + match uvll::uv_signal_start(self.native_handle(), signal_cb, + signum as c_int) { 0 => { let data = self.get_watcher_data(); data.signal_cb = Some(callback); @@ -56,7 +56,7 @@ impl SignalWatcher { pub fn stop(&mut self) { unsafe { - uvll::signal_stop(self.native_handle()); + uvll::uv_signal_stop(self.native_handle()); } } } diff --git a/src/librustuv/timer.rs b/src/librustuv/timer.rs index 9a693f6a27d..4fc4934bf65 100644 --- a/src/librustuv/timer.rs +++ b/src/librustuv/timer.rs @@ -21,7 +21,7 @@ impl TimerWatcher { unsafe { let handle = uvll::malloc_handle(uvll::UV_TIMER); assert!(handle.is_not_null()); - assert!(0 == uvll::timer_init(loop_.native_handle(), handle)); + assert!(0 == uvll::uv_timer_init(loop_.native_handle(), handle)); let mut watcher: TimerWatcher = NativeHandle::from_native_handle(handle); watcher.install_watcher_data(); return watcher; @@ -35,7 +35,7 @@ impl TimerWatcher { } unsafe { - uvll::timer_start(self.native_handle(), timer_cb, timeout, repeat); + uvll::uv_timer_start(self.native_handle(), timer_cb, timeout, repeat); } extern fn timer_cb(handle: *uvll::uv_timer_t, status: c_int) { @@ -49,7 +49,7 @@ impl TimerWatcher { pub fn stop(&mut self) { unsafe { - uvll::timer_stop(self.native_handle()); + uvll::uv_timer_stop(self.native_handle()); } } } diff --git a/src/librustuv/tty.rs b/src/librustuv/tty.rs index 65ba09376c1..ad5f5043737 100644 --- a/src/librustuv/tty.rs +++ b/src/librustuv/tty.rs @@ -28,8 +28,8 @@ impl TTY { assert!(handle.is_not_null()); let ret = unsafe { - uvll::tty_init(loop_.native_handle(), handle, fd as libc::c_int, - readable as libc::c_int) + uvll::uv_tty_init(loop_.native_handle(), handle, fd as libc::c_int, + readable as libc::c_int) }; match ret { 0 => { @@ -51,7 +51,7 @@ impl TTY { #[fixed_stack_segment] #[inline(never)] pub fn set_mode(&self, raw: bool) -> Result<(), UvError> { let raw = raw as libc::c_int; - match unsafe { uvll::tty_set_mode(self.native_handle(), raw) } { + match unsafe { uvll::uv_tty_set_mode(self.native_handle(), raw) } { 0 => Ok(()), n => Err(UvError(n)) } @@ -64,8 +64,8 @@ impl TTY { let widthptr: *libc::c_int = &width; let heightptr: *libc::c_int = &width; - match unsafe { uvll::tty_get_winsize(self.native_handle(), - widthptr, heightptr) } { + match unsafe { uvll::uv_tty_get_winsize(self.native_handle(), + widthptr, heightptr) } { 0 => Ok((width as int, height as int)), n => Err(UvError(n)) } diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs index 3f119bc8ccb..b4382ab4cee 100644 --- a/src/librustuv/uvio.rs +++ b/src/librustuv/uvio.rs @@ -990,7 +990,7 @@ impl RtioSocket for UvTcpAcceptor { fn accept_simultaneously(stream: StreamWatcher, a: int) -> Result<(), IoError> { let r = unsafe { - uvll::tcp_simultaneous_accepts(stream.native_handle(), a as c_int) + uvll::uv_tcp_simultaneous_accepts(stream.native_handle(), a as c_int) }; match status_to_maybe_uv_error(r) { @@ -1194,7 +1194,9 @@ impl RtioTcpStream for UvTcpStream { fn control_congestion(&mut self) -> Result<(), IoError> { do self.home_for_io |self_| { - let r = unsafe { uvll::tcp_nodelay(self_.watcher.native_handle(), 0 as c_int) }; + let r = unsafe { + uvll::uv_tcp_nodelay(self_.watcher.native_handle(), 0 as c_int) + }; match status_to_maybe_uv_error(r) { Some(err) => Err(uv_error_to_io_error(err)), @@ -1205,7 +1207,9 @@ impl RtioTcpStream for UvTcpStream { fn nodelay(&mut self) -> Result<(), IoError> { do self.home_for_io |self_| { - let r = unsafe { uvll::tcp_nodelay(self_.watcher.native_handle(), 1 as c_int) }; + let r = unsafe { + uvll::uv_tcp_nodelay(self_.watcher.native_handle(), 1 as c_int) + }; match status_to_maybe_uv_error(r) { Some(err) => Err(uv_error_to_io_error(err)), @@ -1217,8 +1221,8 @@ impl RtioTcpStream for UvTcpStream { fn keepalive(&mut self, delay_in_seconds: uint) -> Result<(), IoError> { do self.home_for_io |self_| { let r = unsafe { - uvll::tcp_keepalive(self_.watcher.native_handle(), 1 as c_int, - delay_in_seconds as c_uint) + uvll::uv_tcp_keepalive(self_.watcher.native_handle(), 1 as c_int, + delay_in_seconds as c_uint) }; match status_to_maybe_uv_error(r) { @@ -1231,7 +1235,8 @@ impl RtioTcpStream for UvTcpStream { fn letdie(&mut self) -> Result<(), IoError> { do self.home_for_io |self_| { let r = unsafe { - uvll::tcp_keepalive(self_.watcher.native_handle(), 0 as c_int, 0 as c_uint) + uvll::uv_tcp_keepalive(self_.watcher.native_handle(), + 0 as c_int, 0 as c_uint) }; match status_to_maybe_uv_error(r) { @@ -1338,8 +1343,9 @@ impl RtioUdpSocket for UvUdpSocket { do self.home_for_io |self_| { let r = unsafe { do multi.to_str().with_c_str |m_addr| { - uvll::udp_set_membership(self_.watcher.native_handle(), m_addr, - ptr::null(), uvll::UV_JOIN_GROUP) + uvll::uv_udp_set_membership(self_.watcher.native_handle(), + m_addr, ptr::null(), + uvll::UV_JOIN_GROUP) } }; @@ -1354,8 +1360,9 @@ impl RtioUdpSocket for UvUdpSocket { do self.home_for_io |self_| { let r = unsafe { do multi.to_str().with_c_str |m_addr| { - uvll::udp_set_membership(self_.watcher.native_handle(), m_addr, - ptr::null(), uvll::UV_LEAVE_GROUP) + uvll::uv_udp_set_membership(self_.watcher.native_handle(), + m_addr, ptr::null(), + uvll::UV_LEAVE_GROUP) } }; @@ -1370,7 +1377,8 @@ impl RtioUdpSocket for UvUdpSocket { do self.home_for_io |self_| { let r = unsafe { - uvll::udp_set_multicast_loop(self_.watcher.native_handle(), 1 as c_int) + uvll::uv_udp_set_multicast_loop(self_.watcher.native_handle(), + 1 as c_int) }; match status_to_maybe_uv_error(r) { @@ -1384,7 +1392,8 @@ impl RtioUdpSocket for UvUdpSocket { do self.home_for_io |self_| { let r = unsafe { - uvll::udp_set_multicast_loop(self_.watcher.native_handle(), 0 as c_int) + uvll::uv_udp_set_multicast_loop(self_.watcher.native_handle(), + 0 as c_int) }; match status_to_maybe_uv_error(r) { @@ -1398,7 +1407,8 @@ impl RtioUdpSocket for UvUdpSocket { do self.home_for_io |self_| { let r = unsafe { - uvll::udp_set_multicast_ttl(self_.watcher.native_handle(), ttl as c_int) + uvll::uv_udp_set_multicast_ttl(self_.watcher.native_handle(), + ttl as c_int) }; match status_to_maybe_uv_error(r) { @@ -1412,7 +1422,7 @@ impl RtioUdpSocket for UvUdpSocket { do self.home_for_io |self_| { let r = unsafe { - uvll::udp_set_ttl(self_.watcher.native_handle(), ttl as c_int) + uvll::uv_udp_set_ttl(self_.watcher.native_handle(), ttl as c_int) }; match status_to_maybe_uv_error(r) { @@ -1426,7 +1436,8 @@ impl RtioUdpSocket for UvUdpSocket { do self.home_for_io |self_| { let r = unsafe { - uvll::udp_set_broadcast(self_.watcher.native_handle(), 1 as c_int) + uvll::uv_udp_set_broadcast(self_.watcher.native_handle(), + 1 as c_int) }; match status_to_maybe_uv_error(r) { @@ -1440,7 +1451,8 @@ impl RtioUdpSocket for UvUdpSocket { do self.home_for_io |self_| { let r = unsafe { - uvll::udp_set_broadcast(self_.watcher.native_handle(), 0 as c_int) + uvll::uv_udp_set_broadcast(self_.watcher.native_handle(), + 0 as c_int) }; match status_to_maybe_uv_error(r) { @@ -1861,7 +1873,7 @@ impl RtioTTY for UvTTY { } fn isatty(&self) -> bool { - unsafe { uvll::guess_handle(self.fd) == uvll::UV_TTY as c_int } + unsafe { uvll::uv_guess_handle(self.fd) == uvll::UV_TTY } } } diff --git a/src/librustuv/uvll.rs b/src/librustuv/uvll.rs index 2d850383766..120a69fb244 100644 --- a/src/librustuv/uvll.rs +++ b/src/librustuv/uvll.rs @@ -33,7 +33,6 @@ use std::libc::{size_t, c_int, c_uint, c_void, c_char, uintptr_t}; use std::libc::ssize_t; use std::libc::{malloc, free}; use std::libc; -use std::ptr; use std::vec; pub use self::errors::*; @@ -95,6 +94,13 @@ pub struct uv_buf_t { base: *u8, } +#[repr(C)] +pub enum uv_run_mode { + RUN_DEFAULT = 0, + RUN_ONCE, + RUN_NOWAIT, +} + pub struct uv_process_options_t { exit_cb: uv_exit_cb, file: *libc::c_char, @@ -276,6 +282,7 @@ pub struct addrinfo { #[cfg(windows)] pub type uv_uid_t = libc::c_uchar; #[cfg(windows)] pub type uv_gid_t = libc::c_uchar; +#[repr(C)] #[deriving(Eq)] pub enum uv_handle_type { UV_UNKNOWN_HANDLE, @@ -299,6 +306,7 @@ pub enum uv_handle_type { UV_HANDLE_TYPE_MAX } +#[repr(C)] #[cfg(unix)] #[deriving(Eq)] pub enum uv_req_type { @@ -316,6 +324,7 @@ pub enum uv_req_type { // uv_req_type may have additional fields defined by UV_REQ_TYPE_PRIVATE. // See UV_REQ_TYPE_PRIVATE at libuv/include/uv-win.h +#[repr(C)] #[cfg(windows)] #[deriving(Eq)] pub enum uv_req_type { @@ -339,6 +348,7 @@ pub enum uv_req_type { UV_REQ_TYPE_MAX } +#[repr(C)] #[deriving(Eq)] pub enum uv_membership { UV_LEAVE_GROUP, @@ -349,7 +359,7 @@ pub unsafe fn malloc_handle(handle: uv_handle_type) -> *c_void { #[fixed_stack_segment]; #[inline(never)]; assert!(handle != UV_UNKNOWN_HANDLE && handle != UV_HANDLE_TYPE_MAX); - let size = rust_uv_handle_size(handle as uint); + let size = uv_handle_size(handle); let p = malloc(size); assert!(p.is_not_null()); return p; @@ -365,7 +375,7 @@ pub unsafe fn malloc_req(req: uv_req_type) -> *c_void { #[fixed_stack_segment]; #[inline(never)]; assert!(req != UV_UNKNOWN_REQ && req != UV_REQ_TYPE_MAX); - let size = rust_uv_req_size(req as uint); + let size = uv_req_size(req); let p = malloc(size); assert!(p.is_not_null()); return p; @@ -400,54 +410,6 @@ pub unsafe fn loop_new() -> *c_void { return rust_uv_loop_new(); } -pub unsafe fn loop_delete(loop_handle: *c_void) { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_loop_delete(loop_handle); -} - -pub unsafe fn run(loop_handle: *c_void) { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_run(loop_handle); -} - -pub unsafe fn close(handle: *T, cb: uv_close_cb) { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_close(handle as *c_void, cb); -} - -pub unsafe fn walk(loop_handle: *c_void, cb: uv_walk_cb, arg: *c_void) { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_walk(loop_handle, cb, arg); -} - -pub unsafe fn idle_init(loop_handle: *uv_loop_t, handle: *uv_idle_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_idle_init(loop_handle, handle) -} - -pub unsafe fn idle_start(handle: *uv_idle_t, cb: uv_idle_cb) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_idle_start(handle, cb) -} - -pub unsafe fn idle_stop(handle: *uv_idle_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_idle_stop(handle) -} - -pub unsafe fn udp_init(loop_handle: *uv_loop_t, handle: *uv_udp_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_udp_init(loop_handle, handle); -} - pub unsafe fn udp_bind(server: *uv_udp_t, addr: *sockaddr_in, flags: c_uint) -> c_int { #[fixed_stack_segment]; #[inline(never)]; @@ -478,19 +440,6 @@ pub unsafe fn udp_send6(req: *uv_udp_send_t, handle: *T, buf_in: &[uv_buf_t], return rust_uv_udp_send6(req, handle as *c_void, buf_ptr, buf_cnt, addr, cb); } -pub unsafe fn udp_recv_start(server: *uv_udp_t, on_alloc: uv_alloc_cb, - on_recv: uv_udp_recv_cb) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_udp_recv_start(server, on_alloc, on_recv); -} - -pub unsafe fn udp_recv_stop(server: *uv_udp_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_udp_recv_stop(server); -} - pub unsafe fn get_udp_handle_from_send_req(send_req: *uv_udp_send_t) -> *uv_udp_t { #[fixed_stack_segment]; #[inline(never)]; @@ -503,43 +452,6 @@ pub unsafe fn udp_getsockname(handle: *uv_udp_t, name: *sockaddr_storage) -> c_i return rust_uv_udp_getsockname(handle, name); } -pub unsafe fn udp_set_membership(handle: *uv_udp_t, multicast_addr: *c_char, - interface_addr: *c_char, membership: uv_membership) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_udp_set_membership(handle, multicast_addr, interface_addr, membership as c_int); -} - -pub unsafe fn udp_set_multicast_loop(handle: *uv_udp_t, on: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_udp_set_multicast_loop(handle, on); -} - -pub unsafe fn udp_set_multicast_ttl(handle: *uv_udp_t, ttl: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_udp_set_multicast_ttl(handle, ttl); -} - -pub unsafe fn udp_set_ttl(handle: *uv_udp_t, ttl: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_udp_set_ttl(handle, ttl); -} - -pub unsafe fn udp_set_broadcast(handle: *uv_udp_t, on: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_udp_set_broadcast(handle, on); -} - -pub unsafe fn tcp_init(loop_handle: *c_void, handle: *uv_tcp_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_tcp_init(loop_handle, handle); -} - pub unsafe fn tcp_connect(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t, addr_ptr: *sockaddr_in, after_connect_cb: uv_connect_cb) -> c_int { #[fixed_stack_segment]; #[inline(never)]; @@ -578,108 +490,17 @@ pub unsafe fn tcp_getsockname(handle: *uv_tcp_t, name: *sockaddr_storage) -> c_i return rust_uv_tcp_getsockname(handle, name); } -pub unsafe fn tcp_nodelay(handle: *uv_tcp_t, enable: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_tcp_nodelay(handle, enable); -} - -pub unsafe fn tcp_keepalive(handle: *uv_tcp_t, enable: c_int, delay: c_uint) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_tcp_keepalive(handle, enable, delay); -} - -pub unsafe fn tcp_simultaneous_accepts(handle: *uv_tcp_t, enable: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_tcp_simultaneous_accepts(handle, enable); -} - -pub unsafe fn listen(stream: *T, backlog: c_int, - cb: uv_connection_cb) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_listen(stream as *c_void, backlog, cb); -} - -pub unsafe fn accept(server: *c_void, client: *c_void) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_accept(server as *c_void, client as *c_void); -} - -pub unsafe fn write(req: *uv_write_t, - stream: *T, +pub unsafe fn uv_write(req: *uv_write_t, + stream: *uv_stream_t, buf_in: &[uv_buf_t], cb: uv_write_cb) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; + externfn!(fn uv_write(req: *uv_write_t, stream: *uv_stream_t, + buf_in: *uv_buf_t, buf_cnt: c_int, + cb: uv_write_cb) -> c_int) let buf_ptr = vec::raw::to_ptr(buf_in); let buf_cnt = buf_in.len() as i32; - return rust_uv_write(req as *c_void, stream as *c_void, buf_ptr, buf_cnt, cb); -} -pub unsafe fn read_start(stream: *uv_stream_t, - on_alloc: uv_alloc_cb, - on_read: uv_read_cb) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_read_start(stream as *c_void, on_alloc, on_read); -} - -pub unsafe fn read_stop(stream: *uv_stream_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_read_stop(stream as *c_void); -} - -pub unsafe fn strerror(err: c_int) -> *c_char { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_strerror(err); -} -pub unsafe fn err_name(err: c_int) -> *c_char { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_err_name(err); -} - -pub unsafe fn async_init(loop_handle: *c_void, - async_handle: *uv_async_t, - cb: uv_async_cb) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_async_init(loop_handle, async_handle, cb); -} - -pub unsafe fn async_send(async_handle: *uv_async_t) { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_async_send(async_handle); -} -pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t { - #[fixed_stack_segment]; #[inline(never)]; - - let out_buf = uv_buf_t { base: ptr::null(), len: 0 as size_t }; - let out_buf_ptr = ptr::to_unsafe_ptr(&out_buf); - rust_uv_buf_init(out_buf_ptr, input, len as size_t); - return out_buf; -} - -pub unsafe fn timer_init(loop_ptr: *c_void, timer_ptr: *uv_timer_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_timer_init(loop_ptr, timer_ptr); -} -pub unsafe fn timer_start(timer_ptr: *uv_timer_t, - cb: uv_timer_cb, timeout: u64, - repeat: u64) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_timer_start(timer_ptr, cb, timeout, repeat); -} -pub unsafe fn timer_stop(timer_ptr: *uv_timer_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_timer_stop(timer_ptr); + return uv_write(req, stream, buf_ptr, buf_cnt, cb); } pub unsafe fn is_ip4_addr(addr: *sockaddr) -> bool { @@ -731,18 +552,6 @@ pub unsafe fn free_ip6_addr(addr: *sockaddr_in6) { rust_uv_free_ip6_addr(addr); } -pub unsafe fn ip4_name(addr: *sockaddr_in, dst: *u8, size: size_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_ip4_name(addr, dst, size); -} - -pub unsafe fn ip6_name(addr: *sockaddr_in6, dst: *u8, size: size_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_ip6_name(addr, dst, size); -} - pub unsafe fn ip4_port(addr: *sockaddr_in) -> c_uint { #[fixed_stack_segment]; #[inline(never)]; @@ -755,99 +564,6 @@ pub unsafe fn ip6_port(addr: *sockaddr_in6) -> c_uint { return rust_uv_ip6_port(addr); } -pub unsafe fn fs_open(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, flags: int, mode: int, - cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_open(loop_ptr, req, path, flags as c_int, mode as c_int, cb) -} - -pub unsafe fn fs_unlink(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, - cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_unlink(loop_ptr, req, path, cb) -} -pub unsafe fn fs_write(loop_ptr: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void, - len: uint, offset: i64, cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_write(loop_ptr, req, fd, buf, len as c_uint, offset, cb) -} -pub unsafe fn fs_read(loop_ptr: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void, - len: uint, offset: i64, cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_read(loop_ptr, req, fd, buf, len as c_uint, offset, cb) -} -pub unsafe fn fs_close(loop_ptr: *uv_loop_t, req: *uv_fs_t, fd: c_int, - cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_close(loop_ptr, req, fd, cb) -} -pub unsafe fn fs_stat(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_stat(loop_ptr, req, path, cb) -} -pub unsafe fn fs_fstat(loop_ptr: *uv_loop_t, req: *uv_fs_t, fd: c_int, cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_fstat(loop_ptr, req, fd, cb) -} -pub unsafe fn fs_mkdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, - mode: c_int, cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_mkdir(loop_ptr, req, path, mode as c_int, cb) -} -pub unsafe fn fs_rmdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, - cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_rmdir(loop_ptr, req, path, cb) -} -pub unsafe fn fs_rename(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, - to: *c_char, cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_rename(loop_ptr, req, path, to, cb) -} -pub unsafe fn fs_chmod(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, - mode: c_int, cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_chmod(loop_ptr, req, path, mode as c_int, cb) -} -pub unsafe fn fs_readdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, - flags: c_int, cb: *u8) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_readdir(loop_ptr, req, path, flags, cb) -} -pub unsafe fn populate_stat(req_in: *uv_fs_t, stat_out: *uv_stat_t) { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_populate_uv_stat(req_in, stat_out) -} -pub unsafe fn fs_req_cleanup(req: *uv_fs_t) { - #[fixed_stack_segment]; #[inline(never)]; - - rust_uv_fs_req_cleanup(req); -} - -pub unsafe fn spawn(loop_ptr: *c_void, result: *uv_process_t, - options: uv_process_options_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_spawn(loop_ptr, result, options); -} - -pub unsafe fn process_kill(p: *uv_process_t, signum: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_process_kill(p, signum); -} - pub unsafe fn process_pid(p: *uv_process_t) -> c_int { #[fixed_stack_segment]; #[inline(never)]; return rust_uv_process_pid(p); @@ -871,11 +587,6 @@ pub unsafe fn set_stdio_container_stream(c: *uv_stdio_container_t, rust_set_stdio_container_stream(c, stream); } -pub unsafe fn pipe_init(loop_ptr: *c_void, p: *uv_pipe_t, ipc: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_pipe_init(loop_ptr, p, ipc) -} - // data access helpers pub unsafe fn get_result_from_fs_req(req: *uv_fs_t) -> c_int { #[fixed_stack_segment]; #[inline(never)]; @@ -947,114 +658,24 @@ pub unsafe fn set_data_for_req(req: *T, data: *U) { rust_uv_set_data_for_req(req as *c_void, data as *c_void); } -pub unsafe fn get_base_from_buf(buf: uv_buf_t) -> *u8 { +pub unsafe fn populate_stat(req_in: *uv_fs_t, stat_out: *uv_stat_t) { #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_get_base_from_buf(buf); -} -pub unsafe fn get_len_from_buf(buf: uv_buf_t) -> size_t { - #[fixed_stack_segment]; #[inline(never)]; - - return rust_uv_get_len_from_buf(buf); -} -pub unsafe fn getaddrinfo(loop_: *uv_loop_t, req: *uv_getaddrinfo_t, - getaddrinfo_cb: uv_getaddrinfo_cb, - node: *c_char, service: *c_char, - hints: *addrinfo) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_getaddrinfo(loop_, req, getaddrinfo_cb, node, service, hints); -} -pub unsafe fn freeaddrinfo(ai: *addrinfo) { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_freeaddrinfo(ai); -} -pub unsafe fn pipe_open(pipe: *uv_pipe_t, file: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_pipe_open(pipe, file) -} -pub unsafe fn pipe_bind(pipe: *uv_pipe_t, name: *c_char) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_pipe_bind(pipe, name) -} -pub unsafe fn pipe_connect(req: *uv_connect_t, handle: *uv_pipe_t, - name: *c_char, cb: uv_connect_cb) { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_pipe_connect(req, handle, name, cb) -} -pub unsafe fn tty_init(loop_ptr: *uv_loop_t, tty: *uv_tty_t, fd: c_int, - readable: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_tty_init(loop_ptr, tty, fd, readable) -} -pub unsafe fn tty_set_mode(tty: *uv_tty_t, mode: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_tty_set_mode(tty, mode) -} -pub unsafe fn tty_get_winsize(tty: *uv_tty_t, width: *c_int, - height: *c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_tty_get_winsize(tty, width, height) -} -// FIXME(#9613) this should return uv_handle_type, not a c_int -pub unsafe fn guess_handle(fd: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - rust_uv_guess_handle(fd) + rust_uv_populate_uv_stat(req_in, stat_out) } -pub unsafe fn signal_init(loop_: *uv_loop_t, handle: *uv_signal_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_signal_init(loop_, handle); -} -pub unsafe fn signal_start(handle: *uv_signal_t, - signal_cb: uv_signal_cb, - signum: c_int) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_signal_start(handle, signal_cb, signum); -} -pub unsafe fn signal_stop(handle: *uv_signal_t) -> c_int { - #[fixed_stack_segment]; #[inline(never)]; - return rust_uv_signal_stop(handle); -} - -pub struct uv_err_data { - err_name: ~str, - err_msg: ~str, -} // uv_support is the result of compiling rust_uv.cpp #[link_args = "-luv_support -luv"] extern { + fn rust_uv_loop_new() -> *c_void; - fn rust_uv_handle_size(type_: uintptr_t) -> size_t; - fn rust_uv_req_size(type_: uintptr_t) -> size_t; fn rust_uv_handle_type_max() -> uintptr_t; fn rust_uv_req_type_max() -> uintptr_t; - - // libuv public API - fn rust_uv_loop_new() -> *c_void; - fn rust_uv_loop_delete(lp: *c_void); - fn rust_uv_run(loop_handle: *c_void); - fn rust_uv_close(handle: *c_void, cb: uv_close_cb); - fn rust_uv_walk(loop_handle: *c_void, cb: uv_walk_cb, arg: *c_void); - - fn rust_uv_idle_init(loop_handle: *uv_loop_t, handle: *uv_idle_t) -> c_int; - fn rust_uv_idle_start(handle: *uv_idle_t, cb: uv_idle_cb) -> c_int; - fn rust_uv_idle_stop(handle: *uv_idle_t) -> c_int; - - fn rust_uv_async_send(handle: *uv_async_t); - fn rust_uv_async_init(loop_handle: *c_void, - async_handle: *uv_async_t, - 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_buf_init(out_buf: *uv_buf_t, base: *u8, len: size_t); - fn rust_uv_strerror(err: c_int) -> *c_char; - fn rust_uv_err_name(err: c_int) -> *c_char; 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_free_ip4_addr(addr: *sockaddr_in); fn rust_uv_free_ip6_addr(addr: *sockaddr_in6); - fn rust_uv_ip4_name(src: *sockaddr_in, dst: *u8, size: size_t) -> c_int; - fn rust_uv_ip6_name(src: *sockaddr_in6, dst: *u8, size: size_t) -> c_int; fn rust_uv_ip4_port(src: *sockaddr_in) -> c_uint; fn rust_uv_ip6_port(src: *sockaddr_in6) -> c_uint; fn rust_uv_tcp_connect(req: *uv_connect_t, handle: *uv_tcp_t, @@ -1067,80 +688,26 @@ extern { fn rust_uv_tcp_bind6(tcp_server: *uv_tcp_t, addr: *sockaddr_in6) -> c_int; fn rust_uv_tcp_getpeername(tcp_handle_ptr: *uv_tcp_t, name: *sockaddr_storage) -> c_int; fn rust_uv_tcp_getsockname(handle: *uv_tcp_t, name: *sockaddr_storage) -> c_int; - fn rust_uv_tcp_nodelay(handle: *uv_tcp_t, enable: c_int) -> c_int; - fn rust_uv_tcp_keepalive(handle: *uv_tcp_t, enable: c_int, delay: c_uint) -> c_int; - fn rust_uv_tcp_simultaneous_accepts(handle: *uv_tcp_t, enable: c_int) -> c_int; - - fn rust_uv_udp_init(loop_handle: *uv_loop_t, handle_ptr: *uv_udp_t) -> c_int; fn rust_uv_udp_bind(server: *uv_udp_t, addr: *sockaddr_in, flags: c_uint) -> c_int; fn rust_uv_udp_bind6(server: *uv_udp_t, addr: *sockaddr_in6, flags: c_uint) -> c_int; fn rust_uv_udp_send(req: *uv_udp_send_t, handle: *uv_udp_t, buf_in: *uv_buf_t, buf_cnt: c_int, addr: *sockaddr_in, cb: uv_udp_send_cb) -> c_int; fn rust_uv_udp_send6(req: *uv_udp_send_t, handle: *uv_udp_t, buf_in: *uv_buf_t, buf_cnt: c_int, addr: *sockaddr_in6, cb: uv_udp_send_cb) -> c_int; - fn rust_uv_udp_recv_start(server: *uv_udp_t, - on_alloc: uv_alloc_cb, - on_recv: uv_udp_recv_cb) -> c_int; - fn rust_uv_udp_recv_stop(server: *uv_udp_t) -> c_int; fn rust_uv_get_udp_handle_from_send_req(req: *uv_udp_send_t) -> *uv_udp_t; fn rust_uv_udp_getsockname(handle: *uv_udp_t, name: *sockaddr_storage) -> c_int; - fn rust_uv_udp_set_membership(handle: *uv_udp_t, multicast_addr: *c_char, - interface_addr: *c_char, membership: c_int) -> c_int; - fn rust_uv_udp_set_multicast_loop(handle: *uv_udp_t, on: c_int) -> c_int; - fn rust_uv_udp_set_multicast_ttl(handle: *uv_udp_t, ttl: c_int) -> c_int; - fn rust_uv_udp_set_ttl(handle: *uv_udp_t, ttl: c_int) -> c_int; - fn rust_uv_udp_set_broadcast(handle: *uv_udp_t, on: c_int) -> c_int; - fn rust_uv_is_ipv4_sockaddr(addr: *sockaddr) -> c_int; fn rust_uv_is_ipv6_sockaddr(addr: *sockaddr) -> c_int; fn rust_uv_malloc_sockaddr_storage() -> *sockaddr_storage; fn rust_uv_free_sockaddr_storage(ss: *sockaddr_storage); - - fn rust_uv_listen(stream: *c_void, backlog: c_int, - cb: uv_connection_cb) -> c_int; - fn rust_uv_accept(server: *c_void, client: *c_void) -> c_int; - fn rust_uv_write(req: *c_void, stream: *c_void, buf_in: *uv_buf_t, buf_cnt: c_int, - cb: uv_write_cb) -> c_int; - fn rust_uv_read_start(stream: *c_void, - on_alloc: uv_alloc_cb, - on_read: uv_read_cb) -> c_int; - fn rust_uv_read_stop(stream: *c_void) -> c_int; - fn rust_uv_timer_init(loop_handle: *c_void, timer_handle: *uv_timer_t) -> c_int; - fn rust_uv_timer_start(timer_handle: *uv_timer_t, cb: uv_timer_cb, timeout: libc::uint64_t, - repeat: libc::uint64_t) -> c_int; - fn rust_uv_timer_stop(handle: *uv_timer_t) -> c_int; - fn rust_uv_fs_open(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, - flags: c_int, mode: c_int, cb: *u8) -> c_int; - fn rust_uv_fs_unlink(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, - cb: *u8) -> c_int; - fn rust_uv_fs_write(loop_ptr: *c_void, req: *uv_fs_t, fd: c_int, - buf: *c_void, len: c_uint, offset: i64, cb: *u8) -> c_int; - fn rust_uv_fs_read(loop_ptr: *c_void, req: *uv_fs_t, fd: c_int, - buf: *c_void, len: c_uint, offset: i64, cb: *u8) -> c_int; - fn rust_uv_fs_close(loop_ptr: *c_void, req: *uv_fs_t, fd: c_int, - cb: *u8) -> c_int; - fn rust_uv_fs_stat(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, cb: *u8) -> c_int; - fn rust_uv_fs_fstat(loop_ptr: *c_void, req: *uv_fs_t, fd: c_int, cb: *u8) -> c_int; - fn rust_uv_fs_mkdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, - mode: c_int, cb: *u8) -> c_int; - fn rust_uv_fs_rmdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, - cb: *u8) -> c_int; - fn rust_uv_fs_rename(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, - to: *c_char, cb: *u8) -> c_int; - fn rust_uv_fs_chmod(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, - mode: c_int, cb: *u8) -> c_int; - fn rust_uv_fs_readdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char, - flags: c_int, cb: *u8) -> c_int; - fn rust_uv_fs_req_cleanup(req: *uv_fs_t); fn rust_uv_populate_uv_stat(req_in: *uv_fs_t, stat_out: *uv_stat_t); fn rust_uv_get_result_from_fs_req(req: *uv_fs_t) -> c_int; fn rust_uv_get_ptr_from_fs_req(req: *uv_fs_t) -> *libc::c_void; fn rust_uv_get_path_from_fs_req(req: *uv_fs_t) -> *c_char; fn rust_uv_get_loop_from_fs_req(req: *uv_fs_t) -> *uv_loop_t; fn rust_uv_get_loop_from_getaddrinfo_req(req: *uv_fs_t) -> *uv_loop_t; - - fn rust_uv_get_stream_handle_from_connect_req(connect_req: *uv_connect_t) -> *uv_stream_t; - fn rust_uv_get_stream_handle_from_write_req(write_req: *uv_write_t) -> *uv_stream_t; + fn rust_uv_get_stream_handle_from_connect_req(req: *uv_connect_t) -> *uv_stream_t; + fn rust_uv_get_stream_handle_from_write_req(req: *uv_write_t) -> *uv_stream_t; fn rust_uv_get_loop_for_uv_handle(handle: *c_void) -> *c_void; fn rust_uv_get_data_for_uv_loop(loop_ptr: *c_void) -> *c_void; fn rust_uv_set_data_for_uv_loop(loop_ptr: *c_void, data: *c_void); @@ -1148,56 +715,94 @@ extern { fn rust_uv_set_data_for_uv_handle(handle: *c_void, data: *c_void); fn rust_uv_get_data_for_req(req: *c_void) -> *c_void; fn rust_uv_set_data_for_req(req: *c_void, data: *c_void); - fn rust_uv_get_base_from_buf(buf: uv_buf_t) -> *u8; - fn rust_uv_get_len_from_buf(buf: uv_buf_t) -> size_t; - fn rust_uv_getaddrinfo(loop_: *uv_loop_t, req: *uv_getaddrinfo_t, - getaddrinfo_cb: uv_getaddrinfo_cb, - node: *c_char, service: *c_char, - hints: *addrinfo) -> c_int; - fn rust_uv_freeaddrinfo(ai: *addrinfo); - fn rust_uv_spawn(loop_ptr: *c_void, outptr: *uv_process_t, - options: uv_process_options_t) -> c_int; - fn rust_uv_process_kill(p: *uv_process_t, signum: c_int) -> c_int; - fn rust_uv_process_pid(p: *uv_process_t) -> c_int; fn rust_set_stdio_container_flags(c: *uv_stdio_container_t, flags: c_int); fn rust_set_stdio_container_fd(c: *uv_stdio_container_t, fd: c_int); fn rust_set_stdio_container_stream(c: *uv_stdio_container_t, stream: *uv_stream_t); - fn rust_uv_pipe_init(loop_ptr: *c_void, p: *uv_pipe_t, ipc: c_int) -> c_int; - - fn rust_uv_pipe_open(pipe: *uv_pipe_t, file: c_int) -> c_int; - fn rust_uv_pipe_bind(pipe: *uv_pipe_t, name: *c_char) -> c_int; - fn rust_uv_pipe_connect(req: *uv_connect_t, handle: *uv_pipe_t, - name: *c_char, cb: uv_connect_cb); - fn rust_uv_tty_init(loop_ptr: *uv_loop_t, tty: *uv_tty_t, fd: c_int, - readable: c_int) -> c_int; - fn rust_uv_tty_set_mode(tty: *uv_tty_t, mode: c_int) -> c_int; - fn rust_uv_tty_get_winsize(tty: *uv_tty_t, width: *c_int, - height: *c_int) -> c_int; - fn rust_uv_guess_handle(fd: c_int) -> c_int; - - // XXX: see comments in addrinfo.rs - // These should all really be constants... - //#[rust_stack] pub fn rust_SOCK_STREAM() -> c_int; - //#[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int; - //#[rust_stack] pub fn rust_SOCK_RAW() -> c_int; - //#[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int; - //#[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int; - //#[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int; - //#[rust_stack] pub fn rust_AI_ALL() -> c_int; - //#[rust_stack] pub fn rust_AI_CANONNAME() -> c_int; - //#[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int; - //#[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int; - //#[rust_stack] pub fn rust_AI_PASSIVE() -> c_int; - //#[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int; - - fn rust_uv_signal_init(loop_: *uv_loop_t, handle: *uv_signal_t) -> c_int; - fn rust_uv_signal_start(handle: *uv_signal_t, - signal_cb: uv_signal_cb, - signum: c_int) -> c_int; - fn rust_uv_signal_stop(handle: *uv_signal_t) -> c_int; - } + +// generic uv functions +externfn!(fn uv_loop_delete(l: *uv_loop_t)) +externfn!(fn uv_handle_size(ty: uv_handle_type) -> size_t) +externfn!(fn uv_req_size(ty: uv_req_type) -> size_t) +externfn!(fn uv_run(l: *uv_loop_t, mode: uv_run_mode) -> c_int) +externfn!(fn uv_close(h: *uv_handle_t, cb: uv_close_cb)) +externfn!(fn uv_walk(l: *uv_loop_t, cb: uv_walk_cb, arg: *c_void)) +externfn!(fn uv_buf_init(base: *c_char, len: c_uint) -> uv_buf_t) +externfn!(fn uv_strerror(err: c_int) -> *c_char) +externfn!(fn uv_err_name(err: c_int) -> *c_char) +externfn!(fn uv_listen(s: *uv_stream_t, backlog: c_int, + cb: uv_connection_cb) -> c_int) +externfn!(fn uv_accept(server: *uv_stream_t, client: *uv_stream_t) -> c_int) +externfn!(fn uv_read_start(stream: *uv_stream_t, + on_alloc: uv_alloc_cb, + on_read: uv_read_cb) -> c_int) +externfn!(fn uv_read_stop(stream: *uv_stream_t) -> c_int) + +// idle bindings +externfn!(fn uv_idle_init(l: *uv_loop_t, i: *uv_idle_t) -> c_int) +externfn!(fn uv_idle_start(i: *uv_idle_t, cb: uv_idle_cb) -> c_int) +externfn!(fn uv_idle_stop(i: *uv_idle_t) -> c_int) + +// async bindings +externfn!(fn uv_async_init(l: *uv_loop_t, a: *uv_async_t, + cb: uv_async_cb) -> c_int) +externfn!(fn uv_async_send(a: *uv_async_t)) + +// tcp bindings +externfn!(fn uv_tcp_init(l: *uv_loop_t, h: *uv_tcp_t) -> c_int) +externfn!(fn uv_ip4_name(src: *sockaddr_in, dst: *c_char, + size: size_t) -> c_int) +externfn!(fn uv_ip6_name(src: *sockaddr_in6, dst: *c_char, + size: size_t) -> c_int) +externfn!(fn uv_tcp_nodelay(h: *uv_tcp_t, enable: c_int) -> c_int) +externfn!(fn uv_tcp_keepalive(h: *uv_tcp_t, enable: c_int, + delay: c_uint) -> c_int) +externfn!(fn uv_tcp_simultaneous_accepts(h: *uv_tcp_t, enable: c_int) -> c_int) + +// udp bindings +externfn!(fn uv_udp_init(l: *uv_loop_t, h: *uv_udp_t) -> c_int) +externfn!(fn uv_udp_recv_start(server: *uv_udp_t, + on_alloc: uv_alloc_cb, + on_recv: uv_udp_recv_cb) -> c_int) +externfn!(fn uv_udp_set_membership(handle: *uv_udp_t, multicast_addr: *c_char, + interface_addr: *c_char, + membership: uv_membership) -> c_int) +externfn!(fn uv_udp_recv_stop(server: *uv_udp_t) -> c_int) +externfn!(fn uv_udp_set_multicast_loop(handle: *uv_udp_t, on: c_int) -> c_int) +externfn!(fn uv_udp_set_multicast_ttl(handle: *uv_udp_t, ttl: c_int) -> c_int) +externfn!(fn uv_udp_set_ttl(handle: *uv_udp_t, ttl: c_int) -> c_int) +externfn!(fn uv_udp_set_broadcast(handle: *uv_udp_t, on: c_int) -> c_int) + +// timer bindings +externfn!(fn uv_timer_init(l: *uv_loop_t, t: *uv_timer_t) -> c_int) +externfn!(fn uv_timer_start(t: *uv_timer_t, cb: uv_timer_cb, + timeout: libc::uint64_t, + repeat: libc::uint64_t) -> c_int) +externfn!(fn uv_timer_stop(handle: *uv_timer_t) -> c_int) + +// fs operations +externfn!(fn uv_fs_open(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, + flags: c_int, mode: c_int, cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_unlink(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char, + cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_write(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void, + len: c_uint, offset: i64, cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_read(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void, + len: c_uint, offset: i64, cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_close(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, + cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_stat(l: *uv_loop_t, req: *uv_fs_t, path: *c_char, + cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_fstat(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, + cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_mkdir(l: *uv_loop_t, req: *uv_fs_t, path: *c_char, + mode: c_int, cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_rmdir(l: *uv_loop_t, req: *uv_fs_t, path: *c_char, + cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_readdir(l: *uv_loop_t, req: *uv_fs_t, path: *c_char, + flags: c_int, cb: uv_fs_cb) -> c_int) +externfn!(fn uv_fs_req_cleanup(req: *uv_fs_t)) externfn!(fn uv_fs_fsync(handle: *uv_loop_t, req: *uv_fs_t, file: c_int, cb: *u8) -> c_int) externfn!(fn uv_fs_fdatasync(handle: *uv_loop_t, req: *uv_fs_t, file: c_int, @@ -1215,6 +820,39 @@ externfn!(fn uv_fs_chown(handle: *uv_loop_t, req: *uv_fs_t, src: *c_char, externfn!(fn uv_fs_lstat(handle: *uv_loop_t, req: *uv_fs_t, file: *c_char, cb: *u8) -> c_int) +// getaddrinfo +externfn!(fn uv_getaddrinfo(loop_: *uv_loop_t, req: *uv_getaddrinfo_t, + getaddrinfo_cb: uv_getaddrinfo_cb, + node: *c_char, service: *c_char, + hints: *addrinfo) -> c_int) +externfn!(fn uv_freeaddrinfo(ai: *addrinfo)) + +// process spawning +externfn!(fn uv_spawn(loop_ptr: *uv_loop_t, outptr: *uv_process_t, + options: uv_process_options_t) -> c_int) +externfn!(fn uv_process_kill(p: *uv_process_t, signum: c_int) -> c_int) + +// pipes +externfn!(fn uv_pipe_init(l: *uv_loop_t, p: *uv_pipe_t, ipc: c_int) -> c_int) +externfn!(fn uv_pipe_open(pipe: *uv_pipe_t, file: c_int) -> c_int) +externfn!(fn uv_pipe_bind(pipe: *uv_pipe_t, name: *c_char) -> c_int) +externfn!(fn uv_pipe_connect(req: *uv_connect_t, handle: *uv_pipe_t, + name: *c_char, cb: uv_connect_cb)) + +// tty +externfn!(fn uv_tty_init(l: *uv_loop_t, tty: *uv_tty_t, fd: c_int, + readable: c_int) -> c_int) +externfn!(fn uv_tty_set_mode(tty: *uv_tty_t, mode: c_int) -> c_int) +externfn!(fn uv_tty_get_winsize(tty: *uv_tty_t, width: *c_int, + height: *c_int) -> c_int) +externfn!(fn uv_guess_handle(fd: c_int) -> uv_handle_type) + +// signals +externfn!(fn uv_signal_init(loop_: *uv_loop_t, handle: *uv_signal_t) -> c_int) +externfn!(fn uv_signal_start(h: *uv_signal_t, cb: uv_signal_cb, + signum: c_int) -> c_int) +externfn!(fn uv_signal_stop(handle: *uv_signal_t) -> c_int) + // libuv requires various system libraries to successfully link on some // platforms #[cfg(target_os = "linux")] diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp index a4361f14f69..09aa806891a 100644 --- a/src/rt/rust_uv.cpp +++ b/src/rt/rust_uv.cpp @@ -31,80 +31,11 @@ rust_uv_loop_new() { return (void*)uv_loop_new(); } -extern "C" void -rust_uv_loop_delete(uv_loop_t* loop) { - // FIXME: This is a workaround for #1815. libev uses realloc(0) to - // free the loop, which valgrind doesn't like. We have suppressions - // to make valgrind ignore them. - // - // Valgrind also has a sanity check when collecting allocation backtraces - // that the stack pointer must be at least 512 bytes into the stack (at - // least 512 bytes of frames must have come before). When this is not - // the case it doesn't collect the backtrace. - // - // Unfortunately, with our spaghetti stacks that valgrind check triggers - // sometimes and we don't get the backtrace for the realloc(0), it - // fails to be suppressed, and it gets reported as 0 bytes lost - // from a malloc with no backtrace. - // - // This pads our stack with some extra space before deleting the loop - alloca(512); - uv_loop_delete(loop); -} - extern "C" void rust_uv_loop_set_data(uv_loop_t* loop, void* data) { loop->data = data; } -extern "C" void -rust_uv_run(uv_loop_t* loop) { - uv_run(loop, UV_RUN_DEFAULT); -} - -extern "C" void -rust_uv_close(uv_handle_t* handle, uv_close_cb cb) { - uv_close(handle, cb); -} - -extern "C" void -rust_uv_walk(uv_loop_t* loop, uv_walk_cb cb, void* arg) { - uv_walk(loop, cb, arg); -} - -extern "C" void -rust_uv_async_send(uv_async_t* handle) { - uv_async_send(handle); -} - -extern "C" int -rust_uv_async_init(uv_loop_t* loop_handle, - uv_async_t* async_handle, - uv_async_cb cb) { - return uv_async_init(loop_handle, async_handle, cb); -} - -extern "C" int -rust_uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) { - return uv_timer_init(loop, timer); -} - -extern "C" int -rust_uv_timer_start(uv_timer_t* the_timer, uv_timer_cb cb, - int64_t timeout, int64_t repeat) { - return uv_timer_start(the_timer, cb, timeout, repeat); -} - -extern "C" int -rust_uv_timer_stop(uv_timer_t* the_timer) { - return uv_timer_stop(the_timer); -} - -extern "C" int -rust_uv_tcp_init(uv_loop_t* loop, uv_tcp_t* handle) { - return uv_tcp_init(loop, handle); -} - extern "C" int rust_uv_tcp_connect(uv_connect_t* connect_ptr, uv_tcp_t* tcp_ptr, @@ -159,29 +90,6 @@ rust_uv_tcp_getsockname return uv_tcp_getsockname(handle, (sockaddr*)name, &namelen); } -extern "C" int -rust_uv_tcp_nodelay -(uv_tcp_t* handle, int enable) { - return uv_tcp_nodelay(handle, enable); -} - -extern "C" int -rust_uv_tcp_keepalive -(uv_tcp_t* handle, int enable, unsigned int delay) { - return uv_tcp_keepalive(handle, enable, delay); -} - -extern "C" int -rust_uv_tcp_simultaneous_accepts -(uv_tcp_t* handle, int enable) { - return uv_tcp_simultaneous_accepts(handle, enable); -} - -extern "C" int -rust_uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) { - return uv_udp_init(loop, handle); -} - extern "C" int rust_uv_udp_bind(uv_udp_t* server, sockaddr_in* addr_ptr, unsigned flags) { return uv_udp_bind(server, *addr_ptr, flags); @@ -204,16 +112,6 @@ rust_uv_udp_send6(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t* buf_in, return uv_udp_send6(req, handle, buf_in, buf_cnt, *addr_ptr, cb); } -extern "C" int -rust_uv_udp_recv_start(uv_udp_t* server, uv_alloc_cb on_alloc, uv_udp_recv_cb on_read) { - return uv_udp_recv_start(server, on_alloc, on_read); -} - -extern "C" int -rust_uv_udp_recv_stop(uv_udp_t* server) { - return uv_udp_recv_stop(server); -} - extern "C" uv_udp_t* rust_uv_get_udp_handle_from_send_req(uv_udp_send_t* send_req) { return send_req->handle; @@ -228,47 +126,6 @@ rust_uv_udp_getsockname return uv_udp_getsockname(handle, (sockaddr*)name, &namelen); } -extern "C" int -rust_uv_udp_set_membership -(uv_udp_t* handle, const char* m_addr, const char* i_addr, uv_membership membership) { - return uv_udp_set_membership(handle, m_addr, i_addr, membership); -} - -extern "C" int -rust_uv_udp_set_multicast_loop -(uv_udp_t* handle, int on) { - return uv_udp_set_multicast_loop(handle, on); -} - -extern "C" int -rust_uv_udp_set_multicast_ttl -(uv_udp_t* handle, int ttl) { - return uv_udp_set_multicast_ttl(handle, ttl); -} - -extern "C" int -rust_uv_udp_set_ttl -(uv_udp_t* handle, int ttl) { - return uv_udp_set_ttl(handle, ttl); -} - -extern "C" int -rust_uv_udp_set_broadcast -(uv_udp_t* handle, int on) { - return uv_udp_set_broadcast(handle, on); -} - -extern "C" int -rust_uv_listen(uv_stream_t* stream, int backlog, - uv_connection_cb cb) { - return uv_listen(stream, backlog, cb); -} - -extern "C" int -rust_uv_accept(uv_stream_t* server, uv_stream_t* client) { - return uv_accept(server, client); -} - extern "C" uv_stream_t* rust_uv_get_stream_handle_from_connect_req(uv_connect_t* connect) { return connect->handle; @@ -319,43 +176,6 @@ rust_uv_set_data_for_req(uv_req_t* req, void* data) { req->data = data; } -extern "C" char* -rust_uv_get_base_from_buf(uv_buf_t buf) { - return buf.base; -} - -extern "C" size_t -rust_uv_get_len_from_buf(uv_buf_t buf) { - return buf.len; -} - -extern "C" const char* -rust_uv_strerror(int err) { - return uv_strerror(err); -} - -extern "C" const char* -rust_uv_err_name(int err) { - return uv_err_name(err); -} - -extern "C" int -rust_uv_write(uv_write_t* req, uv_stream_t* handle, - uv_buf_t* bufs, int buf_cnt, - uv_write_cb cb) { - return uv_write(req, handle, bufs, buf_cnt, cb); -} -extern "C" int -rust_uv_read_start(uv_stream_t* stream, uv_alloc_cb on_alloc, - uv_read_cb on_read) { - return uv_read_start(stream, on_alloc, on_read); -} - -extern "C" int -rust_uv_read_stop(uv_stream_t* stream) { - return uv_read_stop(stream); -} - extern "C" struct sockaddr_in rust_uv_ip4_addr(const char* ip, int port) { struct sockaddr_in addr = uv_ip4_addr(ip, port); @@ -403,16 +223,6 @@ extern "C" void rust_uv_free_ip6_addr(sockaddr_in6 *addrp) { free(addrp); } - -extern "C" int -rust_uv_ip4_name(struct sockaddr_in* src, char* dst, size_t size) { - return uv_ip4_name(src, dst, size); -} -extern "C" int -rust_uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) { - int result = uv_ip6_name(src, dst, size); - return result; -} extern "C" unsigned int rust_uv_ip4_port(struct sockaddr_in* src) { return ntohs(src->sin_port); @@ -422,18 +232,6 @@ rust_uv_ip6_port(struct sockaddr_in6* src) { return ntohs(src->sin6_port); } -extern "C" int -rust_uv_getaddrinfo(uv_loop_t* loop, uv_getaddrinfo_t* handle, - uv_getaddrinfo_cb cb, - char* node, char* service, - addrinfo* hints) { - return uv_getaddrinfo(loop, handle, cb, node, service, hints); -} -extern "C" void -rust_uv_freeaddrinfo(addrinfo* res) { - uv_freeaddrinfo(res); -} - extern "C" int rust_uv_is_ipv4_sockaddr(sockaddr* addr) { return addr->sa_family == AF_INET; @@ -466,31 +264,6 @@ rust_uv_addrinfo_as_sockaddr_in6(addrinfo* input) { return (sockaddr_in6*)input->ai_addr; } -extern "C" int -rust_uv_idle_init(uv_loop_t* loop, uv_idle_t* idle) { - return uv_idle_init(loop, idle); -} - -extern "C" int -rust_uv_idle_start(uv_idle_t* idle, uv_idle_cb cb) { - return uv_idle_start(idle, cb); -} - -extern "C" int -rust_uv_idle_stop(uv_idle_t* idle) { - return uv_idle_stop(idle); -} - -extern "C" size_t -rust_uv_handle_size(uintptr_t type) { - return uv_handle_size((uv_handle_type)type); -} - -extern "C" size_t -rust_uv_req_size(uintptr_t type) { - return uv_req_size((uv_req_type)type); -} - extern "C" uintptr_t rust_uv_handle_type_max() { return UV_HANDLE_TYPE_MAX; @@ -501,33 +274,6 @@ rust_uv_req_type_max() { return UV_REQ_TYPE_MAX; } -extern "C" int -rust_uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - int mode, uv_fs_cb cb) { - return uv_fs_open(loop, req, path, flags, mode, cb); -} -extern "C" int -rust_uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { - return uv_fs_unlink(loop, req, path, cb); -} -extern "C" int -rust_uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf, - size_t len, int64_t offset, uv_fs_cb cb) { - return uv_fs_write(loop, req, fd, buf, len, offset, cb); -} -extern "C" int -rust_uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf, - size_t len, int64_t offset, uv_fs_cb cb) { - return uv_fs_read(loop, req, fd, buf, len, offset, cb); -} -extern "C" int -rust_uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) { - return uv_fs_close(loop, req, fd, cb); -} -extern "C" void -rust_uv_fs_req_cleanup(uv_fs_t* req) { - uv_fs_req_cleanup(req); -} extern "C" int rust_uv_get_result_from_fs_req(uv_fs_t* req) { return req->result; @@ -550,15 +296,6 @@ rust_uv_get_loop_from_getaddrinfo_req(uv_getaddrinfo_t* req) { return req->loop; } -extern "C" int -rust_uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { - return uv_fs_stat(loop, req, path, cb); -} -extern "C" int -rust_uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { - return uv_fs_fstat(loop, req, file, cb); -} - extern "C" void rust_uv_populate_uv_stat(uv_fs_t* req_in, uv_stat_t* stat_out) { stat_out->st_dev = req_in->statbuf.st_dev; @@ -583,39 +320,6 @@ rust_uv_populate_uv_stat(uv_fs_t* req_in, uv_stat_t* stat_out) { stat_out->st_birthtim.tv_nsec = req_in->statbuf.st_birthtim.tv_nsec; } -extern "C" int -rust_uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { - return uv_fs_mkdir(loop, req, path, mode, cb); -} -extern "C" int -rust_uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { - return uv_fs_rmdir(loop, req, path, cb); -} - -extern "C" int -rust_uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { - return uv_fs_readdir(loop, req, path, flags, cb); -} -extern "C" int -rust_uv_fs_rename(uv_loop_t *loop, uv_fs_t* req, const char *path, - const char *to, uv_fs_cb cb) { - return uv_fs_rename(loop, req, path, to, cb); -} -extern "C" int -rust_uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { - return uv_fs_chmod(loop, req, path, mode, cb); -} - -extern "C" int -rust_uv_spawn(uv_loop_t *loop, uv_process_t *p, uv_process_options_t options) { - return uv_spawn(loop, p, options); -} - -extern "C" int -rust_uv_process_kill(uv_process_t *p, int signum) { - return uv_process_kill(p, signum); -} - extern "C" void rust_set_stdio_container_flags(uv_stdio_container_t *c, int flags) { c->flags = (uv_stdio_flags) flags; @@ -635,59 +339,3 @@ extern "C" int rust_uv_process_pid(uv_process_t* p) { return p->pid; } - -extern "C" int -rust_uv_pipe_init(uv_loop_t *loop, uv_pipe_t* p, int ipc) { - return uv_pipe_init(loop, p, ipc); -} - -extern "C" int -rust_uv_pipe_open(uv_pipe_t *pipe, int file) { - return uv_pipe_open(pipe, file); -} - -extern "C" int -rust_uv_pipe_bind(uv_pipe_t *pipe, char *name) { - return uv_pipe_bind(pipe, name); -} - -extern "C" void -rust_uv_pipe_connect(uv_connect_t *req, uv_pipe_t *handle, - char *name, uv_connect_cb cb) { - uv_pipe_connect(req, handle, name, cb); -} - -extern "C" int -rust_uv_tty_init(uv_loop_t *loop, uv_tty_t *tty, int fd, int readable) { - return uv_tty_init(loop, tty, fd, readable); -} - -extern "C" int -rust_uv_tty_set_mode(uv_tty_t *tty, int mode) { - return uv_tty_set_mode(tty, mode); -} - -extern "C" int -rust_uv_tty_get_winsize(uv_tty_t *tty, int *width, int *height) { - return uv_tty_get_winsize(tty, width, height); -} - -extern "C" int -rust_uv_guess_handle(int fd) { - return uv_guess_handle(fd); -} - -extern "C" int -rust_uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) { - return uv_signal_init(loop, handle); -} - -extern "C" int -rust_uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) { - return uv_signal_start(handle, signal_cb, signum); -} - -extern "C" int -rust_uv_signal_stop(uv_signal_t* handle) { - return uv_signal_stop(handle); -}