Skip to content

Commit fe2ca94

Browse files
committed
Retry vde_send() when it returns ENOBUFS
Same issue as virtualsquare/vde-2#35 Signed-off-by: Jan Dubois <[email protected]>
1 parent 8aeb9b3 commit fe2ca94

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

main.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <assert.h>
2+
#include <errno.h>
3+
#include <sched.h>
24
#include <setjmp.h>
35
#include <stdio.h>
46
#include <stdlib.h>
@@ -119,12 +121,20 @@ static void _on_vmnet_packets_available(interface_ref iface, int64_t buf_count,
119121
received_count, buf_count);
120122
for (int i = 0; i < received_count; i++) {
121123
DEBUGF("[Handler i=%d] Sending to VDE: %ld bytes", i, pdv[i].vm_pkt_size);
122-
ssize_t written =
124+
while (1) {
125+
ssize_t written =
123126
vde_send(vdeconn, pdv[i].vm_pkt_iov->iov_base, pdv[i].vm_pkt_size, 0);
124-
DEBUGF("[Handler i=%d] Sent to VDE: %ld bytes", i, written);
125-
if (written != (ssize_t)pdv[i].vm_pkt_size) {
126-
perror("vde_send");
127-
goto done;
127+
if (written < 0 && errno == ENOBUFS) {
128+
DEBUGF("[Handler i=%d] No buffers available, trying again", i);
129+
sched_yield();
130+
continue;
131+
}
132+
DEBUGF("[Handler i=%d] Sent to VDE: %ld bytes", i, written);
133+
if (written != (ssize_t)pdv[i].vm_pkt_size) {
134+
perror("vde_send");
135+
goto done;
136+
}
137+
break;
128138
}
129139
}
130140
done:

0 commit comments

Comments
 (0)