summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.bin/sndiod/midi.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/usr.bin/sndiod/midi.c b/usr.bin/sndiod/midi.c
index c45024ed490..2af5dd04757 100644
--- a/usr.bin/sndiod/midi.c
+++ b/usr.bin/sndiod/midi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: midi.c,v 1.16 2017/01/03 06:53:20 ratchov Exp $ */
+/* $OpenBSD: midi.c,v 1.17 2019/03/28 11:18:56 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -238,6 +238,16 @@ midi_tickets(struct midi *iep)
int i, tickets, avail, maxavail;
struct midi *oep;
+ /*
+ * don't request iep->ops->fill() too often as it generates
+ * useless network traffic: wait until we reach half of the
+ * max tickets count. As in the worst case (see comment below)
+ * one ticket may consume two bytes, the max ticket count is
+ * BUFSZ / 2 and halt of it is simply BUFSZ / 4.
+ */
+ if (iep->tickets >= MIDI_BUFSZ / 4)
+ return;
+
maxavail = MIDI_BUFSZ;
for (i = 0; i < MIDI_NEP ; i++) {
if ((iep->txmask & (1 << i)) == 0)