summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/socket-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pulsecore/socket-server.c')
-rw-r--r--src/pulsecore/socket-server.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/pulsecore/socket-server.c b/src/pulsecore/socket-server.c
index 4d69b8a4..c878ab1a 100644
--- a/src/pulsecore/socket-server.c
+++ b/src/pulsecore/socket-server.c
@@ -2,17 +2,17 @@
/***
This file is part of PulseAudio.
-
+
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
-
+
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -94,14 +94,14 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
assert(s && s->mainloop == mainloop && s->io_event == e && e && fd >= 0 && fd == s->fd);
pa_socket_server_ref(s);
-
+
if ((nfd = accept(fd, NULL, NULL)) < 0) {
pa_log("accept(): %s", pa_cstrerror(errno));
goto finish;
}
pa_fd_set_cloexec(nfd, 1);
-
+
if (!s->on_connection) {
close(nfd);
goto finish;
@@ -123,13 +123,13 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
pa_log_info("TCP connection accepted by tcpwrap.");
}
#endif
-
+
/* There should be a check for socket type here */
- if (s->type == SOCKET_SERVER_IPV4)
+ if (s->type == SOCKET_SERVER_IPV4)
pa_socket_tcp_low_delay(fd);
else
pa_socket_low_delay(fd);
-
+
io = pa_iochannel_new(s->mainloop, nfd, nfd);
assert(io);
s->on_connection(s, io, s->userdata);
@@ -141,7 +141,7 @@ finish:
pa_socket_server* pa_socket_server_new(pa_mainloop_api *m, int fd) {
pa_socket_server *s;
assert(m && fd >= 0);
-
+
s = pa_xmalloc(sizeof(pa_socket_server));
s->ref = 1;
s->fd = fd;
@@ -155,7 +155,7 @@ pa_socket_server* pa_socket_server_new(pa_mainloop_api *m, int fd) {
assert(s->io_event);
s->type = SOCKET_SERVER_GENERIC;
-
+
return s;
}
@@ -171,7 +171,7 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
int fd = -1;
struct sockaddr_un sa;
pa_socket_server *s;
-
+
assert(m && filename);
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
@@ -197,7 +197,7 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
* because not all OS check the access rights on the socket
* inodes. */
chmod(filename, 0777);
-
+
if (listen(fd, 5) < 0) {
pa_log("listen(): %s", pa_cstrerror(errno));
goto fail;
@@ -208,9 +208,9 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
s->filename = pa_xstrdup(filename);
s->type = SOCKET_SERVER_UNIX;
-
+
return s;
-
+
fail:
if (fd >= 0)
close(fd);
@@ -247,7 +247,7 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
#endif
pa_socket_tcp_low_delay(fd);
-
+
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
@@ -269,7 +269,7 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
}
return ss;
-
+
fail:
if (fd >= 0)
close(fd);
@@ -323,9 +323,9 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
ss->type = SOCKET_SERVER_IPV6;
ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
}
-
+
return ss;
-
+
fail:
if (fd >= 0)
close(fd);
@@ -350,20 +350,20 @@ pa_socket_server* pa_socket_server_new_ipv6_loopback(pa_mainloop_api *m, uint16_
pa_socket_server* pa_socket_server_new_ipv4_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
assert(m);
assert(port > 0);
-
+
return pa_socket_server_new_ipv4(m, INADDR_ANY, port, tcpwrap_service);
}
pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
assert(m);
assert(port > 0);
-
+
return pa_socket_server_new_ipv6(m, in6addr_any.s6_addr, port, tcpwrap_service);
}
pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
struct in_addr ipv4;
-
+
assert(m);
assert(name);
assert(port > 0);
@@ -376,7 +376,7 @@ pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const cha
pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
struct in6_addr ipv6;
-
+
assert(m);
assert(name);
assert(port > 0);
@@ -419,7 +419,7 @@ void pa_socket_server_set_callback(pa_socket_server*s, void (*on_connection)(pa_
char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
assert(s && c && l > 0);
-
+
switch (s->type) {
case SOCKET_SERVER_IPV6: {
struct sockaddr_in6 sa;
@@ -434,23 +434,23 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
char fqdn[256];
if (!pa_get_fqdn(fqdn, sizeof(fqdn)))
return NULL;
-
+
snprintf(c, l, "tcp6:%s:%u", fqdn, (unsigned) ntohs(sa.sin6_port));
-
+
} else if (memcmp(&in6addr_loopback, &sa.sin6_addr, sizeof(in6addr_loopback)) == 0) {
char hn[256];
if (!pa_get_host_name(hn, sizeof(hn)))
return NULL;
-
+
snprintf(c, l, "{%s}tcp6:localhost:%u", hn, (unsigned) ntohs(sa.sin6_port));
} else {
char ip[INET6_ADDRSTRLEN];
-
+
if (!inet_ntop(AF_INET6, &sa.sin6_addr, ip, sizeof(ip))) {
pa_log("inet_ntop(): %s", pa_cstrerror(errno));
return NULL;
}
-
+
snprintf(c, l, "tcp6:[%s]:%u", ip, (unsigned) ntohs(sa.sin6_port));
}
@@ -470,13 +470,13 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
char fqdn[256];
if (!pa_get_fqdn(fqdn, sizeof(fqdn)))
return NULL;
-
+
snprintf(c, l, "tcp:%s:%u", fqdn, (unsigned) ntohs(sa.sin_port));
} else if (sa.sin_addr.s_addr == INADDR_LOOPBACK) {
char hn[256];
if (!pa_get_host_name(hn, sizeof(hn)))
return NULL;
-
+
snprintf(c, l, "{%s}tcp:localhost:%u", hn, (unsigned) ntohs(sa.sin_port));
} else {
char ip[INET_ADDRSTRLEN];
@@ -485,11 +485,11 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
pa_log("inet_ntop(): %s", pa_cstrerror(errno));
return NULL;
}
-
+
snprintf(c, l, "tcp:[%s]:%u", ip, (unsigned) ntohs(sa.sin_port));
}
-
+
return c;
}
@@ -498,7 +498,7 @@ char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
if (!s->filename)
return NULL;
-
+
if (!pa_get_host_name(hn, sizeof(hn)))
return NULL;