Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #31 from lima-vm/no-buffer-available
Browse files Browse the repository at this point in the history
Retry vde_send() when it returns ENOBUFS
  • Loading branch information
jandubois authored Dec 8, 2021
2 parents 8aeb9b3 + fe2ca94 commit b5be24f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <assert.h>
#include <errno.h>
#include <sched.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -119,12 +121,20 @@ static void _on_vmnet_packets_available(interface_ref iface, int64_t buf_count,
received_count, buf_count);
for (int i = 0; i < received_count; i++) {
DEBUGF("[Handler i=%d] Sending to VDE: %ld bytes", i, pdv[i].vm_pkt_size);
ssize_t written =
while (1) {
ssize_t written =
vde_send(vdeconn, pdv[i].vm_pkt_iov->iov_base, pdv[i].vm_pkt_size, 0);
DEBUGF("[Handler i=%d] Sent to VDE: %ld bytes", i, written);
if (written != (ssize_t)pdv[i].vm_pkt_size) {
perror("vde_send");
goto done;
if (written < 0 && errno == ENOBUFS) {
DEBUGF("[Handler i=%d] No buffers available, trying again", i);
sched_yield();
continue;
}
DEBUGF("[Handler i=%d] Sent to VDE: %ld bytes", i, written);
if (written != (ssize_t)pdv[i].vm_pkt_size) {
perror("vde_send");
goto done;
}
break;
}
}
done:
Expand Down

0 comments on commit b5be24f

Please sign in to comment.