U2: drop packets from libslirp if the queue is full (we keep at most 10).

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2021-05-09 19:49:18 +01:00
parent 87f232d990
commit 10e769735a
3 changed files with 17 additions and 3 deletions

View file

@ -131,9 +131,16 @@ void SlirpNet::sendFromGuest(const uint8_t *pkt, const int pkt_len)
}
void SlirpNet::sendToGuest(const uint8_t *pkt, int pkt_len)
{
if (myQueue.size() < ourQueueSize)
{
myQueue.emplace(pkt, pkt + pkt_len);
}
else
{
// drop it
}
}
void SlirpNet::process(uint32_t timeout)
{

View file

@ -21,6 +21,9 @@ public:
std::queue<std::vector<uint8_t>> & getQueue();
void clearQueue();
private:
static constexpr size_t ourQueueSize = 10;
std::shared_ptr<Slirp> mySlirp;
std::vector<pollfd> myFDs;

View file

@ -355,7 +355,7 @@ namespace
#ifdef U2_USE_SLIRP
{
std::queue<std::vector<uint8_t>> & queue = slirp->getQueue();
if (!queue.empty())
while (!queue.empty())
{
const std::vector<uint8_t> & packet = queue.front();
if (isThereRoomFor(i, packet.size(), sizeof(uint16_t)))
@ -366,6 +366,10 @@ namespace
LogFileOutput("U2: READ MACRAW[%d]: +%d -> %d bytes (%04x)\n", i, packet.size(), socket.sn_rx_rsr, socket.sn_rx_wr);
#endif
}
else
{
break;
}
}
}
#else
@ -383,7 +387,7 @@ namespace
}
else
{
// ??? we just skip it
// drop it
#ifdef U2_LOG_TRAFFIC
LogFileOutput("U2: SKIP MACRAW[%d]: %d bytes\n", i, len);
#endif