summaryrefslogtreecommitdiff
path: root/deps/uv/src/unix/tcp.c
diff options
context:
space:
mode:
authorSaúl Ibarra Corretgé <saghul@gmail.com>2015-08-05 21:17:46 +0200
committerthefourtheye <thechargingvolcano@gmail.com>2015-09-02 03:16:47 -0400
commita1615949a591fc523048a09540a2d340ff1b3da8 (patch)
tree1cc576ea6104f1baf8f92c6a82f3ca2b45afaccd /deps/uv/src/unix/tcp.c
parente3740e452402892c1ce03bbbb4807e34f31558ad (diff)
downloadandroid-node-v8-a1615949a591fc523048a09540a2d340ff1b3da8.tar.gz
android-node-v8-a1615949a591fc523048a09540a2d340ff1b3da8.tar.bz2
android-node-v8-a1615949a591fc523048a09540a2d340ff1b3da8.zip
deps: upgrade libuv to 1.7.3
PR-URL: https://github.com/nodejs/node/pull/2310 Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/uv/src/unix/tcp.c')
-rw-r--r--deps/uv/src/unix/tcp.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/deps/uv/src/unix/tcp.c b/deps/uv/src/unix/tcp.c
index 4060e7bd70..6d213a4977 100644
--- a/deps/uv/src/unix/tcp.c
+++ b/deps/uv/src/unix/tcp.c
@@ -28,18 +28,14 @@
#include <errno.h>
-int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* tcp) {
- uv__stream_init(loop, (uv_stream_t*)tcp, UV_TCP);
- return 0;
-}
-
-
static int maybe_new_socket(uv_tcp_t* handle, int domain, int flags) {
int sockfd;
int err;
- if (uv__stream_fd(handle) != -1)
+ if (domain == AF_UNSPEC || uv__stream_fd(handle) != -1) {
+ handle->flags |= flags;
return 0;
+ }
err = uv__socket(domain, SOCK_STREAM, 0);
if (err < 0)
@@ -56,6 +52,40 @@ static int maybe_new_socket(uv_tcp_t* handle, int domain, int flags) {
}
+int uv_tcp_init_ex(uv_loop_t* loop, uv_tcp_t* tcp, unsigned int flags) {
+ int domain;
+
+ /* Use the lower 8 bits for the domain */
+ domain = flags & 0xFF;
+ if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC)
+ return -EINVAL;
+
+ if (flags & ~0xFF)
+ return -EINVAL;
+
+ uv__stream_init(loop, (uv_stream_t*)tcp, UV_TCP);
+
+ /* If anything fails beyond this point we need to remove the handle from
+ * the handle queue, since it was added by uv__handle_init in uv_stream_init.
+ */
+
+ if (domain != AF_UNSPEC) {
+ int err = maybe_new_socket(tcp, domain, 0);
+ if (err) {
+ QUEUE_REMOVE(&tcp->handle_queue);
+ return err;
+ }
+ }
+
+ return 0;
+}
+
+
+int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* tcp) {
+ return uv_tcp_init_ex(loop, tcp, AF_UNSPEC);
+}
+
+
int uv__tcp_bind(uv_tcp_t* tcp,
const struct sockaddr* addr,
unsigned int addrlen,
@@ -91,8 +121,13 @@ int uv__tcp_bind(uv_tcp_t* tcp,
#endif
errno = 0;
- if (bind(tcp->io_watcher.fd, addr, addrlen) && errno != EADDRINUSE)
+ if (bind(tcp->io_watcher.fd, addr, addrlen) && errno != EADDRINUSE) {
+ if (errno == EAFNOSUPPORT)
+ /* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
+ * socket created with AF_INET to an AF_INET6 address or vice versa. */
+ return -EINVAL;
return -errno;
+ }
tcp->delayed_error = -errno;
if (addr->sa_family == AF_INET6)