diff options
-rw-r--r-- | usr.bin/sndiod/midi.c | 27 | ||||
-rw-r--r-- | usr.bin/sndiod/midi.h | 3 | ||||
-rw-r--r-- | usr.bin/sndiod/miofile.c | 4 |
3 files changed, 27 insertions, 7 deletions
diff --git a/usr.bin/sndiod/midi.c b/usr.bin/sndiod/midi.c index a30402abec3..cdb5800e7d9 100644 --- a/usr.bin/sndiod/midi.c +++ b/usr.bin/sndiod/midi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.c,v 1.4 2012/11/30 21:04:35 ratchov Exp $ */ +/* $OpenBSD: midi.c,v 1.5 2012/11/30 22:26:34 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -518,7 +518,7 @@ port_unref(struct port *c) for (rxmask = 0, i = 0; i < MIDI_NEP; i++) rxmask |= midi_ep[i].txmask; if ((rxmask & c->midi->self) == 0 && c->state == PORT_INIT && !c->hold) - port_close(c); + port_drain(c); } struct port * @@ -571,6 +571,24 @@ port_close(struct port *c) return 1; } +void +port_drain(struct port *c) +{ + struct midi *ep = c->midi; + + if (!(ep->mode & MODE_MIDIOUT) || ep->obuf.used == 0) + port_close(c); + else { + c->state = PORT_DRAIN; +#ifdef DEBUG + if (log_level >= 3) { + port_log(c); + log_puts(": draining\n"); + } +#endif + } +} + int port_init(struct port *c) { @@ -582,7 +600,6 @@ port_init(struct port *c) void port_done(struct port *c) { - /* XXX: drain? */ - if (c->state != PORT_CFG) - port_close(c); + if (c->state == PORT_INIT) + port_drain(c); } diff --git a/usr.bin/sndiod/midi.h b/usr.bin/sndiod/midi.h index 35b678f8065..3e1aaeb6ff8 100644 --- a/usr.bin/sndiod/midi.h +++ b/usr.bin/sndiod/midi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.h,v 1.4 2012/11/30 21:04:35 ratchov Exp $ */ +/* $OpenBSD: midi.h,v 1.5 2012/11/30 22:26:34 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -117,6 +117,7 @@ int port_ref(struct port *); void port_unref(struct port *); int port_init(struct port *); void port_done(struct port *); +void port_drain(struct port *); int port_close(struct port *); #endif /* !defined(MIDI_H) */ diff --git a/usr.bin/sndiod/miofile.c b/usr.bin/sndiod/miofile.c index ac56d0d0a0a..4f4da5881fa 100644 --- a/usr.bin/sndiod/miofile.c +++ b/usr.bin/sndiod/miofile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: miofile.c,v 1.2 2012/11/30 20:30:24 ratchov Exp $ */ +/* $OpenBSD: miofile.c,v 1.3 2012/11/30 22:26:34 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -118,6 +118,8 @@ port_mio_out(void *arg) if (n < count) break; } + if (p->state == PORT_DRAIN && ep->obuf.used == 0) + port_close(p); midi_fill(ep); } |