=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sndiod/miofile.c,v retrieving revision 1.4 retrieving revision 1.5 diff -c -r1.4 -r1.5 *** src/usr.bin/sndiod/miofile.c 2015/12/20 11:38:33 1.4 --- src/usr.bin/sndiod/miofile.c 2019/09/21 04:42:46 1.5 *************** *** 1,4 **** ! /* $OpenBSD: miofile.c,v 1.4 2015/12/20 11:38:33 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * --- 1,4 ---- ! /* $OpenBSD: miofile.c,v 1.5 2019/09/21 04:42:46 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * *************** *** 51,60 **** p->mio.hdl = fdpass_mio_open(p->num, p->midi->mode); if (p->mio.hdl == NULL) return 0; ! p->mio.file = file_new(&port_mio_ops, p, p->path, mio_nfds(p->mio.hdl)); return 1; } void port_mio_close(struct port *p) { --- 51,87 ---- p->mio.hdl = fdpass_mio_open(p->num, p->midi->mode); if (p->mio.hdl == NULL) return 0; ! p->mio.file = file_new(&port_mio_ops, p, "port", mio_nfds(p->mio.hdl)); return 1; } + /* + * Open an alternate port. Upon success, close the old port + * and continue using the new one. + */ + int + port_mio_reopen(struct port *p) + { + struct mio_hdl *hdl; + + hdl = fdpass_mio_open(p->num, p->midi->mode); + if (hdl == NULL) { + if (log_level >= 1) { + port_log(p); + log_puts(": couldn't open an alternate port\n"); + } + return 0; + } + + /* close unused device */ + file_del(p->mio.file); + mio_close(p->mio.hdl); + + p->mio.hdl = hdl; + p->mio.file = file_new(&port_mio_ops, p, "port", mio_nfds(hdl)); + return 1; + } + void port_mio_close(struct port *p) { *************** *** 129,133 **** { struct port *p = arg; ! port_close(p); } --- 156,161 ---- { struct port *p = arg; ! if (!port_reopen(p)) ! port_close(p); }