Browse Source

upgrade libuv to 8e50b6043da7b3221f51b3158033255c9a210d08

v0.7.4-release
Igor Zinkovsky 13 years ago
parent
commit
da3356bb38
  1. 2
      deps/uv/.gitignore
  2. 1
      deps/uv/.mailmap
  3. 2
      deps/uv/AUTHORS
  4. 2
      deps/uv/README.md
  5. 2
      deps/uv/config-mingw.mk
  6. 1
      deps/uv/include/uv-private/uv-unix.h
  7. 6
      deps/uv/include/uv-private/uv-win.h
  8. 74
      deps/uv/include/uv.h
  9. 12
      deps/uv/src/unix/core.c
  10. 1
      deps/uv/src/unix/cygwin.c
  11. 212
      deps/uv/src/unix/darwin.c
  12. 170
      deps/uv/src/unix/freebsd.c
  13. 4
      deps/uv/src/unix/fs.c
  14. 6
      deps/uv/src/unix/internal.h
  15. 3
      deps/uv/src/unix/kqueue.c
  16. 365
      deps/uv/src/unix/linux.c
  17. 164
      deps/uv/src/unix/openbsd.c
  18. 5
      deps/uv/src/unix/pipe.c
  19. 10
      deps/uv/src/unix/stream.c
  20. 270
      deps/uv/src/unix/sunos.c
  21. 10
      deps/uv/src/unix/thread.c
  22. 3
      deps/uv/src/unix/udp.c
  23. 86
      deps/uv/src/uv-common.c
  24. 20
      deps/uv/src/win/core.c
  25. 12
      deps/uv/src/win/thread.c
  26. 2
      deps/uv/src/win/tty.c
  27. 343
      deps/uv/src/win/util.c
  28. 6
      deps/uv/src/win/winapi.h
  29. 24
      deps/uv/src/win/winsock.h
  30. 2
      deps/uv/test/benchmark-list.h
  31. 2
      deps/uv/test/run-tests.c
  32. 8
      deps/uv/test/runner.c
  33. 10
      deps/uv/test/runner.h
  34. 22
      deps/uv/test/test-fs-event.c
  35. 17
      deps/uv/test/test-list.h
  36. 31
      deps/uv/test/test-spawn.c
  37. 10
      deps/uv/uv.gyp

2
deps/uv/.gitignore

@ -7,6 +7,8 @@
*.orig
*.sdf
*.suo
core
vgcore.*
/out/
/build/gyp

1
deps/uv/.mailmap

@ -10,3 +10,4 @@ Saúl Ibarra Corretgé <saghul@gmail.com>
Yuki OKUMURA <mjt@cltn.org>
Frank Denis <github@pureftpd.org>
Ryan Emery <seebees@gmail.com>
Yasuhiro Matsumoto <mattn.jp@gmail.com>

2
deps/uv/AUTHORS

@ -36,3 +36,5 @@ Tj Holowaychuk <tj@vision-media.ca>
Shimon Doodkin <helpmepro1@gmail.com>
Ryan Emery <seebees@gmail.com>
Bruce Mitchener <bruce.mitchener@gmail.com>
Maciej Małecki <maciej.malecki@notimplemented.org>
Yasuhiro Matsumoto <mattn.jp@gmail.com>

2
deps/uv/README.md

@ -1,4 +1,4 @@
# libuv
# libuv [![Build Status](https://secure.travis-ci.org/joyent/libuv.png)](http://travis-ci.org/joyent/libuv)
libuv is a new platform layer for Node. Its purpose is to abstract IOCP on
Windows and libev on Unix systems. We intend to eventually contain all

2
deps/uv/config-mingw.mk

@ -24,7 +24,7 @@ CC = $(PREFIX)gcc
AR = $(PREFIX)ar
E=.exe
CFLAGS=$(CPPFLAGS) -g --std=gnu89 -D_WIN32_WINNT=0x0501 -Isrc/ares/config_win32
CFLAGS=$(CPPFLAGS) -g --std=gnu89 -D_WIN32_WINNT=0x0600 -Isrc/ares/config_win32
LINKFLAGS=-lm
CARES_OBJS += src/ares/windows_port.o

1
deps/uv/include/uv-private/uv-unix.h

@ -44,6 +44,7 @@ typedef struct {
typedef int uv_file;
typedef pthread_t uv_thread_t;
typedef pthread_mutex_t uv_mutex_t;
typedef pthread_rwlock_t uv_rwlock_t;

6
deps/uv/include/uv-private/uv-win.h

@ -137,10 +137,14 @@ typedef struct uv_buf_t {
typedef int uv_file;
typedef HANDLE uv_thread_t;
typedef CRITICAL_SECTION uv_mutex_t;
typedef union {
SRWLOCK srwlock_;
/* srwlock_ has type SRWLOCK, but not all toolchains define this type in */
/* windows.h. */
void* srwlock_;
struct {
uv_mutex_t read_mutex_;
uv_mutex_t write_mutex_;

74
deps/uv/include/uv.h

@ -177,6 +177,8 @@ typedef struct uv_async_s uv_async_t;
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
typedef struct uv_process_s uv_process_t;
typedef struct uv_counters_s uv_counters_t;
typedef struct uv_cpu_info_s uv_cpu_info_t;
typedef struct uv_interface_address_s uv_interface_address_t;
/* Request types */
typedef struct uv_req_s uv_req_t;
typedef struct uv_shutdown_s uv_shutdown_t;
@ -212,6 +214,11 @@ UV_EXTERN uv_loop_t* uv_default_loop(void);
*/
UV_EXTERN int uv_run (uv_loop_t*);
/*
* This function polls for new events without blocking.
*/
UV_EXTERN int uv_run_once (uv_loop_t*);
/*
* Manually modify the event loop's reference count. Useful if the user wants
* to have a handle or timeout that doesn't keep the loop alive.
@ -369,6 +376,21 @@ UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
UV_EXTERN uv_buf_t uv_buf_init(char* base, size_t len);
/*
* Utility function. Copies up to `size` characters from `src` to `dst`
* and ensures that `dst` is properly NUL terminated unless `size` is zero.
*/
UV_EXTERN size_t uv_strlcpy(char* dst, const char* src, size_t size);
/*
* Utility function. Appends `src` to `dst` and ensures that `dst` is
* properly NUL terminated unless `size` is zero or `dst` does not
* contain a NUL byte. `size` is the total length of `dst` so at most
* `size - strlen(dst) - 1` characters will be copied from `src`.
*/
UV_EXTERN size_t uv_strlcat(char* dst, const char* src, size_t size);
#define UV_STREAM_FIELDS \
/* number of bytes queued for writing */ \
size_t write_queue_size; \
@ -1016,7 +1038,48 @@ UV_EXTERN int uv_queue_work(uv_loop_t* loop, uv_work_t* req,
uv_work_cb work_cb, uv_after_work_cb after_work_cb);
struct uv_cpu_info_s {
char* model;
int speed;
struct uv_cpu_times_s {
uint64_t user;
uint64_t nice;
uint64_t sys;
uint64_t idle;
uint64_t irq;
} cpu_times;
};
struct uv_interface_address_s {
char* name;
int is_internal;
union {
struct sockaddr_in address4;
struct sockaddr_in6 address6;
} address;
};
UV_EXTERN char** uv_setup_args(int argc, char** argv);
UV_EXTERN uv_err_t uv_get_process_title(char* buffer, size_t size);
UV_EXTERN uv_err_t uv_set_process_title(const char* title);
UV_EXTERN uv_err_t uv_resident_set_memory(size_t* rss);
UV_EXTERN uv_err_t uv_uptime(double* uptime);
/*
* This allocates cpu_infos array, and sets count. The array
* is freed using uv_free_cpu_info().
*/
UV_EXTERN uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
/*
* This allocates addresses array, and sets count. The array
* is freed using uv_free_interface_addresses().
*/
UV_EXTERN uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
int* count);
UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count);
/*
* File System Methods.
@ -1254,12 +1317,19 @@ UV_EXTERN uv_err_t uv_dlclose(uv_lib_t library);
*/
UV_EXTERN uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr);
/*
* The mutex functions return 0 on success, -1 on error
* (unless the return type is void, of course).
*/
UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
/*
* Same goes for the read/write lock functions.
*/
UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
@ -1269,6 +1339,10 @@ UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
UV_EXTERN int uv_thread_create(uv_thread_t *tid,
void (*entry)(void *arg), void *arg);
UV_EXTERN int uv_thread_join(uv_thread_t *tid);
/* the presence of these unions force similar struct layout */
union uv_any_handle {
uv_tcp_t tcp;

12
deps/uv/src/unix/core.c

@ -202,6 +202,12 @@ int uv_run(uv_loop_t* loop) {
}
int uv_run_once(uv_loop_t* loop) {
ev_run(loop->ev, EVRUN_NOWAIT);
return 0;
}
void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle,
uv_handle_type type) {
loop->counters.handle_init++;
@ -317,8 +323,8 @@ int64_t uv_now(uv_loop_t* loop) {
}
void uv__req_init(uv_req_t* req) {
/* loop->counters.req_init++; */
void uv__req_init(uv_loop_t* loop, uv_req_t* req) {
loop->counters.req_init++;
req->type = UV_UNKNOWN_REQ;
}
@ -658,7 +664,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
return -1;
}
uv__req_init((uv_req_t*)handle);
uv__req_init(loop, (uv_req_t*)handle);
handle->type = UV_GETADDRINFO;
handle->loop = loop;
handle->cb = cb;

1
deps/uv/src/unix/cygwin.c

@ -72,6 +72,7 @@ int uv_fs_event_init(uv_loop_t* loop,
const char* filename,
uv_fs_event_cb cb,
int flags) {
loop->counters.fs_event_init++;
uv__set_sys_error(loop, ENOSYS);
return -1;
}

212
deps/uv/src/unix/darwin.c

@ -25,6 +25,9 @@
#include <stdint.h>
#include <errno.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <CoreServices/CoreServices.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
@ -34,6 +37,9 @@
#include <unistd.h> /* sysconf */
static char *process_title;
uint64_t uv_hrtime() {
uint64_t time;
Nanoseconds enano;
@ -71,6 +77,7 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}
uint64_t uv_get_free_memory(void) {
vm_statistics_data_t info;
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);
@ -83,6 +90,7 @@ uint64_t uv_get_free_memory(void) {
return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
}
uint64_t uv_get_total_memory(void) {
uint64_t info;
int which[] = {CTL_HW, HW_MEMSIZE};
@ -95,6 +103,7 @@ uint64_t uv_get_total_memory(void) {
return (uint64_t) info;
}
void uv_loadavg(double avg[3]) {
struct loadavg info;
size_t size = sizeof(info);
@ -106,3 +115,206 @@ void uv_loadavg(double avg[3]) {
avg[1] = (double) info.ldavg[1] / info.fscale;
avg[2] = (double) info.ldavg[2] / info.fscale;
}
char** uv_setup_args(int argc, char** argv) {
process_title = argc ? strdup(argv[0]) : NULL;
return argv;
}
uv_err_t uv_set_process_title(const char* title) {
/* TODO implement me */
return uv__new_artificial_error(UV_ENOSYS);
}
uv_err_t uv_get_process_title(char* buffer, size_t size) {
if (process_title) {
strncpy(buffer, process_title, size);
} else {
if (size > 0) {
buffer[0] = '\0';
}
}
return uv_ok_;
}
uv_err_t uv_resident_set_memory(size_t* rss) {
struct task_basic_info t_info;
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
int r = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&t_info,
&t_info_count);
if (r != KERN_SUCCESS) {
return uv__new_sys_error(errno);
}
*rss = t_info.resident_size;
return uv_ok_;
}
uv_err_t uv_uptime(double* uptime) {
time_t now;
struct timeval info;
size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
return uv__new_sys_error(errno);
}
now = time(NULL);
*uptime = (double)(now - info.tv_sec);
return uv_ok_;
}
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks);
char model[512];
uint64_t cpuspeed;
size_t size;
unsigned int i;
natural_t numcpus;
mach_msg_type_number_t msg_type;
processor_cpu_load_info_data_t *info;
uv_cpu_info_t* cpu_info;
size = sizeof(model);
if (sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) {
return uv__new_sys_error(errno);
}
size = sizeof(cpuspeed);
if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0) < 0) {
return uv__new_sys_error(errno);
}
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
(processor_info_array_t*)&info,
&msg_type) != KERN_SUCCESS) {
return uv__new_sys_error(errno);
}
*cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t));
if (!(*cpu_infos)) {
return uv__new_artificial_error(UV_ENOMEM);
}
*count = numcpus;
for (i = 0; i < numcpus; i++) {
cpu_info = &(*cpu_infos)[i];
cpu_info->cpu_times.user = (uint64_t)(info[i].cpu_ticks[0]) * multiplier;
cpu_info->cpu_times.nice = (uint64_t)(info[i].cpu_ticks[3]) * multiplier;
cpu_info->cpu_times.sys = (uint64_t)(info[i].cpu_ticks[1]) * multiplier;
cpu_info->cpu_times.idle = (uint64_t)(info[i].cpu_ticks[2]) * multiplier;
cpu_info->cpu_times.irq = 0;
cpu_info->model = strdup(model);
cpu_info->speed = cpuspeed/1000000;
}
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);
return uv_ok_;
}
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
free(cpu_infos[i].model);
}
free(cpu_infos);
}
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
struct ifaddrs *addrs, *ent;
char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address;
if (getifaddrs(&addrs) != 0) {
return uv__new_sys_error(errno);
}
*count = 0;
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING) ||
(ent->ifa_addr == NULL) ||
(ent->ifa_addr->sa_family == AF_LINK)) {
continue;
}
(*count)++;
}
*addresses = (uv_interface_address_t*)
malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) {
return uv__new_artificial_error(UV_ENOMEM);
}
address = *addresses;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
bzero(&ip, sizeof (ip));
if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING)) {
continue;
}
if (ent->ifa_addr == NULL) {
continue;
}
/*
* On Mac OS X getifaddrs returns information related to Mac Addresses for
* various devices, such as firewire, etc. These are not relevant here.
*/
if (ent->ifa_addr->sa_family == AF_LINK) {
continue;
}
address->name = strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6 *)ent->ifa_addr);
} else {
address->address.address4 = *((struct sockaddr_in *)ent->ifa_addr);
}
address->is_internal = ent->ifa_flags & IFF_LOOPBACK ? 1 : 0;
address++;
}
freeifaddrs(addrs);
return uv_ok_;
}
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
int i;
for (i = 0; i < count; i++) {
free(addresses[i].name);
}
free(addresses);
}

170
deps/uv/src/unix/freebsd.c

@ -19,22 +19,31 @@
*/
#include "uv.h"
#include "internal.h"
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <kvm.h>
#include <paths.h>
#include <sys/user.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <vm/vm_param.h> /* VM_LOADAVG */
#include <time.h>
#include <stdlib.h>
#include <unistd.h> /* sysconf */
#include <fcntl.h>
#undef NANOSEC
#define NANOSEC 1000000000
static char *process_title;
uint64_t uv_hrtime(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@ -72,6 +81,7 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}
uint64_t uv_get_free_memory(void) {
int freecount;
size_t size = sizeof(freecount);
@ -84,6 +94,7 @@ uint64_t uv_get_free_memory(void) {
}
uint64_t uv_get_total_memory(void) {
unsigned long info;
int which[] = {CTL_HW, HW_PHYSMEM};
@ -97,6 +108,7 @@ uint64_t uv_get_total_memory(void) {
return (uint64_t) info;
}
void uv_loadavg(double avg[3]) {
struct loadavg info;
size_t size = sizeof(info);
@ -108,3 +120,161 @@ void uv_loadavg(double avg[3]) {
avg[1] = (double) info.ldavg[1] / info.fscale;
avg[2] = (double) info.ldavg[2] / info.fscale;
}
char** uv_setup_args(int argc, char** argv) {
process_title = argc ? strdup(argv[0]) : NULL;
return argv;
}
uv_err_t uv_set_process_title(const char* title) {
if (process_title) free(process_title);
process_title = strdup(title);
setproctitle(title);
return uv_ok_;
}
uv_err_t uv_get_process_title(char* buffer, size_t size) {
if (process_title) {
strncpy(buffer, process_title, size);
} else {
if (size > 0) {
buffer[0] = '\0';
}
}
return uv_ok_;
}
uv_err_t uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL;
struct kinfo_proc *kinfo = NULL;
pid_t pid;
int nprocs;
size_t page_size = getpagesize();
pid = getpid();
kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open");
if (kd == NULL) goto error;
kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &nprocs);
if (kinfo == NULL) goto error;
*rss = kinfo->ki_rssize * page_size;
kvm_close(kd);
return uv_ok_;
error:
if (kd) kvm_close(kd);
return uv__new_sys_error(errno);
}
uv_err_t uv_uptime(double* uptime) {
time_t now;
struct timeval info;
size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
return uv__new_sys_error(errno);
}
now = time(NULL);
*uptime = (double)(now - info.tv_sec);
return uv_ok_;
}
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus,
cur = 0;
char model[512];
int numcpus;
size_t size;
uv_cpu_info_t* cpu_info;
size = sizeof(model);
if (sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) {
return uv__new_sys_error(errno);
}
size = sizeof(numcpus);
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0) < 0) {
return uv__new_sys_error(errno);
}
*cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t));
if (!(*cpu_infos)) {
return uv__new_artificial_error(UV_ENOMEM);
}
*count = numcpus;
size = sizeof(cpuspeed);
if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0) < 0) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}
// kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of ncpu
size = sizeof(maxcpus);
if (sysctlbyname("kern.smp.maxcpus", &maxcpus, &size, NULL, 0) < 0) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}
size = maxcpus * CPUSTATES * sizeof(long);
long cp_times[size];
if (sysctlbyname("kern.cp_times", &cp_times, &size, NULL, 0) < 0) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}
for (int i = 0; i < numcpus; i++) {
cpu_info = &(*cpu_infos)[i];
cpu_info->cpu_times.user = (uint64_t)(cp_times[CP_USER+cur]) * multiplier;
cpu_info->cpu_times.nice = (uint64_t)(cp_times[CP_NICE+cur]) * multiplier;
cpu_info->cpu_times.sys = (uint64_t)(cp_times[CP_SYS+cur]) * multiplier;
cpu_info->cpu_times.idle = (uint64_t)(cp_times[CP_IDLE+cur]) * multiplier;
cpu_info->cpu_times.irq = (uint64_t)(cp_times[CP_INTR+cur]) * multiplier;
cpu_info->model = strdup(model);
cpu_info->speed = cpuspeed;
cur+=CPUSTATES;
}
return uv_ok_;
}
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
free(cpu_infos[i].model);
}
free(cpu_infos);
}
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
/* TODO: implement */
*addresses = NULL;
*count = 0;
return uv_ok_;
}
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
}

4
deps/uv/src/unix/fs.c

@ -66,7 +66,7 @@ static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type,
/* Make sure the thread pool is initialized. */
uv_eio_init(loop);
uv__req_init((uv_req_t*) req);
uv__req_init(loop, (uv_req_t*)req);
req->type = UV_FS;
req->loop = loop;
req->fs_type = fs_type;
@ -685,7 +685,7 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
uv_eio_init(loop);
uv__req_init((uv_req_t*) req);
uv__req_init(loop, (uv_req_t*)req);
uv_ref(loop);
req->loop = loop;
req->data = data;

6
deps/uv/src/unix/internal.h

@ -142,10 +142,7 @@ enum {
UV_TCP_KEEPALIVE = 0x100 /* Turn on keep-alive. */
};
size_t uv__strlcpy(char* dst, const char* src, size_t size);
int uv__close(int fd);
void uv__req_init(uv_req_t*);
void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, uv_handle_type type);
@ -157,6 +154,9 @@ int uv__socket(int domain, int type, int protocol);
uv_err_code uv_translate_sys_error(int sys_errno);
void uv_fatal_error(const int errorno, const char* syscall);
/* requests */
void uv__req_init(uv_loop_t* loop, uv_req_t*);
/* stream */
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
uv_handle_type type);

3
deps/uv/src/unix/kqueue.c

@ -90,6 +90,8 @@ int uv_fs_event_init(uv_loop_t* loop,
int flags) {
int fd;
loop->counters.fs_event_init++;
/* We don't support any flags yet. */
assert(!flags);
@ -129,6 +131,7 @@ int uv_fs_event_init(uv_loop_t* loop,
const char* filename,
uv_fs_event_cb cb,
int flags) {
loop->counters.fs_event_init++;
uv__set_sys_error(loop, ENOSYS);
return -1;
}

365
deps/uv/src/unix/linux.c

@ -22,12 +22,16 @@
#include "internal.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <sys/inotify.h>
#include <sys/param.h>
#include <sys/sysinfo.h>
#include <unistd.h>
#include <time.h>
@ -36,6 +40,14 @@
#define NANOSEC 1000000000
static char buf[MAXPATHLEN + 1];
static struct {
char *str;
size_t len;
} process_title;
/* Don't look aghast, this is exactly how glibc's basename() works. */
static char* basename_r(const char* path) {
char* s = strrchr(path, '/');
@ -161,6 +173,8 @@ int uv_fs_event_init(uv_loop_t* loop,
int events;
int fd;
loop->counters.fs_event_init++;
/* We don't support any flags yet. */
assert(!flags);
@ -207,3 +221,354 @@ void uv__fs_event_destroy(uv_fs_event_t* handle) {
free(handle->filename);
handle->filename = NULL;
}
char** uv_setup_args(int argc, char** argv) {
char **new_argv;
char **new_env;
size_t size;
int envc;
char *s;
int i;
for (envc = 0; environ[envc]; envc++);
s = envc ? environ[envc - 1] : argv[argc - 1];
process_title.str = argv[0];
process_title.len = s + strlen(s) + 1 - argv[0];
size = process_title.len;
size += (argc + 1) * sizeof(char **);
size += (envc + 1) * sizeof(char **);
if ((s = (char *) malloc(size)) == NULL) {
process_title.str = NULL;
process_title.len = 0;
return argv;
}
new_argv = (char **) s;
new_env = new_argv + argc + 1;
s = (char *) (new_env + envc + 1);
memcpy(s, process_title.str, process_title.len);
for (i = 0; i < argc; i++)
new_argv[i] = s + (argv[i] - argv[0]);
new_argv[argc] = NULL;
s += environ[0] - argv[0];
for (i = 0; i < envc; i++)
new_env[i] = s + (environ[i] - environ[0]);
new_env[envc] = NULL;
environ = new_env;
return new_argv;
}
uv_err_t uv_set_process_title(const char* title) {
/* No need to terminate, last char is always '\0'. */
if (process_title.len)
strncpy(process_title.str, title, process_title.len - 1);
return uv_ok_;
}
uv_err_t uv_get_process_title(char* buffer, size_t size) {
if (process_title.str) {
strncpy(buffer, process_title.str, size);
} else {
if (size > 0) {
buffer[0] = '\0';
}
}
return uv_ok_;
}
uv_err_t uv_resident_set_memory(size_t* rss) {
FILE* f;
int itmp;
char ctmp;
size_t page_size = getpagesize();
char *cbuf;
int foundExeEnd;
f = fopen("/proc/self/stat", "r");
if (!f) return uv__new_sys_error(errno);
/* PID */
if (fscanf(f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Exec file */
cbuf = buf;
foundExeEnd = 0;
if (fscanf (f, "%c", cbuf++) == 0) goto error;
while (1) {
if (fscanf(f, "%c", cbuf) == 0) goto error;
if (*cbuf == ')') {
foundExeEnd = 1;
} else if (foundExeEnd && *cbuf == ' ') {
*cbuf = 0;
break;
}
cbuf++;
}
/* State */
if (fscanf (f, "%c ", &ctmp) == 0) goto error; /* coverity[secure_coding] */
/* Parent process */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Process group */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Session id */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* TTY */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* TTY owner process group */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Flags */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Minor faults (no memory page) */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Minor faults, children */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Major faults (memory page faults) */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Major faults, children */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* utime */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* stime */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* utime, children */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* stime, children */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* jiffies remaining in current time slice */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* 'nice' value */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* jiffies until next timeout */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* jiffies until next SIGALRM */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* start time (jiffies since system boot) */
if (fscanf (f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Virtual memory size */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Resident set size */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
*rss = (size_t) itmp * page_size;
/* rlim */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Start of text */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* End of text */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
/* Start of stack */
if (fscanf (f, "%u ", &itmp) == 0) goto error; /* coverity[secure_coding] */
fclose (f);
return uv_ok_;
error:
fclose (f);
return uv__new_sys_error(errno);
}
uv_err_t uv_uptime(double* uptime) {
#ifdef CLOCK_MONOTONIC
struct timespec now;
if (0 == clock_gettime(CLOCK_MONOTONIC, &now)) {
*uptime = now.tv_sec;
*uptime += (double)now.tv_nsec / 1000000000.0;
return uv_ok_;
}
return uv__new_sys_error(errno);
#else
struct sysinfo info;
if (sysinfo(&info) < 0) {
return uv__new_sys_error(errno);
}
*uptime = (double)info.uptime;
return uv_ok_;
#endif
}
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks), cpuspeed;
int numcpus = 0, i = 0;
unsigned long long ticks_user, ticks_sys, ticks_idle, ticks_nice, ticks_intr;
char line[512], speedPath[256], model[512];
FILE *fpStat = fopen("/proc/stat", "r");
FILE *fpModel = fopen("/proc/cpuinfo", "r");
FILE *fpSpeed;
uv_cpu_info_t* cpu_info;
if (fpModel) {
while (fgets(line, 511, fpModel) != NULL) {
if (strncmp(line, "model name", 10) == 0) {
numcpus++;
if (numcpus == 1) {
char *p = strchr(line, ':') + 2;
strcpy(model, p);
model[strlen(model)-1] = 0;
}
} else if (strncmp(line, "cpu MHz", 7) == 0) {
if (numcpus == 1) {
sscanf(line, "%*s %*s : %u", &cpuspeed);
}
}
}
fclose(fpModel);
}
*cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t));
if (!(*cpu_infos)) {
return uv__new_artificial_error(UV_ENOMEM);
}
*count = numcpus;
cpu_info = *cpu_infos;
if (fpStat) {
while (fgets(line, 511, fpStat) != NULL) {
if (strncmp(line, "cpu ", 4) == 0) {
continue;
} else if (strncmp(line, "cpu", 3) != 0) {
break;
}
sscanf(line, "%*s %llu %llu %llu %llu %*llu %llu",
&ticks_user, &ticks_nice, &ticks_sys, &ticks_idle, &ticks_intr);
snprintf(speedPath, sizeof(speedPath),
"/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_max_freq", i);
fpSpeed = fopen(speedPath, "r");
if (fpSpeed) {
if (fgets(line, 511, fpSpeed) != NULL) {
sscanf(line, "%u", &cpuspeed);
cpuspeed /= 1000;
}
fclose(fpSpeed);
}
cpu_info->cpu_times.user = ticks_user * multiplier;
cpu_info->cpu_times.nice = ticks_nice * multiplier;
cpu_info->cpu_times.sys = ticks_sys * multiplier;
cpu_info->cpu_times.idle = ticks_idle * multiplier;
cpu_info->cpu_times.irq = ticks_intr * multiplier;
cpu_info->model = strdup(model);
cpu_info->speed = cpuspeed;
cpu_info++;
}
fclose(fpStat);
}
return uv_ok_;
}
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
free(cpu_infos[i].model);
}
free(cpu_infos);
}
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
struct ifaddrs *addrs, *ent;
char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address;
if (getifaddrs(&addrs) != 0) {
return uv__new_sys_error(errno);
}
*count = 0;
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING) ||
(ent->ifa_addr == NULL) ||
(ent->ifa_addr->sa_family == PF_PACKET)) {
continue;
}
(*count)++;
}
*addresses = (uv_interface_address_t*)
malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) {
return uv__new_artificial_error(UV_ENOMEM);
}
address = *addresses;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
bzero(&ip, sizeof (ip));
if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING)) {
continue;
}
if (ent->ifa_addr == NULL) {
continue;
}
/*
* On Linux getifaddrs returns information related to the raw underlying
* devices. We're not interested in this information.
*/
if (ent->ifa_addr->sa_family == PF_PACKET) {
continue;
}
address->name = strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6 *)ent->ifa_addr);
} else {
address->address.address4 = *((struct sockaddr_in *)ent->ifa_addr);
}
address->is_internal = ent->ifa_flags & IFF_LOOPBACK ? 1 : 0;
address++;
}
freeifaddrs(addrs);
return uv_ok_;
}
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
int i;
for (i = 0; i < count; i++) {
free(addresses[i].name);
}
free(addresses);
}

164
deps/uv/src/unix/openbsd.c

@ -33,12 +33,16 @@
#define NANOSEC 1000000000
static char *process_title;
uint64_t uv_hrtime(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
}
void uv_loadavg(double avg[3]) {
struct loadavg info;
size_t size = sizeof(info);
@ -51,6 +55,7 @@ void uv_loadavg(double avg[3]) {
avg[2] = (double) info.ldavg[2] / info.fscale;
}
int uv_exepath(char* buffer, size_t* size) {
int mib[4];
char **argsbuf = NULL;
@ -98,6 +103,7 @@ out:
return status;
}
uint64_t uv_get_free_memory(void) {
struct uvmexp info;
size_t size = sizeof(info);
@ -110,6 +116,7 @@ uint64_t uv_get_free_memory(void) {
return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
}
uint64_t uv_get_total_memory(void) {
uint64_t info;
int which[] = {CTL_HW, HW_PHYSMEM64};
@ -121,3 +128,160 @@ uint64_t uv_get_total_memory(void) {
return (uint64_t) info;
}
char** uv_setup_args(int argc, char** argv) {
process_title = argc ? strdup(argv[0]) : NULL;
return argv;
}
uv_err_t uv_set_process_title(const char* title) {
if (process_title) free(process_title);
process_title = strdup(title);
setproctitle(title);
return uv_ok_;
}
uv_err_t uv_get_process_title(char* buffer, size_t size) {
if (process_title) {
strncpy(buffer, process_title, size);
} else {
if (size > 0) {
buffer[0] = '\0';
}
}
return uv_ok_;
}
uv_err_t uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL;
struct kinfo_proc2 *kinfo = NULL;
pid_t pid;
int nprocs, max_size = sizeof(struct kinfo_proc2);
size_t page_size = getpagesize();
pid = getpid();
kd = kvm_open(NULL, _PATH_MEM, NULL, O_RDONLY, "kvm_open");
if (kd == NULL) goto error;
kinfo = kvm_getproc2(kd, KERN_PROC_PID, pid, max_size, &nprocs);
if (kinfo == NULL) goto error;
*rss = kinfo->p_vm_rssize * page_size;
kvm_close(kd);
return uv_ok_;
error:
if (kd) kvm_close(kd);
return uv__new_sys_error(errno);
}
uv_err_t uv_uptime(double* uptime) {
time_t now;
struct timeval info;
size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
return uv__new_sys_error(errno);
}
now = time(NULL);
*uptime = (double)(now - info.tv_sec);
return uv_ok_;
}
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks), cpuspeed;
uint64_t info[CPUSTATES];
char model[512];
int numcpus = 1;
static int which[] = {CTL_HW, HW_MODEL, NULL};
size_t size;
uv_cpu_info_t* cpu_info;
size = sizeof(model);
if (sysctl(which, 2, &model, &size, NULL, 0) < 0) {
return -1;
}
which[1] = HW_NCPU;
size = sizeof(numcpus);
if (sysctl(which, 2, &numcpus, &size, NULL, 0) < 0) {
return -1;
}
*cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t));
if (!(*cpu_infos)) {
return uv__new_artificial_error(UV_ENOMEM);
}
*count = numcpus;
which[1] = HW_CPUSPEED;
size = sizeof(cpuspeed);
if (sysctl(which, 2, &cpuspeed, &size, NULL, 0) < 0) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}
size = sizeof(info);
which[0] = CTL_KERN;
which[1] = KERN_CPTIME2;
for (int i = 0; i < numcpus; i++) {
which[2] = i;
size = sizeof(info);
if (sysctl(which, 3, &info, &size, NULL, 0) < 0) {
free(*cpu_infos);
return uv__new_sys_error(errno);
}
cpu_info = &(*cpu_infos)[i];
cpu_info->cpu_times.user = (uint64_t)(info[CP_USER]) * multiplier);
cpu_info->cpu_times.nice = ((uint64_t)(info[CP_NICE]) * multiplier);
cpu_info->cpu_times.sys = (uint64_t)(info[CP_SYS]) * multiplier));
cpu_info->cpu_times.idle = (uint64_t)(info[CP_IDLE]) * multiplier));
cpu_info->cpu_times.irq = (uint64_t)(info[CP_INTR]) * multiplier));
cpu_info->model = strdup(model);
cpu_info->speed = cpuspeed;
}
return uv_ok_;
}
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
free(cpu_infos[i].brand);
}
free(cpu_infos);
}
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
/* TODO: implement */
*addresses = NULL;
*count = 0;
return uv_ok_;
}
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
}

5
deps/uv/src/unix/pipe.c

@ -74,7 +74,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
}
memset(&saddr, 0, sizeof saddr);
uv__strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
uv_strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) {
@ -197,7 +197,7 @@ void uv_pipe_connect(uv_connect_t* req,
}
memset(&saddr, 0, sizeof saddr);
uv__strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path));
uv_strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;
/* We don't check for EINPROGRESS. Think about it: the socket
@ -274,5 +274,4 @@ void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) {
void uv_pipe_pending_instances(uv_pipe_t* handle, int count) {
return 0;
}

10
deps/uv/src/unix/stream.c

@ -145,7 +145,7 @@ void uv__stream_destroy(uv_stream_t* stream) {
req = ngx_queue_data(q, uv_write_t, queue);
if (req->cb) {
uv__set_artificial_error(stream->loop, req->error);
uv__set_sys_error(stream->loop, req->error);
req->cb(req, req->error ? -1 : 0);
}
}
@ -497,7 +497,7 @@ static void uv__write_callbacks(uv_stream_t* stream) {
/* NOTE: call callback AFTER freeing the request data. */
if (req->cb) {
uv__set_artificial_error(stream->loop, req->error);
uv__set_sys_error(stream->loop, req->error);
req->cb(req, req->error ? -1 : 0);
}
@ -662,7 +662,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
}
/* Initialize request */
uv__req_init((uv_req_t*)req);
uv__req_init(stream->loop, (uv_req_t*)req);
req->handle = stream;
req->cb = cb;
@ -772,7 +772,7 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
}
}
uv__req_init((uv_req_t*)req);
uv__req_init(stream->loop, (uv_req_t*)req);
req->cb = cb;
req->handle = stream;
req->type = UV_CONNECT;
@ -847,7 +847,7 @@ int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
empty_queue = (stream->write_queue_size == 0);
/* Initialize the req */
uv__req_init((uv_req_t*) req);
uv__req_init(stream->loop, (uv_req_t*)req);
req->cb = cb;
req->handle = stream;
req->error = 0;

270
deps/uv/src/unix/sunos.c

@ -28,6 +28,11 @@
#include <assert.h>
#include <errno.h>
#ifdef SUNOS_HAVE_IFADDRS
# include <ifaddrs.h>
#endif
#include <net/if.h>
#include <sys/loadavg.h>
#include <sys/time.h>
#include <unistd.h>
@ -38,6 +43,19 @@
# include <port.h>
#endif
#if (!defined(_LP64)) && (_FILE_OFFSET_BITS - 0 == 64)
#define PROCFS_FILE_OFFSET_BITS_HACK 1
#undef _FILE_OFFSET_BITS
#else
#define PROCFS_FILE_OFFSET_BITS_HACK 0
#endif
#include <procfs.h>
#if (PROCFS_FILE_OFFSET_BITS_HACK - 0 == 1)
#define _FILE_OFFSET_BITS 64
#endif
uint64_t uv_hrtime() {
return (gethrtime());
@ -145,6 +163,8 @@ int uv_fs_event_init(uv_loop_t* loop,
int flags) {
int portfd;
loop->counters.fs_event_init++;
/* We don't support any flags yet. */
assert(!flags);
@ -185,6 +205,7 @@ int uv_fs_event_init(uv_loop_t* loop,
const char* filename,
uv_fs_event_cb cb,
int flags) {
loop->counters.fs_event_init++;
uv__set_sys_error(loop, ENOSYS);
return -1;
}
@ -195,3 +216,252 @@ void uv__fs_event_destroy(uv_fs_event_t* handle) {
}
#endif /* HAVE_PORTS_FS */
char** uv_setup_args(int argc, char** argv) {
return argv;
}
uv_err_t uv_set_process_title(const char* title) {
return uv_ok_;
}
uv_err_t uv_get_process_title(char* buffer, size_t size) {
if (size > 0) {
buffer[0] = '\0';
}
return uv_ok_;
}
uv_err_t uv_resident_set_memory(size_t* rss) {
pid_t pid = getpid();
psinfo_t psinfo;
char pidpath[1024];
FILE *f;
sprintf(pidpath, "/proc/%d/psinfo", (int)pid);
f = fopen(pidpath, "r");
if (!f) return uv__new_sys_error(errno);
if (fread(&psinfo, sizeof(psinfo_t), 1, f) != 1) {
fclose (f);
return uv__new_sys_error(errno);
}
/* XXX correct? */
*rss = (size_t) psinfo.pr_rssize * 1024;
fclose (f);
return uv_ok_;
}
uv_err_t uv_uptime(double* uptime) {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *knp;
long hz = sysconf(_SC_CLK_TCK);
if ((kc = kstat_open()) == NULL)
return uv__new_sys_error(errno);
ksp = kstat_lookup(kc, (char *)"unix", 0, (char *)"system_misc");
if (kstat_read(kc, ksp, NULL) == -1) {
*uptime = -1;
} else {
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"clk_intr");
*uptime = knp->value.ul / hz;
}
kstat_close(kc);
return uv_ok_;
}
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
int lookup_instance;
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *knp;
uv_cpu_info_t* cpu_info;
if ((kc = kstat_open()) == NULL) {
return uv__new_sys_error(errno);
}
/* Get count of cpus */
lookup_instance = 0;
while ((ksp = kstat_lookup(kc, (char *)"cpu_info", lookup_instance, NULL))) {
lookup_instance++;
}
*cpu_infos = (uv_cpu_info_t*)
malloc(lookup_instance * sizeof(uv_cpu_info_t));
if (!(*cpu_infos)) {
return uv__new_artificial_error(UV_ENOMEM);
}
*count = lookup_instance;
cpu_info = *cpu_infos;
lookup_instance = 0;
while ((ksp = kstat_lookup(kc, (char *)"cpu_info", lookup_instance, NULL))) {
if (kstat_read(kc, ksp, NULL) == -1) {
/*
* It is deeply annoying, but some kstats can return errors
* under otherwise routine conditions. (ACPI is one
* offender; there are surely others.) To prevent these
* fouled kstats from completely ruining our day, we assign
* an "error" member to the return value that consists of
* the strerror().
*/
cpu_info->speed = 0;
cpu_info->model = NULL;
} else {
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"clock_MHz");
assert(knp->data_type == KSTAT_DATA_INT32);
cpu_info->speed = knp->value.i32;
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"brand");
assert(knp->data_type == KSTAT_DATA_STRING);
cpu_info->model = KSTAT_NAMED_STR_PTR(knp);
}
lookup_instance++;
cpu_info++;
}
cpu_info = *cpu_infos;
lookup_instance = 0;
while ((ksp = kstat_lookup(kc, (char *)"cpu", lookup_instance, (char *)"sys"))){
if (kstat_read(kc, ksp, NULL) == -1) {
cpu_info->cpu_times.user = 0;
cpu_info->cpu_times.nice = 0;
cpu_info->cpu_times.sys = 0;
cpu_info->cpu_times.idle = 0;
cpu_info->cpu_times.irq = 0;
} else {
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"cpu_ticks_user");
assert(knp->data_type == KSTAT_DATA_UINT64);
cpu_info->cpu_times.user = knp->value.ui64;
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"cpu_ticks_kernel");
assert(knp->data_type == KSTAT_DATA_UINT64);
cpu_info->cpu_times.sys = knp->value.ui64;
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"cpu_ticks_idle");
assert(knp->data_type == KSTAT_DATA_UINT64);
cpu_info->cpu_times.idle = knp->value.ui64;
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"intr");
assert(knp->data_type == KSTAT_DATA_UINT64);
cpu_info->cpu_times.irq = knp->value.ui64;
cpu_info->cpu_times.nice = 0;
}
lookup_instance++;
cpu_info++;
}
kstat_close(kc);
return uv_ok_;
}
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
free(cpu_infos[i].model);
}
free(cpu_infos);
}
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
#ifndef SUNOS_HAVE_IFADDRS
return uv__new_artificial_error(UV_ENOSYS);
#else
struct ifaddrs *addrs, *ent;
char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address;
if (getifaddrs(&addrs) != 0) {
return uv__new_sys_error(errno);
}
*count = 0;
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING) ||
(ent->ifa_addr == NULL) ||
(ent->ifa_addr->sa_family == PF_PACKET)) {
continue;
}
(*count)++;
}
*addresses = (uv_interface_address_t*)
malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) {
return uv__new_artificial_error(UV_ENOMEM);
}
address = *addresses;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
bzero(&ip, sizeof (ip));
if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING)) {
continue;
}
if (ent->ifa_addr == NULL) {
continue;
}
address->name = strdup(ent->ifa_name);
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6 *)ent->ifa_addr);
} else {
address->address.address4 = *((struct sockaddr_in *)ent->ifa_addr);
}
address->is_internal = ent->ifa_flags & IFF_PRIVATE || ent->ifa_flags &
IFF_LOOPBACK ? 1 : 0;
address++;
}
freeifaddrs(addrs);
return uv_ok_;
#endif /* SUNOS_HAVE_IFADDRS */
}
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
int i;
for (i = 0; i < count; i++) {
free(addresses[i].name);
}
free(addresses);
}

10
deps/uv/src/unix/thread.c

@ -23,9 +23,9 @@
#include "internal.h"
#include <pthread.h>
#include <assert.h>
#include <errno.h>
#ifdef NDEBUG
# define CHECK(r) ((void) (r))
#else
@ -40,6 +40,14 @@
#endif
int uv_thread_join(uv_thread_t *tid) {
if (pthread_join(*tid, NULL))
return -1;
else
return 0;
}
int uv_mutex_init(uv_mutex_t* mutex) {
if (pthread_mutex_init(mutex, NULL))
return -1;

3
deps/uv/src/unix/udp.c

@ -401,8 +401,7 @@ static int uv__udp_send(uv_udp_send_t* req,
if (uv__udp_maybe_deferred_bind(handle, addr->sa_family))
return -1;
/* Don't use uv__req_init(), it zeroes the data field. */
handle->loop->counters.req_init++;
uv__req_init(handle->loop, (uv_req_t*)req);
memcpy(&req->addr, addr, addrlen);
req->addrlen = addrlen;

86
deps/uv/src/uv-common.c

@ -24,6 +24,7 @@
#include <assert.h>
#include <stddef.h> /* NULL */
#include <stdlib.h> /* malloc */
#include <string.h> /* memset */
/* use inet_pton from c-ares if necessary */
@ -40,6 +41,41 @@ uv_counters_t* uv_counters() {
}
size_t uv_strlcpy(char* dst, const char* src, size_t size) {
size_t n;
if (size == 0)
return 0;
for (n = 0; n < (size - 1) && *src != '\0'; n++)
*dst++ = *src++;
*dst = '\0';
return n;
}
size_t uv_strlcat(char* dst, const char* src, size_t size) {
size_t n;
if (size == 0)
return 0;
for (n = 0; n < size && *dst != '\0'; n++, dst++);
if (n == size)
return n;
while (n < (size - 1) && *src != '\0')
n++, *dst++ = *src++;
*dst = '\0';
return n;
}
uv_buf_t uv_buf_init(char* base, size_t len) {
uv_buf_t buf;
buf.base = base;
@ -261,3 +297,53 @@ int uv_tcp_connect6(uv_connect_t* req,
return uv__tcp_connect6(req, handle, address, cb);
}
#ifdef _WIN32
static DWORD __stdcall uv__thread_start(void *ctx_v)
#else
static void *uv__thread_start(void *ctx_v)
#endif
{
void (*entry)(void *arg);
void *arg;
struct {
void (*entry)(void *arg);
void *arg;
} *ctx;
ctx = ctx_v;
arg = ctx->arg;
entry = ctx->entry;
free(ctx);
entry(arg);
return 0;
}
int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
struct {
void (*entry)(void *arg);
void *arg;
} *ctx;
if ((ctx = malloc(sizeof *ctx)) == NULL)
return -1;
ctx->entry = entry;
ctx->arg = arg;
#ifdef _WIN32
*tid = (HANDLE) _beginthreadex(NULL, 0, uv__thread_start, ctx, 0, NULL);
if (*tid == 0) {
#else
if (pthread_create(tid, NULL, uv__thread_start, ctx)) {
#endif
free(ctx);
return -1;
}
return 0;
}

20
deps/uv/src/win/core.c

@ -192,9 +192,8 @@ static void uv_poll_ex(uv_loop_t* loop, int block) {
}
}
#define UV_LOOP(loop, poll) \
while ((loop)->refs > 0) { \
#define UV_LOOP_ONCE(loop, poll) \
do { \
uv_update_time((loop)); \
uv_process_timers((loop)); \
\
@ -219,9 +218,24 @@ static void uv_poll_ex(uv_loop_t* loop, int block) {
(loop)->refs > 0); \
\
uv_check_invoke((loop)); \
} while (0);
#define UV_LOOP(loop, poll) \
while ((loop)->refs > 0) { \
UV_LOOP_ONCE(loop, poll) \
}
int uv_run_once(uv_loop_t* loop) {
if (pGetQueuedCompletionStatusEx) {
UV_LOOP_ONCE(loop, uv_poll_ex);
} else {
UV_LOOP_ONCE(loop, uv_poll);
}
return 0;
}
int uv_run(uv_loop_t* loop) {
if (pGetQueuedCompletionStatusEx) {
UV_LOOP(loop, uv_poll_ex);

12
deps/uv/src/win/thread.c

@ -101,6 +101,18 @@ void uv_once(uv_once_t* guard, void (*callback)(void)) {
uv__once_inner(guard, callback);
}
int uv_thread_join(uv_thread_t *tid) {
if (WaitForSingleObject(*tid, INFINITE))
return -1;
else {
CloseHandle(*tid);
*tid = 0;
return 0;
}
}
int uv_mutex_init(uv_mutex_t* mutex) {
InitializeCriticalSection(mutex);
return 0;

2
deps/uv/src/win/tty.c

@ -90,6 +90,8 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
HANDLE win_handle;
CONSOLE_SCREEN_BUFFER_INFO info;
loop->counters.tty_init++;
win_handle = (HANDLE) _get_osfhandle(fd);
if (win_handle == INVALID_HANDLE_VALUE) {
uv__set_sys_error(loop, ERROR_INVALID_HANDLE);

343
deps/uv/src/win/util.c

@ -22,11 +22,30 @@
#include <assert.h>
#include <direct.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include "uv.h"
#include "internal.h"
#include "tlhelp32.h"
#include "psapi.h"
#include "iphlpapi.h"
/*
* Max title length; the only thing MSDN tells us about the maximum length
* of the console title is that it is smaller than 64K. However in practice
* it is much smaller, and there is no way to figure out what the exact length
* of the title is or can be, at least not on XP. To make it even more
* annoying, GetConsoleTitle failes when the buffer to be read into is bigger
* than the actual maximum length. So we make a conservative guess here;
* just don't put the novel you're writing in the title, unless the plot
* survives truncation.
*/
#define MAX_TITLE_LENGTH 8192
static char *process_title;
int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size,
@ -236,3 +255,327 @@ int uv_parent_pid() {
CloseHandle(handle);
return parent_pid;
}
char** uv_setup_args(int argc, char** argv) {
return argv;
}
uv_err_t uv_set_process_title(const char* title) {
uv_err_t err;
int length;
wchar_t* title_w = NULL;
/* Find out how big the buffer for the wide-char title must be */
length = uv_utf8_to_utf16(title, NULL, 0);
if (!length) {
err = uv__new_sys_error(GetLastError());
goto done;
}
/* Convert to wide-char string */
title_w = (wchar_t*)malloc(sizeof(wchar_t) * length);
if (!title_w) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
length = uv_utf8_to_utf16(title, title_w, length);
if (!length) {
err = uv__new_sys_error(GetLastError());
goto done;
};
/* If the title must be truncated insert a \0 terminator there */
if (length > MAX_TITLE_LENGTH) {
title_w[MAX_TITLE_LENGTH - 1] = L'\0';
}
if (!SetConsoleTitleW(title_w)) {
err = uv__new_sys_error(GetLastError());
goto done;
}
free(process_title);
process_title = strdup(title);
err = uv_ok_;
done:
free(title_w);
return err;
}
static int uv__get_process_title() {
wchar_t title_w[MAX_TITLE_LENGTH];
int length;
if (!GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR))) {
return -1;
}
/* Find out what the size of the buffer is that we need */
length = uv_utf16_to_utf8(title_w, -1, NULL, 0);
if (!length) {
return -1;
}
assert(!process_title);
process_title = (char*)malloc(length);
if (!process_title) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
/* Do utf16 -> utf8 conversion here */
if (!uv_utf16_to_utf8(title_w, -1, process_title, length)) {
free(process_title);
return -1;
}
return 0;
}
uv_err_t uv_get_process_title(char* buffer, size_t size) {
/*
* If the process_title was never read before nor explicitly set,
* we must query it with getConsoleTitleW
*/
if (!process_title && uv__get_process_title() == -1) {
return uv__new_sys_error(GetLastError());
}
assert(process_title);
strncpy(buffer, process_title, size);
return uv_ok_;
}
uv_err_t uv_resident_set_memory(size_t* rss) {
HANDLE current_process;
PROCESS_MEMORY_COUNTERS pmc;
current_process = GetCurrentProcess();
if (!GetProcessMemoryInfo(current_process, &pmc, sizeof(pmc))) {
return uv__new_sys_error(GetLastError());
}
*rss = pmc.WorkingSetSize;
return uv_ok_;
}
uv_err_t uv_uptime(double* uptime) {
*uptime = (double)GetTickCount()/1000.0;
return uv_ok_;
}
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uv_err_t err;
char key[128];
HKEY processor_key = NULL;
DWORD cpu_speed = 0;
DWORD cpu_speed_length = sizeof(cpu_speed);
char cpu_brand[256];
DWORD cpu_brand_length = sizeof(cpu_brand);
SYSTEM_INFO system_info;
uv_cpu_info_t* cpu_info;
unsigned int i;
GetSystemInfo(&system_info);
*cpu_infos = (uv_cpu_info_t*)malloc(system_info.dwNumberOfProcessors *
sizeof(uv_cpu_info_t));
if (!(*cpu_infos)) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
*count = 0;
for (i = 0; i < system_info.dwNumberOfProcessors; i++) {
_snprintf(key, sizeof(key), "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d", i);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE,
&processor_key) != ERROR_SUCCESS) {
if (i == 0) {
err = uv__new_sys_error(GetLastError());
goto done;
}
continue;
}
if (RegQueryValueEx(processor_key, "~MHz", NULL, NULL,
(LPBYTE)&cpu_speed, &cpu_speed_length)
!= ERROR_SUCCESS) {
err = uv__new_sys_error(GetLastError());
goto done;
}
if (RegQueryValueEx(processor_key, "ProcessorNameString", NULL, NULL,
(LPBYTE)&cpu_brand, &cpu_brand_length)
!= ERROR_SUCCESS) {
err = uv__new_sys_error(GetLastError());
goto done;
}
RegCloseKey(processor_key);
processor_key = NULL;
cpu_info = &(*cpu_infos)[i];
/* $TODO: find times on windows */
cpu_info->cpu_times.user = 0;
cpu_info->cpu_times.nice = 0;
cpu_info->cpu_times.sys = 0;
cpu_info->cpu_times.idle = 0;
cpu_info->cpu_times.irq = 0;
cpu_info->model = strdup(cpu_brand);
cpu_info->speed = cpu_speed;
(*count)++;
}
err = uv_ok_;
done:
if (processor_key) {
RegCloseKey(processor_key);
}
if (err.code != UV_OK) {
free(*cpu_infos);
*cpu_infos = NULL;
*count = 0;
}
return err;
}
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
free(cpu_infos[i].model);
}
free(cpu_infos);
}
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
unsigned long size = 0;
IP_ADAPTER_ADDRESSES* adapter_addresses;
IP_ADAPTER_ADDRESSES* adapter_address;
IP_ADAPTER_UNICAST_ADDRESS_XP* unicast_address;
uv_interface_address_t* address;
struct sockaddr* sock_addr;
int length;
char* name;
if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &size)
!= ERROR_BUFFER_OVERFLOW) {
return uv__new_sys_error(GetLastError());
}
adapter_addresses = (IP_ADAPTER_ADDRESSES*)malloc(size);
if (!adapter_addresses) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, adapter_addresses, &size)
!= ERROR_SUCCESS) {
return uv__new_sys_error(GetLastError());
}
/* Count the number of interfaces */
*count = 0;
for (adapter_address = adapter_addresses;
adapter_address != NULL;
adapter_address = adapter_address->Next) {
unicast_address = adapter_address->FirstUnicastAddress;
while (unicast_address) {
(*count)++;
unicast_address = unicast_address->Next;
}
}
*addresses = (uv_interface_address_t*)
malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
address = *addresses;
for (adapter_address = adapter_addresses;
adapter_address != NULL;
adapter_address = adapter_address->Next) {
name = NULL;
unicast_address = adapter_address->FirstUnicastAddress;
while (unicast_address) {
sock_addr = unicast_address->Address.lpSockaddr;
if (sock_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6 *)sock_addr);
} else {
address->address.address4 = *((struct sockaddr_in *)sock_addr);
}
address->is_internal =
adapter_address->IfType == IF_TYPE_SOFTWARE_LOOPBACK ? 1 : 0;
if (!name) {
/* Convert FriendlyName to utf8 */
length = uv_utf16_to_utf8(adapter_address->FriendlyName, -1, NULL, 0);
if (length) {
name = (char*)malloc(length);
if (!name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
if (!uv_utf16_to_utf8(adapter_address->FriendlyName, -1, name,
length)) {
free(name);
name = NULL;
}
}
}
assert(name);
address->name = name;
unicast_address = unicast_address->Next;
address++;
}
}
free(adapter_addresses);
return uv_ok_;
}
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
int i;
char* freed_name = NULL;
for (i = 0; i < count; i++) {
if (freed_name != addresses[i].name) {
freed_name = addresses[i].name;
free(freed_name);
}
}
free(addresses);
}

6
deps/uv/src/win/winapi.h

@ -4337,6 +4337,11 @@ typedef NTSTATUS (NTAPI *sNtSetInformationFile)
} OVERLAPPED_ENTRY, *LPOVERLAPPED_ENTRY;
#endif
#ifdef __MINGW32__
typedef PVOID RTL_SRWLOCK;
typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK;
#endif
/* from wincon.h */
#ifndef ENABLE_INSERT_MODE
# define ENABLE_INSERT_MODE 0x20
@ -4389,6 +4394,7 @@ typedef VOID (WINAPI* sReleaseSRWLockExclusive)
(PSRWLOCK SRWLock);
/* Ntapi function pointers */
extern sRtlNtStatusToDosError pRtlNtStatusToDosError;
extern sNtDeviceIoControlFile pNtDeviceIoControlFile;

24
deps/uv/src/win/winsock.h

@ -23,6 +23,7 @@
#define UV_WIN_WINSOCK_H_
#include <winsock2.h>
#include <iptypes.h>
#include <mswsock.h>
#include <ws2tcpip.h>
#include <windows.h>
@ -107,4 +108,27 @@ typedef struct _AFD_RECV_INFO {
#define IOCTL_AFD_RECEIVE_DATAGRAM \
_AFD_CONTROL_CODE(AFD_RECEIVE_DATAGRAM, METHOD_NEITHER)
#if defined(__MINGW32__) && !defined(__MINGW64__)
typedef struct _IP_ADAPTER_UNICAST_ADDRESS_XP {
/* FIXME: __C89_NAMELESS was removed */
/* __C89_NAMELESS */ union {
ULONGLONG Alignment;
/* __C89_NAMELESS */ struct {
ULONG Length;
DWORD Flags;
};
};
struct _IP_ADAPTER_UNICAST_ADDRESS_XP *Next;
SOCKET_ADDRESS Address;
IP_PREFIX_ORIGIN PrefixOrigin;
IP_SUFFIX_ORIGIN SuffixOrigin;
IP_DAD_STATE DadState;
ULONG ValidLifetime;
ULONG PreferredLifetime;
ULONG LeaseLifetime;
} IP_ADAPTER_UNICAST_ADDRESS_XP,*PIP_ADAPTER_UNICAST_ADDRESS_XP;
#endif
#endif /* UV_WIN_WINSOCK_H_ */

2
deps/uv/test/benchmark-list.h

@ -43,6 +43,7 @@ BENCHMARK_DECLARE (udp_packet_storm_1000v1000)
BENCHMARK_DECLARE (gethostbyname)
BENCHMARK_DECLARE (getaddrinfo)
BENCHMARK_DECLARE (spawn)
BENCHMARK_DECLARE (thread_create)
HELPER_DECLARE (tcp4_blackhole_server)
HELPER_DECLARE (tcp_pump_server)
HELPER_DECLARE (pipe_pump_server)
@ -100,4 +101,5 @@ TASK_LIST_START
BENCHMARK_ENTRY (getaddrinfo)
BENCHMARK_ENTRY (spawn)
BENCHMARK_ENTRY (thread_create)
TASK_LIST_END

2
deps/uv/test/run-tests.c

@ -38,6 +38,8 @@ static int maybe_run_test(int argc, char **argv);
int main(int argc, char **argv) {
platform_init(argc, argv);
argv = uv_setup_args(argc, argv);
switch (argc) {
case 1: return run_tests(TEST_TIMEOUT, 0);
case 2: return maybe_run_test(argc, argv);

8
deps/uv/test/runner.c

@ -71,7 +71,7 @@ int run_tests(int timeout, int benchmark_output) {
log_progress(total, passed, failed, "Done.\n");
}
return 0;
return failed;
}
@ -191,8 +191,10 @@ out:
}
/* Show error and output from processes if the test failed. */
if (status != 0) {
LOGF("\n`%s` failed: %s\n", test, errmsg);
if (status != 0 || task->show_output) {
if (status != 0) {
LOGF("\n`%s` failed: %s\n", test, errmsg);
}
for (i = 0; i < process_count; i++) {
switch (process_output_size(&processes[i])) {

10
deps/uv/test/runner.h

@ -40,6 +40,7 @@ typedef struct {
char *process_name;
int (*main)();
int is_helper;
int show_output;
} task_entry_t, bench_entry_t;
@ -57,19 +58,22 @@ typedef struct {
int run_test_##name();
#define TEST_ENTRY(name) \
{ #name, #name, &run_test_##name, 0 },
{ #name, #name, &run_test_##name, 0, 0 },
#define TEST_OUTPUT_ENTRY(name) \
{ #name, #name, &run_test_##name, 0, 1 },
#define BENCHMARK_DECLARE(name) \
int run_benchmark_##name();
#define BENCHMARK_ENTRY(name) \
{ #name, #name, &run_benchmark_##name, 0 },
{ #name, #name, &run_benchmark_##name, 0, 0 },
#define HELPER_DECLARE(name) \
int run_helper_##name();
#define HELPER_ENTRY(task_name, name) \
{ #task_name, #name, &run_helper_##name, 1 },
{ #task_name, #name, &run_helper_##name, 1, 0 },
#define TEST_HELPER HELPER_ENTRY
#define BENCHMARK_HELPER HELPER_ENTRY

22
deps/uv/test/test-fs-event.c

@ -99,14 +99,34 @@ static void fs_event_cb_file(uv_fs_event_t* handle, const char* filename,
uv_close((uv_handle_t*)handle, close_cb);
}
static void timber_cb_close_handle(uv_timer_t* timer, int status) {
uv_handle_t* handle;
ASSERT(timer != NULL);
ASSERT(status == 0);
handle = timer->data;
uv_close((uv_handle_t*)timer, NULL);
uv_close((uv_handle_t*)handle, close_cb);
}
static void fs_event_cb_file_current_dir(uv_fs_event_t* handle,
const char* filename, int events, int status) {
ASSERT(fs_event_cb_called == 0);
++fs_event_cb_called;
ASSERT(handle == &fs_event);
ASSERT(status == 0);
ASSERT(events == UV_CHANGE);
ASSERT(filename == NULL || strcmp(filename, "watch_file") == 0);
uv_close((uv_handle_t*)handle, close_cb);
/* Regression test for SunOS: touch should generate just one event. */
{
static uv_timer_t timer;
uv_timer_init(handle->loop, &timer);
timer.data = handle;
uv_timer_start(&timer, timber_cb_close_handle, 250, 0);
}
}
static void timer_cb_dir(uv_timer_t* handle, int status) {

17
deps/uv/test/test-list.h

@ -19,6 +19,7 @@
* IN THE SOFTWARE.
*/
TEST_DECLARE (platform_output)
TEST_DECLARE (tty)
TEST_DECLARE (stdio_over_pipes)
TEST_DECLARE (ipc_listen_before_write)
@ -77,6 +78,7 @@ TEST_DECLARE (check_ref)
TEST_DECLARE (unref_in_prepare_cb)
TEST_DECLARE (async)
TEST_DECLARE (get_currentexe)
TEST_DECLARE (process_title)
TEST_DECLARE (cwd_and_chdir)
TEST_DECLARE (get_memory)
TEST_DECLARE (hrtime)
@ -91,6 +93,7 @@ TEST_DECLARE (spawn_exit_code)
TEST_DECLARE (spawn_stdout)
TEST_DECLARE (spawn_stdin)
TEST_DECLARE (spawn_and_kill)
TEST_DECLARE (spawn_and_kill_with_std)
TEST_DECLARE (spawn_and_ping)
TEST_DECLARE (kill)
TEST_DECLARE (fs_file_noent)
@ -118,6 +121,10 @@ TEST_DECLARE (fs_open_dir)
TEST_DECLARE (threadpool_queue_work_simple)
TEST_DECLARE (thread_mutex)
TEST_DECLARE (thread_rwlock)
TEST_DECLARE (thread_create)
TEST_DECLARE (strlcpy)
TEST_DECLARE (strlcat)
TEST_DECLARE (counters_init)
#ifdef _WIN32
TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows)
TEST_DECLARE (argument_escaping)
@ -131,6 +138,8 @@ HELPER_DECLARE (pipe_echo_server)
TASK_LIST_START
TEST_OUTPUT_ENTRY (platform_output)
TEST_ENTRY (pipe_connect_bad_name)
TEST_ENTRY (tty)
@ -219,6 +228,8 @@ TASK_LIST_START
TEST_ENTRY (get_currentexe)
TEST_ENTRY (process_title)
TEST_ENTRY (cwd_and_chdir)
TEST_ENTRY (get_memory)
@ -240,6 +251,7 @@ TASK_LIST_START
TEST_ENTRY (spawn_stdout)
TEST_ENTRY (spawn_stdin)
TEST_ENTRY (spawn_and_kill)
TEST_ENTRY (spawn_and_kill_with_std)
TEST_ENTRY (spawn_and_ping)
TEST_ENTRY (kill)
#ifdef _WIN32
@ -274,7 +286,10 @@ TASK_LIST_START
TEST_ENTRY (threadpool_queue_work_simple)
TEST_ENTRY (thread_mutex)
TEST_ENTRY (thread_rwlock)
TEST_ENTRY (thread_create)
TEST_ENTRY (strlcpy)
TEST_ENTRY (strlcat)
TEST_ENTRY (counters_init)
#if 0
/* These are for testing the test runner. */
TEST_ENTRY (fail_always)

31
deps/uv/test/test-spawn.c

@ -231,6 +231,37 @@ TEST_IMPL(spawn_and_kill) {
}
TEST_IMPL(spawn_and_kill_with_std) {
int r;
uv_pipe_t out;
uv_pipe_t in;
init_process_options("spawn_helper4", kill_cb);
uv_pipe_init(uv_default_loop(), &out, 0);
uv_pipe_init(uv_default_loop(), &in, 0);
options.stdout_stream = &out;
options.stdin_stream = &in;
r = uv_spawn(uv_default_loop(), &process, options);
ASSERT(r == 0);
r = uv_timer_init(uv_default_loop(), &timer);
ASSERT(r == 0);
r = uv_timer_start(&timer, timer_cb, 500, 0);
ASSERT(r == 0);
r = uv_run(uv_default_loop());
ASSERT(r == 0);
ASSERT(exit_cb_called == 1);
ASSERT(close_cb_called == 2); /* Once for process and once for timer. */
return 0;
}
TEST_IMPL(spawn_and_ping) {
uv_write_t write_req;
uv_pipe_t in, out;

10
deps/uv/uv.gyp

@ -3,6 +3,8 @@
'conditions': [
['OS != "win"', {
'defines': [
'_LARGEFILE_SOURCE',
'_FILE_OFFSET_BITS=64',
'_GNU_SOURCE',
'EIO_STACKSIZE=262144'
],
@ -155,6 +157,8 @@
'link_settings': {
'libraries': [
'-lws2_32.lib',
'-lpsapi.lib',
'-liphlpapi.lib'
],
},
}, { # Not Windows i.e. POSIX
@ -273,6 +277,7 @@
'test/runner.h',
'test/test-get-loadavg.c',
'test/task.h',
'test/test-util.c',
'test/test-async.c',
'test/test-error.c',
'test/test-callback-stack.c',
@ -297,6 +302,8 @@
'test/test-ping-pong.c',
'test/test-pipe-bind-error.c',
'test/test-pipe-connect-error.c',
'test/test-platform-output.c',
'test/test-process-title.c',
'test/test-ref.c',
'test/test-shutdown-eof.c',
'test/test-spawn.c',
@ -312,6 +319,7 @@
'test/test-tcp-writealot.c',
'test/test-threadpool.c',
'test/test-mutexes.c',
'test/test-thread.c',
'test/test-timer-again.c',
'test/test-timer.c',
'test/test-tty.c',
@ -319,6 +327,7 @@
'test/test-udp-ipv6.c',
'test/test-udp-send-and-recv.c',
'test/test-udp-multicast-join.c',
'test/test-counters-init.c',
],
'conditions': [
[ 'OS=="win"', {
@ -361,6 +370,7 @@
'test/benchmark-pump.c',
'test/benchmark-sizes.c',
'test/benchmark-spawn.c',
'test/benchmark-thread.c',
'test/benchmark-tcp-write-batch.c',
'test/benchmark-udp-packet-storm.c',
'test/dns-server.c',

Loading…
Cancel
Save