mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-06 13:29:56 -05:00
make O_CLOEXEC, O_NONBLOCK and socket low latency fd ops more uniform: always return void, name them similarly, only pass a single fd
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1867 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
0fcad97782
commit
75f799a3d8
16 changed files with 105 additions and 123 deletions
|
|
@ -184,10 +184,10 @@ int pa_cpu_limit_init(pa_mainloop_api *m) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_make_nonblock_fd(the_pipe[0]);
|
pa_make_fd_nonblock(the_pipe[0]);
|
||||||
pa_make_nonblock_fd(the_pipe[1]);
|
pa_make_fd_nonblock(the_pipe[1]);
|
||||||
pa_fd_set_cloexec(the_pipe[0], 1);
|
pa_make_fd_cloexec(the_pipe[0]);
|
||||||
pa_fd_set_cloexec(the_pipe[1], 1);
|
pa_make_fd_cloexec(the_pipe[1]);
|
||||||
|
|
||||||
api = m;
|
api = m;
|
||||||
io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL);
|
io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL);
|
||||||
|
|
|
||||||
|
|
@ -236,8 +236,8 @@ int pa__init(pa_module*m) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(u->fd, 1);
|
pa_make_fd_cloexec(u->fd);
|
||||||
pa_make_nonblock_fd(u->fd);
|
pa_make_fd_nonblock(u->fd);
|
||||||
|
|
||||||
if (fstat(u->fd, &st) < 0) {
|
if (fstat(u->fd, &st) < 0) {
|
||||||
pa_log("fstat('%s'): %s", u->filename, pa_cstrerror(errno));
|
pa_log("fstat('%s'): %s", u->filename, pa_cstrerror(errno));
|
||||||
|
|
|
||||||
|
|
@ -214,8 +214,8 @@ int pa__init(pa_module*m) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(u->fd, 1);
|
pa_make_fd_cloexec(u->fd);
|
||||||
pa_make_nonblock_fd(u->fd);
|
pa_make_fd_nonblock(u->fd);
|
||||||
|
|
||||||
if (fstat(u->fd, &st) < 0) {
|
if (fstat(u->fd, &st) < 0) {
|
||||||
pa_log("fstat('%s'): %s",u->filename, pa_cstrerror(errno));
|
pa_log("fstat('%s'): %s",u->filename, pa_cstrerror(errno));
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ success:
|
||||||
#endif
|
#endif
|
||||||
*pcaps & DSP_CAP_TRIGGER ? " TRIGGER" : "");
|
*pcaps & DSP_CAP_TRIGGER ? " TRIGGER" : "");
|
||||||
|
|
||||||
pa_fd_set_cloexec(fd, 1);
|
pa_make_fd_cloexec(fd);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -280,8 +280,10 @@ int pa__init(pa_module*m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the socket queue is full, let's drop packets */
|
/* If the socket queue is full, let's drop packets */
|
||||||
pa_make_nonblock_fd(fd);
|
pa_make_fd_nonblock(fd);
|
||||||
pa_socket_udp_low_delay(fd);
|
pa_make_udp_socket_low_delay(fd);
|
||||||
|
pa_make_fd_cloexec(fd);
|
||||||
|
pa_make_fd_cloexec(sap_fd);
|
||||||
|
|
||||||
pa_source_output_new_data_init(&data);
|
pa_source_output_new_data_init(&data);
|
||||||
data.name = "RTP Monitor Stream";
|
data.name = "RTP Monitor Stream";
|
||||||
|
|
|
||||||
|
|
@ -498,10 +498,10 @@ static int context_connect_spawn(pa_context *c) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(fds[0], 1);
|
pa_make_fd_cloexec(fds[0]);
|
||||||
|
|
||||||
pa_socket_low_delay(fds[0]);
|
pa_make_socket_low_delay(fds[0]);
|
||||||
pa_socket_low_delay(fds[1]);
|
pa_make_socket_low_delay(fds[1]);
|
||||||
|
|
||||||
if (c->spawn_api.prefork)
|
if (c->spawn_api.prefork)
|
||||||
c->spawn_api.prefork();
|
c->spawn_api.prefork();
|
||||||
|
|
|
||||||
|
|
@ -123,10 +123,10 @@ int pa_signal_init(pa_mainloop_api *a) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_make_nonblock_fd(signal_pipe[0]);
|
pa_make_fd_nonblock(signal_pipe[0]);
|
||||||
pa_make_nonblock_fd(signal_pipe[1]);
|
pa_make_fd_nonblock(signal_pipe[1]);
|
||||||
pa_assert_se(pa_fd_set_cloexec(signal_pipe[0], 1) == 0);
|
pa_make_fd_cloexec(signal_pipe[0]);
|
||||||
pa_assert_se(pa_fd_set_cloexec(signal_pipe[1], 1) == 0);
|
pa_make_fd_cloexec(signal_pipe[1]);
|
||||||
|
|
||||||
api = a;
|
api = a;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -457,10 +457,10 @@ pa_mainloop *pa_mainloop_new(void) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_make_nonblock_fd(m->wakeup_pipe[0]);
|
pa_make_fd_nonblock(m->wakeup_pipe[0]);
|
||||||
pa_make_nonblock_fd(m->wakeup_pipe[1]);
|
pa_make_fd_nonblock(m->wakeup_pipe[1]);
|
||||||
pa_fd_set_cloexec(m->wakeup_pipe[0], 1);
|
pa_make_fd_cloexec(m->wakeup_pipe[0]);
|
||||||
pa_fd_set_cloexec(m->wakeup_pipe[1], 1);
|
pa_make_fd_cloexec(m->wakeup_pipe[1]);
|
||||||
m->wakeup_requested = 0;
|
m->wakeup_requested = 0;
|
||||||
|
|
||||||
PA_LLIST_HEAD_INIT(pa_io_event, m->io_events);
|
PA_LLIST_HEAD_INIT(pa_io_event, m->io_events);
|
||||||
|
|
|
||||||
|
|
@ -134,23 +134,42 @@ int pa_set_root(HANDLE handle) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Make a file descriptor nonblock. Doesn't do any error checking */
|
/** Make a file descriptor nonblock. Doesn't do any error checking */
|
||||||
void pa_make_nonblock_fd(int fd) {
|
void pa_make_fd_nonblock(int fd) {
|
||||||
|
|
||||||
#ifdef O_NONBLOCK
|
#ifdef O_NONBLOCK
|
||||||
int v;
|
int v;
|
||||||
pa_assert(fd >= 0);
|
pa_assert(fd >= 0);
|
||||||
|
|
||||||
if ((v = fcntl(fd, F_GETFL)) >= 0)
|
pa_assert_se((v = fcntl(fd, F_GETFL)) >= 0);
|
||||||
if (!(v & O_NONBLOCK))
|
|
||||||
fcntl(fd, F_SETFL, v|O_NONBLOCK);
|
if (!(v & O_NONBLOCK))
|
||||||
|
pa_assert_se(fcntl(fd, F_SETFL, v|O_NONBLOCK) >= 0);
|
||||||
|
|
||||||
#elif defined(OS_IS_WIN32)
|
#elif defined(OS_IS_WIN32)
|
||||||
u_long arg = 1;
|
u_long arg = 1;
|
||||||
if (ioctlsocket(fd, FIONBIO, &arg) < 0) {
|
if (ioctlsocket(fd, FIONBIO, &arg) < 0) {
|
||||||
if (WSAGetLastError() == WSAENOTSOCK)
|
pa_assert_se(WSAGetLastError() == WSAENOTSOCK);
|
||||||
pa_log_warn("Only sockets can be made non-blocking!");
|
pa_log_warn("Only sockets can be made non-blocking!");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
pa_log_warn("Non-blocking I/O not supported.!");
|
pa_log_warn("Non-blocking I/O not supported.!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the FD_CLOEXEC flag for a fd */
|
||||||
|
void pa_make_fd_cloexec(int fd) {
|
||||||
|
|
||||||
|
#ifdef FD_CLOEXEC
|
||||||
|
int v;
|
||||||
|
pa_assert(fd >= 0);
|
||||||
|
|
||||||
|
pa_assert_se((v = fcntl(fd, F_GETFD, 0)) >= 0);
|
||||||
|
|
||||||
|
if (!(v & FD_CLOEXEC))
|
||||||
|
pa_assert_se(fcntl(fd, F_SETFD, v|FD_CLOEXEC) >= 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a directory securely */
|
/** Creates a directory securely */
|
||||||
|
|
@ -552,25 +571,6 @@ void pa_reset_priority(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the FD_CLOEXEC flag for a fd */
|
|
||||||
int pa_fd_set_cloexec(int fd, int b) {
|
|
||||||
|
|
||||||
#ifdef FD_CLOEXEC
|
|
||||||
int v;
|
|
||||||
pa_assert(fd >= 0);
|
|
||||||
|
|
||||||
if ((v = fcntl(fd, F_GETFD, 0)) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
v = (v & ~FD_CLOEXEC) | (b ? FD_CLOEXEC : 0);
|
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFD, v) < 0)
|
|
||||||
return -1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Try to parse a boolean string value.*/
|
/* Try to parse a boolean string value.*/
|
||||||
int pa_parse_boolean(const char *v) {
|
int pa_parse_boolean(const char *v) {
|
||||||
|
|
||||||
|
|
@ -629,12 +629,12 @@ const char *pa_sig2str(int sig) {
|
||||||
|
|
||||||
if (sig <= 0)
|
if (sig <= 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
#ifdef NSIG
|
#ifdef NSIG
|
||||||
if (sig >= NSIG)
|
if (sig >= NSIG)
|
||||||
goto fail;
|
goto fail;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SIG2STR
|
#ifdef HAVE_SIG2STR
|
||||||
{
|
{
|
||||||
char buf[SIG2STR_MAX];
|
char buf[SIG2STR_MAX];
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@
|
||||||
|
|
||||||
struct timeval;
|
struct timeval;
|
||||||
|
|
||||||
void pa_make_nonblock_fd(int fd);
|
void pa_make_fd_nonblock(int fd);
|
||||||
|
void pa_make_fd_cloexec(int fd);
|
||||||
|
|
||||||
int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid);
|
int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid);
|
||||||
int pa_make_secure_parent_dir(const char *fn, mode_t, uid_t uid, gid_t gid);
|
int pa_make_secure_parent_dir(const char *fn, mode_t, uid_t uid, gid_t gid);
|
||||||
|
|
@ -59,8 +60,6 @@ void pa_make_realtime(void);
|
||||||
void pa_raise_priority(void);
|
void pa_raise_priority(void);
|
||||||
void pa_reset_priority(void);
|
void pa_reset_priority(void);
|
||||||
|
|
||||||
int pa_fd_set_cloexec(int fd, int b);
|
|
||||||
|
|
||||||
int pa_parse_boolean(const char *s) PA_GCC_PURE;
|
int pa_parse_boolean(const char *s) PA_GCC_PURE;
|
||||||
|
|
||||||
char *pa_split(const char *c, const char*delimiters, const char **state);
|
char *pa_split(const char *c, const char*delimiters, const char **state);
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,8 @@ pa_fdsem *pa_fdsem_new(void) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(f->fds[0], 1);
|
pa_make_fd_cloexec(f->fds[0]);
|
||||||
pa_fd_set_cloexec(f->fds[1], 1);
|
pa_make_fd_cloexec(f->fds[1]);
|
||||||
|
|
||||||
pa_atomic_store(&f->waiting, 0);
|
pa_atomic_store(&f->waiting, 0);
|
||||||
pa_atomic_store(&f->signalled, 0);
|
pa_atomic_store(&f->signalled, 0);
|
||||||
|
|
|
||||||
|
|
@ -145,17 +145,17 @@ pa_iochannel* pa_iochannel_new(pa_mainloop_api*m, int ifd, int ofd) {
|
||||||
|
|
||||||
if (ifd == ofd) {
|
if (ifd == ofd) {
|
||||||
pa_assert(ifd >= 0);
|
pa_assert(ifd >= 0);
|
||||||
pa_make_nonblock_fd(io->ifd);
|
pa_make_fd_nonblock(io->ifd);
|
||||||
io->input_event = io->output_event = m->io_new(m, ifd, PA_IO_EVENT_INPUT|PA_IO_EVENT_OUTPUT, callback, io);
|
io->input_event = io->output_event = m->io_new(m, ifd, PA_IO_EVENT_INPUT|PA_IO_EVENT_OUTPUT, callback, io);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (ifd >= 0) {
|
if (ifd >= 0) {
|
||||||
pa_make_nonblock_fd(io->ifd);
|
pa_make_fd_nonblock(io->ifd);
|
||||||
io->input_event = m->io_new(m, ifd, PA_IO_EVENT_INPUT, callback, io);
|
io->input_event = m->io_new(m, ifd, PA_IO_EVENT_INPUT, callback, io);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ofd >= 0) {
|
if (ofd >= 0) {
|
||||||
pa_make_nonblock_fd(io->ofd);
|
pa_make_fd_nonblock(io->ofd);
|
||||||
io->output_event = m->io_new(m, ofd, PA_IO_EVENT_OUTPUT, callback, io);
|
io->output_event = m->io_new(m, ofd, PA_IO_EVENT_OUTPUT, callback, io);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ static int do_connect(pa_socket_client *c, const struct sockaddr *sa, socklen_t
|
||||||
pa_assert(sa);
|
pa_assert(sa);
|
||||||
pa_assert(len > 0);
|
pa_assert(len > 0);
|
||||||
|
|
||||||
pa_make_nonblock_fd(c->fd);
|
pa_make_fd_nonblock(c->fd);
|
||||||
|
|
||||||
if ((r = connect(c->fd, sa, len)) < 0) {
|
if ((r = connect(c->fd, sa, len)) < 0) {
|
||||||
#ifdef OS_IS_WIN32
|
#ifdef OS_IS_WIN32
|
||||||
|
|
@ -293,11 +293,11 @@ static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(c->fd, 1);
|
pa_make_fd_cloexec(c->fd);
|
||||||
if (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)
|
if (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)
|
||||||
pa_socket_tcp_low_delay(c->fd);
|
pa_make_tcp_socket_low_delay(c->fd);
|
||||||
else
|
else
|
||||||
pa_socket_low_delay(c->fd);
|
pa_make_socket_low_delay(c->fd);
|
||||||
|
|
||||||
if (do_connect(c, sa, salen) < 0)
|
if (do_connect(c, sa, salen) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(nfd, 1);
|
pa_make_fd_cloexec(nfd);
|
||||||
|
|
||||||
if (!s->on_connection) {
|
if (!s->on_connection) {
|
||||||
pa_close(nfd);
|
pa_close(nfd);
|
||||||
|
|
@ -137,9 +137,9 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
|
||||||
|
|
||||||
/* There should be a check for socket type here */
|
/* 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);
|
pa_make_tcp_socket_low_delay(fd);
|
||||||
else
|
else
|
||||||
pa_socket_low_delay(fd);
|
pa_make_socket_low_delay(fd);
|
||||||
|
|
||||||
pa_assert_se(io = pa_iochannel_new(s->mainloop, nfd, nfd));
|
pa_assert_se(io = pa_iochannel_new(s->mainloop, nfd, nfd));
|
||||||
s->on_connection(s, io, s->userdata);
|
s->on_connection(s, io, s->userdata);
|
||||||
|
|
@ -193,13 +193,13 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(fd, 1);
|
pa_make_fd_cloexec(fd);
|
||||||
|
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
|
strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
|
||||||
sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
|
sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
|
||||||
|
|
||||||
pa_socket_low_delay(fd);
|
pa_make_socket_low_delay(fd);
|
||||||
|
|
||||||
if (bind(fd, (struct sockaddr*) &sa, SUN_LEN(&sa)) < 0) {
|
if (bind(fd, (struct sockaddr*) &sa, SUN_LEN(&sa)) < 0) {
|
||||||
pa_log("bind(): %s", pa_cstrerror(errno));
|
pa_log("bind(): %s", pa_cstrerror(errno));
|
||||||
|
|
@ -253,14 +253,14 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(fd, 1);
|
pa_make_fd_cloexec(fd);
|
||||||
|
|
||||||
#ifdef SO_REUSEADDR
|
#ifdef SO_REUSEADDR
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
|
||||||
pa_log("setsockopt(): %s", pa_cstrerror(errno));
|
pa_log("setsockopt(): %s", pa_cstrerror(errno));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pa_socket_tcp_low_delay(fd);
|
pa_make_tcp_socket_low_delay(fd);
|
||||||
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sin_family = AF_INET;
|
sa.sin_family = AF_INET;
|
||||||
|
|
@ -305,7 +305,7 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_fd_set_cloexec(fd, 1);
|
pa_make_fd_cloexec(fd);
|
||||||
|
|
||||||
#ifdef IPV6_V6ONLY
|
#ifdef IPV6_V6ONLY
|
||||||
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0)
|
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0)
|
||||||
|
|
@ -317,7 +317,7 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
|
||||||
pa_log("setsockopt(SOL_SOCKET, SO_REUSEADDR, 1): %s", pa_cstrerror(errno));
|
pa_log("setsockopt(SOL_SOCKET, SO_REUSEADDR, 1): %s", pa_cstrerror(errno));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pa_socket_tcp_low_delay(fd);
|
pa_make_tcp_socket_low_delay(fd);
|
||||||
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sin6_family = AF_INET6;
|
sa.sin6_family = AF_INET6;
|
||||||
|
|
|
||||||
|
|
@ -143,83 +143,64 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) {
|
||||||
pa_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
|
#ifdef SO_PRIORITY
|
||||||
int priority;
|
int priority;
|
||||||
pa_assert(fd >= 0);
|
pa_assert(fd >= 0);
|
||||||
|
|
||||||
priority = 6;
|
priority = 6;
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (void*)&priority, sizeof(priority)) < 0) {
|
if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (void*)&priority, sizeof(priority)) < 0)
|
||||||
pa_log_warn("SO_PRIORITY failed: %s", pa_cstrerror(errno));
|
pa_log_warn("SO_PRIORITY failed: %s", pa_cstrerror(errno));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pa_socket_tcp_low_delay(int fd) {
|
void pa_make_tcp_socket_low_delay(int fd) {
|
||||||
int ret, tos, on;
|
|
||||||
|
|
||||||
pa_assert(fd >= 0);
|
pa_assert(fd >= 0);
|
||||||
|
|
||||||
ret = pa_socket_low_delay(fd);
|
pa_make_socket_low_delay(fd);
|
||||||
|
|
||||||
on = 1;
|
|
||||||
tos = 0;
|
|
||||||
|
|
||||||
#if defined(SOL_TCP) || defined(IPPROTO_TCP)
|
#if defined(SOL_TCP) || defined(IPPROTO_TCP)
|
||||||
|
{
|
||||||
|
int on = 1;
|
||||||
#if defined(SOL_TCP)
|
#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
|
#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
|
#endif
|
||||||
{
|
pa_log_warn("TCP_NODELAY failed: %s", pa_cstrerror(errno));
|
||||||
pa_log_warn("TCP_NODELAY failed: %s", pa_cstrerror(errno));
|
|
||||||
ret = -1;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || defined(IPPROTO_IP))
|
#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || defined(IPPROTO_IP))
|
||||||
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));
|
int tos = IPTOS_LOWDELAY;
|
||||||
ret = -1;
|
#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
|
#endif
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pa_socket_udp_low_delay(int fd) {
|
void pa_make_udp_socket_low_delay(int fd) {
|
||||||
int ret, tos;
|
|
||||||
|
|
||||||
pa_assert(fd >= 0);
|
pa_assert(fd >= 0);
|
||||||
|
|
||||||
ret = pa_socket_low_delay(fd);
|
pa_make_socket_low_delay(fd);
|
||||||
|
|
||||||
tos = 0;
|
|
||||||
|
|
||||||
#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || defined(IPPROTO_IP))
|
#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || defined(IPPROTO_IP))
|
||||||
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
|
|
||||||
{
|
{
|
||||||
ret = -1;
|
int tos = IPTOS_LOWDELAY;
|
||||||
pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
|
#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
|
#endif
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pa_socket_set_rcvbuf(int fd, size_t l) {
|
int pa_socket_set_rcvbuf(int fd, size_t l) {
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@
|
||||||
|
|
||||||
void pa_socket_peer_to_string(int fd, char *c, size_t l);
|
void pa_socket_peer_to_string(int fd, char *c, size_t l);
|
||||||
|
|
||||||
int pa_socket_low_delay(int fd);
|
void pa_make_socket_low_delay(int fd);
|
||||||
int pa_socket_tcp_low_delay(int fd);
|
void pa_make_tcp_socket_low_delay(int fd);
|
||||||
int pa_socket_udp_low_delay(int fd);
|
void pa_make_udp_socket_low_delay(int fd);
|
||||||
|
|
||||||
int pa_socket_set_sndbuf(int fd, size_t l);
|
int pa_socket_set_sndbuf(int fd, size_t l);
|
||||||
int pa_socket_set_rcvbuf(int fd, size_t l);
|
int pa_socket_set_rcvbuf(int fd, size_t l);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue