ncmixer

ncurses audio mixer with cross-fade support
git clone git://git.2f30.org/ncmixer.git
Log | Files | Refs | README | LICENSE

commit f55715c7227e2ac8fe44d420bb2c7e73d426426b
parent 26775faa67ed1de5fe9e5cfa9070280d27fc9c6d
Author: sin <sin@2f30.org>
Date:   Thu Jun  2 14:10:14 +0100

Allow a maximum of one connection per socket

Diffstat:
ncmixer.c | 32+++++++++++++++++++++-----------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/ncmixer.c b/ncmixer.c @@ -203,7 +203,7 @@ loop(void) struct sockaddr_un sun; socklen_t len; struct pollfd pfd[5]; - int i, nready; + int i, clifd, nready; #define CH0_LISTEN 1 #define CH1_LISTEN 2 @@ -237,22 +237,32 @@ loop(void) if (pfd[CH0_LISTEN].revents & POLLIN) { len = sizeof(sun); - pfd[CH0_CLIENT].fd = accept(pfd[CH0_LISTEN].fd, - (SA *)&sun, &len); - if (pfd[CH0_CLIENT].fd == -1) + clifd = accept(pfd[CH0_LISTEN].fd, (SA *)&sun, &len); + if (clifd == -1) err(1, "accept"); - pfd[CH0_CLIENT].events = POLLIN; - puts("channel 0 connected"); + if (pfd[CH0_CLIENT].fd == -1) { + pfd[CH0_CLIENT].fd = clifd; + pfd[CH0_CLIENT].events = POLLIN; + puts("channel 0 connected"); + } else { + /* disallow further connections on the socket */ + close(clifd); + } } if (pfd[CH1_LISTEN].revents & POLLIN) { len = sizeof(sun); - pfd[CH1_CLIENT].fd = accept(pfd[CH1_LISTEN].fd, - (SA *)&sun, &len); - if (pfd[CH1_CLIENT].fd == -1) + clifd = accept(pfd[CH1_LISTEN].fd, (SA *)&sun, &len); + if (clifd == -1) err(1, "accept"); - pfd[CH1_CLIENT].events = POLLIN; - puts("channel 1 connected"); + if (pfd[CH1_CLIENT].fd == -1) { + pfd[CH1_CLIENT].fd = clifd; + pfd[CH1_CLIENT].events = POLLIN; + puts("channel 1 connected"); + } else { + /* disallow further connections on the socket */ + close(clifd); + } } if (pfd[CH0_CLIENT].revents & (POLLIN | POLLHUP)) {