aboutsummaryrefslogtreecommitdiff
path: root/deps/uv/src/unix
diff options
context:
space:
mode:
authorTimothy J Fontaine <tjfontaine@gmail.com>2013-12-31 10:33:54 -0800
committerTimothy J Fontaine <tjfontaine@gmail.com>2013-12-31 10:33:54 -0800
commit8590f810a534628a7ee449530d93fee67597476a (patch)
treeed6f9b845444d7a560b25fad820cf3ce9248ca37 /deps/uv/src/unix
parent58d6ca3a958f75487fa630004c683052b102dd74 (diff)
downloadandroid-node-v8-8590f810a534628a7ee449530d93fee67597476a.tar.gz
android-node-v8-8590f810a534628a7ee449530d93fee67597476a.tar.bz2
android-node-v8-8590f810a534628a7ee449530d93fee67597476a.zip
uv: Upgrade to v0.11.17
Diffstat (limited to 'deps/uv/src/unix')
-rw-r--r--deps/uv/src/unix/core.c7
-rw-r--r--deps/uv/src/unix/fs.c7
-rw-r--r--deps/uv/src/unix/kqueue.c3
-rw-r--r--deps/uv/src/unix/stream.c85
4 files changed, 58 insertions, 44 deletions
diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c
index 6bb2057351..df2a5f8042 100644
--- a/deps/uv/src/unix/core.c
+++ b/deps/uv/src/unix/core.c
@@ -248,13 +248,18 @@ int uv_backend_timeout(const uv_loop_t* loop) {
}
-static int uv__loop_alive(uv_loop_t* loop) {
+static int uv__loop_alive(const uv_loop_t* loop) {
return uv__has_active_handles(loop) ||
uv__has_active_reqs(loop) ||
loop->closing_handles != NULL;
}
+int uv_loop_alive(const uv_loop_t* loop) {
+ return uv__loop_alive(loop);
+}
+
+
int uv_run(uv_loop_t* loop, uv_run_mode mode) {
int timeout;
int r;
diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c
index 4e572b7d96..1aa6539cb4 100644
--- a/deps/uv/src/unix/fs.c
+++ b/deps/uv/src/unix/fs.c
@@ -213,9 +213,12 @@ static ssize_t uv__fs_readdir(uv_fs_t* req) {
int i;
int n;
+ dents = NULL;
n = scandir(req->path, &dents, uv__fs_readdir_filter, alphasort);
- if (n == -1 || n == 0)
+ if (n == 0)
+ goto out; /* osx still needs to deallocate some memory */
+ else if (n == -1)
return n;
len = 0;
@@ -243,7 +246,7 @@ static ssize_t uv__fs_readdir(uv_fs_t* req) {
out:
saved_errno = errno;
- {
+ if (dents != NULL) {
for (i = 0; i < n; i++)
free(dents[i]);
free(dents);
diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c
index 70f5d9edb4..f86f291fc0 100644
--- a/deps/uv/src/unix/kqueue.c
+++ b/deps/uv/src/unix/kqueue.c
@@ -167,11 +167,10 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
for (i = 0; i < nfds; i++) {
ev = events + i;
fd = ev->ident;
- w = loop->watchers[fd];
-
/* Skip invalidated events, see uv__platform_invalidate_fd */
if (fd == -1)
continue;
+ w = loop->watchers[fd];
if (w == NULL) {
/* File descriptor that we've stopped watching, disarm it. */
diff --git a/deps/uv/src/unix/stream.c b/deps/uv/src/unix/stream.c
index afd2a051aa..9f5d40cf4b 100644
--- a/deps/uv/src/unix/stream.c
+++ b/deps/uv/src/unix/stream.c
@@ -138,6 +138,31 @@ void uv__stream_init(uv_loop_t* loop,
}
+static void uv__stream_osx_interrupt_select(uv_stream_t* stream) {
+#if defined(__APPLE__)
+ /* Notify select() thread about state change */
+ uv__stream_select_t* s;
+ int r;
+
+ s = stream->select;
+ if (s == NULL)
+ return;
+
+ /* Interrupt select() loop
+ * NOTE: fake_fd and int_fd are socketpair(), thus writing to one will
+ * emit read event on other side
+ */
+ do
+ r = write(s->fake_fd, "x", 1);
+ while (r == -1 && errno == EINTR);
+
+ assert(r == 1);
+#else /* !defined(__APPLE__) */
+ /* No-op on any other platform */
+#endif /* !defined(__APPLE__) */
+}
+
+
#if defined(__APPLE__)
static void uv__stream_osx_select(void* arg) {
uv_stream_t* stream;
@@ -168,9 +193,9 @@ static void uv__stream_osx_select(void* arg) {
FD_ZERO(&sread);
FD_ZERO(&swrite);
- if (uv_is_readable(stream))
+ if (uv__io_active(&stream->io_watcher, UV__POLLIN))
FD_SET(fd, &sread);
- if (uv_is_writable(stream))
+ if (uv__io_active(&stream->io_watcher, UV__POLLOUT))
FD_SET(fd, &swrite);
FD_SET(s->int_fd, &sread);
@@ -229,25 +254,6 @@ static void uv__stream_osx_select(void* arg) {
}
-static void uv__stream_osx_interrupt_select(uv_stream_t* stream) {
- /* Notify select() thread about state change */
- uv__stream_select_t* s;
- int r;
-
- s = stream->select;
-
- /* Interrupt select() loop
- * NOTE: fake_fd and int_fd are socketpair(), thus writing to one will
- * emit read event on other side
- */
- do
- r = write(s->fake_fd, "x", 1);
- while (r == -1 && errno == EINTR);
-
- assert(r == 1);
-}
-
-
static void uv__stream_osx_select_cb(uv_async_t* handle, int status) {
uv__stream_select_t* s;
uv_stream_t* stream;
@@ -622,6 +628,7 @@ static void uv__drain(uv_stream_t* stream) {
assert(QUEUE_EMPTY(&stream->write_queue));
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
+ uv__stream_osx_interrupt_select(stream);
/* Shutdown? */
if ((stream->flags & UV_STREAM_SHUTTING) &&
@@ -802,6 +809,7 @@ start:
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
if (!uv__io_active(&stream->io_watcher, UV__POLLIN))
uv__handle_stop(stream);
+ uv__stream_osx_interrupt_select(stream);
return;
} else if (stream->flags & UV_STREAM_BLOCKING) {
/* If this is a blocking stream, try again. */
@@ -863,6 +871,9 @@ start:
/* We're not done. */
uv__io_start(stream->loop, &stream->io_watcher, UV__POLLOUT);
+
+ /* Notify select() thread about state change */
+ uv__stream_osx_interrupt_select(stream);
}
@@ -947,6 +958,7 @@ static void uv__stream_eof(uv_stream_t* stream, const uv_buf_t* buf) {
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN);
if (!uv__io_active(&stream->io_watcher, UV__POLLOUT))
uv__handle_stop(stream);
+ uv__stream_osx_interrupt_select(stream);
uv__stream_read_cb(stream, UV_EOF, buf, UV_UNKNOWN_HANDLE);
}
@@ -1013,6 +1025,7 @@ static void uv__read(uv_stream_t* stream) {
/* Wait for the next one. */
if (stream->flags & UV_STREAM_READING) {
uv__io_start(stream->loop, &stream->io_watcher, UV__POLLIN);
+ uv__stream_osx_interrupt_select(stream);
}
uv__stream_read_cb(stream, 0, &buf, UV_UNKNOWN_HANDLE);
} else {
@@ -1105,6 +1118,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
stream->flags |= UV_STREAM_SHUTTING;
uv__io_start(stream->loop, &stream->io_watcher, UV__POLLOUT);
+ uv__stream_osx_interrupt_select(stream);
return 0;
}
@@ -1281,6 +1295,7 @@ int uv_write2(uv_write_t* req,
*/
assert(!(stream->flags & UV_STREAM_BLOCKING));
uv__io_start(stream->loop, &stream->io_watcher, UV__POLLOUT);
+ uv__stream_osx_interrupt_select(stream);
}
return 0;
@@ -1305,13 +1320,14 @@ void uv_try_write_cb(uv_write_t* req, int status) {
}
-int uv_try_write(uv_stream_t* stream, const char* buf, size_t size) {
+int uv_try_write(uv_stream_t* stream,
+ const uv_buf_t bufs[],
+ unsigned int nbufs) {
int r;
int has_pollout;
size_t written;
size_t req_size;
uv_write_t req;
- uv_buf_t bufstruct;
/* Connecting or already writing some data */
if (stream->connect_req != NULL || stream->write_queue_size != 0)
@@ -1319,13 +1335,12 @@ int uv_try_write(uv_stream_t* stream, const char* buf, size_t size) {
has_pollout = uv__io_active(&stream->io_watcher, UV__POLLOUT);
- bufstruct = uv_buf_init((char*) buf, size);
- r = uv_write(&req, stream, &bufstruct, 1, uv_try_write_cb);
+ r = uv_write(&req, stream, bufs, nbufs, uv_try_write_cb);
if (r != 0)
return r;
/* Remove not written bytes from write queue size */
- written = size;
+ written = uv_count_bufs(bufs, nbufs);
if (req.bufs != NULL)
req_size = uv__write_req_size(&req);
else
@@ -1341,8 +1356,10 @@ int uv_try_write(uv_stream_t* stream, const char* buf, size_t size) {
req.bufs = NULL;
/* Do not poll for writable, if we wasn't before calling this */
- if (!has_pollout)
+ if (!has_pollout) {
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
+ uv__stream_osx_interrupt_select(stream);
+ }
return (int) written;
}
@@ -1363,12 +1380,6 @@ static int uv__read_start_common(uv_stream_t* stream,
*/
stream->flags |= UV_STREAM_READING;
-#if defined(__APPLE__)
- /* Notify select() thread about state change */
- if (stream->select != NULL)
- uv__stream_osx_interrupt_select(stream);
-#endif /* defined(__APPLE__) */
-
/* TODO: try to do the read inline? */
/* TODO: keep track of tcp state. If we've gotten a EOF then we should
* not start the IO watcher.
@@ -1382,6 +1393,7 @@ static int uv__read_start_common(uv_stream_t* stream,
uv__io_start(stream->loop, &stream->io_watcher, UV__POLLIN);
uv__handle_start(stream);
+ uv__stream_osx_interrupt_select(stream);
return 0;
}
@@ -1414,12 +1426,7 @@ int uv_read_stop(uv_stream_t* stream) {
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN);
if (!uv__io_active(&stream->io_watcher, UV__POLLOUT))
uv__handle_stop(stream);
-
-#if defined(__APPLE__)
- /* Notify select() thread about state change */
- if (stream->select != NULL)
- uv__stream_osx_interrupt_select(stream);
-#endif /* defined(__APPLE__) */
+ uv__stream_osx_interrupt_select(stream);
stream->read_cb = NULL;
stream->read2_cb = NULL;