From 51f2e8439e4e26f7f3b58193112916c711085c91 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 12 Sep 2011 14:53:27 -0700 Subject: [PATCH] Upgrade libuv to e7eeacb --- deps/uv/config-unix.mk | 1 + deps/uv/include/uv-private/uv-unix.h | 2 + deps/uv/include/uv-private/uv-win.h | 3 ++ deps/uv/include/uv.h | 28 +++++++++- deps/uv/src/unix/pipe.c | 5 ++ deps/uv/src/unix/tty.c | 69 ++++++++++++++++++++++++ deps/uv/src/win/pipe.c | 6 +++ deps/uv/src/win/threads.c | 81 ++++++++++++++++++++++++++++ deps/uv/src/win/tty.c | 37 +++++++++++++ deps/uv/uv.gyp | 2 + 10 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 deps/uv/src/unix/tty.c create mode 100644 deps/uv/src/win/threads.c create mode 100644 deps/uv/src/win/tty.c diff --git a/deps/uv/config-unix.mk b/deps/uv/config-unix.mk index 49e0e3bc21..2f8525c145 100644 --- a/deps/uv/config-unix.mk +++ b/deps/uv/config-unix.mk @@ -37,6 +37,7 @@ OBJS += src/unix/error.o OBJS += src/unix/process.o OBJS += src/unix/tcp.o OBJS += src/unix/pipe.o +OBJS += src/unix/tty.o OBJS += src/unix/stream.o ifeq (SunOS,$(uname_S)) diff --git a/deps/uv/include/uv-private/uv-unix.h b/deps/uv/include/uv-private/uv-unix.h index 6b6272cca5..e6982c71dd 100644 --- a/deps/uv/include/uv-private/uv-unix.h +++ b/deps/uv/include/uv-private/uv-unix.h @@ -173,4 +173,6 @@ typedef int uv_file; #define UV_WORK_PRIVATE_FIELDS \ eio_req* eio; +#define UV_TTY_PRIVATE_FIELDS /* empty */ + #endif /* UV_UNIX_H */ diff --git a/deps/uv/include/uv-private/uv-win.h b/deps/uv/include/uv-private/uv-win.h index 8be0c8a452..c43313f7b2 100644 --- a/deps/uv/include/uv-private/uv-win.h +++ b/deps/uv/include/uv-private/uv-win.h @@ -261,6 +261,9 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s); #define UV_WORK_PRIVATE_FIELDS \ + +#define UV_TTY_PRIVATE_FIELDS /* empty */ + 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, diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index 58678c563e..13b40d86ba 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -49,6 +49,7 @@ typedef struct uv_stream_s uv_stream_t; typedef struct uv_tcp_s uv_tcp_t; typedef struct uv_udp_s uv_udp_t; typedef struct uv_pipe_s uv_pipe_t; +typedef struct uv_tty_s uv_tty_t; typedef struct uv_timer_s uv_timer_t; typedef struct uv_prepare_s uv_prepare_t; typedef struct uv_check_s uv_check_t; @@ -324,7 +325,7 @@ uv_buf_t uv_buf_init(char* base, size_t len); * * uv_stream is an abstract class. * - * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t + * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t, uv_tty_t * and soon uv_file_t. */ struct uv_stream_s { @@ -587,6 +588,25 @@ int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, int uv_udp_recv_stop(uv_udp_t* handle); +/* + * uv_tty_t is a subclass of uv_stream_t + * + * Representing a stream for the console. + */ +struct uv_tty_s { + UV_HANDLE_FIELDS + UV_STREAM_FIELDS + UV_TTY_PRIVATE_FIELDS +}; + +int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd); + +/* + * Set mode. 0 for normal, 1 for raw. + */ +int uv_tty_set_mode(uv_tty_t*, int mode); + + /* * uv_pipe_t is a subclass of uv_stream_t * @@ -601,6 +621,11 @@ struct uv_pipe_s { int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle); +/* + * Opens an existing file descriptor or HANDLE as a pipe. + */ +void uv_pipe_open(uv_pipe_t*, uv_file file); + int uv_pipe_bind(uv_pipe_t* handle, const char* name); int uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, @@ -1026,6 +1051,7 @@ struct uv_counters_s { uint64_t tcp_init; uint64_t udp_init; uint64_t pipe_init; + uint64_t tty_init; uint64_t prepare_init; uint64_t check_init; uint64_t idle_init; diff --git a/deps/uv/src/unix/pipe.c b/deps/uv/src/unix/pipe.c index d4e08896a4..50dc635b7e 100644 --- a/deps/uv/src/unix/pipe.c +++ b/deps/uv/src/unix/pipe.c @@ -170,6 +170,11 @@ int uv_pipe_cleanup(uv_pipe_t* handle) { } +void uv_pipe_open(uv_pipe_t* handle, uv_file fd) { + uv__stream_open((uv_stream_t*)handle, fd, UV_READABLE | UV_WRITABLE); +} + + int uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, const char* name, diff --git a/deps/uv/src/unix/tty.c b/deps/uv/src/unix/tty.c new file mode 100644 index 0000000000..3ceeb5f1c0 --- /dev/null +++ b/deps/uv/src/unix/tty.c @@ -0,0 +1,69 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "internal.h" + +#include +#include +#include + + +int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd) { + uv__nonblock(fd, 1); + uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY); + uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE | UV_WRITABLE); + loop->counters.tty_init++; + return 0; +} + + +int uv_tty_set_mode(uv_tty_t* tty, int mode) { + int fd = tty->fd; + struct termios orig_termios; /* in order to restore at exit */ + struct termios raw; + + if (tcgetattr(fd, &orig_termios) == -1) goto fatal; + + raw = orig_termios; /* modify the original mode */ + /* input modes: no break, no CR to NL, no parity check, no strip char, + * no start/stop output control. */ + raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); + /* output modes */ + raw.c_oflag |= (ONLCR); + /* control modes - set 8 bit chars */ + raw.c_cflag |= (CS8); + /* local modes - echoing off, canonical off, no extended functions, + * no signal chars (^Z,^C) */ + raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); + /* control chars - set return condition: min number of bytes and timer. + * We want read to return every single byte, without timeout. */ + raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0; /* 1 byte, no timer */ + + /* put terminal in raw mode after flushing */ + if (tcsetattr(fd, TCSAFLUSH, &raw) < 0) goto fatal; + return 0; + +fatal: + uv_err_new(tty->loop, ENOTTY); + return -1; +} + diff --git a/deps/uv/src/win/pipe.c b/deps/uv/src/win/pipe.c index 87854f614c..7832c6a41a 100644 --- a/deps/uv/src/win/pipe.c +++ b/deps/uv/src/win/pipe.c @@ -1059,3 +1059,9 @@ static void eof_timer_close_cb(uv_handle_t* handle) { assert(handle->type == UV_TIMER); free(handle); } + + +void uv_pipe_open(uv_pipe_t* pipe, uv_file file) { + assert(0 && "implement me"); +} + diff --git a/deps/uv/src/win/threads.c b/deps/uv/src/win/threads.c new file mode 100644 index 0000000000..1fc6b73f87 --- /dev/null +++ b/deps/uv/src/win/threads.c @@ -0,0 +1,81 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +#include "uv.h" +#include "../uv-common.h" +#include "internal.h" + + +#ifdef _MSC_VER /* msvc */ +# define NOINLINE __declspec (noinline) +#else /* gcc */ +# define NOINLINE __attribute__ ((noinline)) +#endif + + +static NOINLINE void uv__once_inner(uv_once_t* guard, + void (*callback)(void)) { + DWORD result; + HANDLE existing_event, created_event; + HANDLE* event_ptr; + + /* Fetch and align event_ptr */ + event_ptr = (HANDLE*) (((uintptr_t) &guard->event + (sizeof(HANDLE) - 1)) & + ~(sizeof(HANDLE) - 1)); + + created_event = CreateEvent(NULL, 1, 0, NULL); + if (created_event == 0) { + /* Could fail in a low-memory situation? */ + uv_fatal_error(GetLastError(), "CreateEvent"); + } + + existing_event = InterlockedCompareExchangePointer(event_ptr, + created_event, + NULL); + + if (existing_event == NULL) { + /* We won the race */ + callback(); + + result = SetEvent(created_event); + assert(result); + guard->ran = 1; + + } else { + /* We lost the race. Destroy the event we created and wait for the */ + /* existing one to become signaled. */ + CloseHandle(created_event); + result = WaitForSingleObject(existing_event, INFINITE); + assert(result == WAIT_OBJECT_0); + } +} + + +void uv_once(uv_once_t* guard, void (*callback)(void)) { + /* Fast case - avoid WaitForSingleObject. */ + if (guard->ran) { + return; + } + + uv__once_inner(guard, callback); +} diff --git a/deps/uv/src/win/tty.c b/deps/uv/src/win/tty.c new file mode 100644 index 0000000000..5498eec99c --- /dev/null +++ b/deps/uv/src/win/tty.c @@ -0,0 +1,37 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "internal.h" + +#include + + +int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd) { + assert(0 && "implement me"); + return -1; +} + + +int uv_tty_set_mode(uv_tty_t* tty, int mode) { + assert(0 && "implement me"); + return -1; +} diff --git a/deps/uv/uv.gyp b/deps/uv/uv.gyp index b056624022..b70940ed7a 100644 --- a/deps/uv/uv.gyp +++ b/deps/uv/uv.gyp @@ -113,6 +113,7 @@ 'src/win/stdio.c', 'src/win/stream.c', 'src/win/tcp.c', + 'src/win/tty.c', 'src/win/threadpool.c', 'src/win/threads.c', 'src/win/timer.c', @@ -149,6 +150,7 @@ 'src/unix/udp.c', 'src/unix/tcp.c', 'src/unix/pipe.c', + 'src/unix/tty.c', 'src/unix/stream.c', 'src/unix/cares.c', 'src/unix/error.c',