4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <sys/select.h>
29 #include <sys/socket.h>
43 struct sockaddr_un sa;
44 char ibuf[256], obuf[256];
45 size_t ibuf_index, ibuf_length, obuf_index, obuf_length;
48 if (pa_pid_file_check_running(&pid) < 0) {
49 pa_log(__FILE__": no Polypaudio daemon running\n");
53 if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
54 pa_log(__FILE__": socket(PF_UNIX, SOCK_STREAM, 0): %s\n", strerror(errno));
58 memset(&sa, 0, sizeof(sa));
59 sa.sun_family = AF_UNIX;
60 pa_runtime_path("cli", sa.sun_path, sizeof(sa.sun_path));
62 for (i = 0; i < 5; i++) {
65 if ((r = connect(fd, (struct sockaddr*) &sa, sizeof(sa))) < 0 && (errno != ECONNREFUSED && errno != ENOENT)) {
66 pa_log(__FILE__": connect() failed: %s\n", strerror(errno));
73 if (pa_pid_file_kill(SIGUSR2, NULL) < 0) {
74 pa_log(__FILE__": failed to kill Polypaudio daemon.\n");
82 pa_log(__FILE__": daemon to responding.\n");
86 ibuf_index = ibuf_length = obuf_index = obuf_length = 0;
96 if (select(FD_SETSIZE, &ifds, &ofds, NULL, NULL) < 0) {
97 pa_log(__FILE__": select() failed: %s\n", strerror(errno));
101 if (FD_ISSET(0, &ifds)) {
103 assert(!ibuf_length);
105 if ((r = read(0, ibuf, sizeof(ibuf))) <= 0) {
109 pa_log(__FILE__": read() failed: %s\n", strerror(errno));
113 ibuf_length = (size_t) r;
117 if (FD_ISSET(fd, &ifds)) {
119 assert(!obuf_length);
121 if ((r = read(fd, obuf, sizeof(obuf))) <= 0) {
125 pa_log(__FILE__": read() failed: %s\n", strerror(errno));
129 obuf_length = (size_t) r;
133 if (FD_ISSET(1, &ofds)) {
137 if ((r = write(1, obuf + obuf_index, obuf_length)) < 0) {
138 pa_log(__FILE__": write() failed: %s\n", strerror(errno));
142 obuf_length -= (size_t) r;
143 obuf_index += obuf_index;
147 if (FD_ISSET(fd, &ofds)) {
151 if ((r = write(fd, ibuf + ibuf_index, ibuf_length)) < 0) {
152 pa_log(__FILE__": write() failed: %s\n", strerror(errno));
156 ibuf_length -= (size_t) r;
157 ibuf_index += obuf_index;
164 if (obuf_length <= 0)
169 if (ibuf_length <= 0)