diff --git a/sndiod/Makefile.in b/sndiod/Makefile.in index ee91472..d246be5 100644 --- a/sndiod/Makefile.in +++ b/sndiod/Makefile.in @@ -55,7 +55,8 @@ sndiod: ${OBJS} abuf.o: abuf.c abuf.h utils.h dev.o: dev.c ../bsd-compat/bsd-compat.h abuf.h defs.h dev.h \ - dsp.h siofile.h midi.h miofile.h opt.h sysex.h utils.h + dsp.h siofile.h file.h midi.h miofile.h opt.h sysex.h \ + utils.h dsp.o: dsp.c dsp.h defs.h utils.h file.o: file.c file.h utils.h listen.o: listen.c listen.h file.h sock.h ../libsndio/amsg.h \ @@ -63,7 +64,8 @@ listen.o: listen.c listen.h file.h sock.h ../libsndio/amsg.h \ midi.o: midi.c abuf.h defs.h dev.h dsp.h siofile.h file.h midi.h \ miofile.h sysex.h utils.h ../bsd-compat/bsd-compat.h miofile.o: miofile.c defs.h file.h midi.h abuf.h miofile.h utils.h -opt.o: opt.c dev.h abuf.h dsp.h defs.h siofile.h opt.h utils.h +opt.o: opt.c dev.h abuf.h dsp.h defs.h siofile.h file.h opt.h \ + utils.h siofile.o: siofile.c abuf.h defs.h dev.h dsp.h siofile.h file.h \ utils.h sndiod.o: sndiod.c ../libsndio/amsg.h defs.h dev.h abuf.h dsp.h \ diff --git a/sndiod/siofile.c b/sndiod/siofile.c index 9402b2c..128414f 100644 --- a/sndiod/siofile.c +++ b/sndiod/siofile.c @@ -31,6 +31,8 @@ #include "siofile.h" #include "utils.h" +#define WATCHDOG_USEC 2000000 /* 2 seconds */ + int dev_sio_pollfd(void *, struct pollfd *); int dev_sio_revents(void *, struct pollfd *); void dev_sio_run(void *); @@ -69,6 +71,16 @@ dev_sio_onmove(void *arg, int delta) dev_onmove(d, delta); } +void +dev_sio_timeout(void *arg) +{ + struct dev *d = arg; + + dev_log(d); + log_puts(": watchdog timeout\n"); + dev_close(d); +} + /* * open the device. */ @@ -136,6 +148,7 @@ dev_sio_open(struct dev *d) d->mode &= ~MODE_REC; sio_onmove(d->sio.hdl, dev_sio_onmove, d); d->sio.file = file_new(&dev_sio_ops, d, d->path, sio_nfds(d->sio.hdl)); + timo_set(&d->sio.watchdog, dev_sio_timeout, d); return 1; bad_close: sio_close(d->sio.hdl); @@ -184,6 +197,7 @@ dev_sio_start(struct dev *d) log_puts(": started\n"); } #endif + timo_add(&d->sio.watchdog, WATCHDOG_USEC); } void @@ -206,6 +220,7 @@ dev_sio_stop(struct dev *d) log_puts("\n"); } #endif + timo_del(&d->sio.watchdog); } int @@ -315,6 +330,9 @@ dev_sio_run(void *arg) d->sio.cstate = DEV_SIO_CYCLE; break; case DEV_SIO_CYCLE: + timo_del(&d->sio.watchdog); + timo_add(&d->sio.watchdog, WATCHDOG_USEC); + #ifdef DEBUG /* * check that we're called at cycle boundary: diff --git a/sndiod/siofile.h b/sndiod/siofile.h index 258f58d..72c1200 100644 --- a/sndiod/siofile.h +++ b/sndiod/siofile.h @@ -17,6 +17,8 @@ #ifndef SIOFILE_H #define SIOFILE_H +#include "file.h" + struct dev; struct siofile_ { @@ -32,6 +34,7 @@ struct siofile_ { #define DEV_SIO_CYCLE 1 #define DEV_SIO_WRITE 2 int cstate; + struct timo watchdog; }; int dev_sio_open(struct dev *);