return -1;
}
- pa_make_nonblock_fd(the_pipe[0]);
- pa_make_nonblock_fd(the_pipe[1]);
- pa_fd_set_cloexec(the_pipe[0], 1);
- pa_fd_set_cloexec(the_pipe[1], 1);
+ pa_make_fd_nonblock(the_pipe[0]);
+ pa_make_fd_nonblock(the_pipe[1]);
+ pa_make_fd_cloexec(the_pipe[0]);
+ pa_make_fd_cloexec(the_pipe[1]);
api = m;
io_event = api->io_new(m, the_pipe[0], PA_IO_EVENT_INPUT, callback, NULL);
goto fail;
}
- pa_fd_set_cloexec(u->fd, 1);
- pa_make_nonblock_fd(u->fd);
+ pa_make_fd_cloexec(u->fd);
+ pa_make_fd_nonblock(u->fd);
if (fstat(u->fd, &st) < 0) {
pa_log("fstat('%s'): %s", u->filename, pa_cstrerror(errno));
goto fail;
}
- pa_fd_set_cloexec(u->fd, 1);
- pa_make_nonblock_fd(u->fd);
+ pa_make_fd_cloexec(u->fd);
+ pa_make_fd_nonblock(u->fd);
if (fstat(u->fd, &st) < 0) {
pa_log("fstat('%s'): %s",u->filename, pa_cstrerror(errno));
#endif
*pcaps & DSP_CAP_TRIGGER ? " TRIGGER" : "");
- pa_fd_set_cloexec(fd, 1);
+ pa_make_fd_cloexec(fd);
return fd;
}
/* If the socket queue is full, let's drop packets */
- pa_make_nonblock_fd(fd);
- pa_socket_udp_low_delay(fd);
+ pa_make_fd_nonblock(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);
data.name = "RTP Monitor Stream";
goto fail;
}
- pa_fd_set_cloexec(fds[0], 1);
+ pa_make_fd_cloexec(fds[0]);
- pa_socket_low_delay(fds[0]);
- pa_socket_low_delay(fds[1]);
+ pa_make_socket_low_delay(fds[0]);
+ pa_make_socket_low_delay(fds[1]);
if (c->spawn_api.prefork)
c->spawn_api.prefork();
return -1;
}
- pa_make_nonblock_fd(signal_pipe[0]);
- pa_make_nonblock_fd(signal_pipe[1]);
- pa_assert_se(pa_fd_set_cloexec(signal_pipe[0], 1) == 0);
- pa_assert_se(pa_fd_set_cloexec(signal_pipe[1], 1) == 0);
+ pa_make_fd_nonblock(signal_pipe[0]);
+ pa_make_fd_nonblock(signal_pipe[1]);
+ pa_make_fd_cloexec(signal_pipe[0]);
+ pa_make_fd_cloexec(signal_pipe[1]);
api = a;
return NULL;
}
- pa_make_nonblock_fd(m->wakeup_pipe[0]);
- pa_make_nonblock_fd(m->wakeup_pipe[1]);
- pa_fd_set_cloexec(m->wakeup_pipe[0], 1);
- pa_fd_set_cloexec(m->wakeup_pipe[1], 1);
+ pa_make_fd_nonblock(m->wakeup_pipe[0]);
+ pa_make_fd_nonblock(m->wakeup_pipe[1]);
+ pa_make_fd_cloexec(m->wakeup_pipe[0]);
+ pa_make_fd_cloexec(m->wakeup_pipe[1]);
m->wakeup_requested = 0;
PA_LLIST_HEAD_INIT(pa_io_event, m->io_events);
#endif
/** 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
int v;
pa_assert(fd >= 0);
- if ((v = fcntl(fd, F_GETFL)) >= 0)
- if (!(v & O_NONBLOCK))
- fcntl(fd, F_SETFL, v|O_NONBLOCK);
+ pa_assert_se((v = fcntl(fd, F_GETFL)) >= 0);
+
+ if (!(v & O_NONBLOCK))
+ pa_assert_se(fcntl(fd, F_SETFL, v|O_NONBLOCK) >= 0);
+
#elif defined(OS_IS_WIN32)
u_long arg = 1;
if (ioctlsocket(fd, FIONBIO, &arg) < 0) {
- if (WSAGetLastError() == WSAENOTSOCK)
- pa_log_warn("Only sockets can be made non-blocking!");
+ pa_assert_se(WSAGetLastError() == WSAENOTSOCK);
+ pa_log_warn("Only sockets can be made non-blocking!");
}
#else
pa_log_warn("Non-blocking I/O not supported.!");
#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 */
#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.*/
int pa_parse_boolean(const char *v) {
if (sig <= 0)
goto fail;
-
+
#ifdef NSIG
- if (sig >= NSIG)
- goto fail;
+ if (sig >= NSIG)
+ goto fail;
#endif
-
+
#ifdef HAVE_SIG2STR
{
char buf[SIG2STR_MAX];
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_parent_dir(const char *fn, mode_t, uid_t uid, gid_t gid);
void pa_raise_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;
char *pa_split(const char *c, const char*delimiters, const char **state);
return NULL;
}
- pa_fd_set_cloexec(f->fds[0], 1);
- pa_fd_set_cloexec(f->fds[1], 1);
+ pa_make_fd_cloexec(f->fds[0]);
+ pa_make_fd_cloexec(f->fds[1]);
pa_atomic_store(&f->waiting, 0);
pa_atomic_store(&f->signalled, 0);
if (ifd == ofd) {
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);
} else {
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);
}
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);
}
}
pa_assert(sa);
pa_assert(len > 0);
- pa_make_nonblock_fd(c->fd);
+ pa_make_fd_nonblock(c->fd);
if ((r = connect(c->fd, sa, len)) < 0) {
#ifdef OS_IS_WIN32
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)
- pa_socket_tcp_low_delay(c->fd);
+ pa_make_tcp_socket_low_delay(c->fd);
else
- pa_socket_low_delay(c->fd);
+ pa_make_socket_low_delay(c->fd);
if (do_connect(c, sa, salen) < 0)
return -1;
goto finish;
}
- pa_fd_set_cloexec(nfd, 1);
+ pa_make_fd_cloexec(nfd);
if (!s->on_connection) {
pa_close(nfd);
/* There should be a check for socket type here */
if (s->type == SOCKET_SERVER_IPV4)
- pa_socket_tcp_low_delay(fd);
+ pa_make_tcp_socket_low_delay(fd);
else
- pa_socket_low_delay(fd);
+ pa_make_socket_low_delay(fd);
pa_assert_se(io = pa_iochannel_new(s->mainloop, nfd, nfd));
s->on_connection(s, io, s->userdata);
goto fail;
}
- pa_fd_set_cloexec(fd, 1);
+ pa_make_fd_cloexec(fd);
sa.sun_family = AF_UNIX;
strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
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) {
pa_log("bind(): %s", pa_cstrerror(errno));
goto fail;
}
- pa_fd_set_cloexec(fd, 1);
+ pa_make_fd_cloexec(fd);
#ifdef SO_REUSEADDR
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
pa_log("setsockopt(): %s", pa_cstrerror(errno));
#endif
- pa_socket_tcp_low_delay(fd);
+ pa_make_tcp_socket_low_delay(fd);
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
goto fail;
}
- pa_fd_set_cloexec(fd, 1);
+ pa_make_fd_cloexec(fd);
#ifdef IPV6_V6ONLY
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0)
pa_log("setsockopt(SOL_SOCKET, SO_REUSEADDR, 1): %s", pa_cstrerror(errno));
#endif
- pa_socket_tcp_low_delay(fd);
+ pa_make_tcp_socket_low_delay(fd);
memset(&sa, 0, sizeof(sa));
sa.sin6_family = AF_INET6;
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;
pa_assert(fd >= 0);
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));
- return -1;
- }
#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);
-
- 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
- {
- pa_log_warn("TCP_NODELAY failed: %s", pa_cstrerror(errno));
- 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;
+ {
+ 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
- {
- pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
- ret = -1;
+ pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
}
#endif
-
- return ret;
}
-int pa_socket_udp_low_delay(int fd) {
- int ret, tos;
-
+void pa_make_udp_socket_low_delay(int fd) {
pa_assert(fd >= 0);
-
- ret = pa_socket_low_delay(fd);
-
- tos = 0;
-
+
+ pa_make_socket_low_delay(fd);
+
#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || defined(IPPROTO_IP))
- tos = IPTOS_LOWDELAY;
+ {
+ 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));
+ pa_log_warn("IP_TOS failed: %s", pa_cstrerror(errno));
}
#endif
-
- return ret;
}
int pa_socket_set_rcvbuf(int fd, size_t l) {
void pa_socket_peer_to_string(int fd, char *c, size_t l);
-int pa_socket_low_delay(int fd);
-int pa_socket_tcp_low_delay(int fd);
-int pa_socket_udp_low_delay(int fd);
+void pa_make_socket_low_delay(int fd);
+void pa_make_tcp_socket_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_rcvbuf(int fd, size_t l);