Upgrade uv to 604802a
authorisaacs <i@izs.me>
Thu, 24 May 2012 21:26:32 +0000 (14:26 -0700)
committerisaacs <i@izs.me>
Thu, 24 May 2012 21:26:32 +0000 (14:26 -0700)
20 files changed:
deps/uv/config-unix.mk
deps/uv/include/uv-private/uv-unix.h
deps/uv/include/uv.h
deps/uv/src/unix/core.c
deps/uv/src/unix/internal.h
deps/uv/src/unix/loop.c
deps/uv/src/unix/pipe.c
deps/uv/src/unix/poll.c
deps/uv/src/unix/stream.c
deps/uv/src/unix/tty.c
deps/uv/src/unix/udp.c
deps/uv/src/win/core.c
deps/uv/test/benchmark-list.h
deps/uv/test/benchmark-sizes.c
deps/uv/test/test-fs.c
deps/uv/test/test-ipc-send-recv.c
deps/uv/test/test-list.h
deps/uv/test/test-pipe-bind-error.c
deps/uv/test/test-run-once.c
deps/uv/uv.gyp

index ce98c1f05355b25d8ee8f939b35dc9d40341a343..c1ba2d0ad11d8382f145e5268c7dcc82e267872e 100644 (file)
@@ -33,6 +33,7 @@ OBJS += src/unix/dl.o
 OBJS += src/unix/error.o
 OBJS += src/unix/fs.o
 OBJS += src/unix/loop.o
+OBJS += src/unix/loop-watcher.o
 OBJS += src/unix/pipe.o
 OBJS += src/unix/poll.o
 OBJS += src/unix/process.o
index 71253bc9ad9026fe1ee884f06c7adbcf695cf32e..27ed333cfdbd39c0b81605ff76c96095cc5a3e39 100644 (file)
@@ -131,10 +131,9 @@ struct uv__io_s {
 
 #define UV_UDP_SEND_PRIVATE_FIELDS  \
   ngx_queue_t queue;                \
-  struct sockaddr_storage addr;     \
-  socklen_t addrlen;                \
-  uv_buf_t* bufs;                   \
+  struct sockaddr_in6 addr;         \
   int bufcnt;                       \
+  uv_buf_t* bufs;                   \
   ssize_t status;                   \
   uv_udp_send_cb send_cb;           \
   uv_buf_t bufsml[UV_REQ_BUFSML_SIZE];  \
@@ -144,7 +143,6 @@ struct uv__io_s {
 
 /* TODO: union or classes please! */
 #define UV_HANDLE_PRIVATE_FIELDS \
-  int fd; \
   int flags; \
   uv_handle_t* next_pending; \
 
@@ -156,10 +154,10 @@ struct uv__io_s {
   uv__io_t write_watcher; \
   ngx_queue_t write_queue; \
   ngx_queue_t write_completed_queue; \
-  int delayed_error; \
   uv_connection_cb connection_cb; \
+  int delayed_error; \
   int accepted_fd; \
-  int blocking;
+  int fd; \
 
 
 /* UV_TCP */
@@ -168,6 +166,7 @@ struct uv__io_s {
 
 /* UV_UDP */
 #define UV_UDP_PRIVATE_FIELDS         \
+  int fd;                             \
   uv_alloc_cb alloc_cb;               \
   uv_udp_recv_cb recv_cb;             \
   uv__io_t read_watcher;              \
@@ -183,6 +182,7 @@ struct uv__io_s {
 
 /* UV_POLL */
 #define UV_POLL_PRIVATE_FIELDS        \
+  int fd;                             \
   uv__io_t io_watcher;
 
 
@@ -248,7 +248,8 @@ struct uv__io_s {
     struct uv_fs_event_s* rbe_parent; \
     int rbe_color;                    \
   } node;                             \
-  uv_fs_event_cb cb;
+  uv_fs_event_cb cb;                  \
+  int fd;                             \
 
 #elif defined(__APPLE__)  \
   || defined(__FreeBSD__) \
@@ -260,6 +261,7 @@ struct uv__io_s {
   ev_io event_watcher; \
   uv_fs_event_cb cb; \
   int fflags; \
+  int fd;
 
 #elif defined(__sun)
 
@@ -267,7 +269,8 @@ struct uv__io_s {
 # define UV_FS_EVENT_PRIVATE_FIELDS \
   ev_io event_watcher; \
   uv_fs_event_cb cb; \
-  file_obj_t fo;
+  file_obj_t fo; \
+  int fd;
 #else /* !PORT_SOURCE_FILE */
 # define UV_FS_EVENT_PRIVATE_FIELDS
 #endif
index 218cebe0714a267959b1a4a8d641364534c0ddf0..f784546795dc5c7be13f2c3bda14a6144dd76cb8 100644 (file)
@@ -230,14 +230,17 @@ UV_EXTERN uv_loop_t* uv_default_loop(void);
 
 /*
  * This function starts the event loop. It blocks until the reference count
- * of the loop drops to zero.
+ * of the loop drops to zero. Always returns zero.
  */
-UV_EXTERN int uv_run (uv_loop_t*);
+UV_EXTERN int uv_run(uv_loop_t*);
 
 /*
- * This function polls for new events without blocking.
+ * Poll for new events once. Note that this function blocks if there are no
+ * pending events. Returns zero when done (no active handles or requests left),
+ * or non-zero if more events are expected (meaning you should call
+ * uv_run_once() again sometime in the future).
  */
-UV_EXTERN int uv_run_once (uv_loop_t*);
+UV_EXTERN int uv_run_once(uv_loop_t*);
 
 /*
  * Manually modify the event loop's reference count. Useful if the user wants
@@ -338,13 +341,13 @@ UV_EXTERN const char* uv_err_name(uv_err_t err);
 #endif
 
 #define UV_REQ_FIELDS \
-  /* read-only */ \
-  uv_req_type type; \
   /* public */ \
   void* data; \
   UV_REQ_EXTRA_FIELDS \
   /* private */ \
-  UV_REQ_PRIVATE_FIELDS
+  UV_REQ_PRIVATE_FIELDS \
+  /* read-only */ \
+  uv_req_type type; \
 
 /* Abstract base class of all requests. */
 struct uv_req_s {
@@ -381,16 +384,17 @@ struct uv_shutdown_s {
 # define UV_HANDLE_EXTRA_FIELDS
 #endif
 
-#define UV_HANDLE_FIELDS \
-  /* read-only */ \
-  uv_loop_t* loop; \
-  uv_handle_type type; \
-  /* public */ \
-  uv_close_cb close_cb; \
-  void* data; \
-  UV_HANDLE_EXTRA_FIELDS \
-  /* private */ \
-  UV_HANDLE_PRIVATE_FIELDS
+#define UV_HANDLE_FIELDS                                                      \
+  /* read-only */                                                             \
+  uv_loop_t* loop;                                                            \
+  /* public */                                                                \
+  uv_close_cb close_cb;                                                       \
+  void* data;                                                                 \
+  /* read-only */                                                             \
+  uv_handle_type type;                                                        \
+  /* private */                                                               \
+  UV_HANDLE_PRIVATE_FIELDS                                                    \
+  UV_HANDLE_EXTRA_FIELDS                                                      \
 
 /* The abstract base class of all handles.  */
 struct uv_handle_s {
@@ -1362,8 +1366,8 @@ typedef enum {
 /* uv_fs_t is a subclass of uv_req_t */
 struct uv_fs_s {
   UV_REQ_FIELDS
-  uv_loop_t* loop;
   uv_fs_type fs_type;
+  uv_loop_t* loop;
   uv_fs_cb cb;
   ssize_t result;
   void* ptr;
index 49785da035b652c99e92de580ae99397399847c0..657397becf7f8d1561fa78cdcb49936c26453569 100644 (file)
@@ -235,8 +235,7 @@ int uv_run(uv_loop_t* loop) {
 
 
 int uv_run_once(uv_loop_t* loop) {
-  uv__run(loop);
-  return 0;
+  return uv__run(loop);
 }
 
 
@@ -269,8 +268,8 @@ void uv__finish_close(uv_handle_t* handle) {
     case UV_NAMED_PIPE:
     case UV_TCP:
     case UV_TTY:
-      assert(!ev_is_active(&((uv_stream_t*)handle)->read_watcher));
-      assert(!ev_is_active(&((uv_stream_t*)handle)->write_watcher));
+      assert(!uv__io_active(&((uv_stream_t*)handle)->read_watcher));
+      assert(!uv__io_active(&((uv_stream_t*)handle)->write_watcher));
       assert(((uv_stream_t*)handle)->fd == -1);
       uv__stream_destroy((uv_stream_t*)handle);
       break;
@@ -318,6 +317,7 @@ static int uv_getaddrinfo_done(eio_req* req_) {
   uv_getaddrinfo_t* req = req_->data;
   struct addrinfo *res = req->res;
 #if __sun
+  uv_getaddrinfo_t* handle = req->data;
   size_t hostlen = strlen(handle->hostname);
 #endif
 
@@ -446,14 +446,18 @@ out:
 }
 
 
-int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) {
+int uv__accept(int sockfd) {
   int peerfd;
 
   assert(sockfd >= 0);
 
   while (1) {
 #if __linux__
-    peerfd = uv__accept4(sockfd, saddr, &slen, UV__SOCK_NONBLOCK|UV__SOCK_CLOEXEC);
+    peerfd = uv__accept4(sockfd,
+                         NULL,
+                         NULL,
+                         UV__SOCK_NONBLOCK|UV__SOCK_CLOEXEC);
+
     if (peerfd != -1)
       break;
 
@@ -464,7 +468,9 @@ int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) {
       break;
 #endif
 
-    if ((peerfd = accept(sockfd, saddr, &slen)) == -1) {
+    peerfd = accept(sockfd, NULL, NULL);
+
+    if (peerfd == -1) {
       if (errno == EINTR)
         continue;
       else
index 328d76d77b2c7c73b54a87e3195efd05d1954ece..551d69040e2cbfad0ad9a9613bd2fd4dd8b743ff 100644 (file)
 
 /* flags */
 enum {
-  UV_CLOSING       = 0x01,   /* uv_close() called but not finished. */
-  UV_CLOSED        = 0x02,   /* close(2) finished. */
+  UV_CLOSING          = 0x01,   /* uv_close() called but not finished. */
+  UV_CLOSED           = 0x02,   /* close(2) finished. */
   UV_STREAM_READING   = 0x04,   /* uv_read_start() called. */
   UV_STREAM_SHUTTING  = 0x08,   /* uv_shutdown() called but not complete. */
   UV_STREAM_SHUT      = 0x10,   /* Write side closed. */
   UV_STREAM_READABLE  = 0x20,   /* The stream is readable */
   UV_STREAM_WRITABLE  = 0x40,   /* The stream is writable */
-  UV_TCP_NODELAY   = 0x080,  /* Disable Nagle. */
-  UV_TCP_KEEPALIVE = 0x100,  /* Turn on keep-alive. */
-  UV_TIMER_REPEAT  = 0x100,
-  UV__PENDING      = 0x800
+  UV_STREAM_BLOCKING  = 0x80,   /* Synchronous writes. */
+  UV_TCP_NODELAY      = 0x100,  /* Disable Nagle. */
+  UV_TCP_KEEPALIVE    = 0x200,  /* Turn on keep-alive. */
+  UV_TIMER_REPEAT     = 0x100,
+  UV__PENDING         = 0x800
 };
 
 inline static int uv__has_pending_handles(const uv_loop_t* loop) {
@@ -155,7 +156,7 @@ void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
 int uv__stream_open(uv_stream_t*, int fd, int flags);
 void uv__stream_destroy(uv_stream_t* stream);
 void uv__server_io(uv_loop_t* loop, uv__io_t* watcher, int events);
-int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t len);
+int uv__accept(int sockfd);
 int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
     socklen_t addrlen, uv_connect_cb cb);
 
index 08b34994fc05bf676ad51a1cf759d375e482a5f5..14743daaf80b9d29ec0565b12f77d0eac729649c 100644 (file)
@@ -77,40 +77,3 @@ void uv__loop_delete(uv_loop_t* loop) {
     close(loop->fs_fd);
 #endif
 }
-
-
-#define X(name, type) \
-  int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) {              \
-    uv__handle_init(loop, (uv_handle_t*)handle, type);                        \
-    loop->counters.name##_init++;                                             \
-    handle->name##_cb = NULL;                                                 \
-    return 0;                                                                 \
-  }                                                                           \
-  int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) {           \
-    if (uv__is_active(handle)) return 0;                                      \
-    ngx_queue_insert_head(&handle->loop->name##_handles, &handle->queue);     \
-    handle->name##_cb = cb;                                                   \
-    uv__handle_start(handle);                                                 \
-    return 0;                                                                 \
-  }                                                                           \
-  int uv_##name##_stop(uv_##name##_t* handle) {                               \
-    if (!uv__is_active(handle)) return 0;                                     \
-    ngx_queue_remove(&handle->queue);                                         \
-    uv__handle_stop(handle);                                                  \
-    return 0;                                                                 \
-  }                                                                           \
-  void uv__run_##name(uv_loop_t* loop) {                                      \
-    uv_##name##_t* h;                                                         \
-    ngx_queue_t* q;                                                           \
-    ngx_queue_foreach(q, &loop->name##_handles) {                             \
-      h = ngx_queue_data(q, uv_##name##_t, queue);                            \
-      if (h->name##_cb) h->name##_cb(h, 0);                                   \
-    }                                                                         \
-  }                                                                           \
-  void uv__##name##_close(uv_##name##_t* handle) {                            \
-    uv_##name##_stop(handle);                                                 \
-  }
-X(idle, UV_IDLE)
-X(check, UV_CHECK)
-X(prepare, UV_PREPARE)
-#undef X
index fb40e9622afff0be0ff3a897bbe16398dd822844..666ebec833853d4bf466e7e64ed835040a0b5839 100644 (file)
@@ -81,22 +81,10 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
   uv_strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
   saddr.sun_family = AF_UNIX;
 
-  if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) {
-    /* On EADDRINUSE:
-     *
-     * We hold the file lock so there is no other process listening
-     * on the socket. Ergo, it's stale - remove it.
-     *
-     * This assumes that the other process uses locking too
-     * but that's a good enough assumption for now.
-     */
-    if (errno != EADDRINUSE
-        || unlink(pipe_fname) == -1
-        || bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) {
-      /* Convert ENOENT to EACCES for compatibility with Windows. */
-      uv__set_sys_error(handle->loop, (errno == ENOENT) ? EACCES : errno);
-      goto out;
-    }
+  if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
+    /* Convert ENOENT to EACCES for compatibility with Windows. */
+    uv__set_sys_error(handle->loop, (errno == ENOENT) ? EACCES : errno);
+    goto out;
   }
   bound = 1;
 
@@ -241,7 +229,6 @@ out:
 
 /* TODO merge with uv__server_io()? */
 static void uv__pipe_accept(uv_loop_t* loop, uv__io_t* w, int events) {
-  struct sockaddr_un saddr;
   uv_pipe_t* pipe;
   int saved_errno;
   int sockfd;
@@ -251,7 +238,7 @@ static void uv__pipe_accept(uv_loop_t* loop, uv__io_t* w, int events) {
 
   assert(pipe->type == UV_NAMED_PIPE);
 
-  sockfd = uv__accept(pipe->fd, (struct sockaddr *)&saddr, sizeof saddr);
+  sockfd = uv__accept(pipe->fd);
   if (sockfd == -1) {
     if (errno != EAGAIN && errno != EWOULDBLOCK) {
       uv__set_sys_error(pipe->loop, errno);
index f0a4344e1899f6778a8e962cb190b037c26f4b61..13796ab5755e24a799f86330e8e1e268e15a4b9e 100644 (file)
@@ -100,6 +100,7 @@ int uv_poll_start(uv_poll_t* handle, int pevents, uv_poll_cb poll_cb) {
   if (pevents & UV_WRITABLE)
     events |= UV__IO_WRITE;
 
+  uv__io_stop(handle->loop, &handle->io_watcher);
   uv__io_set(&handle->io_watcher, uv__poll_io, handle->fd, events);
   uv__io_start(handle->loop, &handle->io_watcher);
 
index f441c9b9451b354afd2bb8e6ce7f0ff4900bf339..7ea44874511b1af193d5e9b2e69b93f10b8b9551 100644 (file)
@@ -67,7 +67,6 @@ void uv__stream_init(uv_loop_t* loop,
   stream->accepted_fd = -1;
   stream->fd = -1;
   stream->delayed_error = 0;
-  stream->blocking = 0;
   ngx_queue_init(&stream->write_queue);
   ngx_queue_init(&stream->write_completed_queue);
   stream->write_queue_size = 0;
@@ -166,7 +165,6 @@ void uv__stream_destroy(uv_stream_t* stream) {
 
 void uv__server_io(uv_loop_t* loop, uv__io_t* w, int events) {
   int fd;
-  struct sockaddr_storage addr;
   uv_stream_t* stream = container_of(w, uv_stream_t, read_watcher);
 
   assert(events == UV__IO_READ);
@@ -182,7 +180,7 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, int events) {
    */
   while (stream->fd != -1) {
     assert(stream->accepted_fd < 0);
-    fd = uv__accept(stream->fd, (struct sockaddr*)&addr, sizeof addr);
+    fd = uv__accept(stream->fd);
 
     if (fd < 0) {
       if (errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -444,7 +442,7 @@ start:
       stream->write_queue_size -= uv__write_req_size(req);
       uv__write_req_finish(req);
       return;
-    } else if (stream->blocking) {
+    } else if (stream->flags & UV_STREAM_BLOCKING) {
       /* If this is a blocking stream, try again. */
       goto start;
     }
@@ -465,7 +463,7 @@ start:
         n = 0;
 
         /* There is more to write. */
-        if (stream->blocking) {
+        if (stream->flags & UV_STREAM_BLOCKING) {
           /*
            * If we're blocking then we should not be enabling the write
            * watcher - instead we need to try again.
@@ -501,7 +499,7 @@ start:
   assert(n == 0 || n == -1);
 
   /* Only non-blocking streams should use the write_watcher. */
-  assert(!stream->blocking);
+  assert(!(stream->flags & UV_STREAM_BLOCKING));
 
   /* We're not done. */
   uv__io_start(stream->loop, &stream->write_watcher);
@@ -626,7 +624,7 @@ static void uv__read(uv_stream_t* stream) {
           stream->read2_cb((uv_pipe_t*)stream, -1, buf, UV_UNKNOWN_HANDLE);
         }
 
-        assert(!ev_is_active(&stream->read_watcher));
+        assert(!uv__io_active(&stream->read_watcher));
         return;
       }
 
@@ -634,7 +632,7 @@ static void uv__read(uv_stream_t* stream) {
       /* EOF */
       uv__set_artificial_error(stream->loop, UV_EOF);
       uv__io_stop(stream->loop, &stream->read_watcher);
-      if (!ev_is_active(&stream->write_watcher))
+      if (!uv__io_active(&stream->write_watcher))
         uv__handle_stop(stream);
 
       if (stream->read_cb) {
@@ -931,7 +929,7 @@ int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
      * if this assert fires then somehow the blocking stream isn't being
      * sufficently flushed in uv__write.
      */
-    assert(!stream->blocking);
+    assert(!(stream->flags & UV_STREAM_BLOCKING));
 
     uv__io_start(stream->loop, &stream->write_watcher);
   }
@@ -1027,6 +1025,6 @@ void uv__stream_close(uv_stream_t* handle) {
     handle->accepted_fd = -1;
   }
 
-  assert(!ev_is_active(&handle->read_watcher));
-  assert(!ev_is_active(&handle->write_watcher));
+  assert(!uv__io_active(&handle->read_watcher));
+  assert(!uv__io_active(&handle->write_watcher));
 }
index 572d19c60aa3c534e7a97488907bdbb344cb8f53..7193db8bcbdeaa5628a2d15e5a609b25ff9cb15b 100644 (file)
@@ -42,7 +42,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
   } else {
     /* Note: writable tty we set to blocking mode. */
     uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_WRITABLE);
-    tty->blocking = 1;
+    tty->flags |= UV_STREAM_BLOCKING;
   }
 
   loop->counters.tty_init++;
index a9c03066ad75cac858848eb5ddfe9223f5947f39..523d2823d2c569233249ebc343b8afc7f7f74a3a 100644 (file)
@@ -61,35 +61,9 @@ static void uv__udp_stop_watcher(uv_udp_t* handle, uv__io_t* w) {
 }
 
 
-static void uv__udp_start_read_watcher(uv_udp_t* handle) {
-  uv__udp_start_watcher(handle,
-                        &handle->read_watcher,
-                        uv__udp_recvmsg,
-                        UV__IO_READ);
-}
-
-
-static void uv__udp_start_write_watcher(uv_udp_t* handle) {
-  uv__udp_start_watcher(handle,
-                        &handle->write_watcher,
-                        uv__udp_sendmsg,
-                        UV__IO_WRITE);
-}
-
-
-static void uv__udp_stop_read_watcher(uv_udp_t* handle) {
-  uv__udp_stop_watcher(handle, &handle->read_watcher);
-}
-
-
-static void uv__udp_stop_write_watcher(uv_udp_t* handle) {
-  uv__udp_stop_watcher(handle, &handle->write_watcher);
-}
-
-
 void uv__udp_close(uv_udp_t* handle) {
-  uv__udp_stop_write_watcher(handle);
-  uv__udp_stop_read_watcher(handle);
+  uv__udp_stop_watcher(handle, &handle->write_watcher);
+  uv__udp_stop_watcher(handle, &handle->read_watcher);
   close(handle->fd);
   handle->fd = -1;
 }
@@ -142,7 +116,8 @@ static void uv__udp_run_pending(uv_udp_t* handle) {
 
     memset(&h, 0, sizeof h);
     h.msg_name = &req->addr;
-    h.msg_namelen = req->addrlen;
+    h.msg_namelen = (req->addr.sin6_family == AF_INET6 ?
+      sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in));
     h.msg_iov = (struct iovec*)req->bufs;
     h.msg_iovlen = req->bufcnt;
 
@@ -224,7 +199,7 @@ static void uv__udp_recvmsg(uv_loop_t* loop, uv__io_t* w, int revents) {
 
   handle = container_of(w, uv_udp_t, read_watcher);
   assert(handle->type == UV_UDP);
-  assert(revents & EV_READ);
+  assert(revents & UV__IO_READ);
 
   assert(handle->recv_cb != NULL);
   assert(handle->alloc_cb != NULL);
@@ -281,7 +256,7 @@ static void uv__udp_sendmsg(uv_loop_t* loop, uv__io_t* w, int revents) {
 
   handle = container_of(w, uv_udp_t, write_watcher);
   assert(handle->type == UV_UDP);
-  assert(revents & EV_WRITE);
+  assert(revents & UV__IO_WRITE);
 
   assert(!ngx_queue_empty(&handle->write_queue)
       || !ngx_queue_empty(&handle->write_completed_queue));
@@ -298,7 +273,7 @@ static void uv__udp_sendmsg(uv_loop_t* loop, uv__io_t* w, int revents) {
   }
   else if (ngx_queue_empty(&handle->write_queue)) {
     /* Pending queue and completion queue empty, stop watcher. */
-    uv__udp_stop_write_watcher(handle);
+    uv__udp_stop_watcher(handle, &handle->write_watcher);
   }
 }
 
@@ -441,8 +416,8 @@ static int uv__udp_send(uv_udp_send_t* req,
 
   uv__req_init(handle->loop, req, UV_UDP_SEND);
 
+  assert(addrlen <= sizeof(req->addr));
   memcpy(&req->addr, addr, addrlen);
-  req->addrlen = addrlen;
   req->send_cb = send_cb;
   req->handle = handle;
   req->bufcnt = bufcnt;
@@ -457,7 +432,11 @@ static int uv__udp_send(uv_udp_send_t* req,
   memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0]));
 
   ngx_queue_insert_tail(&handle->write_queue, &req->queue);
-  uv__udp_start_write_watcher(handle);
+
+  uv__udp_start_watcher(handle,
+                        &handle->write_watcher,
+                        uv__udp_sendmsg,
+                        UV__IO_WRITE);
 
   return 0;
 }
@@ -657,14 +636,18 @@ int uv_udp_recv_start(uv_udp_t* handle,
 
   handle->alloc_cb = alloc_cb;
   handle->recv_cb = recv_cb;
-  uv__udp_start_read_watcher(handle);
+
+  uv__udp_start_watcher(handle,
+                        &handle->read_watcher,
+                        uv__udp_recvmsg,
+                        UV__IO_READ);
 
   return 0;
 }
 
 
 int uv_udp_recv_stop(uv_udp_t* handle) {
-  uv__udp_stop_read_watcher(handle);
+  uv__udp_stop_watcher(handle, &handle->read_watcher);
   handle->alloc_cb = NULL;
   handle->recv_cb = NULL;
   return 0;
index c24cfc3bbb503f83356e40ae3bfa3c6fb4d9ec76..f32b9162a21bfe464f347d24b054f1ec652ef47f 100644 (file)
@@ -268,7 +268,7 @@ int uv_run_once(uv_loop_t* loop) {
   } else {
     UV_LOOP_ONCE(loop, uv_poll);
   }
-  return 0;
+  return UV_LOOP_ALIVE(loop);
 }
 
 
index deb5ed1f748d11c9f78d308d14a735f9cfcfb7df..26267f4acc1da1cfde1fbefbead4b19ad34058ef 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 BENCHMARK_DECLARE (sizes)
+BENCHMARK_DECLARE (loop_count)
 BENCHMARK_DECLARE (ping_pongs)
 BENCHMARK_DECLARE (tcp_write_batch)
 BENCHMARK_DECLARE (tcp4_pound_100)
@@ -53,6 +54,7 @@ HELPER_DECLARE    (dns_server)
 
 TASK_LIST_START
   BENCHMARK_ENTRY  (sizes)
+  BENCHMARK_ENTRY  (loop_count)
 
   BENCHMARK_ENTRY  (ping_pongs)
   BENCHMARK_HELPER (ping_pongs, tcp4_echo_server)
index 09e06e8f3de28c983e174c77fc90893a014b44d6..6d16e3ca50d21b4931b8fe08c540c48eaf5b42dc 100644 (file)
@@ -27,6 +27,7 @@ BENCHMARK_IMPL(sizes) {
   LOGF("uv_shutdown_t: %u bytes\n", (unsigned int) sizeof(uv_shutdown_t));
   LOGF("uv_write_t: %u bytes\n", (unsigned int) sizeof(uv_write_t));
   LOGF("uv_connect_t: %u bytes\n", (unsigned int) sizeof(uv_connect_t));
+  LOGF("uv_udp_send_t: %u bytes\n", (unsigned int) sizeof(uv_udp_send_t));
   LOGF("uv_tcp_t: %u bytes\n", (unsigned int) sizeof(uv_tcp_t));
   LOGF("uv_pipe_t: %u bytes\n", (unsigned int) sizeof(uv_pipe_t));
   LOGF("uv_tty_t: %u bytes\n", (unsigned int) sizeof(uv_tty_t));
index be962e824cebfbac329e677b5b4028bc04eec0c7..36b68f3033ebb11ac484d36d1c2ff41a6d631bd5 100644 (file)
@@ -1305,7 +1305,6 @@ TEST_IMPL(fs_symlink) {
 TEST_IMPL(fs_symlink_dir) {
   uv_fs_t req;
   int r;
-  char src_path_buf[PATHMAX];
   char* test_dir;
 
   /* set-up */
@@ -1320,10 +1319,13 @@ TEST_IMPL(fs_symlink_dir) {
   uv_fs_req_cleanup(&req);
 
 #ifdef _WIN32
-  strcpy(src_path_buf, "\\\\?\\");
-  uv_cwd(src_path_buf + 4, sizeof(src_path_buf)/sizeof(src_path_buf[0]));
-  strcat(src_path_buf, "\\test_dir\\");
-  test_dir = src_path_buf;
+  {
+    static char src_path_buf[PATHMAX];
+    strcpy(src_path_buf, "\\\\?\\");
+    uv_cwd(src_path_buf + 4, sizeof(src_path_buf));
+    strcat(src_path_buf, "\\test_dir\\");
+    test_dir = src_path_buf;
+  }
 #else
   test_dir = "test_dir";
 #endif
index 970bf1effee1efa3bf8f1bb44eeafe7844cdcfb7..faedc5469d33145ffaf07c2e0da5cf41d0e11e93 100644 (file)
@@ -120,6 +120,11 @@ TEST_IMPL(ipc_send_recv_pipe) {
   r = uv_pipe_init(uv_default_loop(), &ctx.send.pipe, 1);
   ASSERT(r == 0);
 
+#ifndef _WIN32
+  /* Clean up stale socket from previous test run. */
+  remove(TEST_PIPENAME);
+#endif
+
   r = uv_pipe_bind(&ctx.send.pipe, TEST_PIPENAME);
   ASSERT(r == 0);
 
index 134cb8cea29ae5528b927e9b55964bda439eb0d4..6b2883cf498d8a85630f1a934541ebca2d5b168f 100644 (file)
@@ -21,6 +21,7 @@
 
 TEST_DECLARE   (platform_output)
 TEST_DECLARE   (callback_order)
+TEST_DECLARE   (run_once)
 TEST_DECLARE   (tty)
 TEST_DECLARE   (stdio_over_pipes)
 TEST_DECLARE   (ipc_listen_before_write)
@@ -185,6 +186,7 @@ TASK_LIST_START
 #if 0
   TEST_ENTRY  (callback_order)
 #endif
+  TEST_ENTRY  (run_once)
 
   TEST_ENTRY  (pipe_connect_bad_name)
   TEST_ENTRY  (pipe_connect_to_file)
index b84d20f1eaf4be694bc8bca54b6ed2a27e31ae45..4e73b639b62494a0f4ab0da4e53b6ebc7298d48f 100644 (file)
 
 #ifdef _WIN32
 # define BAD_PIPENAME "bad-pipe"
+# define UNLINK_PIPE(name)
 #else
 # define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there"
+# define UNLINK_PIPE(name) remove(name)
 #endif
 
 
@@ -45,6 +47,8 @@ TEST_IMPL(pipe_bind_error_addrinuse) {
   uv_pipe_t server1, server2;
   int r;
 
+  UNLINK_PIPE(TEST_PIPENAME);
+
   r = uv_pipe_init(uv_default_loop(), &server1, 0);
   ASSERT(r == 0);
   r = uv_pipe_bind(&server1, TEST_PIPENAME);
index c03ab88e8f3fdd4870d638da719099a96b2b1964..f74e9f37a5a0eed466729b40634fa9abbf513ee8 100644 (file)
 #include "uv.h"
 #include "task.h"
 
-static idle_counter = 0;
+#define NUM_TICKS 64
+
+static uv_idle_t idle_handle;
+static int idle_counter;
+
 
 static void idle_cb(uv_idle_t* handle, int status) {
-  ASSERT(handle != NULL);
+  ASSERT(handle == &idle_handle);
   ASSERT(status == 0);
-  idle_counter ++;
+
+  if (++idle_counter == NUM_TICKS)
+    uv_idle_stop(handle);
 }
 
 
 TEST_IMPL(run_once) {
-  int n;
-  uv_idle_t h;
-  uv_idle_init(uv_default_loop(), &h);
-  uv_idle_start(&h, idle_cb);
-  for (n = 0; n < 500; n++) {
-    uv_run_once(uv_default_loop());
-  }
-  ASSERT(n == 500);
+  uv_idle_init(uv_default_loop(), &idle_handle);
+  uv_idle_start(&idle_handle, idle_cb);
+
+  while (uv_run_once(uv_default_loop()));
+  ASSERT(idle_counter == NUM_TICKS);
+
   return 0;
 }
index 28f99948260fb4f5ab93010aa13073cb13e69dfb..605b5b1c56e584bd565eeae34d5a0d6519aed3e8 100644 (file)
             'src/unix/fs.c',
             'src/unix/internal.h',
             'src/unix/loop.c',
+            'src/unix/loop-watcher.c',
             'src/unix/pipe.c',
             'src/unix/poll.c',
             'src/unix/process.c',
         'test/test-poll.c',
         'test/test-process-title.c',
         'test/test-ref.c',
+        'test/test-run-once.c',
         'test/test-shutdown-close.c',
         'test/test-shutdown-eof.c',
         'test/test-spawn.c',
         'test/benchmark-ares.c',
         'test/benchmark-getaddrinfo.c',
         'test/benchmark-list.h',
+        'test/benchmark-loop-count.c',
         'test/benchmark-ping-pongs.c',
         'test/benchmark-pound.c',
         'test/benchmark-pump.c',