diff --git a/libsndio/aucat.c b/libsndio/aucat.c index dd5d2a4..8ceec03 100644 --- a/libsndio/aucat.c +++ b/libsndio/aucat.c @@ -323,6 +323,17 @@ aucat_close(struct aucat *hdl, int eof) ; /* nothing */ } +int +aucat_setfl(struct aucat *hdl, int nbio, int *eof) +{ + if (fcntl(hdl->fd, F_SETFL, nbio ? O_NONBLOCK : 0) < 0) { + DPERROR("aucat_setfl: fcntl"); + *eof = 1; + return 0; + } + return 1; +} + int aucat_pollfd(struct aucat *hdl, struct pollfd *pfd, int events) { diff --git a/libsndio/aucat.h b/libsndio/aucat.h index 66b0d4f..aef23e0 100644 --- a/libsndio/aucat.h +++ b/libsndio/aucat.h @@ -24,5 +24,6 @@ int aucat_open(struct aucat *, const char *, char *, unsigned, int); void aucat_close(struct aucat *, int); int aucat_pollfd(struct aucat *, struct pollfd *, int); int aucat_revents(struct aucat *, struct pollfd *); +int aucat_setfl(struct aucat *, int, int *); #endif /* !defined(AUCAT_H) */ diff --git a/libsndio/sio_aucat.c b/libsndio/sio_aucat.c index ca15269..a6787d8 100644 --- a/libsndio/sio_aucat.c +++ b/libsndio/sio_aucat.c @@ -42,7 +42,7 @@ struct sio_aucat_hdl { unsigned curvol, reqvol; /* current and requested volume */ int delta; /* some of received deltas */ #define PSTATE_INIT 0 -#define RSTATE_UN 1 +#define PSTATE_RUN 1 int pstate; }; @@ -194,12 +194,9 @@ sio_aucat_start(struct sio_hdl *sh) return 0; hdl->aucat.rstate = RSTATE_MSG; hdl->aucat.rtodo = sizeof(struct amsg); - if (fcntl(hdl->aucat.fd, F_SETFL, O_NONBLOCK) < 0) { - DPERROR("sio_aucat_start: fcntl(0)"); - hdl->sio.eof = 1; + if (!aucat_setfl(&hdl->aucat, 1, &hdl->sio.eof)) return 0; - } - hdl->pstate = RSTATE_UN; + hdl->pstate = PSTATE_RUN; return 1; } @@ -211,12 +208,8 @@ sio_aucat_stop(struct sio_hdl *sh) struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh; unsigned n, count; - if (fcntl(hdl->aucat.fd, F_SETFL, 0) < 0) { - DPERROR("sio_aucat_stop: fcntl(0)"); - hdl->sio.eof = 1; + if (!aucat_setfl(&hdl->aucat, 0, &hdl->sio.eof)) return 0; - } - /* * complete message or data block in progress */