Skip to content

Commit

Permalink
Fix pure udp not handle packet forward
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Feb 1, 2024
1 parent fcafc35 commit d79fa4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions yasio/io_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions yasio/io_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; }

Expand Down

0 comments on commit d79fa4f

Please sign in to comment.