mirror of https://github.com/ericonr/sndio.git
add watchdog timeout for bogus devices
This commit is contained in:
parent
55c6148e0b
commit
ffe27f434f
|
@ -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 \
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 *);
|
||||
|
|
Loading…
Reference in New Issue