diff options
author | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2024-10-18 20:31:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-18 20:31:38 +0300 |
commit | 2a74bac2d2d3bccb4e10120f1ead805640ec9dd0 (patch) | |
tree | 047e4818ced5aaf73f58517629e5260b5291f9f0 /contrib/libs/curl/lib/socketpair.c | |
parent | 2d9656823e9521d8c29ea4c9a1d0eab78391abfc (diff) | |
parent | 3d834a1923bbf9403cd4a448e7f32b670aa4124f (diff) | |
download | ydb-2a74bac2d2d3bccb4e10120f1ead805640ec9dd0.tar.gz |
Merge pull request #10502 from ydb-platform/mergelibs-241016-1210
Library import 241016-1210
Diffstat (limited to 'contrib/libs/curl/lib/socketpair.c')
-rw-r--r-- | contrib/libs/curl/lib/socketpair.c | 91 |
1 files changed, 10 insertions, 81 deletions
diff --git a/contrib/libs/curl/lib/socketpair.c b/contrib/libs/curl/lib/socketpair.c index b14f5a5f14..e3d40ff94e 100644 --- a/contrib/libs/curl/lib/socketpair.c +++ b/contrib/libs/curl/lib/socketpair.c @@ -27,82 +27,15 @@ #include "urldata.h" #include "rand.h" -#if defined(USE_EVENTFD) -#ifdef HAVE_SYS_EVENTFD_H -#include <sys/eventfd.h> -#endif - -int Curl_eventfd(curl_socket_t socks[2], bool nonblocking) -{ - int efd = eventfd(0, nonblocking ? EFD_CLOEXEC | EFD_NONBLOCK : EFD_CLOEXEC); - if(efd == -1) { - socks[0] = socks[1] = CURL_SOCKET_BAD; - return -1; - } - socks[0] = socks[1] = efd; - return 0; -} -#elif defined(HAVE_PIPE) -#ifdef HAVE_FCNTL -#include <fcntl.h> -#endif - -int Curl_pipe(curl_socket_t socks[2], bool nonblocking) -{ - if(pipe(socks)) - return -1; -#ifdef HAVE_FCNTL - if(fcntl(socks[0], F_SETFD, FD_CLOEXEC) || - fcntl(socks[1], F_SETFD, FD_CLOEXEC) ) { - close(socks[0]); - close(socks[1]); - socks[0] = socks[1] = CURL_SOCKET_BAD; - return -1; - } -#endif - if(nonblocking) { - if(curlx_nonblock(socks[0], TRUE) < 0 || - curlx_nonblock(socks[1], TRUE) < 0) { - close(socks[0]); - close(socks[1]); - socks[0] = socks[1] = CURL_SOCKET_BAD; - return -1; - } - } - - return 0; -} -#endif - - -#ifndef CURL_DISABLE_SOCKETPAIR -#ifdef HAVE_SOCKETPAIR -int Curl_socketpair(int domain, int type, int protocol, - curl_socket_t socks[2], bool nonblocking) -{ -#ifdef SOCK_NONBLOCK - type = nonblocking ? type | SOCK_NONBLOCK : type; -#endif - if(socketpair(domain, type, protocol, socks)) - return -1; -#ifndef SOCK_NONBLOCK - if(nonblocking) { - if(curlx_nonblock(socks[0], TRUE) < 0 || - curlx_nonblock(socks[1], TRUE) < 0) { - close(socks[0]); - close(socks[1]); - return -1; - } - } -#endif - return 0; -} -#else /* !HAVE_SOCKETPAIR */ +#if !defined(HAVE_SOCKETPAIR) && !defined(CURL_DISABLE_SOCKETPAIR) #ifdef _WIN32 /* * This is a socketpair() implementation for Windows. */ #include <string.h> +#include <winsock2.h> +#include <ws2tcpip.h> +#include <windows.h> #include <io.h> #else #ifdef HAVE_NETDB_H @@ -129,7 +62,7 @@ int Curl_socketpair(int domain, int type, int protocol, #include "memdebug.h" int Curl_socketpair(int domain, int type, int protocol, - curl_socket_t socks[2], bool nonblocking) + curl_socket_t socks[2]) { union { struct sockaddr_in inaddr; @@ -155,7 +88,7 @@ int Curl_socketpair(int domain, int type, int protocol, socks[0] = socks[1] = CURL_SOCKET_BAD; #if defined(_WIN32) || defined(__CYGWIN__) - /* do not set SO_REUSEADDR on Windows */ + /* don't set SO_REUSEADDR on Windows */ (void)reuse; #ifdef SO_EXCLUSIVEADDRUSE { @@ -183,7 +116,7 @@ int Curl_socketpair(int domain, int type, int protocol, if(connect(socks[0], &a.addr, sizeof(a.inaddr)) == -1) goto error; - /* use non-blocking accept to make sure we do not block forever */ + /* use non-blocking accept to make sure we don't block forever */ if(curlx_nonblock(listener, TRUE) < 0) goto error; pfd[0].fd = listener; @@ -217,7 +150,7 @@ int Curl_socketpair(int domain, int type, int protocol, nread = sread(socks[1], p, s); if(nread == -1) { int sockerr = SOCKERRNO; - /* Do not block forever */ + /* Don't block forever */ if(Curl_timediff(Curl_now(), start) > (60 * 1000)) goto error; if( @@ -247,10 +180,6 @@ int Curl_socketpair(int domain, int type, int protocol, } while(1); } - if(nonblocking) - if(curlx_nonblock(socks[0], TRUE) < 0 || - curlx_nonblock(socks[1], TRUE) < 0) - goto error; sclose(listener); return 0; @@ -260,5 +189,5 @@ error: sclose(socks[1]); return -1; } -#endif -#endif /* !CURL_DISABLE_SOCKETPAIR */ + +#endif /* ! HAVE_SOCKETPAIR */ |