aboutsummaryrefslogtreecommitdiffstats
path: root/util/network/pair.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/network/pair.cpp
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/network/pair.cpp')
-rw-r--r--util/network/pair.cpp154
1 files changed, 77 insertions, 77 deletions
diff --git a/util/network/pair.cpp b/util/network/pair.cpp
index 2e410b842e..9751ef5c96 100644
--- a/util/network/pair.cpp
+++ b/util/network/pair.cpp
@@ -1,82 +1,82 @@
-#include "pair.h"
-
+#include "pair.h"
+
int SocketPair(SOCKET socks[2], bool overlapped, bool cloexec) {
-#if defined(_win_)
- struct sockaddr_in addr;
- SOCKET listener;
- int e;
- int addrlen = sizeof(addr);
+#if defined(_win_)
+ struct sockaddr_in addr;
+ SOCKET listener;
+ int e;
+ int addrlen = sizeof(addr);
DWORD flags = (overlapped ? WSA_FLAG_OVERLAPPED : 0) | (cloexec ? WSA_FLAG_NO_HANDLE_INHERIT : 0);
-
- if (socks == 0) {
- WSASetLastError(WSAEINVAL);
-
- return SOCKET_ERROR;
- }
-
- socks[0] = INVALID_SOCKET;
- socks[1] = INVALID_SOCKET;
-
- if ((listener = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
- return SOCKET_ERROR;
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(0x7f000001);
- addr.sin_port = 0;
-
- e = bind(listener, (const struct sockaddr*)&addr, sizeof(addr));
-
- if (e == SOCKET_ERROR) {
- e = WSAGetLastError();
- closesocket(listener);
- WSASetLastError(e);
-
- return SOCKET_ERROR;
- }
-
- e = getsockname(listener, (struct sockaddr*)&addr, &addrlen);
-
- if (e == SOCKET_ERROR) {
- e = WSAGetLastError();
- closesocket(listener);
- WSASetLastError(e);
-
- return SOCKET_ERROR;
- }
-
- do {
- if (listen(listener, 1) == SOCKET_ERROR)
- break;
-
+
+ if (socks == 0) {
+ WSASetLastError(WSAEINVAL);
+
+ return SOCKET_ERROR;
+ }
+
+ socks[0] = INVALID_SOCKET;
+ socks[1] = INVALID_SOCKET;
+
+ if ((listener = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
+ return SOCKET_ERROR;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = htonl(0x7f000001);
+ addr.sin_port = 0;
+
+ e = bind(listener, (const struct sockaddr*)&addr, sizeof(addr));
+
+ if (e == SOCKET_ERROR) {
+ e = WSAGetLastError();
+ closesocket(listener);
+ WSASetLastError(e);
+
+ return SOCKET_ERROR;
+ }
+
+ e = getsockname(listener, (struct sockaddr*)&addr, &addrlen);
+
+ if (e == SOCKET_ERROR) {
+ e = WSAGetLastError();
+ closesocket(listener);
+ WSASetLastError(e);
+
+ return SOCKET_ERROR;
+ }
+
+ do {
+ if (listen(listener, 1) == SOCKET_ERROR)
+ break;
+
if ((socks[0] = WSASocket(AF_INET, SOCK_STREAM, 0, nullptr, 0, flags)) == INVALID_SOCKET)
- break;
-
- if (connect(socks[0], (const struct sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR)
- break;
-
+ break;
+
+ if (connect(socks[0], (const struct sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR)
+ break;
+
if ((socks[1] = accept(listener, nullptr, nullptr)) == INVALID_SOCKET)
- break;
-
- closesocket(listener);
-
- return 0;
- } while (0);
-
- e = WSAGetLastError();
- closesocket(listener);
- closesocket(socks[0]);
- closesocket(socks[1]);
- WSASetLastError(e);
-
- return SOCKET_ERROR;
-#else
- (void)overlapped;
-
- #if defined(_linux_)
+ break;
+
+ closesocket(listener);
+
+ return 0;
+ } while (0);
+
+ e = WSAGetLastError();
+ closesocket(listener);
+ closesocket(socks[0]);
+ closesocket(socks[1]);
+ WSASetLastError(e);
+
+ return SOCKET_ERROR;
+#else
+ (void)overlapped;
+
+ #if defined(_linux_)
return socketpair(AF_LOCAL, SOCK_STREAM | (cloexec ? SOCK_CLOEXEC : 0), 0, socks);
- #else
+ #else
int r = socketpair(AF_LOCAL, SOCK_STREAM, 0, socks);
// Non-atomic wrt exec
if (r == 0 && cloexec) {
@@ -92,6 +92,6 @@ int SocketPair(SOCKET socks[2], bool overlapped, bool cloexec) {
}
}
return r;
- #endif
-#endif
-}
+ #endif
+#endif
+}