Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

uv: upgrade to 25a177a

Fixes #1869.
  • Loading branch information...
bnoordhuis committed Oct 12, 2011
1 parent c82828e commit bc96302fae117d36fad47adc1eec1fd7a8d5adb2
@@ -76,12 +76,14 @@ typedef enum {
UV_ENFILE,
UV_ENOBUFS,
UV_ENOMEM,
UV_ENOTDIR,
UV_ENONET,
UV_ENOPROTOOPT,
UV_ENOTCONN,
UV_ENOTSOCK,
UV_ENOTSUP,
UV_ENOENT,
UV_ENOSYS,
UV_EPIPE,
UV_EPROTO,
UV_EPROTONOSUPPORT,
@@ -239,6 +241,11 @@ typedef void (*uv_after_work_cb)(uv_work_t* req);
typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle, const char* filename,
int events, int status);

typedef enum {
UV_LEAVE_GROUP = 0,
UV_JOIN_GROUP
} uv_membership;


struct uv_err_s {
/* read-only */
@@ -550,6 +557,21 @@ int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned flags);
int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags);
int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int* namelen);

/*
* Set membership for a multicast address
*
* Arguments:
* handle UDP handle. Should have been initialized with `uv_udp_init`.
* multicast_addr multicast address to set membership for
* interface_addr interface address
* membership Should be UV_JOIN_GROUP or UV_LEAVE_GROUP
*
* Returns:
* 0 on success, -1 on error.
*/
int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
const char* interface_addr, uv_membership membership);

/*
* 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)
@@ -11,7 +11,7 @@
#define HAVE_UTIMES 1

/* futimes(2) is available */
/* #undef HAVE_FUTIMES */
#define HAVE_FUTIMES 1

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
@@ -108,6 +108,10 @@ static void eio_destroy (eio_req *req);

#define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1)

#ifdef __sun
# define futimes(fd, times) futimesat (fd, NULL, times)
#endif

#ifdef _WIN32

#include <direct.h>
@@ -58,6 +58,7 @@ void uv_fatal_error(const int errorno, const char* syscall) {

static int uv__translate_lib_error(int code) {
switch (code) {
case UV_ENOSYS: return ENOSYS;
case UV_ENOENT: return ENOENT;
case UV_EACCESS: return EACCES;
case UV_EBADF: return EBADF;
@@ -71,6 +72,7 @@ static int uv__translate_lib_error(int code) {
case UV_ECONNREFUSED: return ECONNREFUSED;
case UV_EADDRINUSE: return EADDRINUSE;
case UV_EADDRNOTAVAIL: return EADDRNOTAVAIL;
case UV_ENOTDIR: return ENOTDIR;
case UV_ENOTCONN: return ENOTCONN;
case UV_EEXIST: return EEXIST;
default: return -1;
@@ -84,6 +86,7 @@ static int uv__translate_lib_error(int code) {
uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case 0: return UV_OK;
case ENOSYS: return UV_ENOSYS;
case ENOENT: return UV_ENOENT;
case EACCES: return UV_EACCESS;
case EBADF: return UV_EBADF;
@@ -97,6 +100,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case ECONNREFUSED: return UV_ECONNREFUSED;
case EADDRINUSE: return UV_EADDRINUSE;
case EADDRNOTAVAIL: return UV_EADDRNOTAVAIL;
case ENOTDIR: return UV_ENOTDIR;
case ENOTCONN: return UV_ENOTCONN;
case EEXIST: return UV_EEXIST;
default: return UV_UNKNOWN;
@@ -496,7 +496,7 @@ int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
}


#if defined(HAVE_FUTIMES)
#if HAVE_FUTIMES
static int _futime(const uv_file file, double atime, double mtime) {
struct timeval tv[2];

@@ -507,14 +507,18 @@ static int _futime(const uv_file file, double atime, double mtime) {
tv[1].tv_sec = mtime;
tv[1].tv_usec = (unsigned long)(mtime * 1000000) % 1000000;

#ifdef __sun
return futimesat(file, NULL, tv);
#else
return futimes(file, tv);
#endif
}
#endif


int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime,
double mtime, uv_fs_cb cb) {
#if defined(HAVE_FUTIMES)
#if HAVE_FUTIMES
const char* path = NULL;

uv_fs_req_init(loop, req, UV_FS_FUTIME, path, cb);
@@ -49,11 +49,7 @@

#endif /* __linux__ */

#ifdef __APPLE__
# define HAVE_FUTIMES 1
#endif

#ifdef __FreeBSD__
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun)
# define HAVE_FUTIMES 1
#endif

@@ -65,35 +65,17 @@ int uv_exepath(char* buffer, size_t* size) {
return (0);
}

double uv_get_free_memory(void) {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *knp;

ulong_t freemem;

if ((kc = kstat_open()) == NULL) return -1;

ksp = kstat_lookup(kc, (char *)"unix", 0, (char *)"system_pages");

if(kstat_read(kc, ksp, NULL) == -1){
return -1;
}
else {
knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"freemem");
freemem = knp->value.ul;
}

kstat_close(kc);

return (double) freemem * sysconf(_SC_PAGESIZE);
double uv_get_free_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
}


double uv_get_total_memory(void) {
return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
}


void uv_loadavg(double avg[3]) {
(void) getloadavg(avg, 3);
}
@@ -459,6 +459,42 @@ int uv__udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags) {
}


int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
const char* interface_addr, uv_membership membership) {

int optname;
struct ip_mreq mreq;
memset(&mreq, 0, sizeof mreq);

if (interface_addr) {
mreq.imr_interface.s_addr = inet_addr(interface_addr);
} else {
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
}

mreq.imr_multiaddr.s_addr = inet_addr(multicast_addr);

switch (membership) {
case UV_JOIN_GROUP:
optname = IP_ADD_MEMBERSHIP;
break;
case UV_LEAVE_GROUP:
optname = IP_DROP_MEMBERSHIP;
break;
default:
uv__set_sys_error(handle->loop, EFAULT);
return -1;
}

if (setsockopt(handle->fd, IPPROTO_IP, optname, (void*) &mreq, sizeof mreq) == -1) {
uv__set_sys_error(handle->loop, errno);
return -1;
}

return 0;
}


int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int* namelen) {
socklen_t socklen;
@@ -76,12 +76,14 @@ const char* uv_err_name(uv_err_t err) {
case UV_ENFILE: return "ENFILE";
case UV_ENOBUFS: return "ENOBUFS";
case UV_ENOMEM: return "ENOMEM";
case UV_ENOTDIR: return "ENOTDIR";
case UV_ENONET: return "ENONET";
case UV_ENOPROTOOPT: return "ENOPROTOOPT";
case UV_ENOTCONN: return "ENOTCONN";
case UV_ENOTSOCK: return "ENOTSOCK";
case UV_ENOTSUP: return "ENOTSUP";
case UV_ENOENT: return "ENOENT";
case UV_ENOSYS: return "ENOSYS";
case UV_EPIPE: return "EPIPE";
case UV_EPROTO: return "EPROTO";
case UV_EPROTONOSUPPORT: return "EPROTONOSUPPORT";
@@ -72,7 +72,6 @@
req->flags |= UV_FS_ASYNC_QUEUED; \
uv_ref((loop));


#define SET_UV_LAST_ERROR_FROM_REQ(req) \
if (req->flags & UV_FS_LAST_ERROR_SET) { \
uv__set_sys_error(req->loop, req->last_error); \
@@ -96,6 +95,14 @@
req->errorno = uv_translate_sys_error(sys_errno); \
SET_REQ_LAST_ERROR(req, sys_errno);

#define VERIFY_UV_FILE(file, req) \
if (file == -1) { \
req->result = -1; \
req->errorno = UV_EBADF; \
req->last_error = ERROR_SUCCESS; \
return; \
}


void uv_fs_init() {
_fmode = _O_BINARY;
@@ -241,7 +248,11 @@ void fs__open(uv_fs_t* req, const char* path, int flags, int mode) {
}

void fs__close(uv_fs_t* req, uv_file file) {
int result = _close(file);
int result;

VERIFY_UV_FILE(file, req);

result = _close(file);
SET_REQ_RESULT(req, result);
}

@@ -253,6 +264,8 @@ void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length,
LARGE_INTEGER offset_;
DWORD bytes;

VERIFY_UV_FILE(file, req);

handle = (HANDLE) _get_osfhandle(file);
if (handle == INVALID_HANDLE_VALUE) {
SET_REQ_RESULT(req, -1);
@@ -291,6 +304,8 @@ void fs__write(uv_fs_t* req, uv_file file, void *buf, size_t length,
LARGE_INTEGER offset_;
DWORD bytes;

VERIFY_UV_FILE(file, req);

handle = (HANDLE) _get_osfhandle(file);
if (handle == INVALID_HANDLE_VALUE) {
SET_REQ_RESULT(req, -1);
@@ -342,7 +357,7 @@ void fs__rmdir(uv_fs_t* req, const char* path) {

void fs__readdir(uv_fs_t* req, const char* path, int flags) {
int result;
char* buf, *ptr, *name;
char* buf = NULL, *ptr, *name;
HANDLE dir;
WIN32_FIND_DATAA ent = {0};
size_t len = strlen(path);
@@ -365,12 +380,6 @@ void fs__readdir(uv_fs_t* req, const char* path, int flags) {
return;
}

buf = (char*)malloc(buf_size);
if (!buf) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

ptr = buf;
result = 0;

do {
@@ -379,6 +388,15 @@ void fs__readdir(uv_fs_t* req, const char* path, int flags) {
if (name[0] != '.' || (name[1] && (name[1] != '.' || name[2]))) {
len = strlen(name);

if (!buf) {
buf = (char*)malloc(buf_size);
if (!buf) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

ptr = buf;
}

while ((ptr - buf) + len + 1 > buf_size) {
buf_size *= 2;
path2 = buf;
@@ -422,6 +440,8 @@ void fs__stat(uv_fs_t* req, const char* path) {
void fs__fstat(uv_fs_t* req, uv_file file) {
int result;

VERIFY_UV_FILE(file, req);

result = _fstati64(file, &req->stat);
if (result == -1) {
req->ptr = NULL;
@@ -440,7 +460,11 @@ void fs__rename(uv_fs_t* req, const char* path, const char* new_path) {


void fs__fsync(uv_fs_t* req, uv_file file) {
int result = FlushFileBuffers((HANDLE)_get_osfhandle(file)) ? 0 : -1;
int result;

VERIFY_UV_FILE(file, req);

result = FlushFileBuffers((HANDLE)_get_osfhandle(file)) ? 0 : -1;
if (result == -1) {
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
} else {
@@ -450,7 +474,11 @@ void fs__fsync(uv_fs_t* req, uv_file file) {


void fs__ftruncate(uv_fs_t* req, uv_file file, off_t offset) {
int result = _chsize(file, offset);
int result;

VERIFY_UV_FILE(file, req);

result = _chsize(file, offset);
SET_REQ_RESULT(req, result);
}

@@ -508,6 +536,8 @@ void fs__fchmod(uv_fs_t* req, uv_file file, int mode) {
IO_STATUS_BLOCK io_status;
FILE_BASIC_INFORMATION file_info;

VERIFY_UV_FILE(file, req);

handle = (HANDLE)_get_osfhandle(file);

nt_status = pNtQueryInformationFile(handle,
@@ -556,6 +586,9 @@ void fs__utime(uv_fs_t* req, const char* path, double atime, double mtime) {
void fs__futime(uv_fs_t* req, uv_file file, double atime, double mtime) {
int result;
struct _utimbuf b = {(time_t)atime, (time_t)mtime};

VERIFY_UV_FILE(file, req);

result = _futime(file, &b);
SET_REQ_RESULT(req, result);
}

0 comments on commit bc96302

Please sign in to comment.
You can’t perform that action at this time.