summaryrefslogtreecommitdiffstats
path: root/src/unix/tcp.c
diff options
context:
space:
mode:
authorlibuv upstream <libuv@googlegroups.com>2021-11-09 21:17:50 (GMT)
committerBrad King <brad.king@kitware.com>2021-11-17 11:39:32 (GMT)
commit27e34e6190ba1014c20ef5e8ffa7d653595ced12 (patch)
tree3a8f3a9e4569de887afeaeb65b9560995128bbaf /src/unix/tcp.c
parentc1463f959f7445207d932ec7640d77aebc2a6498 (diff)
downloadCMake-27e34e6190ba1014c20ef5e8ffa7d653595ced12.zip
CMake-27e34e6190ba1014c20ef5e8ffa7d653595ced12.tar.gz
CMake-27e34e6190ba1014c20ef5e8ffa7d653595ced12.tar.bz2
libuv 2021-11-09 (0f696da5)
Code extracted from: https://github.com/libuv/libuv.git at commit 0f696da5f0328dde1f9cc0372692ce22f0d17100 (v1.x).
Diffstat (limited to 'src/unix/tcp.c')
-rw-r--r--src/unix/tcp.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/unix/tcp.c b/src/unix/tcp.c
index 18acd20..bc0fb66 100644
--- a/src/unix/tcp.c
+++ b/src/unix/tcp.c
@@ -214,14 +214,15 @@ int uv__tcp_connect(uv_connect_t* req,
if (handle->connect_req != NULL)
return UV_EALREADY; /* FIXME(bnoordhuis) UV_EINVAL or maybe UV_EBUSY. */
+ if (handle->delayed_error != 0)
+ goto out;
+
err = maybe_new_socket(handle,
addr->sa_family,
UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
if (err)
return err;
- handle->delayed_error = 0;
-
do {
errno = 0;
r = connect(uv__stream_fd(handle), addr, addrlen);
@@ -249,6 +250,8 @@ int uv__tcp_connect(uv_connect_t* req,
return UV__ERR(errno);
}
+out:
+
uv__req_init(handle->loop, req, UV_CONNECT);
req->cb = cb;
req->handle = (uv_stream_t*) handle;
@@ -459,3 +462,49 @@ int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable) {
void uv__tcp_close(uv_tcp_t* handle) {
uv__stream_close((uv_stream_t*)handle);
}
+
+
+int uv_socketpair(int type, int protocol, uv_os_sock_t fds[2], int flags0, int flags1) {
+ uv_os_sock_t temp[2];
+ int err;
+#if defined(__FreeBSD__) || defined(__linux__)
+ int flags;
+
+ flags = type | SOCK_CLOEXEC;
+ if ((flags0 & UV_NONBLOCK_PIPE) && (flags1 & UV_NONBLOCK_PIPE))
+ flags |= SOCK_NONBLOCK;
+
+ if (socketpair(AF_UNIX, flags, protocol, temp))
+ return UV__ERR(errno);
+
+ if (flags & UV_FS_O_NONBLOCK) {
+ fds[0] = temp[0];
+ fds[1] = temp[1];
+ return 0;
+ }
+#else
+ if (socketpair(AF_UNIX, type, protocol, temp))
+ return UV__ERR(errno);
+
+ if ((err = uv__cloexec(temp[0], 1)))
+ goto fail;
+ if ((err = uv__cloexec(temp[1], 1)))
+ goto fail;
+#endif
+
+ if (flags0 & UV_NONBLOCK_PIPE)
+ if ((err = uv__nonblock(temp[0], 1)))
+ goto fail;
+ if (flags1 & UV_NONBLOCK_PIPE)
+ if ((err = uv__nonblock(temp[1], 1)))
+ goto fail;
+
+ fds[0] = temp[0];
+ fds[1] = temp[1];
+ return 0;
+
+fail:
+ uv__close(temp[0]);
+ uv__close(temp[1]);
+ return err;
+}