From d79fa4f5999f87e3307876d09afe1d42cb9956d1 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 1 Feb 2024 20:02:01 +0800 Subject: [PATCH] Fix pure udp not handle packet forward --- yasio/io_service.cpp | 10 +++++++--- yasio/io_service.hpp | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/yasio/io_service.cpp b/yasio/io_service.cpp index d9954939..614b8e3d 100644 --- a/yasio/io_service.cpp +++ b/yasio/io_service.cpp @@ -659,9 +659,13 @@ void io_transport_udp::set_primitives() }; } } -int io_transport_udp::handle_input(const char* data, int bytes_transferred, int& /*error*/, highp_time_t&) +int io_transport_udp::handle_input(char* data, int bytes_transferred, int& /*error*/, highp_time_t&) { // pure udp, dispatch to upper layer directly - get_service().fire_event(this->cindex(), io_packet{data, data + bytes_transferred}, this); + auto& service = get_service(); + if (!service.options_.forward_packet_) + service.fire_event(this->cindex(), io_packet{data, data + bytes_transferred}, this); + else + service.forward_packet(this->cindex(), io_packet_view{data, bytes_transferred}, this); return bytes_transferred; } @@ -730,7 +734,7 @@ int io_transport_kcp::do_read(int revent, int& error, highp_time_t& wait_duratio } return n; } -int io_transport_kcp::handle_input(const char* buf, int len, int& error, highp_time_t& wait_duration) +int io_transport_kcp::handle_input(char* buf, int len, int& error, highp_time_t& wait_duration) { // ikcp in event always in service thread, so no need to lock if (0 == ::ikcp_input(kcp_, buf, len)) diff --git a/yasio/io_service.hpp b/yasio/io_service.hpp index 8deb6e21..2b55d3f0 100644 --- a/yasio/io_service.hpp +++ b/yasio/io_service.hpp @@ -840,7 +840,7 @@ class YASIO_API io_transport_udp : public io_transport { YASIO__DECL void confgure_remote(const ip::endpoint& peer); // process received data from low level - YASIO__DECL virtual int handle_input(const char* data, int bytes_transferred, int& error, highp_time_t& wait_duration); + YASIO__DECL virtual int handle_input(char* data, int bytes_transferred, int& error, highp_time_t& wait_duration); ip::endpoint peer_; // for recv only, unstable mutable ip::endpoint destination_; // for sendto only, stable @@ -861,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(const char* buf, int len, int& error, 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; }