summaryrefslogtreecommitdiff
path: root/src/pulsecore/socket-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-10-28 19:13:50 +0000
committerLennart Poettering <lennart@poettering.net>2007-10-28 19:13:50 +0000
commita67c21f093202f142438689d3f7cfbdf4ea82eea (patch)
tree5c3295037f033904bc11ab8b3adae5b7331101e9 /src/pulsecore/socket-util.c
parent6687dd013169fd8436aa1b45ccdacff074a40d05 (diff)
downloadpulseaudio-a67c21f093202f142438689d3f7cfbdf4ea82eea.tar.gz
merge 'lennart' branch back into trunk.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pulsecore/socket-util.c')
-rw-r--r--src/pulsecore/socket-util.c118
1 files changed, 67 insertions, 51 deletions
diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c
index 673058e2a..456accb82 100644
--- a/src/pulsecore/socket-util.c
+++ b/src/pulsecore/socket-util.c
@@ -31,7 +31,6 @@
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
-#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
@@ -75,19 +74,19 @@
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
+#include <pulsecore/macro.h>
#include "socket-util.h"
void pa_socket_peer_to_string(int fd, char *c, size_t l) {
struct stat st;
- assert(c && l && fd >= 0);
+ pa_assert(fd >= 0);
+ pa_assert(c);
+ pa_assert(l > 0);
#ifndef OS_IS_WIN32
- if (fstat(fd, &st) < 0) {
- snprintf(c, l, "Invalid client fd");
- return;
- }
+ pa_assert_se(fstat(fd, &st) == 0);
#endif
#ifndef OS_IS_WIN32
@@ -108,12 +107,12 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) {
if (sa.sa.sa_family == AF_INET) {
uint32_t ip = ntohl(sa.in.sin_addr.s_addr);
- snprintf(c, l, "TCP/IP client from %i.%i.%i.%i:%u",
- ip >> 24,
- (ip >> 16) & 0xFF,
- (ip >> 8) & 0xFF,
- ip & 0xFF,
- ntohs(sa.in.sin_port));
+ pa_snprintf(c, l, "TCP/IP client from %i.%i.%i.%i:%u",
+ ip >> 24,
+ (ip >> 16) & 0xFF,
+ (ip >> 8) & 0xFF,
+ ip & 0xFF,
+ ntohs(sa.in.sin_port));
return;
} else if (sa.sa.sa_family == AF_INET6) {
char buf[INET6_ADDRSTRLEN];
@@ -121,94 +120,107 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) {
res = inet_ntop(AF_INET6, &sa.in6.sin6_addr, buf, sizeof(buf));
if (res) {
- snprintf(c, l, "TCP/IP client from [%s]:%u", buf, ntohs(sa.in6.sin6_port));
+ pa_snprintf(c, l, "TCP/IP client from [%s]:%u", buf, ntohs(sa.in6.sin6_port));
return;
}
#ifdef HAVE_SYS_UN_H
} else if (sa.sa.sa_family == AF_UNIX) {
- snprintf(c, l, "UNIX socket client");
+ pa_snprintf(c, l, "UNIX socket client");
return;
#endif
}
}
#ifndef OS_IS_WIN32
- snprintf(c, l, "Unknown network client");
+ pa_snprintf(c, l, "Unknown network client");
return;
} else if (S_ISCHR(st.st_mode) && (fd == 0 || fd == 1)) {
- snprintf(c, l, "STDIN/STDOUT client");
+ pa_snprintf(c, l, "STDIN/STDOUT client");
return;
}
#endif /* OS_IS_WIN32 */
- snprintf(c, l, "Unknown client");
+ pa_snprintf(c, l, "Unknown client");
}
-int pa_socket_low_delay(int fd) {
+void pa_make_socket_low_delay(int fd) {
+
#ifdef SO_PRIORITY
int priority;
- assert(fd >= 0);
+ pa_assert(fd >= 0);
- priority = 7;
+ priority = 6;
if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (void*)&priority, sizeof(priority)) < 0)
- return -1;
+ pa_log_warn("SO_PRIORITY failed: %s", pa_cstrerror(errno));
#endif
-
- return 0;
}
-int pa_socket_tcp_low_delay(int fd) {
- int ret, tos, on;
+void pa_make_tcp_socket_low_delay(int fd) {
+ pa_assert(fd >= 0);
- assert(fd >= 0);
-
- ret = pa_socket_low_delay(fd);
-
- on = 1;
- tos = 0;
+ pa_make_socket_low_delay(fd);
#if defined(SOL_TCP) || defined(IPPROTO_TCP)
+ {
+ int on = 1;
#if defined(SOL_TCP)
- if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (void*)&on, sizeof(on)) < 0)
+ if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (void*)&on, sizeof(on)) < 0)
#else
- if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof(on)) < 0)
+ if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof(on)) < 0)
#endif
- ret = -1;
+ pa_log_warn("TCP_NODELAY failed: %s", pa_cstrerror(errno));
+ }
#endif
-#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || \
- defined(IPPROTO_IP))
- tos = IPTOS_LOWDELAY;
+#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || defined(IPPROTO_IP))
+ {
+ int tos = IPTOS_LOWDELAY;
#ifdef SOL_IP
- if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
+ if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
#else
- if (setsockopt(fd, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
+ if (setsockopt(fd, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
#endif
- ret = -1;
+ pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
+ }
#endif
+}
- return ret;
+void pa_make_udp_socket_low_delay(int fd) {
+ pa_assert(fd >= 0);
+ pa_make_socket_low_delay(fd);
+
+#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || defined(IPPROTO_IP))
+ {
+ int tos = IPTOS_LOWDELAY;
+#ifdef SOL_IP
+ if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
+#else
+ if (setsockopt(fd, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
+#endif
+ pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
+ }
+#endif
}
int pa_socket_set_rcvbuf(int fd, size_t l) {
- assert(fd >= 0);
+ pa_assert(fd >= 0);
-/* if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void*)&l, sizeof(l)) < 0) { */
-/* pa_log("SO_RCVBUF: %s", strerror(errno)); */
-/* return -1; */
-/* } */
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void*)&l, sizeof(l)) < 0) {
+ pa_log_warn("SO_RCVBUF: %s", pa_cstrerror(errno));
+ return -1;
+ }
return 0;
}
int pa_socket_set_sndbuf(int fd, size_t l) {
- assert(fd >= 0);
+ pa_assert(fd >= 0);
-/* if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&l, sizeof(l)) < 0) { */
-/* pa_log("SO_SNDBUF: %s", strerror(errno)); */
-/* return -1; */
-/* } */
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&l, sizeof(l)) < 0) {
+ pa_log("SO_SNDBUF: %s", pa_cstrerror(errno));
+ return -1;
+ }
return 0;
}
@@ -219,6 +231,8 @@ int pa_unix_socket_is_stale(const char *fn) {
struct sockaddr_un sa;
int fd = -1, ret = -1;
+ pa_assert(fn);
+
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
pa_log("socket(): %s", pa_cstrerror(errno));
goto finish;
@@ -244,6 +258,8 @@ finish:
int pa_unix_socket_remove_stale(const char *fn) {
int r;
+ pa_assert(fn);
+
if ((r = pa_unix_socket_is_stale(fn)) < 0)
return errno != ENOENT ? -1 : 0;