|
@ -19,7 +19,7 @@ |
|
|
* IN THE SOFTWARE. |
|
|
* IN THE SOFTWARE. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
/* See http://nikhilm.github.com/uvbook/ for an introduction. */ |
|
|
/* See https://github.com/joyent/libuv#documentation for documentation. */ |
|
|
|
|
|
|
|
|
#ifndef UV_H |
|
|
#ifndef UV_H |
|
|
#define UV_H |
|
|
#define UV_H |
|
@ -46,6 +46,7 @@ extern "C" { |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#include "uv-errno.h" |
|
|
#include "uv-errno.h" |
|
|
|
|
|
#include "uv-version.h" |
|
|
#include <stddef.h> |
|
|
#include <stddef.h> |
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1600 |
|
|
#if defined(_MSC_VER) && _MSC_VER < 1600 |
|
@ -94,6 +95,7 @@ extern "C" { |
|
|
XX(EDESTADDRREQ, "destination address required") \ |
|
|
XX(EDESTADDRREQ, "destination address required") \ |
|
|
XX(EEXIST, "file already exists") \ |
|
|
XX(EEXIST, "file already exists") \ |
|
|
XX(EFAULT, "bad address in system call argument") \ |
|
|
XX(EFAULT, "bad address in system call argument") \ |
|
|
|
|
|
XX(EFBIG, "file too large") \ |
|
|
XX(EHOSTUNREACH, "host is unreachable") \ |
|
|
XX(EHOSTUNREACH, "host is unreachable") \ |
|
|
XX(EINTR, "interrupted system call") \ |
|
|
XX(EINTR, "interrupted system call") \ |
|
|
XX(EINVAL, "invalid argument") \ |
|
|
XX(EINVAL, "invalid argument") \ |
|
@ -112,6 +114,7 @@ extern "C" { |
|
|
XX(ENOENT, "no such file or directory") \ |
|
|
XX(ENOENT, "no such file or directory") \ |
|
|
XX(ENOMEM, "not enough memory") \ |
|
|
XX(ENOMEM, "not enough memory") \ |
|
|
XX(ENONET, "machine is not on the network") \ |
|
|
XX(ENONET, "machine is not on the network") \ |
|
|
|
|
|
XX(ENOPROTOOPT, "protocol not available") \ |
|
|
XX(ENOSPC, "no space left on device") \ |
|
|
XX(ENOSPC, "no space left on device") \ |
|
|
XX(ENOSYS, "function not implemented") \ |
|
|
XX(ENOSYS, "function not implemented") \ |
|
|
XX(ENOTCONN, "socket is not connected") \ |
|
|
XX(ENOTCONN, "socket is not connected") \ |
|
@ -124,11 +127,13 @@ extern "C" { |
|
|
XX(EPROTO, "protocol error") \ |
|
|
XX(EPROTO, "protocol error") \ |
|
|
XX(EPROTONOSUPPORT, "protocol not supported") \ |
|
|
XX(EPROTONOSUPPORT, "protocol not supported") \ |
|
|
XX(EPROTOTYPE, "protocol wrong type for socket") \ |
|
|
XX(EPROTOTYPE, "protocol wrong type for socket") \ |
|
|
|
|
|
XX(ERANGE, "result too large") \ |
|
|
XX(EROFS, "read-only file system") \ |
|
|
XX(EROFS, "read-only file system") \ |
|
|
XX(ESHUTDOWN, "cannot send after transport endpoint shutdown") \ |
|
|
XX(ESHUTDOWN, "cannot send after transport endpoint shutdown") \ |
|
|
XX(ESPIPE, "invalid seek") \ |
|
|
XX(ESPIPE, "invalid seek") \ |
|
|
XX(ESRCH, "no such process") \ |
|
|
XX(ESRCH, "no such process") \ |
|
|
XX(ETIMEDOUT, "connection timed out") \ |
|
|
XX(ETIMEDOUT, "connection timed out") \ |
|
|
|
|
|
XX(ETXTBSY, "text file is busy") \ |
|
|
XX(EXDEV, "cross-device link not permitted") \ |
|
|
XX(EXDEV, "cross-device link not permitted") \ |
|
|
XX(UNKNOWN, "unknown error") \ |
|
|
XX(UNKNOWN, "unknown error") \ |
|
|
XX(EOF, "end of file") \ |
|
|
XX(EOF, "end of file") \ |
|
@ -243,21 +248,43 @@ UV_EXTERN const char* uv_version_string(void); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* This function must be called before any other functions in libuv. |
|
|
|
|
|
* |
|
|
|
|
|
* All functions besides uv_run() are non-blocking. |
|
|
* All functions besides uv_run() are non-blocking. |
|
|
* |
|
|
* |
|
|
* All callbacks in libuv are made asynchronously. That is they are never |
|
|
* All callbacks in libuv are made asynchronously. That is they are never |
|
|
* made by the function that takes them as a parameter. |
|
|
* made by the function that takes them as a parameter. |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN uv_loop_t* uv_loop_new(void); |
|
|
|
|
|
UV_EXTERN void uv_loop_delete(uv_loop_t*); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Returns the default loop. |
|
|
* Returns the default loop. |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN uv_loop_t* uv_default_loop(void); |
|
|
UV_EXTERN uv_loop_t* uv_default_loop(void); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Initializes a uv_loop_t structure. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN int uv_loop_init(uv_loop_t* loop); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Closes all internal loop resources. This function must only be called once |
|
|
|
|
|
* the loop has finished it's execution or it will return UV_EBUSY. After this |
|
|
|
|
|
* function returns the user shall free the memory allocated for the loop. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN int uv_loop_close(uv_loop_t* loop); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Allocates and initializes a new loop. |
|
|
|
|
|
* NOTE: This function is DEPRECATED (to be removed after 0.12), users should |
|
|
|
|
|
* allocate the loop manually and use uv_loop_init instead. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN uv_loop_t* uv_loop_new(void); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Cleans up a loop once it has finished executio and frees its memory. |
|
|
|
|
|
* NOTE: This function is DEPRECATED (to be removed after 0.12). Users should use |
|
|
|
|
|
* uv_loop_close and free the memory manually instead. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN void uv_loop_delete(uv_loop_t*); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* This function runs the event loop. It will act differently depending on the |
|
|
* This function runs the event loop. It will act differently depending on the |
|
|
* specified mode: |
|
|
* specified mode: |
|
@ -435,8 +462,10 @@ typedef struct { |
|
|
* will be a relative path to a file contained in the directory. |
|
|
* will be a relative path to a file contained in the directory. |
|
|
* The events parameter is an ORed mask of enum uv_fs_event elements. |
|
|
* The events parameter is an ORed mask of enum uv_fs_event elements. |
|
|
*/ |
|
|
*/ |
|
|
typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle, const char* filename, |
|
|
typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle, |
|
|
int events, int status); |
|
|
const char* filename, |
|
|
|
|
|
int events, |
|
|
|
|
|
int status); |
|
|
|
|
|
|
|
|
typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle, |
|
|
typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle, |
|
|
int status, |
|
|
int status, |
|
@ -486,8 +515,9 @@ UV_PRIVATE_REQ_TYPES |
|
|
* initialized stream. req should be an uninitialized shutdown request |
|
|
* initialized stream. req should be an uninitialized shutdown request |
|
|
* struct. The cb is called after shutdown is complete. |
|
|
* struct. The cb is called after shutdown is complete. |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, |
|
|
UV_EXTERN int uv_shutdown(uv_shutdown_t* req, |
|
|
uv_shutdown_cb cb); |
|
|
uv_stream_t* handle, |
|
|
|
|
|
uv_shutdown_cb cb); |
|
|
|
|
|
|
|
|
struct uv_shutdown_s { |
|
|
struct uv_shutdown_s { |
|
|
UV_REQ_FIELDS |
|
|
UV_REQ_FIELDS |
|
@ -499,12 +529,12 @@ struct uv_shutdown_s { |
|
|
|
|
|
|
|
|
#define UV_HANDLE_FIELDS \ |
|
|
#define UV_HANDLE_FIELDS \ |
|
|
/* public */ \ |
|
|
/* public */ \ |
|
|
uv_close_cb close_cb; \ |
|
|
|
|
|
void* data; \ |
|
|
void* data; \ |
|
|
/* read-only */ \ |
|
|
/* read-only */ \ |
|
|
uv_loop_t* loop; \ |
|
|
uv_loop_t* loop; \ |
|
|
uv_handle_type type; \ |
|
|
uv_handle_type type; \ |
|
|
/* private */ \ |
|
|
/* private */ \ |
|
|
|
|
|
uv_close_cb close_cb; \ |
|
|
void* handle_queue[2]; \ |
|
|
void* handle_queue[2]; \ |
|
|
UV_HANDLE_PRIVATE_FIELDS \ |
|
|
UV_HANDLE_PRIVATE_FIELDS \ |
|
|
|
|
|
|
|
@ -590,8 +620,7 @@ UV_EXTERN uv_buf_t uv_buf_init(char* base, unsigned int len); |
|
|
* |
|
|
* |
|
|
* uv_stream is an abstract class. |
|
|
* uv_stream is an abstract class. |
|
|
* |
|
|
* |
|
|
* uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t, uv_tty_t, and |
|
|
* uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t and uv_tty_t. |
|
|
* soon uv_file_t. |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
struct uv_stream_s { |
|
|
struct uv_stream_s { |
|
|
UV_HANDLE_FIELDS |
|
|
UV_HANDLE_FIELDS |
|
@ -625,8 +654,9 @@ UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client); |
|
|
* eof; it happens when libuv requested a buffer through the alloc callback |
|
|
* eof; it happens when libuv requested a buffer through the alloc callback |
|
|
* but then decided that it didn't need that buffer. |
|
|
* but then decided that it didn't need that buffer. |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN int uv_read_start(uv_stream_t*, uv_alloc_cb alloc_cb, |
|
|
UV_EXTERN int uv_read_start(uv_stream_t*, |
|
|
uv_read_cb read_cb); |
|
|
uv_alloc_cb alloc_cb, |
|
|
|
|
|
uv_read_cb read_cb); |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_read_stop(uv_stream_t*); |
|
|
UV_EXTERN int uv_read_stop(uv_stream_t*); |
|
|
|
|
|
|
|
@ -719,11 +749,7 @@ UV_EXTERN int uv_is_writable(const uv_stream_t* handle); |
|
|
* Relying too much on this API is not recommended. It is likely to change |
|
|
* Relying too much on this API is not recommended. It is likely to change |
|
|
* significantly in the future. |
|
|
* significantly in the future. |
|
|
* |
|
|
* |
|
|
* On windows this currently works only for uv_pipe_t instances. On unix it |
|
|
* Currently this only works on Windows and only for uv_pipe_t handles. |
|
|
* works for tcp, pipe and tty instances. Be aware that changing the blocking |
|
|
|
|
|
* mode on unix sets or clears the O_NONBLOCK bit. If you are sharing a handle |
|
|
|
|
|
* with another process, the other process is affected by the change too, |
|
|
|
|
|
* which can lead to unexpected results. |
|
|
|
|
|
* |
|
|
* |
|
|
* Also libuv currently makes no ordering guarantee when the blocking mode |
|
|
* Also libuv currently makes no ordering guarantee when the blocking mode |
|
|
* is changed after write requests have already been submitted. Therefore it is |
|
|
* is changed after write requests have already been submitted. Therefore it is |
|
@ -843,7 +869,7 @@ enum uv_udp_flags { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Called after a uv_udp_send() or uv_udp_send6(). status 0 indicates |
|
|
* Called after uv_udp_send(). status 0 indicates |
|
|
* success otherwise error. |
|
|
* success otherwise error. |
|
|
*/ |
|
|
*/ |
|
|
typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status); |
|
|
typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status); |
|
@ -908,7 +934,7 @@ UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle); |
|
|
UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock); |
|
|
UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Bind to a IPv4 address and port. |
|
|
* Bind to an IP address and port. |
|
|
* |
|
|
* |
|
|
* Arguments: |
|
|
* Arguments: |
|
|
* handle UDP handle. Should have been initialized with `uv_udp_init`. |
|
|
* handle UDP handle. Should have been initialized with `uv_udp_init`. |
|
@ -931,8 +957,9 @@ UV_EXTERN int uv_udp_bind(uv_udp_t* handle, |
|
|
const struct sockaddr* addr, |
|
|
const struct sockaddr* addr, |
|
|
unsigned int flags); |
|
|
unsigned int flags); |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, |
|
|
UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, |
|
|
int* namelen); |
|
|
struct sockaddr* name, |
|
|
|
|
|
int* namelen); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Set membership for a multicast address |
|
|
* Set membership for a multicast address |
|
@ -948,8 +975,9 @@ UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, |
|
|
* 0 on success, or an error code < 0 on failure. |
|
|
* 0 on success, or an error code < 0 on failure. |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle, |
|
|
UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle, |
|
|
const char* multicast_addr, const char* interface_addr, |
|
|
const char* multicast_addr, |
|
|
uv_membership membership); |
|
|
const char* interface_addr, |
|
|
|
|
|
uv_membership membership); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Set IP multicast loop flag. Makes multicast packets loop back to |
|
|
* Set IP multicast loop flag. Makes multicast packets loop back to |
|
@ -978,6 +1006,21 @@ UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on); |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl); |
|
|
UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Set the multicast interface to send on |
|
|
|
|
|
* |
|
|
|
|
|
* Arguments: |
|
|
|
|
|
* handle UDP handle. Should have been initialized with |
|
|
|
|
|
* `uv_udp_init`. |
|
|
|
|
|
* interface_addr interface address |
|
|
|
|
|
* |
|
|
|
|
|
* Returns: |
|
|
|
|
|
* 0 on success, or an error code < 0 on failure. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN int uv_udp_set_multicast_interface(uv_udp_t* handle, |
|
|
|
|
|
const char* interface_addr); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Set broadcast on or off |
|
|
* Set broadcast on or off |
|
|
* |
|
|
* |
|
@ -1005,16 +1048,17 @@ UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on); |
|
|
UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl); |
|
|
UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Send data. If the socket has not previously been bound with `uv_udp_bind` |
|
|
* Send data. If the socket has not previously been bound with `uv_udp_bind,` |
|
|
* or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address) |
|
|
* it is bound to 0.0.0.0 (the "all interfaces" address) and a random |
|
|
* and a random port number. |
|
|
* port number. |
|
|
* |
|
|
* |
|
|
* Arguments: |
|
|
* Arguments: |
|
|
* req UDP request handle. Need not be initialized. |
|
|
* req UDP request handle. Need not be initialized. |
|
|
* handle UDP handle. Should have been initialized with `uv_udp_init`. |
|
|
* handle UDP handle. Should have been initialized with `uv_udp_init`. |
|
|
* bufs List of buffers to send. |
|
|
* bufs List of buffers to send. |
|
|
* nbufs Number of buffers in `bufs`. |
|
|
* nbufs Number of buffers in `bufs`. |
|
|
* addr Address of the remote peer. See `uv_ip4_addr`. |
|
|
* addr struct sockaddr_in or struct sockaddr_in6 with the address and |
|
|
|
|
|
* port of the remote peer. |
|
|
* send_cb Callback to invoke when the data has been sent out. |
|
|
* send_cb Callback to invoke when the data has been sent out. |
|
|
* |
|
|
* |
|
|
* Returns: |
|
|
* Returns: |
|
@ -1029,8 +1073,8 @@ UV_EXTERN int uv_udp_send(uv_udp_send_t* req, |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Receive data. If the socket has not previously been bound with `uv_udp_bind` |
|
|
* Receive data. If the socket has not previously been bound with `uv_udp_bind` |
|
|
* or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address) |
|
|
* it is bound to 0.0.0.0 (the "all interfaces" address) and a random |
|
|
* and a random port number. |
|
|
* port number. |
|
|
* |
|
|
* |
|
|
* Arguments: |
|
|
* Arguments: |
|
|
* handle UDP handle. Should have been initialized with `uv_udp_init`. |
|
|
* handle UDP handle. Should have been initialized with `uv_udp_init`. |
|
@ -1040,8 +1084,9 @@ UV_EXTERN int uv_udp_send(uv_udp_send_t* req, |
|
|
* Returns: |
|
|
* Returns: |
|
|
* 0 on success, or an error code < 0 on failure. |
|
|
* 0 on success, or an error code < 0 on failure. |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, |
|
|
UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle, |
|
|
uv_udp_recv_cb recv_cb); |
|
|
uv_alloc_cb alloc_cb, |
|
|
|
|
|
uv_udp_recv_cb recv_cb); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Stop listening for incoming datagrams. |
|
|
* Stop listening for incoming datagrams. |
|
@ -1144,8 +1189,22 @@ UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name); |
|
|
* Paths on UNIX get truncated to `sizeof(sockaddr_un.sun_path)` bytes, |
|
|
* Paths on UNIX get truncated to `sizeof(sockaddr_un.sun_path)` bytes, |
|
|
* typically between 92 and 108 bytes. |
|
|
* typically between 92 and 108 bytes. |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, |
|
|
UV_EXTERN void uv_pipe_connect(uv_connect_t* req, |
|
|
const char* name, uv_connect_cb cb); |
|
|
uv_pipe_t* handle, |
|
|
|
|
|
const char* name, |
|
|
|
|
|
uv_connect_cb cb); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Get the name of the UNIX domain socket or the named pipe. |
|
|
|
|
|
* |
|
|
|
|
|
* A preallocated buffer must be provided. The len parameter holds the |
|
|
|
|
|
* length of the buffer and it's set to the number of bytes written to the |
|
|
|
|
|
* buffer on output. If the buffer is not big enough UV_ENOBUFS will be |
|
|
|
|
|
* returned and len will contain the required size. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle, |
|
|
|
|
|
char* buf, |
|
|
|
|
|
size_t* len); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* This setting applies to Windows only. |
|
|
* This setting applies to Windows only. |
|
@ -1200,8 +1259,9 @@ UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd); |
|
|
|
|
|
|
|
|
/* Initialize the poll watcher using a socket descriptor. On unix this is */ |
|
|
/* Initialize the poll watcher using a socket descriptor. On unix this is */ |
|
|
/* identical to uv_poll_init. On windows it takes a SOCKET handle. */ |
|
|
/* identical to uv_poll_init. On windows it takes a SOCKET handle. */ |
|
|
UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle, |
|
|
UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop, |
|
|
uv_os_sock_t socket); |
|
|
uv_poll_t* handle, |
|
|
|
|
|
uv_os_sock_t socket); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Starts polling the file descriptor. `events` is a bitmask consisting made up |
|
|
* Starts polling the file descriptor. `events` is a bitmask consisting made up |
|
@ -1299,13 +1359,12 @@ struct uv_async_s { |
|
|
* Note that uv_async_init(), unlike other libuv functions, immediately |
|
|
* Note that uv_async_init(), unlike other libuv functions, immediately |
|
|
* starts the handle. To stop the handle again, close it with uv_close(). |
|
|
* starts the handle. To stop the handle again, close it with uv_close(). |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN int uv_async_init(uv_loop_t*, uv_async_t* async, |
|
|
UV_EXTERN int uv_async_init(uv_loop_t*, |
|
|
uv_async_cb async_cb); |
|
|
uv_async_t* async, |
|
|
|
|
|
uv_async_cb async_cb); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* This can be called from other threads to wake up a libuv thread. |
|
|
* This can be called from other threads to wake up a libuv thread. |
|
|
* |
|
|
|
|
|
* libuv is single threaded at the moment. |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN int uv_async_send(uv_async_t* async); |
|
|
UV_EXTERN int uv_async_send(uv_async_t* async); |
|
|
|
|
|
|
|
@ -1425,7 +1484,7 @@ typedef struct uv_stdio_container_s { |
|
|
|
|
|
|
|
|
typedef struct uv_process_options_s { |
|
|
typedef struct uv_process_options_s { |
|
|
uv_exit_cb exit_cb; /* Called after the process exits. */ |
|
|
uv_exit_cb exit_cb; /* Called after the process exits. */ |
|
|
const char* file; /* Path to program to execute. */ |
|
|
const char* file; /* Path to program to execute. */ |
|
|
/*
|
|
|
/*
|
|
|
* Command line arguments. args[0] should be the path to the program. On |
|
|
* Command line arguments. args[0] should be the path to the program. On |
|
|
* Windows this uses CreateProcess which concatenates the arguments into a |
|
|
* Windows this uses CreateProcess which concatenates the arguments into a |
|
@ -1535,11 +1594,27 @@ UV_EXTERN int uv_spawn(uv_loop_t* loop, |
|
|
/*
|
|
|
/*
|
|
|
* Kills the process with the specified signal. The user must still |
|
|
* Kills the process with the specified signal. The user must still |
|
|
* call uv_close on the process. |
|
|
* call uv_close on the process. |
|
|
|
|
|
* |
|
|
|
|
|
* Emulates some aspects of Unix exit status on Windows, in that while the |
|
|
|
|
|
* underlying process will be terminated with a status of `1`, |
|
|
|
|
|
* `uv_process_t.exit_signal` will be set to signum, so the process will appear |
|
|
|
|
|
* to have been killed by `signum`. |
|
|
*/ |
|
|
*/ |
|
|
UV_EXTERN int uv_process_kill(uv_process_t*, int signum); |
|
|
UV_EXTERN int uv_process_kill(uv_process_t*, int signum); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Kills the process with the specified signal. */ |
|
|
/* Kills the process with the specified signal.
|
|
|
|
|
|
* |
|
|
|
|
|
* Emulates some aspects of Unix signals on Windows: |
|
|
|
|
|
* - SIGTERM, SIGKILL, and SIGINT call TerminateProcess() to unconditionally |
|
|
|
|
|
* cause the target to exit with status 1. Unlike Unix, this cannot be caught |
|
|
|
|
|
* or ignored (but see uv_process_kill() and uv_signal_start()). |
|
|
|
|
|
* - Signal number `0` causes a check for target existence, as in Unix. Return |
|
|
|
|
|
* value is 0 on existence, UV_ESRCH on non-existence. |
|
|
|
|
|
* |
|
|
|
|
|
* Returns 0 on success, or an error code on failure. UV_ESRCH is portably used |
|
|
|
|
|
* for non-existence of target process, other errors may be system specific. |
|
|
|
|
|
*/ |
|
|
UV_EXTERN int uv_kill(int pid, int signum); |
|
|
UV_EXTERN int uv_kill(int pid, int signum); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1555,8 +1630,10 @@ struct uv_work_s { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/* Queues a work request to execute asynchronously on the thread pool. */ |
|
|
/* Queues a work request to execute asynchronously on the thread pool. */ |
|
|
UV_EXTERN int uv_queue_work(uv_loop_t* loop, uv_work_t* req, |
|
|
UV_EXTERN int uv_queue_work(uv_loop_t* loop, |
|
|
uv_work_cb work_cb, uv_after_work_cb after_work_cb); |
|
|
uv_work_t* req, |
|
|
|
|
|
uv_work_cb work_cb, |
|
|
|
|
|
uv_after_work_cb after_work_cb); |
|
|
|
|
|
|
|
|
/* Cancel a pending request. Fails if the request is executing or has finished
|
|
|
/* Cancel a pending request. Fails if the request is executing or has finished
|
|
|
* executing. |
|
|
* executing. |
|
@ -1615,6 +1692,36 @@ UV_EXTERN int uv_set_process_title(const char* title); |
|
|
UV_EXTERN int uv_resident_set_memory(size_t* rss); |
|
|
UV_EXTERN int uv_resident_set_memory(size_t* rss); |
|
|
UV_EXTERN int uv_uptime(double* uptime); |
|
|
UV_EXTERN int uv_uptime(double* uptime); |
|
|
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
|
long tv_sec; |
|
|
|
|
|
long tv_usec; |
|
|
|
|
|
} uv_timeval_t; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
|
uv_timeval_t ru_utime; /* user CPU time used */ |
|
|
|
|
|
uv_timeval_t ru_stime; /* system CPU time used */ |
|
|
|
|
|
uint64_t ru_maxrss; /* maximum resident set size */ |
|
|
|
|
|
uint64_t ru_ixrss; /* integral shared memory size */ |
|
|
|
|
|
uint64_t ru_idrss; /* integral unshared data size */ |
|
|
|
|
|
uint64_t ru_isrss; /* integral unshared stack size */ |
|
|
|
|
|
uint64_t ru_minflt; /* page reclaims (soft page faults) */ |
|
|
|
|
|
uint64_t ru_majflt; /* page faults (hard page faults) */ |
|
|
|
|
|
uint64_t ru_nswap; /* swaps */ |
|
|
|
|
|
uint64_t ru_inblock; /* block input operations */ |
|
|
|
|
|
uint64_t ru_oublock; /* block output operations */ |
|
|
|
|
|
uint64_t ru_msgsnd; /* IPC messages sent */ |
|
|
|
|
|
uint64_t ru_msgrcv; /* IPC messages received */ |
|
|
|
|
|
uint64_t ru_nsignals; /* signals received */ |
|
|
|
|
|
uint64_t ru_nvcsw; /* voluntary context switches */ |
|
|
|
|
|
uint64_t ru_nivcsw; /* involuntary context switches */ |
|
|
|
|
|
} uv_rusage_t; |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Get information about OS resource utilization for the current process. |
|
|
|
|
|
* Please note that not all uv_rusage_t struct fields will be filled on Windows. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN int uv_getrusage(uv_rusage_t* rusage); |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* This allocates cpu_infos array, and sets count. The array |
|
|
* This allocates cpu_infos array, and sets count. The array |
|
|
* is freed using uv_free_cpu_info(). |
|
|
* is freed using uv_free_cpu_info(). |
|
@ -1697,13 +1804,13 @@ UV_EXTERN int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, |
|
|
int flags, int mode, uv_fs_cb cb); |
|
|
int flags, int mode, uv_fs_cb cb); |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file, |
|
|
UV_EXTERN int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file, |
|
|
void* buf, size_t length, int64_t offset, uv_fs_cb cb); |
|
|
const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb); |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, |
|
|
UV_EXTERN int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, |
|
|
uv_fs_cb cb); |
|
|
uv_fs_cb cb); |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, |
|
|
UV_EXTERN int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, |
|
|
const void* buf, size_t length, int64_t offset, uv_fs_cb cb); |
|
|
const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb); |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, |
|
|
UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, |
|
|
int mode, uv_fs_cb cb); |
|
|
int mode, uv_fs_cb cb); |
|
@ -1786,7 +1893,8 @@ enum uv_fs_event { |
|
|
|
|
|
|
|
|
struct uv_fs_event_s { |
|
|
struct uv_fs_event_s { |
|
|
UV_HANDLE_FIELDS |
|
|
UV_HANDLE_FIELDS |
|
|
char* filename; |
|
|
/* private */ |
|
|
|
|
|
char* path; |
|
|
UV_FS_EVENT_PRIVATE_FIELDS |
|
|
UV_FS_EVENT_PRIVATE_FIELDS |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -1824,6 +1932,15 @@ UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle, |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle); |
|
|
UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Get the path being monitored by the handle. The buffer must be preallocated |
|
|
|
|
|
* by the user. Returns 0 on success or an error code < 0 in case of failure. |
|
|
|
|
|
* On sucess, `buf` will contain the path and `len` its length. If the buffer |
|
|
|
|
|
* is not big enough UV_ENOBUFS will be returned and len will be set to the |
|
|
|
|
|
* required size. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buf, size_t* len); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* UNIX signal handling on a per-event loop basis. The implementation is not |
|
|
* UNIX signal handling on a per-event loop basis. The implementation is not |
|
@ -1835,7 +1952,7 @@ UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle); |
|
|
* signals will lead to unpredictable behavior and is strongly discouraged. |
|
|
* signals will lead to unpredictable behavior and is strongly discouraged. |
|
|
* Future versions of libuv may simply reject them. |
|
|
* Future versions of libuv may simply reject them. |
|
|
* |
|
|
* |
|
|
* Some signal support is available on Windows: |
|
|
* Reception of some signals is emulated on Windows: |
|
|
* |
|
|
* |
|
|
* SIGINT is normally delivered when the user presses CTRL+C. However, like |
|
|
* SIGINT is normally delivered when the user presses CTRL+C. However, like |
|
|
* on Unix, it is not generated when terminal raw mode is enabled. |
|
|
* on Unix, it is not generated when terminal raw mode is enabled. |
|
@ -1854,11 +1971,14 @@ UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle); |
|
|
* the console buffer will also trigger a SIGWINCH signal. |
|
|
* the console buffer will also trigger a SIGWINCH signal. |
|
|
* |
|
|
* |
|
|
* Watchers for other signals can be successfully created, but these signals |
|
|
* Watchers for other signals can be successfully created, but these signals |
|
|
* are never generated. These signals are: SIGILL, SIGABRT, SIGFPE, SIGSEGV, |
|
|
* are never received. These signals are: SIGILL, SIGABRT, SIGFPE, SIGSEGV, |
|
|
* SIGTERM and SIGKILL. |
|
|
* SIGTERM and SIGKILL. |
|
|
* |
|
|
* |
|
|
* Note that calls to raise() or abort() to programmatically raise a signal are |
|
|
* Note that calls to raise() or abort() to programmatically raise a signal are |
|
|
* not detected by libuv; these will not trigger a signal watcher. |
|
|
* not detected by libuv; these will not trigger a signal watcher. |
|
|
|
|
|
* |
|
|
|
|
|
* See uv_process_kill() and uv_kill() for information about support for sending |
|
|
|
|
|
* signals. |
|
|
*/ |
|
|
*/ |
|
|
struct uv_signal_s { |
|
|
struct uv_signal_s { |
|
|
UV_HANDLE_FIELDS |
|
|
UV_HANDLE_FIELDS |
|
@ -1919,11 +2039,22 @@ UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle); |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle, |
|
|
UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle, |
|
|
uv_fs_event_cb cb, |
|
|
uv_fs_event_cb cb, |
|
|
const char* filename, |
|
|
const char* path, |
|
|
unsigned int flags); |
|
|
unsigned int flags); |
|
|
|
|
|
|
|
|
UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle); |
|
|
UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Get the path being monitored by the handle. The buffer must be preallocated |
|
|
|
|
|
* by the user. Returns 0 on success or an error code < 0 in case of failure. |
|
|
|
|
|
* On sucess, `buf` will contain the path and `len` its length. If the buffer |
|
|
|
|
|
* is not big enough UV_ENOBUFS will be returned and len will be set to the |
|
|
|
|
|
* required size. |
|
|
|
|
|
*/ |
|
|
|
|
|
UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle, |
|
|
|
|
|
char* buf, |
|
|
|
|
|
size_t* len); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Utility */ |
|
|
/* Utility */ |
|
|
|
|
|
|
|
|