Skip to content

Commit

Permalink
uv: upgrade to 58ef43e
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Sep 6, 2011
1 parent ece5c64 commit 5003ba9
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 47 deletions.
2 changes: 1 addition & 1 deletion deps/uv/config-unix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ endif
ifeq (Linux,$(uname_S))
EV_CONFIG=config_linux.h
EIO_CONFIG=config_linux.h
CSTDFLAG += -D_XOPEN_SOURCE=600
CSTDFLAG += -D_GNU_SOURCE
CPPFLAGS += -Isrc/ares/config_linux
LINKFLAGS+=-lrt
OBJS += src/unix/linux.o
Expand Down
1 change: 1 addition & 0 deletions deps/uv/include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ typedef enum {
UV_ENOTCONN,
UV_ENOTSOCK,
UV_ENOTSUP,
UV_ENOENT,
UV_EPIPE,
UV_EPROTO,
UV_EPROTONOSUPPORT,
Expand Down
24 changes: 0 additions & 24 deletions deps/uv/src/unix/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
* IN THE SOFTWARE.
*/

#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* O_CLOEXEC, accept4(), etc. */
#endif

#include "uv.h"
#include "unix/internal.h"

Expand All @@ -42,26 +38,6 @@
#include <limits.h> /* PATH_MAX */
#include <sys/uio.h> /* writev */

#if defined(__linux__)

#include <linux/version.h>
#include <features.h>

#undef HAVE_PIPE2
#undef HAVE_ACCEPT4

/* pipe2() requires linux >= 2.6.27 and glibc >= 2.9 */
#if LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9)
#define HAVE_PIPE2
#endif

/* accept4() requires linux >= 2.6.28 and glib >= 2.10 */
#if LINUX_VERSION_CODE >= 0x2061C && __GLIBC_PREREQ(2, 10)
#define HAVE_ACCEPT4
#endif

#endif /* __linux__ */

#ifdef __sun
# include <sys/types.h>
# include <sys/wait.h>
Expand Down
7 changes: 6 additions & 1 deletion deps/uv/src/unix/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>


/* TODO Expose callback to user to handle fatal error like V8 does. */
Expand Down Expand Up @@ -65,9 +66,10 @@ char* uv_strerror(uv_err_t err) {
}


static uv_err_code uv_translate_sys_error(int sys_errno) {
uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case 0: return UV_OK;
case ENOENT: return UV_ENOENT;
case EACCES: return UV_EACCESS;
case EBADF: return UV_EBADF;
case EPIPE: return UV_EPIPE;
Expand All @@ -83,6 +85,9 @@ static uv_err_code uv_translate_sys_error(int sys_errno) {
case ENOTCONN: return UV_ENOTCONN;
default: return UV_UNKNOWN;
}

assert(0 && "unreachable");
return -1;
}


Expand Down
13 changes: 7 additions & 6 deletions deps/uv/src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <utime.h>
#include <sys/time.h>


#define ARGS1(a) (a)
Expand All @@ -43,12 +44,12 @@
uv_fs_req_init(loop, req, type, path, cb); \
if (cb) { \
/* async */ \
uv_ref(loop); \
req->eio = eiofunc(args, EIO_PRI_DEFAULT, uv__fs_after, req); \
if (!req->eio) { \
uv_err_new(loop, ENOMEM); \
return -1; \
} \
uv_ref(loop); \
} else { \
/* sync */ \
req->result = func(args); \
Expand All @@ -61,7 +62,7 @@


static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type,
char* path, uv_fs_cb cb) {
const char* path, uv_fs_cb cb) {
/* Make sure the thread pool is initialized. */
uv_eio_init(loop);

Expand Down Expand Up @@ -110,7 +111,7 @@ static int uv__fs_after(eio_req* eio) {
assert(req->cb);

req->result = req->eio->result;
req->errorno = req->eio->errorno;
req->errorno = uv_translate_sys_error(req->eio->errorno);

switch (req->fs_type) {
case UV_FS_READDIR:
Expand Down Expand Up @@ -344,7 +345,7 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,


int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
char* pathdup = path;
char* pathdup;
int pathlen;

uv_fs_req_init(loop, req, UV_FS_STAT, path, cb);
Expand Down Expand Up @@ -479,7 +480,7 @@ int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime,


int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
char* pathdup = path;
char* pathdup;
int pathlen;

uv_fs_req_init(loop, req, UV_FS_LSTAT, path, cb);
Expand Down Expand Up @@ -538,7 +539,7 @@ int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path,

int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
uv_fs_cb cb) {
size_t size;
ssize_t size;
int status;
char* buf;

Expand Down
27 changes: 27 additions & 0 deletions deps/uv/src/unix/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@
#include "uv-common.h"
#include "uv-eio.h"

#if defined(__linux__)

#include <linux/version.h>
#include <features.h>

#undef HAVE_FUTIMES
#undef HAVE_PIPE2
#undef HAVE_ACCEPT4

/* futimes() requires linux >= 2.6.22 and glib >= 2.6 */
#if LINUX_VERSION_CODE >= 0x20616 && __GLIBC_PREREQ(2, 6)
#define HAVE_FUTIMES
#endif

/* pipe2() requires linux >= 2.6.27 and glibc >= 2.9 */
#if LINUX_VERSION_CODE >= 0x2061B && __GLIBC_PREREQ(2, 9)
#define HAVE_PIPE2
#endif

/* accept4() requires linux >= 2.6.28 and glib >= 2.10 */
#if LINUX_VERSION_CODE >= 0x2061C && __GLIBC_PREREQ(2, 10)
#define HAVE_ACCEPT4
#endif

#endif /* __linux__ */

/* flags */
enum {
UV_CLOSING = 0x00000001, /* uv_close() called but not finished. */
Expand All @@ -48,6 +74,7 @@ int uv__cloexec(int fd, int set) __attribute__((unused));
int uv__socket(int domain, int type, int protocol);

/* error */
uv_err_code uv_translate_sys_error(int sys_errno);
uv_err_t uv_err_new(uv_loop_t* loop, int sys_error);
uv_err_t uv_err_new_artificial(uv_loop_t* loop, int code);
void uv_fatal_error(const int errorno, const char* syscall);
Expand Down
1 change: 1 addition & 0 deletions deps/uv/src/unix/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <assert.h>
#include <errno.h>
#include <sys/wait.h>
#include <fcntl.h> /* O_CLOEXEC, O_NONBLOCK */
#include <poll.h>
#include <unistd.h>
#include <stdio.h>
Expand Down
1 change: 1 addition & 0 deletions deps/uv/src/uv-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const char* uv_err_name(uv_err_t err) {
case UV_ENOTCONN: return "ENOTCONN";
case UV_ENOTSOCK: return "ENOTSOCK";
case UV_ENOTSUP: return "ENOTSUP";
case UV_ENOENT: return "ENOENT";
case UV_EPIPE: return "EPIPE";
case UV_EPROTO: return "EPROTO";
case UV_EPROTONOSUPPORT: return "EPROTONOSUPPORT";
Expand Down
6 changes: 3 additions & 3 deletions deps/uv/src/uv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
#define COUNTOF(a) (sizeof(a) / sizeof(a[0]))

/* Used for the uv_fs_ functions */
#define SET_REQ_RESULT(req, result) \
req->result = result; \
if (result == -1) { \
#define SET_REQ_RESULT(req, result_value) \
req->result = (result_value); \
if (req->result == -1) { \
req->errorno = errno; \
}

Expand Down
69 changes: 57 additions & 12 deletions deps/uv/src/win/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <errno.h>
#include <fcntl.h>
#include <io.h>
#include <limits.h>
#include <sys/stat.h>
#include <sys/utime.h>
#include <stdio.h>
Expand Down Expand Up @@ -239,33 +240,77 @@ void fs__close(uv_fs_t* req, uv_file file) {

void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length,
off_t offset) {
int result = 0;
HANDLE handle;
OVERLAPPED overlapped, *overlapped_ptr;
LARGE_INTEGER offset_;
DWORD bytes;

if (offset != -1) {
result = _lseek(file, offset, SEEK_SET);
handle = (HANDLE) _get_osfhandle(file);
if (handle == INVALID_HANDLE_VALUE) {
SET_REQ_RESULT(req, -1);
return;
}

if (result != -1) {
result = _read(file, buf, length);
if (length > INT_MAX) {
SET_REQ_ERROR(req, ERROR_INSUFFICIENT_BUFFER);
return;
}

SET_REQ_RESULT(req, result);
if (offset != -1) {
memset(&overlapped, 0, sizeof overlapped);

offset_.QuadPart = offset;
overlapped.Offset = offset_.LowPart;
overlapped.OffsetHigh = offset_.HighPart;

overlapped_ptr = &overlapped;
} else {
overlapped_ptr = NULL;
}

if (ReadFile(handle, buf, length, &bytes, overlapped_ptr)) {
SET_REQ_RESULT(req, bytes);
} else {
SET_REQ_ERROR(req, GetLastError());
}
}


void fs__write(uv_fs_t* req, uv_file file, void *buf, size_t length,
off_t offset) {
int result = 0;
HANDLE handle;
OVERLAPPED overlapped, *overlapped_ptr;
LARGE_INTEGER offset_;
DWORD bytes;

if (offset != -1) {
result = _lseek(file, offset, SEEK_SET);
handle = (HANDLE) _get_osfhandle(file);
if (handle == INVALID_HANDLE_VALUE) {
SET_REQ_RESULT(req, -1);
return;
}

if (result != -1) {
result = _write(file, buf, length);
if (length > INT_MAX) {
SET_REQ_ERROR(req, ERROR_INSUFFICIENT_BUFFER);
return;
}

SET_REQ_RESULT(req, result);
if (offset != -1) {
memset(&overlapped, 0, sizeof overlapped);

offset_.QuadPart = offset;
overlapped.Offset = offset_.LowPart;
overlapped.OffsetHigh = offset_.HighPart;

overlapped_ptr = &overlapped;
} else {
overlapped_ptr = NULL;
}

if (WriteFile(handle, buf, length, &bytes, overlapped_ptr)) {
SET_REQ_RESULT(req, bytes);
} else {
SET_REQ_ERROR(req, GetLastError());
}
}


Expand Down
35 changes: 35 additions & 0 deletions deps/uv/test/test-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,41 @@ static void sendfile_cb(uv_fs_t* req) {
}


static void open_noent_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN);
ASSERT(req->errorno == UV_ENOENT);
ASSERT(req->result == -1);
open_cb_count++;
uv_fs_req_cleanup(req);
}


TEST_IMPL(fs_file_noent) {
uv_fs_t req;
int r;

uv_init();
loop = uv_default_loop();

r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL);
ASSERT(r == -1);
ASSERT(req.result == -1);
ASSERT(uv_last_error(loop).code == UV_ENOENT);
uv_fs_req_cleanup(&req);

r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb);
ASSERT(r == 0);

ASSERT(open_cb_count == 0);
uv_run(loop);
ASSERT(open_cb_count == 1);

/* TODO add EACCES test */

return 0;
}


TEST_IMPL(fs_file_async) {
int r;

Expand Down
2 changes: 2 additions & 0 deletions deps/uv/test/test-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ TEST_DECLARE (spawn_exit_code)
TEST_DECLARE (spawn_stdout)
TEST_DECLARE (spawn_stdin)
TEST_DECLARE (spawn_and_kill)
TEST_DECLARE (fs_file_noent)
TEST_DECLARE (fs_file_async)
TEST_DECLARE (fs_file_sync)
TEST_DECLARE (fs_async_dir)
Expand Down Expand Up @@ -180,6 +181,7 @@ TASK_LIST_START
TEST_ENTRY (environment_creation)
#endif

TEST_ENTRY (fs_file_noent)
TEST_ENTRY (fs_file_async)
TEST_ENTRY (fs_file_sync)
TEST_ENTRY (fs_async_dir)
Expand Down

0 comments on commit 5003ba9

Please sign in to comment.