Skip to content

Commit

Permalink
Update yasio to 4.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Jun 18, 2024
1 parent deac616 commit 216081f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 41 deletions.
2 changes: 1 addition & 1 deletion NativeLibs/yasio/yasio/bindings/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 6 additions & 24 deletions NativeLibs/yasio/yasio/bindings/yasio_ni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SOFTWARE.
#include <array>
#include <string.h>
#include "yasio/yasio.hpp"
#include "yasio/split.hpp"

#if defined(_WINDLL)
# define YASIO_NI_API __declspec(dllexport)
Expand All @@ -45,25 +46,6 @@ using namespace yasio;

namespace
{
template <typename _CStr, typename _Fn>
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
Expand Down Expand Up @@ -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<io_service*>(service_ptr);
if (!service)
if (!service || !pszArgs || !*pszArgs)
return;

// process one arg
Expand All @@ -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<cxx17::string_view, YASIO_MAX_OPTION_ARGC> 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)
Expand Down
2 changes: 1 addition & 1 deletion NativeLibs/yasio/yasio/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions NativeLibs/yasio/yasio/io_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ struct yasio_kcp_options {
auto __msg = ::yasio::strfmt(127, "[yasio][%lld]" format "\n", ::yasio::clock<system_clock_t>(), ##__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

Expand Down Expand Up @@ -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<size_t>(va_arg(ap, int)));
if (channel)
channel->decode_len_ = *va_arg(ap, decode_len_fn_t*);
Expand Down
11 changes: 5 additions & 6 deletions NativeLibs/yasio/yasio/io_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,19 @@ 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,
YCM_UDP = 1 << 3,
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,
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion NativeLibs/yasio/yasio/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
# include <unistd.h>
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__)
Expand Down
2 changes: 1 addition & 1 deletion NativeLibs/yasio/yasio/obstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
5 changes: 4 additions & 1 deletion NativeLibs/yasio/yasio/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ SOFTWARE.
*/

#pragma once

#include <cstddef>
#include <type_traits>
#include "yasio/sz.hpp"

namespace yasio
{
template <typename _Ty>
struct aligned_storage_size {
static const size_t value = sizeof(typename std::aligned_storage<sizeof(_Ty)>::type);
static const size_t value = YASIO_SZ_ALIGN(sizeof(_Ty), sizeof(std::max_align_t));
};
template <typename _Ty>
struct is_aligned_storage {
Expand Down
12 changes: 8 additions & 4 deletions NativeLibs/yasio/yasio/xxsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -986,7 +986,7 @@ const char* xxsocket::strerror(int error)
#else
return ::strerror(error);
#endif
}
}
return YASIO_NO_ERROR;
}

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 216081f

Please sign in to comment.