From fd29f31a5ce866fc51ebda12fead9e7fafddcfd6 Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Wed, 6 Sep 2023 08:36:25 +0200 Subject: [PATCH 1/4] Introduce v_sock_size for socklen_t Signed-off-by: Ferry Huberts --- src/oatpp/core/IODefinitions.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/oatpp/core/IODefinitions.hpp b/src/oatpp/core/IODefinitions.hpp index dfb62f5d..493870a3 100644 --- a/src/oatpp/core/IODefinitions.hpp +++ b/src/oatpp/core/IODefinitions.hpp @@ -28,6 +28,8 @@ #include "oatpp/core/async/Error.hpp" #include "oatpp/core/Types.hpp" +#include + namespace oatpp { /** @@ -39,9 +41,11 @@ namespace oatpp { #else typedef unsigned long v_io_handle; #endif + typedef int v_sock_size; constexpr const v_io_handle INVALID_IO_HANDLE = v_io_handle (-1); #else typedef int v_io_handle; + typedef socklen_t v_sock_size; constexpr const v_io_handle INVALID_IO_HANDLE = (-1); #endif From 02936f708799abeab2ac1aa78a30a0d58880a359 Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Wed, 6 Sep 2023 08:36:38 +0200 Subject: [PATCH 2/4] Convert uses of socklen_t to v_sock_size --- src/oatpp/network/tcp/client/ConnectionProvider.cpp | 4 ++-- src/oatpp/network/tcp/server/ConnectionProvider.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/oatpp/network/tcp/client/ConnectionProvider.cpp b/src/oatpp/network/tcp/client/ConnectionProvider.cpp index 4117fd0e..cfc8312a 100644 --- a/src/oatpp/network/tcp/client/ConnectionProvider.cpp +++ b/src/oatpp/network/tcp/client/ConnectionProvider.cpp @@ -123,7 +123,7 @@ provider::ResourceHandle ConnectionProvider::get() { if(clientHandle >= 0) { - if(connect(clientHandle, currResult->ai_addr, static_cast(currResult->ai_addrlen)) == 0) { + if(connect(clientHandle, currResult->ai_addr, static_cast(currResult->ai_addrlen)) == 0) { break; } else { err = errno; @@ -282,7 +282,7 @@ oatpp::async::CoroutineStarterForResultai_addr, static_cast(m_currentResult->ai_addrlen)); + auto res = connect(m_clientHandle, m_currentResult->ai_addr, static_cast(m_currentResult->ai_addrlen)); #if defined(WIN32) || defined(_WIN32) diff --git a/src/oatpp/network/tcp/server/ConnectionProvider.cpp b/src/oatpp/network/tcp/server/ConnectionProvider.cpp index 2b22ec45..8165269d 100644 --- a/src/oatpp/network/tcp/server/ConnectionProvider.cpp +++ b/src/oatpp/network/tcp/server/ConnectionProvider.cpp @@ -46,7 +46,7 @@ // Workaround for MinGW from: https://www.mail-archive.com/users@ipv6.org/msg02107.html #if defined(__MINGW32__) && _WIN32_WINNT < 0x0600 - const char * inet_ntop (int af, const void *src, char *dst, socklen_t cnt) { + const char * inet_ntop (int af, const void *src, char *dst, oatpp::v_sock_size cnt) { if (af == AF_INET) { struct sockaddr_in in; @@ -228,7 +228,7 @@ oatpp::v_io_handle ConnectionProvider::instantiateServer(){ // Update port after binding (typicaly in case of port = 0) struct ::sockaddr_in s_in; ::memset(&s_in, 0, sizeof(s_in)); - ::socklen_t s_in_len = sizeof(s_in); + oatpp::v_sock_size s_in_len = sizeof(s_in); ::getsockname(serverHandle, (struct sockaddr *)&s_in, &s_in_len); setProperty(PROPERTY_PORT, oatpp::utils::conversion::int32ToStr(ntohs(s_in.sin_port))); @@ -280,7 +280,7 @@ oatpp::v_io_handle ConnectionProvider::instantiateServer(){ "Warning. Failed to set %s for accepting socket: %s", "SO_REUSEADDR", strerror(errno)); } - if (bind(serverHandle, currResult->ai_addr, static_cast(currResult->ai_addrlen)) == 0 && + if (bind(serverHandle, currResult->ai_addr, static_cast(currResult->ai_addrlen)) == 0 && listen(serverHandle, 10000) == 0) { break; @@ -309,7 +309,7 @@ oatpp::v_io_handle ConnectionProvider::instantiateServer(){ // Update port after binding (typicaly in case of port = 0) ::sockaddr_in s_in; ::memset(&s_in, 0, sizeof(s_in)); - ::socklen_t s_in_len = sizeof(s_in); + oatpp::v_sock_size s_in_len = sizeof(s_in);//FIXME trace ::getsockname(serverHandle, reinterpret_cast(&s_in), &s_in_len); setProperty(PROPERTY_PORT, oatpp::utils::conversion::int32ToStr(ntohs(s_in.sin_port))); @@ -351,7 +351,7 @@ provider::ResourceHandle ConnectionProvider::getDefaultC provider::ResourceHandle ConnectionProvider::getExtendedConnection() { sockaddr_storage clientAddress; - socklen_t clientAddressSize = sizeof(clientAddress); + v_sock_size clientAddressSize = sizeof(clientAddress); data::stream::Context::Properties properties; From defda0ff16af2059289f1cd98d992646d6e3b74e Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Wed, 6 Sep 2023 08:42:37 +0200 Subject: [PATCH 3/4] Use auto for 2 locals Signed-off-by: Ferry Huberts --- src/oatpp/parser/json/mapping/Deserializer.cpp | 2 +- src/oatpp/parser/json/mapping/Serializer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/oatpp/parser/json/mapping/Deserializer.cpp b/src/oatpp/parser/json/mapping/Deserializer.cpp index 9c6c1c67..f9f9f202 100644 --- a/src/oatpp/parser/json/mapping/Deserializer.cpp +++ b/src/oatpp/parser/json/mapping/Deserializer.cpp @@ -494,7 +494,7 @@ oatpp::Void Deserializer::deserializeObject(Deserializer* deserializer, parser:: } oatpp::Void Deserializer::deserialize(parser::Caret& caret, const Type* const type) { - v_uint32 id = static_cast(type->classId.id); + auto id = static_cast(type->classId.id); auto& method = m_methods[id]; if(method) { return (*method)(this, caret, type); diff --git a/src/oatpp/parser/json/mapping/Serializer.cpp b/src/oatpp/parser/json/mapping/Serializer.cpp index a4e638af..c0df709c 100644 --- a/src/oatpp/parser/json/mapping/Serializer.cpp +++ b/src/oatpp/parser/json/mapping/Serializer.cpp @@ -259,7 +259,7 @@ void Serializer::serializeObject(Serializer* serializer, void Serializer::serialize(data::stream::ConsistentOutputStream* stream, const oatpp::Void& polymorph) { - v_uint32 id = static_cast(polymorph.getValueType()->classId.id); + auto id = static_cast(polymorph.getValueType()->classId.id); auto& method = m_methods[id]; if(method) { (*method)(this, stream, polymorph); From 11852eb3b51020fb22220d39fb27d72b414f450f Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Wed, 6 Sep 2023 09:11:00 +0200 Subject: [PATCH 4/4] Fix v_sock_size definition Signed-off-by: Ferry Huberts --- src/oatpp/core/IODefinitions.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/oatpp/core/IODefinitions.hpp b/src/oatpp/core/IODefinitions.hpp index 493870a3..26ca9c03 100644 --- a/src/oatpp/core/IODefinitions.hpp +++ b/src/oatpp/core/IODefinitions.hpp @@ -28,7 +28,9 @@ #include "oatpp/core/async/Error.hpp" #include "oatpp/core/Types.hpp" -#include +#if !defined(WIN32) && !defined(_WIN32) +#include +#endif namespace oatpp {