Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
upgrade uv to 812e410772
  • Loading branch information
Igor Zinkovsky committed Jan 30, 2012
1 parent e97b961 commit ff40253
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 19 deletions.
3 changes: 3 additions & 0 deletions deps/uv/include/uv-private/uv-unix.h
Expand Up @@ -192,6 +192,9 @@ typedef void* uv_lib_t;
struct termios orig_termios; \
int mode;

#define UV_STREAM_INFO_PRIVATE_FIELDS \
int fd;

/* UV_FS_EVENT_PRIVATE_FIELDS */
#if defined(__linux__)

Expand Down
5 changes: 5 additions & 0 deletions deps/uv/include/uv-private/uv-win.h
Expand Up @@ -450,6 +450,11 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
wchar_t* dirw; \
char* buffer;

#define UV_STREAM_INFO_PRIVATE_FIELDS \
union { \
WSAPROTOCOL_INFOW socket_info; \
};

int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size);
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer,
Expand Down
23 changes: 23 additions & 0 deletions deps/uv/include/uv.h
Expand Up @@ -180,6 +180,7 @@ 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;
typedef struct uv_stream_info_s uv_stream_info_t;
/* Request types */
typedef struct uv_req_s uv_req_t;
typedef struct uv_shutdown_s uv_shutdown_t;
Expand Down Expand Up @@ -530,6 +531,28 @@ UV_EXTERN int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name,
UV_EXTERN int uv_tcp_getpeername(uv_tcp_t* handle, struct sockaddr* name,
int* namelen);

/*
* uv_stream_info_t is used to store exported stream (using uv_export),
* which can be imported into a different event-loop within the same process
* (using uv_import).
*/
struct uv_stream_info_s {
uv_handle_type type;
UV_STREAM_INFO_PRIVATE_FIELDS
};

/*
* Exports uv_stream_t as uv_stream_info_t value, which could
* be used to initialize shared streams within the same process.
*/
UV_EXTERN int uv_export(uv_stream_t* stream, uv_stream_info_t* info);

/*
* Imports uv_stream_info_t value into uv_stream_t to initialize
* shared stream.
*/
UV_EXTERN int uv_import(uv_stream_t* stream, uv_stream_info_t* info);

/*
* uv_tcp_connect, uv_tcp_connect6
* These functions establish IPv4 and IPv6 TCP connections. Provide an
Expand Down
18 changes: 18 additions & 0 deletions deps/uv/src/unix/core.c
Expand Up @@ -825,6 +825,24 @@ int uv__cloexec(int fd, int set) {
}


/* This function is not execve-safe, there is a race window
* between the call to dup() and fcntl(FD_CLOEXEC).
*/
int uv__dup(int fd) {
fd = dup(fd);

if (fd == -1)
return -1;

if (uv__cloexec(fd, 1)) {
SAVE_ERRNO(uv__close(fd));
return -1;
}

return fd;
}


/* TODO move to uv-common.c? */
size_t uv__strlcpy(char* dst, const char* src, size_t size) {
const char *org;
Expand Down
4 changes: 1 addition & 3 deletions deps/uv/src/unix/error.c
Expand Up @@ -86,7 +86,5 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case ETIMEDOUT: return UV_ETIMEDOUT;
default: return UV_UNKNOWN;
}

assert(0 && "unreachable");
return -1;
UNREACHABLE();
}
24 changes: 17 additions & 7 deletions deps/uv/src/unix/internal.h
Expand Up @@ -25,6 +25,8 @@
#include "uv-common.h"
#include "uv-eio.h"

#include <assert.h>
#include <stdlib.h> /* abort */
#include <stddef.h> /* offsetof */

#if __STRICT_ANSI__
Expand Down Expand Up @@ -133,13 +135,20 @@ inline static int sys_accept4(int fd,
#define container_of(ptr, type, member) \
((type *) ((char *) (ptr) - offsetof(type, member)))

#define SAVE_ERRNO(block) \
do { \
int _saved_errno = errno; \
do { block; } while (0); \
errno = _saved_errno; \
} \
while (0);
#define UNREACHABLE() \
do { \
assert(0 && "unreachable code"); \
abort(); \
} \
while (0)

#define SAVE_ERRNO(block) \
do { \
int _saved_errno = errno; \
do { block; } while (0); \
errno = _saved_errno; \
} \
while (0)

/* flags */
enum {
Expand All @@ -159,6 +168,7 @@ void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, uv_handle_type type);
int uv__nonblock(int fd, int set) __attribute__((unused));
int uv__cloexec(int fd, int set) __attribute__((unused));
int uv__socket(int domain, int type, int protocol);
int uv__dup(int fd);

/* We used to handle EINTR in uv__close() but linux 2.6 will have closed the
* file descriptor anyway, even on EINTR. Retrying in that case isn't merely
Expand Down
4 changes: 2 additions & 2 deletions deps/uv/src/unix/kqueue.c
Expand Up @@ -141,13 +141,13 @@ int uv_fs_event_init(uv_loop_t* loop,


void uv__fs_event_destroy(uv_fs_event_t* handle) {
assert(0 && "unreachable");
UNREACHABLE();
}


/* Called by libev, don't touch. */
void uv__kqueue_hack(EV_P_ int fflags, ev_io *w) {
assert(0 && "unreachable");
UNREACHABLE();
}

#endif /* HAVE_KQUEUE */
3 changes: 1 addition & 2 deletions deps/uv/src/unix/linux.c
Expand Up @@ -679,8 +679,7 @@ int uv_fs_event_init(uv_loop_t* loop,


void uv__fs_event_destroy(uv_fs_event_t* handle) {
assert(0 && "unreachable");
abort();
UNREACHABLE();
}

#endif /* HAVE_INOTIFY_INIT || HAVE_INOTIFY_INIT1 */
37 changes: 37 additions & 0 deletions deps/uv/src/unix/stream.c
Expand Up @@ -966,3 +966,40 @@ int uv_read_stop(uv_stream_t* stream) {
}


int uv_export(uv_stream_t* stream, uv_stream_info_t* info) {
int fd;

if (stream->type != UV_TCP) {
uv__set_artificial_error(stream->loop, UV_EINVAL);
return -1;
}

fd = uv__dup(stream->fd);

if (fd == -1) {
uv__set_sys_error(stream->loop, errno);
return -1;
}

info->type = stream->type;
info->fd = fd;

return 0;
}


int uv_import(uv_stream_t* stream, uv_stream_info_t* info) {
if (info->type != UV_TCP) {
uv__set_artificial_error(stream->loop, UV_EINVAL);
return -1;
}

if (stream->fd != -1) {
uv__set_artificial_error(stream->loop, UV_EALREADY);
return -1;
}

stream->fd = info->fd;

return 0;
}
2 changes: 1 addition & 1 deletion deps/uv/src/unix/sunos.c
Expand Up @@ -214,7 +214,7 @@ int uv_fs_event_init(uv_loop_t* loop,


void uv__fs_event_destroy(uv_fs_event_t* handle) {
assert(0 && "unreachable"); /* should never be called */
UNREACHABLE();
}

#endif /* HAVE_PORTS_FS */
Expand Down
5 changes: 4 additions & 1 deletion deps/uv/src/win/internal.h
Expand Up @@ -143,11 +143,14 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,

void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle);

int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info);
int uv__tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info);

int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid,
LPWSAPROTOCOL_INFOW protocol_info);

int uv_tcp_export(uv_tcp_t* tcp, uv_stream_info_t* info);
int uv_tcp_import(uv_tcp_t* tcp, uv_stream_info_t* info);


/*
* UDP
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/win/pipe.c
Expand Up @@ -649,7 +649,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
return -1;
}

return uv_tcp_import((uv_tcp_t*)client, server->pending_socket_info);
return uv__tcp_import((uv_tcp_t*)client, server->pending_socket_info);
} else {
pipe_client = (uv_pipe_t*)client;

Expand Down
24 changes: 24 additions & 0 deletions deps/uv/src/win/stream.c
Expand Up @@ -186,3 +186,27 @@ size_t uv_count_bufs(uv_buf_t bufs[], int count) {

return bytes;
}


int uv_export(uv_stream_t* stream, uv_stream_info_t* info) {
switch (stream->type) {
case UV_TCP:
return uv_tcp_export((uv_tcp_t*)stream, info);
default:
assert(0);
uv__set_sys_error(stream->loop, WSAEINVAL);
return -1;
}
}


int uv_import(uv_stream_t* stream, uv_stream_info_t* info) {
switch (stream->type) {
case UV_TCP:
return uv_tcp_import((uv_tcp_t*)stream, info);
default:
assert(0);
uv__set_sys_error(stream->loop, WSAEINVAL);
return -1;
}
}
25 changes: 23 additions & 2 deletions deps/uv/src/win/tcp.c
Expand Up @@ -1019,7 +1019,7 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
}


int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info) {
int uv__tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info) {
SOCKET socket = WSASocketW(AF_INET,
SOCK_STREAM,
IPPROTO_IP,
Expand Down Expand Up @@ -1140,4 +1140,25 @@ int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable) {
}

return 0;
}
}


int uv_tcp_export(uv_tcp_t* tcp, uv_stream_info_t* info) {
if (uv_tcp_duplicate_socket(tcp, GetCurrentProcessId(),
&info->socket_info) == -1) {
return -1;
}

info->type = UV_TCP;
return 0;
}


int uv_tcp_import(uv_tcp_t* tcp, uv_stream_info_t* info) {
if (info->type != UV_TCP) {
uv__set_sys_error(tcp->loop, WSAEINVAL);
return -1;
}

return uv__tcp_import(tcp, &info->socket_info);
}
4 changes: 4 additions & 0 deletions deps/uv/test/test-list.h
Expand Up @@ -24,6 +24,8 @@ TEST_DECLARE (tty)
TEST_DECLARE (stdio_over_pipes)
TEST_DECLARE (ipc_listen_before_write)
TEST_DECLARE (ipc_listen_after_write)
TEST_DECLARE (ipc_threads_listen_after_write)
TEST_DECLARE (ipc_threads_listen_before_write)
TEST_DECLARE (tcp_ping_pong)
TEST_DECLARE (tcp_ping_pong_v6)
TEST_DECLARE (pipe_ping_pong)
Expand Down Expand Up @@ -161,6 +163,8 @@ TASK_LIST_START
TEST_ENTRY (stdio_over_pipes)
TEST_ENTRY (ipc_listen_before_write)
TEST_ENTRY (ipc_listen_after_write)
TEST_ENTRY (ipc_threads_listen_after_write)
TEST_ENTRY (ipc_threads_listen_before_write)

TEST_ENTRY (tcp_ping_pong)
TEST_HELPER (tcp_ping_pong, tcp4_echo_server)
Expand Down
1 change: 1 addition & 0 deletions deps/uv/uv.gyp
Expand Up @@ -301,6 +301,7 @@
'test/test-hrtime.c',
'test/test-idle.c',
'test/test-ipc.c',
'test/test-ipc-threads.c',
'test/test-list.h',
'test/test-loop-handles.c',
'test/test-multiple-listen.c',
Expand Down

0 comments on commit ff40253

Please sign in to comment.