aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared
diff options
context:
space:
mode:
authornalpp <nalpp@yandex-team.ru>2022-02-10 16:46:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:46 +0300
commit30d1ef3941e0dc835be7609de5ebee66958f215a (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared
parent87f3eb38999df2d3c1cb77f8ffb9c52ec9c516fb (diff)
downloadydb-30d1ef3941e0dc835be7609de5ebee66958f215a.tar.gz
Restoring authorship annotation for <nalpp@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared')
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/Net.cpp48
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/SimpleUDP.cpp320
2 files changed, 184 insertions, 184 deletions
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/Net.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/Net.cpp
index e39cb3dcf5..244df21945 100644
--- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/Net.cpp
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/Net.cpp
@@ -2,27 +2,27 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
-
-#include <aws/core/net/Net.h>
-
-namespace Aws
-{
- namespace Net
- {
- // For Posix system, currently we don't need to do anything for network stack initialization.
- // But we need to do initialization for WinSock on Windows and call them in Aws.cpp. So these functions
- // also exist for Posix systems.
- bool IsNetworkInitiated()
- {
- return true;
- }
-
- void InitNetwork()
- {
- }
-
- void CleanupNetwork()
- {
- }
- }
-}
+
+#include <aws/core/net/Net.h>
+
+namespace Aws
+{
+ namespace Net
+ {
+ // For Posix system, currently we don't need to do anything for network stack initialization.
+ // But we need to do initialization for WinSock on Windows and call them in Aws.cpp. So these functions
+ // also exist for Posix systems.
+ bool IsNetworkInitiated()
+ {
+ return true;
+ }
+
+ void InitNetwork()
+ {
+ }
+
+ void CleanupNetwork()
+ {
+ }
+ }
+}
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/SimpleUDP.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/SimpleUDP.cpp
index 446de6689a..d9e0c385fd 100644
--- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/SimpleUDP.cpp
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/net/linux-shared/SimpleUDP.cpp
@@ -2,35 +2,35 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
-
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
#include <netdb.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <cassert>
-#include <string.h>
-#include <aws/core/net/SimpleUDP.h>
-#include <aws/core/utils/logging/LogMacros.h>
-
-namespace Aws
-{
- namespace Net
- {
- static const char ALLOC_TAG[] = "SimpleUDP";
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <cassert>
+#include <string.h>
+#include <aws/core/net/SimpleUDP.h>
+#include <aws/core/utils/logging/LogMacros.h>
+
+namespace Aws
+{
+ namespace Net
+ {
+ static const char ALLOC_TAG[] = "SimpleUDP";
static const char IPV4_LOOP_BACK_ADDRESS[] = "127.0.0.1";
static const char IPV6_LOOP_BACK_ADDRESS[] = "::1";
static inline bool IsValidIPAddress(const char* ip, int addressFamily/*AF_INET or AF_INET6*/)
- {
+ {
char buffer[128];
return inet_pton(addressFamily, ip, (void*)buffer) == 1 ?true :false;
- }
-
+ }
+
static bool GetASockAddrFromHostName(const char* hostName, void* sockAddrBuffer, size_t& addrLength, int& addressFamily)
- {
+ {
struct addrinfo hints, *res;
memset(&hints, 0, sizeof(hints));
@@ -47,8 +47,8 @@ namespace Aws
addressFamily = res->ai_family;
freeaddrinfo(res);
return true;
- }
-
+ }
+
static sockaddr_in BuildAddrInfoIPV4(const char* hostIP, short port)
{
#if (__GNUC__ == 4) && !defined(__clang__)
@@ -79,18 +79,18 @@ namespace Aws
return addrinfo;
}
- SimpleUDP::SimpleUDP(int addressFamily, size_t sendBufSize, size_t receiveBufSize, bool nonBlocking):
+ SimpleUDP::SimpleUDP(int addressFamily, size_t sendBufSize, size_t receiveBufSize, bool nonBlocking):
m_addressFamily(addressFamily), m_connected(false), m_socket(-1), m_port(0)
- {
- CreateSocket(addressFamily, sendBufSize, receiveBufSize, nonBlocking);
- }
-
- SimpleUDP::SimpleUDP(bool IPV4, size_t sendBufSize, size_t receiveBufSize, bool nonBlocking) :
+ {
+ CreateSocket(addressFamily, sendBufSize, receiveBufSize, nonBlocking);
+ }
+
+ SimpleUDP::SimpleUDP(bool IPV4, size_t sendBufSize, size_t receiveBufSize, bool nonBlocking) :
m_addressFamily(IPV4 ? AF_INET : AF_INET6), m_connected(false), m_socket(-1), m_port(0)
- {
- CreateSocket(m_addressFamily, sendBufSize, receiveBufSize, nonBlocking);
- }
-
+ {
+ CreateSocket(m_addressFamily, sendBufSize, receiveBufSize, nonBlocking);
+ }
+
SimpleUDP::SimpleUDP(const char* host, unsigned short port, size_t sendBufSize, size_t receiveBufSize, bool nonBlocking) :
m_addressFamily(AF_INET), m_connected(false), m_socket(-1), m_port(port)
{
@@ -131,76 +131,76 @@ namespace Aws
CreateSocket(m_addressFamily, sendBufSize, receiveBufSize, nonBlocking);
}
- SimpleUDP::~SimpleUDP()
- {
- close(GetUnderlyingSocket());
- }
-
- void SimpleUDP::CreateSocket(int addressFamily, size_t sendBufSize, size_t receiveBufSize, bool nonBlocking)
- {
- int sock = socket(addressFamily, SOCK_DGRAM, IPPROTO_UDP);
- assert(sock != -1);
-
- // Try to set sock to nonblocking mode.
- if (nonBlocking)
- {
- int flags = fcntl(sock, F_GETFL, 0);
- if (flags != -1)
- {
- flags |= O_NONBLOCK;
- fcntl(sock, F_SETFL, flags);
- }
- }
-
- // if sendBufSize is not zero, try to set send buffer size
- if (sendBufSize)
- {
- int ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &sendBufSize, sizeof(sendBufSize));
- if (ret)
- {
- AWS_LOGSTREAM_WARN(ALLOC_TAG, "Failed to set UDP send buffer size to " << sendBufSize << " for socket " << sock << " error message: " << strerror(errno));
- }
- assert(ret == 0);
- }
-
- // if receiveBufSize is not zero, try to set receive buffer size
- if (receiveBufSize)
- {
- int ret = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &receiveBufSize, sizeof(receiveBufSize));
- if (ret)
- {
- AWS_LOGSTREAM_WARN(ALLOC_TAG, "Failed to set UDP receive buffer size to " << receiveBufSize << " for socket " << sock << " error message: " << strerror(errno));
- }
- assert(ret == 0);
- }
-
- SetUnderlyingSocket(sock);
- }
-
- int SimpleUDP::Connect(const sockaddr* address, size_t addressLength)
- {
- int ret = connect(GetUnderlyingSocket(), address, static_cast<socklen_t>(addressLength));
- m_connected = ret ? false : true;
- return ret;
- }
-
+ SimpleUDP::~SimpleUDP()
+ {
+ close(GetUnderlyingSocket());
+ }
+
+ void SimpleUDP::CreateSocket(int addressFamily, size_t sendBufSize, size_t receiveBufSize, bool nonBlocking)
+ {
+ int sock = socket(addressFamily, SOCK_DGRAM, IPPROTO_UDP);
+ assert(sock != -1);
+
+ // Try to set sock to nonblocking mode.
+ if (nonBlocking)
+ {
+ int flags = fcntl(sock, F_GETFL, 0);
+ if (flags != -1)
+ {
+ flags |= O_NONBLOCK;
+ fcntl(sock, F_SETFL, flags);
+ }
+ }
+
+ // if sendBufSize is not zero, try to set send buffer size
+ if (sendBufSize)
+ {
+ int ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &sendBufSize, sizeof(sendBufSize));
+ if (ret)
+ {
+ AWS_LOGSTREAM_WARN(ALLOC_TAG, "Failed to set UDP send buffer size to " << sendBufSize << " for socket " << sock << " error message: " << strerror(errno));
+ }
+ assert(ret == 0);
+ }
+
+ // if receiveBufSize is not zero, try to set receive buffer size
+ if (receiveBufSize)
+ {
+ int ret = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &receiveBufSize, sizeof(receiveBufSize));
+ if (ret)
+ {
+ AWS_LOGSTREAM_WARN(ALLOC_TAG, "Failed to set UDP receive buffer size to " << receiveBufSize << " for socket " << sock << " error message: " << strerror(errno));
+ }
+ assert(ret == 0);
+ }
+
+ SetUnderlyingSocket(sock);
+ }
+
+ int SimpleUDP::Connect(const sockaddr* address, size_t addressLength)
+ {
+ int ret = connect(GetUnderlyingSocket(), address, static_cast<socklen_t>(addressLength));
+ m_connected = ret ? false : true;
+ return ret;
+ }
+
int SimpleUDP::ConnectToHost(const char* hostIP, unsigned short port) const
- {
- int ret;
- if (m_addressFamily == AF_INET6)
- {
+ {
+ int ret;
+ if (m_addressFamily == AF_INET6)
+ {
sockaddr_in6 addrinfo = BuildAddrInfoIPV6(hostIP, port);
- ret = connect(GetUnderlyingSocket(), reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in6));
- }
- else
- {
+ ret = connect(GetUnderlyingSocket(), reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in6));
+ }
+ else
+ {
sockaddr_in addrinfo = BuildAddrInfoIPV4(hostIP, port);
- ret = connect(GetUnderlyingSocket(), reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in));
- }
- m_connected = ret ? false : true;
- return ret;
- }
-
+ ret = connect(GetUnderlyingSocket(), reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in));
+ }
+ m_connected = ret ? false : true;
+ return ret;
+ }
+
int SimpleUDP::ConnectToLocalHost(unsigned short port) const
{
if (m_addressFamily == AF_INET6)
@@ -213,73 +213,73 @@ namespace Aws
}
}
- int SimpleUDP::Bind(const sockaddr* address, size_t addressLength) const
- {
- return bind(GetUnderlyingSocket(), address, static_cast<socklen_t>(addressLength));
- }
-
- int SimpleUDP::BindToLocalHost(unsigned short port) const
- {
- if (m_addressFamily == AF_INET6)
- {
+ int SimpleUDP::Bind(const sockaddr* address, size_t addressLength) const
+ {
+ return bind(GetUnderlyingSocket(), address, static_cast<socklen_t>(addressLength));
+ }
+
+ int SimpleUDP::BindToLocalHost(unsigned short port) const
+ {
+ if (m_addressFamily == AF_INET6)
+ {
sockaddr_in6 addrinfo = BuildAddrInfoIPV6(IPV6_LOOP_BACK_ADDRESS, port);
- return bind(GetUnderlyingSocket(), reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in6));
- }
- else
- {
+ return bind(GetUnderlyingSocket(), reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in6));
+ }
+ else
+ {
sockaddr_in addrinfo = BuildAddrInfoIPV4(IPV4_LOOP_BACK_ADDRESS, port);
- return bind(GetUnderlyingSocket(), reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in));
- }
- }
-
- int SimpleUDP::SendData(const uint8_t* data, size_t dataLen) const
- {
+ return bind(GetUnderlyingSocket(), reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in));
+ }
+ }
+
+ int SimpleUDP::SendData(const uint8_t* data, size_t dataLen) const
+ {
if (!m_connected)
{
ConnectToHost(m_hostIP.c_str(), m_port);
}
- return send(GetUnderlyingSocket(), data, dataLen, 0);
- }
-
- int SimpleUDP::SendDataTo(const sockaddr* address, size_t addressLength, const uint8_t* data, size_t dataLen) const
- {
- if (m_connected)
- {
+ return send(GetUnderlyingSocket(), data, dataLen, 0);
+ }
+
+ int SimpleUDP::SendDataTo(const sockaddr* address, size_t addressLength, const uint8_t* data, size_t dataLen) const
+ {
+ if (m_connected)
+ {
return send(GetUnderlyingSocket(), data, dataLen, 0);
- }
- else
- {
- return sendto(GetUnderlyingSocket(), data, dataLen, 0, address, static_cast<socklen_t>(addressLength));
- }
- }
-
- int SimpleUDP::SendDataToLocalHost(const uint8_t* data, size_t dataLen, unsigned short port) const
- {
- if (m_connected)
- {
+ }
+ else
+ {
+ return sendto(GetUnderlyingSocket(), data, dataLen, 0, address, static_cast<socklen_t>(addressLength));
+ }
+ }
+
+ int SimpleUDP::SendDataToLocalHost(const uint8_t* data, size_t dataLen, unsigned short port) const
+ {
+ if (m_connected)
+ {
return send(GetUnderlyingSocket(), data, dataLen, 0);
- }
- else if (m_addressFamily == AF_INET6)
- {
+ }
+ else if (m_addressFamily == AF_INET6)
+ {
sockaddr_in6 addrinfo = BuildAddrInfoIPV6(IPV6_LOOP_BACK_ADDRESS, port);
- return sendto(GetUnderlyingSocket(), data, dataLen, 0, reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in6));
- }
- else
- {
+ return sendto(GetUnderlyingSocket(), data, dataLen, 0, reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in6));
+ }
+ else
+ {
sockaddr_in addrinfo = BuildAddrInfoIPV4(IPV4_LOOP_BACK_ADDRESS, port);
- return sendto(GetUnderlyingSocket(), data, dataLen, 0, reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in));
- }
- }
-
- int SimpleUDP::ReceiveData(uint8_t* buffer, size_t bufferLen) const
- {
- return recv(GetUnderlyingSocket(), buffer, static_cast<int>(bufferLen), 0);
- }
-
-
- int SimpleUDP::ReceiveDataFrom(sockaddr* address, size_t* addressLength, uint8_t* buffer, size_t bufferLen) const
- {
- return recvfrom(GetUnderlyingSocket(), buffer, static_cast<int>(bufferLen), 0, address, reinterpret_cast<socklen_t*>(addressLength));
- }
- }
-}
+ return sendto(GetUnderlyingSocket(), data, dataLen, 0, reinterpret_cast<sockaddr*>(&addrinfo), sizeof(sockaddr_in));
+ }
+ }
+
+ int SimpleUDP::ReceiveData(uint8_t* buffer, size_t bufferLen) const
+ {
+ return recv(GetUnderlyingSocket(), buffer, static_cast<int>(bufferLen), 0);
+ }
+
+
+ int SimpleUDP::ReceiveDataFrom(sockaddr* address, size_t* addressLength, uint8_t* buffer, size_t bufferLen) const
+ {
+ return recvfrom(GetUnderlyingSocket(), buffer, static_cast<int>(bufferLen), 0, address, reinterpret_cast<socklen_t*>(addressLength));
+ }
+ }
+}