From 77a353db2960e6fd244da1dc05e01dc836523b99 Mon Sep 17 00:00:00 2001 From: Carsten Patzke <carsten.patzke@desy.de> Date: Wed, 31 Jan 2018 14:58:10 +0100 Subject: [PATCH] Fixed windows build --- .../cpp/include/system_wrappers/system_io.h | 4 ++- common/cpp/src/system_io.cpp | 26 +++++++++++++------ common/cpp/src/system_io_windows.cpp | 1 - .../ip_tcp_network_speedtest.cpp | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/common/cpp/include/system_wrappers/system_io.h b/common/cpp/include/system_wrappers/system_io.h index 78f742e01..65a18e029 100644 --- a/common/cpp/include/system_wrappers/system_io.h +++ b/common/cpp/include/system_wrappers/system_io.h @@ -14,6 +14,8 @@ class SystemIO final : public IO { private: static const int kNetBufferSize;//TODO: need to set by config + void ApplyNetworkOptions(SocketDescriptor socket_fd, IOErrors * err) const; + //void CollectFileInformationRecursivly(const std::string& path, std::vector<FileInfo>* files, IOErrors* err) const; int FileOpenModeToPosixFileOpenMode(int open_flags) const; IOErrors GetLastError() const; @@ -58,7 +60,7 @@ class SystemIO final : public IO { void InetBind(SocketDescriptor socket_fd, const std::string& address, IOErrors* err) const; std::unique_ptr<std::tuple<std::string, SocketDescriptor>> InetAccept(SocketDescriptor socket_fd, IOErrors* err) const; void InetConnect(SocketDescriptor socket_fd, const std::string& address, IOErrors* err) const; - SocketDescriptor CreateAndConnectIPTCPSocket(const std::string& address, IOErrors* err) const; + SocketDescriptor CreateAndConnectIPTCPSocket(const std::string& address, IOErrors* err) const; size_t Receive(SocketDescriptor socket_fd, void* buf, size_t length, IOErrors* err) const; size_t ReceiveTimeout(SocketDescriptor socket_fd, void* buf, size_t length, long timeout_in_usec, IOErrors* err) const; diff --git a/common/cpp/src/system_io.cpp b/common/cpp/src/system_io.cpp index 22dc6a907..ccd872dbd 100644 --- a/common/cpp/src/system_io.cpp +++ b/common/cpp/src/system_io.cpp @@ -36,6 +36,19 @@ void StripBasePath(const std::string& folder, std::vector<FileInfo>* file_list) // PRIVATE FUNCTIONS - END + +void hidra2::SystemIO::ApplyNetworkOptions(SocketDescriptor socket_fd, IOErrors* err) const +{ + if ( + setsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF, (char*)&kNetBufferSize, sizeof(kNetBufferSize)) != 0 + || + setsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF, (char*)&kNetBufferSize, sizeof(kNetBufferSize)) != 0 + ) { + *err = GetLastError(); + } +} + + std::thread* SystemIO::NewThread(std::function<void()> function) const { return new std::thread(function); } @@ -71,8 +84,6 @@ hidra2::FileDescriptor hidra2::SystemIO::CreateAndConnectIPTCPSocket(const std:: FileDescriptor fd = CreateSocket(AddressFamilies::INET, SocketTypes::STREAM, SocketProtocols::IP, err); - setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &kNetBufferSize, sizeof(kNetBufferSize)); - setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &kNetBufferSize, sizeof(kNetBufferSize)); if(*err != IOErrors::kNoError) { return -1; @@ -235,16 +246,16 @@ SocketDescriptor SystemIO::CreateSocket(AddressFamilies address_family, return -1; } - int socket_fd = _socket(domain, type, protocol); + SocketDescriptor socket_fd = _socket(domain, type, protocol); if(socket_fd == -1) { *err = GetLastError(); return socket_fd; } - setsockopt(socket_fd, SOL_SOCKET, SO_SNDBUF, &kNetBufferSize, sizeof(kNetBufferSize)); - setsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF, &kNetBufferSize, sizeof(kNetBufferSize)); + *err = IOErrors::kNoError; + + ApplyNetworkOptions(socket_fd, err); - *err = IOErrors::kNoError; return socket_fd; } @@ -473,8 +484,7 @@ IOErrors* err) const { return nullptr; } - setsockopt(peer_fd, SOL_SOCKET, SO_RCVBUF, &kNetBufferSize, sizeof(kNetBufferSize)); - setsockopt(peer_fd, SOL_SOCKET, SO_SNDBUF, &kNetBufferSize, sizeof(kNetBufferSize)); + ApplyNetworkOptions(peer_fd, err); std::string address = std::string(inet_ntoa(client_address.sin_addr)) + ':' + std::to_string(client_address.sin_port); diff --git a/common/cpp/src/system_io_windows.cpp b/common/cpp/src/system_io_windows.cpp index 1e84733c7..9d36dac27 100644 --- a/common/cpp/src/system_io_windows.cpp +++ b/common/cpp/src/system_io_windows.cpp @@ -37,7 +37,6 @@ IOErrors IOErrorFromGetLastError() { } } - IOErrors SystemIO::GetLastError() const { return IOErrorFromGetLastError(); } diff --git a/tests/system_io/ip_tcp_network_speedtest/ip_tcp_network_speedtest.cpp b/tests/system_io/ip_tcp_network_speedtest/ip_tcp_network_speedtest.cpp index c58a5736f..5dd9efb42 100644 --- a/tests/system_io/ip_tcp_network_speedtest/ip_tcp_network_speedtest.cpp +++ b/tests/system_io/ip_tcp_network_speedtest/ip_tcp_network_speedtest.cpp @@ -20,7 +20,7 @@ static const std::unique_ptr<SystemIO> io(new SystemIO()); static const std::string kListenAddress = "127.0.0.1:4206"; static std::promise<void> kThreadStarted; -static size_t kTestSize = size_t(1024) * size_t(1024) * size_t(1024) * size_t(1); //1GiByte +static size_t kTestSize = size_t(1024) * size_t(1024) * size_t(512); //512MiByte static int kTestCount = 50; void Exit(int exit_number) { -- GitLab