From 216081ffb71b8ea03eae2b92895bf0febb845da8 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 18 Jun 2024 16:54:23 +0800 Subject: [PATCH] Update yasio to 4.2.3 --- .../yasio/yasio/bindings/lua/CMakeLists.txt | 2 +- NativeLibs/yasio/yasio/bindings/yasio_ni.cpp | 30 ++++--------------- NativeLibs/yasio/yasio/config.hpp | 2 +- NativeLibs/yasio/yasio/io_service.cpp | 6 ++-- NativeLibs/yasio/yasio/io_service.hpp | 11 ++++--- NativeLibs/yasio/yasio/logging.hpp | 5 +++- NativeLibs/yasio/yasio/obstream.hpp | 2 +- NativeLibs/yasio/yasio/type_traits.hpp | 5 +++- NativeLibs/yasio/yasio/xxsocket.cpp | 12 +++++--- 9 files changed, 34 insertions(+), 41 deletions(-) diff --git a/NativeLibs/yasio/yasio/bindings/lua/CMakeLists.txt b/NativeLibs/yasio/yasio/bindings/lua/CMakeLists.txt index b6ffdf0..dd3e130 100644 --- a/NativeLibs/yasio/yasio/bindings/lua/CMakeLists.txt +++ b/NativeLibs/yasio/yasio/bindings/lua/CMakeLists.txt @@ -1,6 +1,6 @@ set(target_name plainlua) -get_filename_component(LUA_SRC_PATH ../../../thirdparty/lua ABSOLUTE) +get_filename_component(LUA_SRC_PATH ../../../3rdparty/lua ABSOLUTE) message(STATUS "LUA_SRC_PATH=${LUA_SRC_PATH}") file(GLOB LUA_SRC_FILES diff --git a/NativeLibs/yasio/yasio/bindings/yasio_ni.cpp b/NativeLibs/yasio/yasio/bindings/yasio_ni.cpp index 3aaf65b..e30f3eb 100644 --- a/NativeLibs/yasio/yasio/bindings/yasio_ni.cpp +++ b/NativeLibs/yasio/yasio/bindings/yasio_ni.cpp @@ -32,6 +32,7 @@ SOFTWARE. #include #include #include "yasio/yasio.hpp" +#include "yasio/split.hpp" #if defined(_WINDLL) # define YASIO_NI_API __declspec(dllexport) @@ -45,25 +46,6 @@ using namespace yasio; namespace { -template -inline void fast_split(_CStr s, size_t slen, typename std::remove_pointer<_CStr>::type delim, _Fn func) -{ - auto _Start = s; // the start of every string - auto _Ptr = s; // source string iterator - auto _End = s + slen; - while ((_Ptr = strchr(_Ptr, delim))) - { - if (_Start < _Ptr) - if (func(_Start, _Ptr)) - return; - _Start = _Ptr + 1; - ++_Ptr; - } - if (_Start < _End) - { - func(_Start, _End); - } -} inline int svtoi(cxx17::string_view& sv) { return !sv.empty() ? atoi(sv.data()) : 0; } inline const char* svtoa(cxx17::string_view& sv) { return !sv.empty() ? sv.data() : ""; } } // namespace @@ -154,7 +136,7 @@ YASIO_NI_API void yasio_set_resolv_fn(void* service_ptr, int(YASIO_INTEROP_DECL* YASIO_NI_API void yasio_set_option(void* service_ptr, int opt, const char* pszArgs) { auto service = reinterpret_cast(service_ptr); - if (!service) + if (!service || !pszArgs || !*pszArgs) return; // process one arg @@ -174,10 +156,10 @@ YASIO_NI_API void yasio_set_option(void* service_ptr, int opt, const char* pszAr std::string strArgs = pszArgs; std::array args; int argc = 0; - fast_split(&strArgs.front(), strArgs.length(), ';', [&](char* s, char* e) { - *e = '\0'; // to c style string - args[argc] = cxx17::string_view(s, e - s); - return (++argc == YASIO_MAX_OPTION_ARGC); + yasio::split_if(&strArgs.front(), ';', [&](char* s, char* e) { + *e = '\0'; // to c style string + args[argc++] = cxx17::string_view(s, e - s); + return (argc < YASIO_MAX_OPTION_ARGC); }); switch (opt) diff --git a/NativeLibs/yasio/yasio/config.hpp b/NativeLibs/yasio/yasio/config.hpp index c3e7264..77c35c1 100644 --- a/NativeLibs/yasio/yasio/config.hpp +++ b/NativeLibs/yasio/yasio/config.hpp @@ -205,7 +205,7 @@ SOFTWARE. /* ** The yasio version macros */ -#define YASIO_VERSION_NUM 0x040201 +#define YASIO_VERSION_NUM 0x040203 /* ** The macros used by io_service. diff --git a/NativeLibs/yasio/yasio/io_service.cpp b/NativeLibs/yasio/yasio/io_service.cpp index 6611c68..fa39f07 100644 --- a/NativeLibs/yasio/yasio/io_service.cpp +++ b/NativeLibs/yasio/yasio/io_service.cpp @@ -76,8 +76,10 @@ struct yasio_kcp_options { auto __msg = ::yasio::strfmt(127, "[yasio][%lld]" format "\n", ::yasio::clock(), ##__VA_ARGS__); \ if (__cprint) \ __cprint(level, __msg.c_str()); \ - else \ + else { \ + __msg.back() = '\0'; \ YASIO_LOG_TAG("", "%s", __msg.c_str()); \ + } \ } while (false) // clang-format on @@ -2258,7 +2260,7 @@ void io_service::set_option_internal(int opt, va_list ap) // lgtm [cpp/poorly-do channel->uparams_.no_bswap = va_arg(ap, int); break; } - case YOPT_C_LFBFD_FN: { + case YOPT_C_UNPACK_FN: { auto channel = channel_at(static_cast(va_arg(ap, int))); if (channel) channel->decode_len_ = *va_arg(ap, decode_len_fn_t*); diff --git a/NativeLibs/yasio/yasio/io_service.hpp b/NativeLibs/yasio/yasio/io_service.hpp index 2277943..eba21ae 100644 --- a/NativeLibs/yasio/yasio/io_service.hpp +++ b/NativeLibs/yasio/yasio/io_service.hpp @@ -301,9 +301,10 @@ enum YOPT_B_SOCKOPT = 201, }; -// channel masks: only for internal use, not for user +// channel masks and kinds enum { + // masks: only for internal use, not for user YCM_CLIENT = 1, YCM_SERVER = 1 << 1, YCM_TCP = 1 << 2, @@ -311,11 +312,8 @@ enum YCM_KCP = 1 << 4, YCM_SSL = 1 << 5, YCM_UDS = 1 << 6, // IPC: posix domain socket -}; -// channel kinds: for user to call io_service::open -enum -{ + // kinds YCK_TCP_CLIENT = YCM_TCP | YCM_CLIENT, YCK_TCP_SERVER = YCM_TCP | YCM_SERVER, YCK_UDP_CLIENT = YCM_UDP | YCM_CLIENT, @@ -849,6 +847,7 @@ class YASIO_API io_transport_udp : public io_transport { #if defined(YASIO_ENABLE_KCP) class io_transport_kcp : public io_transport_udp { friend class io_service; + public: YASIO__DECL io_transport_kcp(io_channel* ctx, xxsocket_ptr&& s); YASIO__DECL ~io_transport_kcp(); @@ -862,7 +861,7 @@ class io_transport_kcp : public io_transport_udp { YASIO__DECL bool do_write(highp_time_t& wait_duration) override; YASIO__DECL int handle_input(char* buf, int len, int& error, highp_time_t& wait_duration) override; - + int interval() const { return kcp_->interval * std::milli::den; } sbyte_buffer rawbuf_; // the low level raw buffer diff --git a/NativeLibs/yasio/yasio/logging.hpp b/NativeLibs/yasio/yasio/logging.hpp index bcde280..12b79b9 100644 --- a/NativeLibs/yasio/yasio/logging.hpp +++ b/NativeLibs/yasio/yasio/logging.hpp @@ -30,7 +30,10 @@ SOFTWARE. #include "yasio/strfmt.hpp" #if defined(__EMSCRIPTEN__) -# define YASIO_LOG_TAG(tag, format, ...) printf((tag format "\n"), ##__VA_ARGS__) +# include +# include +inline void yasio__print(std::string&& message) { ::write(::fileno(stdout), message.c_str(), message.size()); } +# define YASIO_LOG_TAG(tag, format, ...) yasio__print(::yasio::strfmt(127, (tag format), ##__VA_ARGS__)) #elif defined(_WIN32) # define YASIO_LOG_TAG(tag, format, ...) OutputDebugStringA(::yasio::strfmt(127, (tag format "\n"), ##__VA_ARGS__).c_str()) #elif defined(ANDROID) || defined(__ANDROID__) diff --git a/NativeLibs/yasio/yasio/obstream.hpp b/NativeLibs/yasio/yasio/obstream.hpp index 89f0aeb..e9dce03 100644 --- a/NativeLibs/yasio/yasio/obstream.hpp +++ b/NativeLibs/yasio/yasio/obstream.hpp @@ -149,7 +149,7 @@ class dynamic_buffer_span { using implementation_type = _Cont; using size_type = typename _Cont::size_type; implementation_type& get_implementation() { return *this->outs_; } - const implementation_type& get_implementation() const { return *this->impl_; } + const implementation_type& get_implementation() const { return *this->outs_; } dynamic_buffer_span(_Cont* outs) : outs_(outs) {} diff --git a/NativeLibs/yasio/yasio/type_traits.hpp b/NativeLibs/yasio/yasio/type_traits.hpp index 7774ce6..9c1dd26 100644 --- a/NativeLibs/yasio/yasio/type_traits.hpp +++ b/NativeLibs/yasio/yasio/type_traits.hpp @@ -27,13 +27,16 @@ SOFTWARE. */ #pragma once + +#include #include +#include "yasio/sz.hpp" namespace yasio { template struct aligned_storage_size { - static const size_t value = sizeof(typename std::aligned_storage::type); + static const size_t value = YASIO_SZ_ALIGN(sizeof(_Ty), sizeof(std::max_align_t)); }; template struct is_aligned_storage { diff --git a/NativeLibs/yasio/yasio/xxsocket.cpp b/NativeLibs/yasio/yasio/xxsocket.cpp index 87c8894..9477578 100644 --- a/NativeLibs/yasio/yasio/xxsocket.cpp +++ b/NativeLibs/yasio/yasio/xxsocket.cpp @@ -128,8 +128,7 @@ int xxsocket::xpconnect_n(const char* hostname, u_short port, const std::chrono: else if (flags & ipsv_ipv6) { xxsocket::resolve_i([&](const addrinfo* ai6) { return 0 == (error = pconnect_n(ip::endpoint{ai6}, wtimeout, local_port)); }, hostname, port, - AF_INET6, - AI_V4MAPPED); + AF_INET6, AI_V4MAPPED); } break; case AF_INET6: @@ -231,7 +230,8 @@ bool xxsocket::popen(int af, int type, int protocol) return ok; } -int xxsocket::paccept(socket_native_type& new_sock) { +int xxsocket::paccept(socket_native_type& new_sock) +{ for (;;) { // Accept the waiting connection. @@ -986,7 +986,7 @@ const char* xxsocket::strerror(int error) #else return ::strerror(error); #endif - } + } return YASIO_NO_ERROR; } @@ -1035,7 +1035,11 @@ struct ws2_32_gc { ~ws2_32_gc(void) { WSACleanup(); } }; +# pragma warning(push) +# pragma warning(disable : 4073) +# pragma init_seg(lib) ws2_32_gc __ws32_lib_gc; +# pragma warning(pop) } // namespace #endif