summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deps/uv/include/uv-private/uv-unix.h3
-rw-r--r--deps/uv/include/uv.h13
-rw-r--r--deps/uv/src/unix/stream.c3
-rw-r--r--deps/uv/src/unix/tty.c15
-rw-r--r--deps/uv/src/win/tty.c2
-rw-r--r--deps/uv/test/test-tty.c2
-rw-r--r--lib/tty_uv.js4
-rw-r--r--src/tty_wrap.cc6
8 files changed, 35 insertions, 13 deletions
diff --git a/deps/uv/include/uv-private/uv-unix.h b/deps/uv/include/uv-private/uv-unix.h
index 72709c8a58..0db14e9c7f 100644
--- a/deps/uv/include/uv-private/uv-unix.h
+++ b/deps/uv/include/uv-private/uv-unix.h
@@ -99,7 +99,8 @@ typedef int uv_file;
ngx_queue_t write_completed_queue; \
int delayed_error; \
uv_connection_cb connection_cb; \
- int accepted_fd;
+ int accepted_fd; \
+ int blocking;
/* UV_TCP */
diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h
index e938fe5500..8082afaf83 100644
--- a/deps/uv/include/uv.h
+++ b/deps/uv/include/uv.h
@@ -626,7 +626,18 @@ struct uv_tty_s {
UV_TTY_PRIVATE_FIELDS
};
-int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd);
+/*
+ * Initialize a new TTY stream with the given file descriptor. Usually the
+ * file descriptor will be
+ * 0 = stdin
+ * 1 = stdout
+ * 2 = stderr
+ * The last argument, readable, specifies if you plan on calling
+ * uv_read_start with this stream. stdin is readable, stdout is not.
+ *
+ * TTY streams which are not readable have blocking writes.
+ */
+int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable);
/*
* Set mode. 0 for normal, 1 for raw.
diff --git a/deps/uv/src/unix/stream.c b/deps/uv/src/unix/stream.c
index 7de318e277..9f2f0ecf92 100644
--- a/deps/uv/src/unix/stream.c
+++ b/deps/uv/src/unix/stream.c
@@ -53,6 +53,7 @@ void uv__stream_init(uv_loop_t* loop,
uv_stream_t* stream,
uv_handle_type type) {
uv__handle_init(loop, (uv_handle_t*)stream, type);
+ loop->counters.stream_init++;
stream->alloc_cb = NULL;
stream->close_cb = NULL;
@@ -83,7 +84,7 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
assert(fd >= 0);
stream->fd = fd;
- ((uv_handle_t*)stream)->flags |= flags;
+ stream->flags |= flags;
/* Reuse the port address if applicable. */
yes = 1;
diff --git a/deps/uv/src/unix/tty.c b/deps/uv/src/unix/tty.c
index 3d074bf488..32ac2c71c7 100644
--- a/deps/uv/src/unix/tty.c
+++ b/deps/uv/src/unix/tty.c
@@ -33,10 +33,19 @@ static int orig_termios_fd = -1;
static struct termios orig_termios;
-int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd) {
- uv__nonblock(fd, 1);
+int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
- uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE | UV_WRITABLE);
+
+ if (readable) {
+ uv__nonblock(fd, 1);
+ uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE);
+ } else {
+ /* Note: writable tty we set to blocking mode. */
+ uv__nonblock(fd, 0);
+ uv__stream_open((uv_stream_t*)tty, fd, UV_WRITABLE);
+ tty->blocking = 1;
+ }
+
loop->counters.tty_init++;
tty->mode = 0;
return 0;
diff --git a/deps/uv/src/win/tty.c b/deps/uv/src/win/tty.c
index b989bebe0c..16064eed10 100644
--- a/deps/uv/src/win/tty.c
+++ b/deps/uv/src/win/tty.c
@@ -86,7 +86,7 @@ void uv_console_init() {
}
-int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd) {
+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;
diff --git a/deps/uv/test/test-tty.c b/deps/uv/test/test-tty.c
index 5dbd4aff4e..60aedf39a9 100644
--- a/deps/uv/test/test-tty.c
+++ b/deps/uv/test/test-tty.c
@@ -33,7 +33,7 @@ TEST_IMPL(tty) {
*/
ASSERT(UV_TTY == uv_guess_handle(0));
- r = uv_tty_init(uv_default_loop(), &tty, 0);
+ r = uv_tty_init(uv_default_loop(), &tty, 0, 1);
ASSERT(r == 0);
r = uv_tty_get_winsize(&tty, &width, &height);
diff --git a/lib/tty_uv.js b/lib/tty_uv.js
index bd632472ae..ec2c8f5f09 100644
--- a/lib/tty_uv.js
+++ b/lib/tty_uv.js
@@ -53,7 +53,7 @@ exports.setWindowSize = function() {
function ReadStream(fd) {
if (!(this instanceof ReadStream)) return new ReadStream(fd);
net.Socket.call(this, {
- handle: new TTY(fd)
+ handle: new TTY(fd, true)
});
this.writable = false;
@@ -314,7 +314,7 @@ ReadStream.prototype._emitKey = function(s) {
function WriteStream(fd) {
if (!(this instanceof WriteStream)) return new WriteStream(fd);
net.Socket.call(this, {
- handle: new TTY(fd)
+ handle: new TTY(fd, false)
});
this.readable = false;
diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc
index 82ad7a80dc..eaa8cfdcd4 100644
--- a/src/tty_wrap.cc
+++ b/src/tty_wrap.cc
@@ -136,16 +136,16 @@ class TTYWrap : StreamWrap {
int fd = args[0]->Int32Value();
assert(fd >= 0);
- TTYWrap* wrap = new TTYWrap(args.This(), fd);
+ TTYWrap* wrap = new TTYWrap(args.This(), fd, args[1]->IsTrue());
assert(wrap);
wrap->UpdateWriteQueueSize();
return scope.Close(args.This());
}
- TTYWrap(Handle<Object> object, int fd)
+ TTYWrap(Handle<Object> object, int fd, bool readable)
: StreamWrap(object, (uv_stream_t*)&handle_) {
- uv_tty_init(uv_default_loop(), &handle_, fd);
+ uv_tty_init(uv_default_loop(), &handle_, fd, readable);
}
uv_tty_t handle_;