1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 * Low-level bindings to the libuv library.
14 * This module contains a set of direct, 'bare-metal' wrappers around
17 * We're not bothering yet to redefine uv's structs as Rust structs
18 * because they are quite large and change often between versions.
19 * The maintenance burden is just too high. Instead we use the uv's
20 * `uv_handle_size` and `uv_req_size` to find the correct size of the
21 * structs and allocate them on the heap. This can be revisited later.
23 * There are also a collection of helper functions to ease interacting
24 * with the low-level API.
26 * As new functionality, existent in uv.h, is added to the rust stdlib,
27 * the mappings should be added in this module.
30 #![allow(non_camel_case_types)] // C types
32 use libc::{size_t, c_int, c_uint, c_void, c_char, c_double};
33 use libc::{ssize_t, sockaddr, free, addrinfo};
35 use std::rt::libc_heap::malloc_raw;
40 pub use self::errors::{EACCES, ECONNREFUSED, ECONNRESET, EPIPE, ECONNABORTED,
41 ECANCELED, EBADF, ENOTCONN, ENOENT, EADDRNOTAVAIL,
44 pub static OK: c_int = 0;
45 pub static EOF: c_int = -4095;
46 pub static UNKNOWN: c_int = -4094;
48 // uv-errno.h redefines error codes for windows, but not for unix...
49 // https://github.com/joyent/libuv/blob/master/include/uv-errno.h
55 pub static EACCES: c_int = -4092;
56 pub static ECONNREFUSED: c_int = -4078;
57 pub static ECONNRESET: c_int = -4077;
58 pub static ENOENT: c_int = -4058;
59 pub static ENOTCONN: c_int = -4053;
60 pub static EPIPE: c_int = -4047;
61 pub static ECONNABORTED: c_int = -4079;
62 pub static ECANCELED: c_int = -4081;
63 pub static EBADF: c_int = -4083;
64 pub static EADDRNOTAVAIL: c_int = -4090;
65 pub static EADDRINUSE: c_int = -4091;
66 pub static EPERM: c_int = -4048;
73 pub static EACCES: c_int = -libc::EACCES;
74 pub static ECONNREFUSED: c_int = -libc::ECONNREFUSED;
75 pub static ECONNRESET: c_int = -libc::ECONNRESET;
76 pub static ENOENT: c_int = -libc::ENOENT;
77 pub static ENOTCONN: c_int = -libc::ENOTCONN;
78 pub static EPIPE: c_int = -libc::EPIPE;
79 pub static ECONNABORTED: c_int = -libc::ECONNABORTED;
80 pub static ECANCELED : c_int = -libc::ECANCELED;
81 pub static EBADF : c_int = -libc::EBADF;
82 pub static EADDRNOTAVAIL : c_int = -libc::EADDRNOTAVAIL;
83 pub static EADDRINUSE : c_int = -libc::EADDRINUSE;
84 pub static EPERM: c_int = -libc::EPERM;
87 pub static PROCESS_SETUID: c_int = 1 << 0;
88 pub static PROCESS_SETGID: c_int = 1 << 1;
89 pub static PROCESS_WINDOWS_VERBATIM_ARGUMENTS: c_int = 1 << 2;
90 pub static PROCESS_DETACHED: c_int = 1 << 3;
91 pub static PROCESS_WINDOWS_HIDE: c_int = 1 << 4;
93 pub static STDIO_IGNORE: c_int = 0x00;
94 pub static STDIO_CREATE_PIPE: c_int = 0x01;
95 pub static STDIO_INHERIT_FD: c_int = 0x02;
96 pub static STDIO_INHERIT_STREAM: c_int = 0x04;
97 pub static STDIO_READABLE_PIPE: c_int = 0x10;
98 pub static STDIO_WRITABLE_PIPE: c_int = 0x20;
101 pub type uv_buf_len_t = libc::size_t;
103 pub type uv_buf_len_t = libc::c_ulong;
105 // see libuv/include/uv-unix.h
107 pub struct uv_buf_t {
109 pub len: uv_buf_len_t,
113 pub type uv_os_socket_t = c_int;
115 // see libuv/include/uv-win.h
117 pub struct uv_buf_t {
118 pub len: uv_buf_len_t,
123 pub type uv_os_socket_t = libc::SOCKET;
126 pub enum uv_run_mode {
133 pub enum uv_poll_event {
138 pub struct uv_process_options_t {
139 pub exit_cb: uv_exit_cb,
140 pub file: *const libc::c_char,
141 pub args: *const *const libc::c_char,
142 pub env: *const *const libc::c_char,
143 pub cwd: *const libc::c_char,
144 pub flags: libc::c_uint,
145 pub stdio_count: libc::c_int,
146 pub stdio: *mut uv_stdio_container_t,
151 // These fields are private because they must be interfaced with through the
154 pub struct uv_stdio_container_t {
156 stream: *mut uv_stream_t,
159 pub type uv_handle_t = c_void;
160 pub type uv_req_t = c_void;
161 pub type uv_loop_t = c_void;
162 pub type uv_idle_t = c_void;
163 pub type uv_tcp_t = c_void;
164 pub type uv_udp_t = c_void;
165 pub type uv_poll_t = c_void;
166 pub type uv_connect_t = c_void;
167 pub type uv_connection_t = c_void;
168 pub type uv_write_t = c_void;
169 pub type uv_async_t = c_void;
170 pub type uv_timer_t = c_void;
171 pub type uv_stream_t = c_void;
172 pub type uv_fs_t = c_void;
173 pub type uv_udp_send_t = c_void;
174 pub type uv_getaddrinfo_t = c_void;
175 pub type uv_process_t = c_void;
176 pub type uv_pipe_t = c_void;
177 pub type uv_tty_t = c_void;
178 pub type uv_signal_t = c_void;
179 pub type uv_shutdown_t = c_void;
181 pub struct uv_timespec_t {
182 pub tv_sec: libc::c_long,
183 pub tv_nsec: libc::c_long
186 pub struct uv_stat_t {
187 pub st_dev: libc::uint64_t,
188 pub st_mode: libc::uint64_t,
189 pub st_nlink: libc::uint64_t,
190 pub st_uid: libc::uint64_t,
191 pub st_gid: libc::uint64_t,
192 pub st_rdev: libc::uint64_t,
193 pub st_ino: libc::uint64_t,
194 pub st_size: libc::uint64_t,
195 pub st_blksize: libc::uint64_t,
196 pub st_blocks: libc::uint64_t,
197 pub st_flags: libc::uint64_t,
198 pub st_gen: libc::uint64_t,
199 pub st_atim: uv_timespec_t,
200 pub st_mtim: uv_timespec_t,
201 pub st_ctim: uv_timespec_t,
202 pub st_birthtim: uv_timespec_t
206 pub fn new() -> uv_stat_t {
220 st_atim: uv_timespec_t { tv_sec: 0, tv_nsec: 0 },
221 st_mtim: uv_timespec_t { tv_sec: 0, tv_nsec: 0 },
222 st_ctim: uv_timespec_t { tv_sec: 0, tv_nsec: 0 },
223 st_birthtim: uv_timespec_t { tv_sec: 0, tv_nsec: 0 }
226 pub fn is_file(&self) -> bool {
227 ((self.st_mode) & libc::S_IFMT as libc::uint64_t) == libc::S_IFREG as libc::uint64_t
229 pub fn is_dir(&self) -> bool {
230 ((self.st_mode) & libc::S_IFMT as libc::uint64_t) == libc::S_IFDIR as libc::uint64_t
234 pub type uv_idle_cb = extern "C" fn(handle: *mut uv_idle_t);
235 pub type uv_alloc_cb = extern "C" fn(stream: *mut uv_stream_t,
236 suggested_size: size_t,
238 pub type uv_read_cb = extern "C" fn(stream: *mut uv_stream_t,
240 buf: *const uv_buf_t);
241 pub type uv_udp_send_cb = extern "C" fn(req: *mut uv_udp_send_t,
243 pub type uv_udp_recv_cb = extern "C" fn(handle: *mut uv_udp_t,
245 buf: *const uv_buf_t,
246 addr: *const sockaddr,
248 pub type uv_close_cb = extern "C" fn(handle: *mut uv_handle_t);
249 pub type uv_poll_cb = extern "C" fn(handle: *mut uv_poll_t,
252 pub type uv_walk_cb = extern "C" fn(handle: *mut uv_handle_t,
254 pub type uv_async_cb = extern "C" fn(handle: *mut uv_async_t);
255 pub type uv_connect_cb = extern "C" fn(handle: *mut uv_connect_t,
257 pub type uv_connection_cb = extern "C" fn(handle: *mut uv_connection_t,
259 pub type uv_timer_cb = extern "C" fn(handle: *mut uv_timer_t);
260 pub type uv_write_cb = extern "C" fn(handle: *mut uv_write_t,
262 pub type uv_getaddrinfo_cb = extern "C" fn(req: *mut uv_getaddrinfo_t,
264 res: *const addrinfo);
265 pub type uv_exit_cb = extern "C" fn(handle: *mut uv_process_t,
268 pub type uv_signal_cb = extern "C" fn(handle: *mut uv_signal_t,
270 pub type uv_fs_cb = extern "C" fn(req: *mut uv_fs_t);
271 pub type uv_shutdown_cb = extern "C" fn(req: *mut uv_shutdown_t, status: c_int);
273 #[cfg(unix)] pub type uv_uid_t = libc::types::os::arch::posix88::uid_t;
274 #[cfg(unix)] pub type uv_gid_t = libc::types::os::arch::posix88::gid_t;
275 #[cfg(windows)] pub type uv_uid_t = libc::c_uchar;
276 #[cfg(windows)] pub type uv_gid_t = libc::c_uchar;
279 #[deriving(PartialEq)]
280 pub enum uv_handle_type {
304 #[deriving(PartialEq)]
305 pub enum uv_req_type {
318 // uv_req_type may have additional fields defined by UV_REQ_TYPE_PRIVATE.
319 // See UV_REQ_TYPE_PRIVATE at libuv/include/uv-win.h
322 #[deriving(PartialEq)]
323 pub enum uv_req_type {
345 #[deriving(PartialEq)]
346 pub enum uv_membership {
351 pub unsafe fn malloc_handle(handle: uv_handle_type) -> *mut c_void {
352 assert!(handle != UV_UNKNOWN_HANDLE && handle != UV_HANDLE_TYPE_MAX);
353 let size = uv_handle_size(handle);
354 malloc_raw(size as uint) as *mut c_void
357 pub unsafe fn free_handle(v: *mut c_void) {
358 free(v as *mut c_void)
361 pub unsafe fn malloc_req(req: uv_req_type) -> *mut c_void {
362 assert!(req != UV_UNKNOWN_REQ && req != UV_REQ_TYPE_MAX);
363 let size = uv_req_size(req);
364 malloc_raw(size as uint) as *mut c_void
367 pub unsafe fn free_req(v: *mut c_void) {
368 free(v as *mut c_void)
372 fn handle_sanity_check() {
374 assert_eq!(UV_HANDLE_TYPE_MAX as uint, rust_uv_handle_type_max());
379 fn request_sanity_check() {
381 assert_eq!(UV_REQ_TYPE_MAX as uint, rust_uv_req_type_max());
385 // FIXME Event loops ignore SIGPIPE by default.
386 pub unsafe fn loop_new() -> *mut c_void {
387 return rust_uv_loop_new();
390 pub unsafe fn uv_write(req: *mut uv_write_t,
391 stream: *mut uv_stream_t,
393 cb: uv_write_cb) -> c_int {
395 fn uv_write(req: *mut uv_write_t, stream: *mut uv_stream_t,
396 buf_in: *const uv_buf_t, buf_cnt: c_int,
397 cb: uv_write_cb) -> c_int;
400 let buf_ptr = buf_in.as_ptr();
401 let buf_cnt = buf_in.len() as i32;
402 return uv_write(req, stream, buf_ptr, buf_cnt, cb);
405 pub unsafe fn uv_udp_send(req: *mut uv_udp_send_t,
406 handle: *mut uv_udp_t,
408 addr: *const sockaddr,
409 cb: uv_udp_send_cb) -> c_int {
411 fn uv_udp_send(req: *mut uv_write_t, stream: *mut uv_stream_t,
412 buf_in: *const uv_buf_t, buf_cnt: c_int,
413 addr: *const sockaddr,
414 cb: uv_udp_send_cb) -> c_int;
417 let buf_ptr = buf_in.as_ptr();
418 let buf_cnt = buf_in.len() as i32;
419 return uv_udp_send(req, handle, buf_ptr, buf_cnt, addr, cb);
422 pub unsafe fn get_udp_handle_from_send_req(send_req: *mut uv_udp_send_t) -> *mut uv_udp_t {
423 return rust_uv_get_udp_handle_from_send_req(send_req);
426 pub unsafe fn process_pid(p: *mut uv_process_t) -> c_int {
428 return rust_uv_process_pid(p);
431 pub unsafe fn set_stdio_container_flags(c: *mut uv_stdio_container_t,
432 flags: libc::c_int) {
434 rust_set_stdio_container_flags(c, flags);
437 pub unsafe fn set_stdio_container_fd(c: *mut uv_stdio_container_t,
440 rust_set_stdio_container_fd(c, fd);
443 pub unsafe fn set_stdio_container_stream(c: *mut uv_stdio_container_t,
444 stream: *mut uv_stream_t) {
445 rust_set_stdio_container_stream(c, stream);
448 // data access helpers
449 pub unsafe fn get_result_from_fs_req(req: *mut uv_fs_t) -> ssize_t {
450 rust_uv_get_result_from_fs_req(req)
452 pub unsafe fn get_ptr_from_fs_req(req: *mut uv_fs_t) -> *mut libc::c_void {
453 rust_uv_get_ptr_from_fs_req(req)
455 pub unsafe fn get_path_from_fs_req(req: *mut uv_fs_t) -> *mut c_char {
456 rust_uv_get_path_from_fs_req(req)
458 pub unsafe fn get_loop_from_fs_req(req: *mut uv_fs_t) -> *mut uv_loop_t {
459 rust_uv_get_loop_from_fs_req(req)
461 pub unsafe fn get_loop_from_getaddrinfo_req(req: *mut uv_getaddrinfo_t) -> *mut uv_loop_t {
462 rust_uv_get_loop_from_getaddrinfo_req(req)
464 pub unsafe fn get_loop_for_uv_handle<T>(handle: *mut T) -> *mut c_void {
465 return rust_uv_get_loop_for_uv_handle(handle as *mut c_void);
467 pub unsafe fn get_stream_handle_from_connect_req(connect: *mut uv_connect_t) -> *mut uv_stream_t {
468 return rust_uv_get_stream_handle_from_connect_req(connect);
470 pub unsafe fn get_stream_handle_from_write_req(write_req: *mut uv_write_t) -> *mut uv_stream_t {
471 return rust_uv_get_stream_handle_from_write_req(write_req);
473 pub unsafe fn get_data_for_uv_loop(loop_ptr: *mut c_void) -> *mut c_void {
474 rust_uv_get_data_for_uv_loop(loop_ptr)
476 pub unsafe fn set_data_for_uv_loop(loop_ptr: *mut c_void, data: *mut c_void) {
477 rust_uv_set_data_for_uv_loop(loop_ptr, data);
479 pub unsafe fn get_data_for_uv_handle<T>(handle: *mut T) -> *mut c_void {
480 return rust_uv_get_data_for_uv_handle(handle as *mut c_void);
482 pub unsafe fn set_data_for_uv_handle<T, U>(handle: *mut T, data: *mut U) {
483 rust_uv_set_data_for_uv_handle(handle as *mut c_void, data as *mut c_void);
485 pub unsafe fn get_data_for_req<T>(req: *mut T) -> *mut c_void {
486 return rust_uv_get_data_for_req(req as *mut c_void);
488 pub unsafe fn set_data_for_req<T, U>(req: *mut T, data: *mut U) {
489 rust_uv_set_data_for_req(req as *mut c_void, data as *mut c_void);
491 pub unsafe fn populate_stat(req_in: *mut uv_fs_t, stat_out: *mut uv_stat_t) {
492 rust_uv_populate_uv_stat(req_in, stat_out)
494 pub unsafe fn guess_handle(handle: c_int) -> c_int {
495 rust_uv_guess_handle(handle)
499 // uv_support is the result of compiling rust_uv.cpp
501 // Note that this is in a cfg'd block so it doesn't get linked during testing.
502 // There's a bit of a conundrum when testing in that we're actually assuming
503 // that the tests are running in a uv loop, but they were created from the
504 // statically linked uv to the original rustuv crate. When we create the test
505 // executable, on some platforms if we re-link against uv, it actually creates
506 // second copies of everything. We obviously don't want this, so instead of
507 // dying horribly during testing, we allow all of the test rustuv's references
508 // to get resolved to the original rustuv crate.
510 #[link(name = "uv_support", kind = "static")]
511 #[link(name = "uv", kind = "static")]
515 fn rust_uv_loop_new() -> *mut c_void;
518 fn rust_uv_handle_type_max() -> uintptr_t;
520 fn rust_uv_req_type_max() -> uintptr_t;
521 fn rust_uv_get_udp_handle_from_send_req(req: *mut uv_udp_send_t) -> *mut uv_udp_t;
523 fn rust_uv_populate_uv_stat(req_in: *mut uv_fs_t, stat_out: *mut uv_stat_t);
524 fn rust_uv_get_result_from_fs_req(req: *mut uv_fs_t) -> ssize_t;
525 fn rust_uv_get_ptr_from_fs_req(req: *mut uv_fs_t) -> *mut libc::c_void;
526 fn rust_uv_get_path_from_fs_req(req: *mut uv_fs_t) -> *mut c_char;
527 fn rust_uv_get_loop_from_fs_req(req: *mut uv_fs_t) -> *mut uv_loop_t;
528 fn rust_uv_get_loop_from_getaddrinfo_req(req: *mut uv_fs_t) -> *mut uv_loop_t;
529 fn rust_uv_get_stream_handle_from_connect_req(req: *mut uv_connect_t) -> *mut uv_stream_t;
530 fn rust_uv_get_stream_handle_from_write_req(req: *mut uv_write_t) -> *mut uv_stream_t;
531 fn rust_uv_get_loop_for_uv_handle(handle: *mut c_void) -> *mut c_void;
532 fn rust_uv_get_data_for_uv_loop(loop_ptr: *mut c_void) -> *mut c_void;
533 fn rust_uv_set_data_for_uv_loop(loop_ptr: *mut c_void, data: *mut c_void);
534 fn rust_uv_get_data_for_uv_handle(handle: *mut c_void) -> *mut c_void;
535 fn rust_uv_set_data_for_uv_handle(handle: *mut c_void, data: *mut c_void);
536 fn rust_uv_get_data_for_req(req: *mut c_void) -> *mut c_void;
537 fn rust_uv_set_data_for_req(req: *mut c_void, data: *mut c_void);
538 fn rust_set_stdio_container_flags(c: *mut uv_stdio_container_t, flags: c_int);
539 fn rust_set_stdio_container_fd(c: *mut uv_stdio_container_t, fd: c_int);
540 fn rust_set_stdio_container_stream(c: *mut uv_stdio_container_t,
541 stream: *mut uv_stream_t);
542 fn rust_uv_process_pid(p: *mut uv_process_t) -> c_int;
543 fn rust_uv_guess_handle(fd: c_int) -> c_int;
545 // generic uv functions
546 pub fn uv_loop_delete(l: *mut uv_loop_t);
547 pub fn uv_ref(t: *mut uv_handle_t);
548 pub fn uv_unref(t: *mut uv_handle_t);
549 pub fn uv_handle_size(ty: uv_handle_type) -> size_t;
550 pub fn uv_req_size(ty: uv_req_type) -> size_t;
551 pub fn uv_run(l: *mut uv_loop_t, mode: uv_run_mode) -> c_int;
552 pub fn uv_close(h: *mut uv_handle_t, cb: uv_close_cb);
553 pub fn uv_walk(l: *mut uv_loop_t, cb: uv_walk_cb, arg: *mut c_void);
554 pub fn uv_buf_init(base: *mut c_char, len: c_uint) -> uv_buf_t;
555 pub fn uv_strerror(err: c_int) -> *const c_char;
556 pub fn uv_err_name(err: c_int) -> *const c_char;
557 pub fn uv_listen(s: *mut uv_stream_t, backlog: c_int,
558 cb: uv_connection_cb) -> c_int;
559 pub fn uv_accept(server: *mut uv_stream_t, client: *mut uv_stream_t) -> c_int;
560 pub fn uv_read_start(stream: *mut uv_stream_t,
561 on_alloc: uv_alloc_cb,
562 on_read: uv_read_cb) -> c_int;
563 pub fn uv_read_stop(stream: *mut uv_stream_t) -> c_int;
564 pub fn uv_shutdown(req: *mut uv_shutdown_t, handle: *mut uv_stream_t,
565 cb: uv_shutdown_cb) -> c_int;
568 pub fn uv_idle_init(l: *mut uv_loop_t, i: *mut uv_idle_t) -> c_int;
569 pub fn uv_idle_start(i: *mut uv_idle_t, cb: uv_idle_cb) -> c_int;
570 pub fn uv_idle_stop(i: *mut uv_idle_t) -> c_int;
573 pub fn uv_async_init(l: *mut uv_loop_t, a: *mut uv_async_t,
574 cb: uv_async_cb) -> c_int;
575 pub fn uv_async_send(a: *mut uv_async_t);
578 pub fn uv_tcp_init(l: *mut uv_loop_t, h: *mut uv_tcp_t) -> c_int;
579 pub fn uv_tcp_connect(c: *mut uv_connect_t, h: *mut uv_tcp_t,
580 addr: *const sockaddr, cb: uv_connect_cb) -> c_int;
581 pub fn uv_tcp_bind(t: *mut uv_tcp_t, addr: *const sockaddr) -> c_int;
582 pub fn uv_tcp_nodelay(h: *mut uv_tcp_t, enable: c_int) -> c_int;
583 pub fn uv_tcp_keepalive(h: *mut uv_tcp_t, enable: c_int,
584 delay: c_uint) -> c_int;
585 pub fn uv_tcp_simultaneous_accepts(h: *mut uv_tcp_t, enable: c_int) -> c_int;
586 pub fn uv_tcp_getsockname(h: *mut uv_tcp_t, name: *mut sockaddr,
587 len: *mut c_int) -> c_int;
588 pub fn uv_tcp_getpeername(h: *mut uv_tcp_t, name: *mut sockaddr,
589 len: *mut c_int) -> c_int;
592 pub fn uv_udp_init(l: *mut uv_loop_t, h: *mut uv_udp_t) -> c_int;
593 pub fn uv_udp_bind(h: *mut uv_udp_t, addr: *const sockaddr,
594 flags: c_uint) -> c_int;
595 pub fn uv_udp_recv_start(server: *mut uv_udp_t,
596 on_alloc: uv_alloc_cb,
597 on_recv: uv_udp_recv_cb) -> c_int;
598 pub fn uv_udp_set_membership(handle: *mut uv_udp_t,
599 multicast_addr: *const c_char,
600 interface_addr: *const c_char,
601 membership: uv_membership) -> c_int;
602 pub fn uv_udp_recv_stop(server: *mut uv_udp_t) -> c_int;
603 pub fn uv_udp_set_multicast_loop(handle: *mut uv_udp_t, on: c_int) -> c_int;
604 pub fn uv_udp_set_multicast_ttl(handle: *mut uv_udp_t, ttl: c_int) -> c_int;
605 pub fn uv_udp_set_ttl(handle: *mut uv_udp_t, ttl: c_int) -> c_int;
606 pub fn uv_udp_set_broadcast(handle: *mut uv_udp_t, on: c_int) -> c_int;
607 pub fn uv_udp_getsockname(h: *mut uv_udp_t, name: *mut sockaddr,
608 len: *mut c_int) -> c_int;
611 pub fn uv_timer_init(l: *mut uv_loop_t, t: *mut uv_timer_t) -> c_int;
612 pub fn uv_timer_start(t: *mut uv_timer_t, cb: uv_timer_cb,
613 timeout: libc::uint64_t,
614 repeat: libc::uint64_t) -> c_int;
615 pub fn uv_timer_stop(handle: *mut uv_timer_t) -> c_int;
618 pub fn uv_fs_open(loop_ptr: *mut uv_loop_t, req: *mut uv_fs_t,
619 path: *const c_char, flags: c_int, mode: c_int,
620 cb: uv_fs_cb) -> c_int;
621 pub fn uv_fs_unlink(loop_ptr: *mut uv_loop_t, req: *mut uv_fs_t,
622 path: *const c_char, cb: uv_fs_cb) -> c_int;
623 pub fn uv_fs_write(l: *mut uv_loop_t, req: *mut uv_fs_t, fd: c_int,
624 bufs: *const uv_buf_t, nbufs: c_uint,
625 offset: i64, cb: uv_fs_cb) -> c_int;
626 pub fn uv_fs_read(l: *mut uv_loop_t, req: *mut uv_fs_t, fd: c_int,
627 bufs: *mut uv_buf_t, nbufs: c_uint,
628 offset: i64, cb: uv_fs_cb) -> c_int;
629 pub fn uv_fs_close(l: *mut uv_loop_t, req: *mut uv_fs_t, fd: c_int,
630 cb: uv_fs_cb) -> c_int;
631 pub fn uv_fs_stat(l: *mut uv_loop_t, req: *mut uv_fs_t, path: *const c_char,
632 cb: uv_fs_cb) -> c_int;
633 pub fn uv_fs_fstat(l: *mut uv_loop_t, req: *mut uv_fs_t, fd: c_int,
634 cb: uv_fs_cb) -> c_int;
635 pub fn uv_fs_mkdir(l: *mut uv_loop_t, req: *mut uv_fs_t, path: *const c_char,
636 mode: c_int, cb: uv_fs_cb) -> c_int;
637 pub fn uv_fs_rmdir(l: *mut uv_loop_t, req: *mut uv_fs_t, path: *const c_char,
638 cb: uv_fs_cb) -> c_int;
639 pub fn uv_fs_readdir(l: *mut uv_loop_t, req: *mut uv_fs_t,
640 path: *const c_char, flags: c_int,
641 cb: uv_fs_cb) -> c_int;
642 pub fn uv_fs_req_cleanup(req: *mut uv_fs_t);
643 pub fn uv_fs_fsync(handle: *mut uv_loop_t, req: *mut uv_fs_t, file: c_int,
644 cb: uv_fs_cb) -> c_int;
645 pub fn uv_fs_fdatasync(handle: *mut uv_loop_t, req: *mut uv_fs_t, file: c_int,
646 cb: uv_fs_cb) -> c_int;
647 pub fn uv_fs_ftruncate(handle: *mut uv_loop_t, req: *mut uv_fs_t, file: c_int,
648 offset: i64, cb: uv_fs_cb) -> c_int;
649 pub fn uv_fs_readlink(handle: *mut uv_loop_t, req: *mut uv_fs_t,
650 file: *const c_char, cb: uv_fs_cb) -> c_int;
651 pub fn uv_fs_symlink(handle: *mut uv_loop_t, req: *mut uv_fs_t,
652 src: *const c_char, dst: *const c_char, flags: c_int,
653 cb: uv_fs_cb) -> c_int;
654 pub fn uv_fs_rename(handle: *mut uv_loop_t, req: *mut uv_fs_t,
655 src: *const c_char, dst: *const c_char,
656 cb: uv_fs_cb) -> c_int;
657 pub fn uv_fs_utime(handle: *mut uv_loop_t, req: *mut uv_fs_t,
658 path: *const c_char, atime: c_double, mtime: c_double,
659 cb: uv_fs_cb) -> c_int;
660 pub fn uv_fs_link(handle: *mut uv_loop_t, req: *mut uv_fs_t,
661 src: *const c_char, dst: *const c_char,
662 cb: uv_fs_cb) -> c_int;
663 pub fn uv_fs_chown(handle: *mut uv_loop_t, req: *mut uv_fs_t, src: *const c_char,
664 uid: uv_uid_t, gid: uv_gid_t, cb: uv_fs_cb) -> c_int;
665 pub fn uv_fs_chmod(handle: *mut uv_loop_t, req: *mut uv_fs_t,
666 path: *const c_char, mode: c_int, cb: uv_fs_cb) -> c_int;
667 pub fn uv_fs_lstat(handle: *mut uv_loop_t, req: *mut uv_fs_t,
668 file: *const c_char, cb: uv_fs_cb) -> c_int;
671 pub fn uv_poll_init_socket(l: *mut uv_loop_t, h: *mut uv_poll_t, s: uv_os_socket_t) -> c_int;
672 pub fn uv_poll_start(h: *mut uv_poll_t, events: c_int, cb: uv_poll_cb) -> c_int;
673 pub fn uv_poll_stop(h: *mut uv_poll_t) -> c_int;
676 pub fn uv_getaddrinfo(loop_: *mut uv_loop_t, req: *mut uv_getaddrinfo_t,
677 getaddrinfo_cb: uv_getaddrinfo_cb,
678 node: *const c_char, service: *const c_char,
679 hints: *const addrinfo) -> c_int;
680 pub fn uv_freeaddrinfo(ai: *mut addrinfo);
683 pub fn uv_spawn(loop_ptr: *mut uv_loop_t, outptr: *mut uv_process_t,
684 options: *mut uv_process_options_t) -> c_int;
685 pub fn uv_process_kill(p: *mut uv_process_t, signum: c_int) -> c_int;
686 pub fn uv_kill(pid: c_int, signum: c_int) -> c_int;
689 pub fn uv_pipe_init(l: *mut uv_loop_t, p: *mut uv_pipe_t,
690 ipc: c_int) -> c_int;
691 pub fn uv_pipe_open(pipe: *mut uv_pipe_t, file: c_int) -> c_int;
692 pub fn uv_pipe_bind(pipe: *mut uv_pipe_t, name: *const c_char) -> c_int;
693 pub fn uv_pipe_connect(req: *mut uv_connect_t, handle: *mut uv_pipe_t,
694 name: *const c_char, cb: uv_connect_cb);
697 pub fn uv_tty_init(l: *mut uv_loop_t, tty: *mut uv_tty_t, fd: c_int,
698 readable: c_int) -> c_int;
699 pub fn uv_tty_set_mode(tty: *mut uv_tty_t, mode: c_int) -> c_int;
700 pub fn uv_tty_get_winsize(tty: *mut uv_tty_t,
702 height: *mut c_int) -> c_int;
705 pub fn uv_signal_init(loop_: *mut uv_loop_t,
706 handle: *mut uv_signal_t) -> c_int;
707 pub fn uv_signal_start(h: *mut uv_signal_t, cb: uv_signal_cb,
708 signum: c_int) -> c_int;
709 pub fn uv_signal_stop(handle: *mut uv_signal_t) -> c_int;
712 // libuv requires other native libraries on various platforms. These are all
713 // listed here (for each platform)
715 // libuv doesn't use pthread on windows
716 // android libc (bionic) provides pthread, so no additional link is required
717 #[cfg(not(windows), not(target_os = "android"))]
718 #[link(name = "pthread")]
721 #[cfg(target_os = "linux")]
725 #[cfg(target_os = "win32")]
726 #[link(name = "ws2_32")]
727 #[link(name = "psapi")]
728 #[link(name = "iphlpapi")]
731 #[cfg(target_os = "freebsd")]
732 #[link(name = "kvm")]