From fa9d943c69346b5bebda615c93bc350843c258b8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 3 Sep 2008 02:58:35 +0200 Subject: Split out O_NONBLOCK setting into seperate function Since we set O_NONBLOCK more than once, make it a nice and correct function. --- pulse/pulse.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'pulse') diff --git a/pulse/pulse.c b/pulse/pulse.c index 9bd1d10..f91d0e7 100644 --- a/pulse/pulse.c +++ b/pulse/pulse.c @@ -148,6 +148,18 @@ static void context_state_cb(pa_context * c, void *userdata) } } +static int make_nonblock(int fd) { + int fl; + + if ((fl = fcntl(fd, F_GETFL)) < 0) + return fl; + + if (fl & O_NONBLOCK) + return 0; + + return fcntl(fd, F_SETFL, fl | O_NONBLOCK); +} + snd_pulse_t *pulse_new(void) { snd_pulse_t *p; @@ -169,8 +181,8 @@ snd_pulse_t *pulse_new(void) p->main_fd = fd[0]; p->thread_fd = fd[1]; - fcntl(fd[0], F_SETFL, O_NONBLOCK); - fcntl(fd[1], F_SETFL, O_NONBLOCK); + make_nonblock(p->main_fd); + make_nonblock(p->thread_fd); p->mainloop = pa_threaded_mainloop_new(); if (!p->mainloop) -- cgit