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:
parent
87f232d990
commit
10e769735a
3 changed files with 17 additions and 3 deletions
|
@ -132,7 +132,14 @@ void SlirpNet::sendFromGuest(const uint8_t *pkt, const int pkt_len)
|
|||
|
||||
void SlirpNet::sendToGuest(const uint8_t *pkt, int pkt_len)
|
||||
{
|
||||
myQueue.emplace(pkt, pkt + pkt_len);
|
||||
if (myQueue.size() < ourQueueSize)
|
||||
{
|
||||
myQueue.emplace(pkt, pkt + pkt_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
// drop it
|
||||
}
|
||||
}
|
||||
|
||||
void SlirpNet::process(uint32_t timeout)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue