Browse Source

eliminate extra copy of vector of SSU2 packets

gha
orignal 3 months ago
parent
commit
a06cce0aaf
  1. 9
      libi2pd/SSU2.cpp
  2. 2
      libi2pd/SSU2.h
  3. 4
      libi2pd/util.h

9
libi2pd/SSU2.cpp

@ -391,7 +391,10 @@ namespace transport @@ -391,7 +391,10 @@ namespace transport
break;
}
}
GetService ().post (std::bind (&SSU2Server::HandleReceivedPackets, this, packets));
GetService ().post ([packets = std::move (packets), this]() mutable
{
HandleReceivedPackets (std::move (packets));
});
}
else
GetService ().post (std::bind (&SSU2Server::HandleReceivedPacket, this, packet));
@ -435,7 +438,7 @@ namespace transport @@ -435,7 +438,7 @@ namespace transport
}
}
void SSU2Server::HandleReceivedPackets (std::vector<Packet *> packets)
void SSU2Server::HandleReceivedPackets (std::vector<Packet *>&& packets)
{
if (m_IsThroughProxy)
for (auto& packet: packets)
@ -443,7 +446,7 @@ namespace transport @@ -443,7 +446,7 @@ namespace transport
else
for (auto& packet: packets)
ProcessNextPacket (packet->buf, packet->len, packet->from);
m_PacketsPool.ReleaseMt (packets);
m_PacketsPool.ReleaseMt (std::move (packets));
if (m_LastSession && m_LastSession->GetState () != eSSU2SessionStateTerminated)
m_LastSession->FlushData ();
}

2
libi2pd/SSU2.h

@ -126,7 +126,7 @@ namespace transport @@ -126,7 +126,7 @@ namespace transport
void HandleReceivedFrom (const boost::system::error_code& ecode, size_t bytes_transferred,
Packet * packet, boost::asio::ip::udp::socket& socket);
void HandleReceivedPacket (Packet * packet);
void HandleReceivedPackets (std::vector<Packet *> packets);
void HandleReceivedPackets (std::vector<Packet *>&& packets);
void ProcessNextPacket (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);
void ScheduleTermination ();

4
libi2pd/util.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2022, The PurpleI2P Project
* Copyright (c) 2013-2024, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -132,7 +132,7 @@ namespace util @@ -132,7 +132,7 @@ namespace util
}
template<template<typename, typename...>class C, typename... R>
void ReleaseMt(const C<T *, R...>& c)
void ReleaseMt(C<T *, R...>&& c)
{
std::lock_guard<std::mutex> l(m_Mutex);
for (auto& it: c)

Loading…
Cancel
Save