diff --git a/thirdparty/README.md b/thirdparty/README.md index b0f52ac187..bc6e4fabc4 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -238,7 +238,7 @@ ## yasio - [![Upstream](https://img.shields.io/github/v/release/yasio/yasio?label=Upstream)](https://github.com/yasio/yasio) -- Version: 3.39.4 +- Version: 3.39.5 - License: MIT WITH Anti-996 ## zlib diff --git a/thirdparty/yasio/.clang-format b/thirdparty/yasio/.clang-format index 01c25c1e87..3a4e19cd63 100644 --- a/thirdparty/yasio/.clang-format +++ b/thirdparty/yasio/.clang-format @@ -6,8 +6,8 @@ Standard: Cpp11 SortIncludes: false -# Keep lines under 100 columns long. -ColumnLimit: 100 +# Keep lines under 160 columns long. +ColumnLimit: 160 # Always break before braces BreakBeforeBraces: Custom diff --git a/thirdparty/yasio/bindings/yasio_cclua.cpp b/thirdparty/yasio/bindings/yasio_cclua.cpp index 3383554f46..67fd481d26 100644 --- a/thirdparty/yasio/bindings/yasio_cclua.cpp +++ b/thirdparty/yasio/bindings/yasio_cclua.cpp @@ -36,7 +36,7 @@ SOFTWARE. # undef __has_attribute # endif #include "cocos2d.h" -USING_NS_AX; +using namespace cocos2d; namespace lyasio { diff --git a/thirdparty/yasio/detail/config.hpp b/thirdparty/yasio/detail/config.hpp index ad317fe0a0..fb191c2f5f 100644 --- a/thirdparty/yasio/detail/config.hpp +++ b/thirdparty/yasio/detail/config.hpp @@ -192,7 +192,7 @@ SOFTWARE. /* ** The yasio version macros */ -#define YASIO_VERSION_NUM 0x033904 +#define YASIO_VERSION_NUM 0x033905 /* ** The macros used by io_service. diff --git a/thirdparty/yasio/yasio.cpp b/thirdparty/yasio/yasio.cpp index cf5a1b8448..a66c6436bd 100644 --- a/thirdparty/yasio/yasio.cpp +++ b/thirdparty/yasio/yasio.cpp @@ -350,7 +350,7 @@ io_transport::io_transport(io_channel* ctx, xxsocket_ptr&& s) : ctx_(ctx) #endif } const print_fn2_t& io_transport::__get_cprint() const { return ctx_->get_service().options_.print_; } -int io_transport::write(sbyte_buffer&& buffer, completion_cb_t&& handler) +int io_transport::write(dynamic_buffer_t&& buffer, completion_cb_t&& handler) { int n = static_cast(buffer.size()); send_queue_.emplace(cxx14::make_unique(std::move(buffer), std::move(handler))); @@ -603,11 +603,11 @@ void io_transport_udp::disconnect() connected_ = false; set_primitives(); } -int io_transport_udp::write(sbyte_buffer&& buffer, completion_cb_t&& handler) +int io_transport_udp::write(dynamic_buffer_t&& buffer, completion_cb_t&& handler) { return connected_ ? io_transport::write(std::move(buffer), std::move(handler)) : write_to(std::move(buffer), ensure_destination(), std::move(handler)); } -int io_transport_udp::write_to(sbyte_buffer&& buffer, const ip::endpoint& to, completion_cb_t&& handler) +int io_transport_udp::write_to(dynamic_buffer_t&& buffer, const ip::endpoint& to, completion_cb_t&& handler) { int n = static_cast(buffer.size()); send_queue_.emplace(cxx14::make_unique(std::move(buffer), std::move(handler), to)); @@ -658,12 +658,12 @@ io_transport_kcp::io_transport_kcp(io_channel* ctx, xxsocket_ptr&& s) : io_trans if (yasio__min_wait_duration == 0) return t->write_cb_(buf, len, std::addressof(t->ensure_destination())); // Enqueue to transport queue - return t->io_transport_udp::write(sbyte_buffer{buf, buf + len}, nullptr); + return t->io_transport_udp::write(dynamic_buffer_t{buf, buf + len}, nullptr); }); } io_transport_kcp::~io_transport_kcp() { ::ikcp_release(this->kcp_); } -int io_transport_kcp::write(sbyte_buffer&& buffer, completion_cb_t&& /*handler*/) +int io_transport_kcp::write(dynamic_buffer_t&& buffer, completion_cb_t&& /*handler*/) { std::lock_guard lck(send_mtx_); int len = static_cast(buffer.size()); @@ -1117,7 +1117,7 @@ void io_service::unregister_descriptor(const socket_native_type fd, int flags) if (yasio__testbits(flags, YEM_POLLERR)) FD_CLR(fd, &(fds_array_[except_op])); } -int io_service::write(transport_handle_t transport, sbyte_buffer buffer, completion_cb_t handler) +int io_service::write(transport_handle_t transport, dynamic_buffer_t buffer, completion_cb_t handler) { if (transport && transport->is_open()) return !buffer.empty() ? transport->write(std::move(buffer), std::move(handler)) : 0; @@ -1127,7 +1127,7 @@ int io_service::write(transport_handle_t transport, sbyte_buffer buffer, complet return -1; } } -int io_service::write_to(transport_handle_t transport, sbyte_buffer buffer, const ip::endpoint& to, completion_cb_t handler) +int io_service::write_to(transport_handle_t transport, dynamic_buffer_t buffer, const ip::endpoint& to, completion_cb_t handler) { if (transport && transport->is_open()) return !buffer.empty() ? transport->write_to(std::move(buffer), to, std::move(handler)) : 0; @@ -1839,8 +1839,8 @@ void io_service::unpack(transport_handle_t transport, int bytes_expected, int by { auto& offset = transport->offset_; auto bytes_available = bytes_transferred + offset; - transport->expected_packet_.insert(transport->expected_packet_.end(), transport->buffer_ + bytes_to_strip, - transport->buffer_ + (std::min)(bytes_expected, bytes_available)); + auto& pkt = transport->expected_packet_; + pkt.insert(pkt.end(), transport->buffer_ + bytes_to_strip, transport->buffer_ + (std::min)(bytes_expected, bytes_available)); // set 'offset' to bytes of remain buffer offset = bytes_available - bytes_expected; @@ -2124,7 +2124,10 @@ void io_service::start_query(io_channel* ctx) # endif } else + { + ctx->set_last_errno(yasio::errc::resolve_host_failed); YASIO_KLOGE("[index: %d] query %s failed, ec=%d, detail:%s", ctx->index_, ctx->remote_host_.c_str(), error, xxsocket::gai_strerror(error)); + } this->interrupt(); }); async_resolv_thread.detach(); diff --git a/thirdparty/yasio/yasio.hpp b/thirdparty/yasio/yasio.hpp index a46dcc6e62..86a90ffeae 100644 --- a/thirdparty/yasio/yasio.hpp +++ b/thirdparty/yasio/yasio.hpp @@ -361,6 +361,10 @@ typedef highp_timer_ptr deadline_timer_ptr; typedef event_cb_t io_event_cb_t; typedef completion_cb_t io_completion_cb_t; +typedef sbyte_buffer dynamic_buffer_t; + +inline dynamic_buffer_t make_dynamic_buffer(const void* p, size_t n) { return dynamic_buffer_t{(const char*)p, (const char*)p + n, std::true_type{}}; } + struct io_hostent { io_hostent() = default; io_hostent(cxx17::string_view ip, u_short port) : host_(cxx17::svtos(ip)), port_(port) {} @@ -615,7 +619,7 @@ private: ip::endpoint multiaddr_, multiif_; // Current it's only for UDP - sbyte_buffer buffer_; + dynamic_buffer_t buffer_; // The bytes transferred from socket low layer, currently, only works for client channel long long bytes_transferred_ = 0; @@ -634,11 +638,11 @@ private: // for tcp transport only class YASIO_API io_send_op { public: - io_send_op(sbyte_buffer&& buffer, completion_cb_t&& handler) : offset_(0), buffer_(std::move(buffer)), handler_(std::move(handler)) {} + io_send_op(dynamic_buffer_t&& buffer, completion_cb_t&& handler) : offset_(0), buffer_(std::move(buffer)), handler_(std::move(handler)) {} virtual ~io_send_op() {} - size_t offset_; // read pos from sending buffer - sbyte_buffer buffer_; // sending data buffer + size_t offset_; // read pos from sending buffer + dynamic_buffer_t buffer_; // sending data buffer completion_cb_t handler_; YASIO__DECL virtual int perform(transport_handle_t transport, const void* buf, int n); @@ -651,7 +655,7 @@ public: // for udp transport only class YASIO_API io_sendto_op : public io_send_op { public: - io_sendto_op(sbyte_buffer&& buffer, completion_cb_t&& handler, const ip::endpoint& destination) + io_sendto_op(dynamic_buffer_t&& buffer, completion_cb_t&& handler, const ip::endpoint& destination) : io_send_op(std::move(buffer), std::move(handler)), destination_(destination) {} @@ -687,7 +691,7 @@ public: protected: io_service& get_service() const { return ctx_->get_service(); } bool is_open() const { return state_ == state::OPENED && socket_ && socket_->is_open(); } - sbyte_buffer fetch_packet() + dynamic_buffer_t fetch_packet() { expected_size_ = -1; return std::move(expected_packet_); @@ -697,10 +701,10 @@ protected: YASIO__DECL const print_fn2_t& __get_cprint() const; // Call at user thread - YASIO__DECL virtual int write(sbyte_buffer&&, completion_cb_t&&); + YASIO__DECL virtual int write(dynamic_buffer_t&&, completion_cb_t&&); // Call at user thread - virtual int write_to(sbyte_buffer&&, const ip::endpoint&, completion_cb_t&&) + virtual int write_to(dynamic_buffer_t&&, const ip::endpoint&, completion_cb_t&&) { YASIO_LOG("[warning] io_transport doesn't support 'write_to' operation!"); return 0; @@ -727,7 +731,7 @@ protected: int offset_ = 0; // recv buffer offset int expected_size_ = -1; - sbyte_buffer expected_packet_; + dynamic_buffer_t expected_packet_; io_channel* ctx_; @@ -770,8 +774,8 @@ protected: YASIO__DECL void connect(); YASIO__DECL void disconnect(); - YASIO__DECL int write(sbyte_buffer&&, completion_cb_t&&) override; - YASIO__DECL int write_to(sbyte_buffer&&, const ip::endpoint&, completion_cb_t&&) override; + YASIO__DECL int write(dynamic_buffer_t&&, completion_cb_t&&) override; + YASIO__DECL int write_to(dynamic_buffer_t&&, const ip::endpoint&, completion_cb_t&&) override; YASIO__DECL void set_primitives() override; @@ -796,7 +800,7 @@ public: ikcpcb* internal_object() { return kcp_; } protected: - YASIO__DECL int write(sbyte_buffer&&, completion_cb_t&&) override; + YASIO__DECL int write(dynamic_buffer_t&&, completion_cb_t&&) override; YASIO__DECL int do_read(int revent, int& error, highp_time_t& wait_duration) override; YASIO__DECL bool do_write(highp_time_t& wait_duration) override; @@ -805,7 +809,7 @@ protected: YASIO__DECL void check_timeout(highp_time_t& wait_duration) const; - sbyte_buffer rawbuf_; // the low level raw buffer + dynamic_buffer_t rawbuf_; // the low level raw buffer ikcpcb* kcp_; std::recursive_mutex send_mtx_; }; @@ -813,7 +817,7 @@ protected: class io_transport_kcp {}; #endif -using io_packet = sbyte_buffer; +using io_packet = dynamic_buffer_t; #if !defined(YASIO_USE_SHARED_PACKET) using packet_t = io_packet; inline packet_t wrap_packet(io_packet& raw_packet) { return std::move(raw_packet); } @@ -1007,9 +1011,9 @@ public: */ int write(transport_handle_t thandle, const void* buf, size_t len, completion_cb_t completion_handler = nullptr) { - return write(thandle, sbyte_buffer{(const char*)buf, (const char*)buf + len, std::true_type{}}, std::move(completion_handler)); + return write(thandle, make_dynamic_buffer(buf, len), std::move(completion_handler)); } - YASIO__DECL int write(transport_handle_t thandle, sbyte_buffer buffer, completion_cb_t completion_handler = nullptr); + YASIO__DECL int write(transport_handle_t thandle, dynamic_buffer_t buffer, completion_cb_t completion_handler = nullptr); /* ** Summary: Write data to unconnected UDP transport with specified address. @@ -1020,9 +1024,9 @@ public: */ int write_to(transport_handle_t thandle, const void* buf, size_t len, const ip::endpoint& to, completion_cb_t completion_handler = nullptr) { - return write_to(thandle, sbyte_buffer{(const char*)buf, (const char*)buf + len, std::true_type{}}, to, std::move(completion_handler)); + return write_to(thandle, make_dynamic_buffer(buf, len), to, std::move(completion_handler)); } - YASIO__DECL int write_to(transport_handle_t thandle, sbyte_buffer buffer, const ip::endpoint& to, completion_cb_t completion_handler = nullptr); + YASIO__DECL int write_to(transport_handle_t thandle, dynamic_buffer_t buffer, const ip::endpoint& to, completion_cb_t completion_handler = nullptr); // The highp_timer support, !important, the callback is called on the thread of io_service YASIO__DECL highp_timer_ptr schedule(const std::chrono::microseconds& duration, timer_cb_t);