system: use spa_system functions for fds

This commit is contained in:
Wim Taymans 2019-11-19 13:40:46 +01:00
parent b14bb1f496
commit 68e94a2e7e
16 changed files with 96 additions and 60 deletions

View file

@ -28,7 +28,6 @@
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <sys/eventfd.h>
#include <spa/monitor/device.h>
#include <spa/monitor/utils.h>

View file

@ -26,7 +26,6 @@
#include <dlfcn.h>
#include <sys/socket.h>
#include <sys/mman.h>
#include <sys/eventfd.h>
#include <spa/node/node.h>
#include <spa/node/utils.h>
@ -317,8 +316,7 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
static inline void do_flush(struct node *this)
{
uint64_t cmd = 1;
if (write(this->writefd, &cmd, 8) != 8)
if (spa_system_eventfd_write(this->data_system, this->writefd, 1) < 0)
spa_log_warn(this->log, "node %p: error flushing : %s", this, strerror(errno));
}
@ -1036,7 +1034,7 @@ static void node_on_data_fd_events(struct spa_source *source)
struct pw_client_node0_message message;
uint64_t cmd;
if (read(this->data_source.fd, &cmd, sizeof(uint64_t)) != sizeof(uint64_t))
if (spa_system_eventfd_read(this->data_system, this->data_source.fd, &cmd) < 0)
spa_log_warn(this->log, "node %p: error reading message: %s",
this, strerror(errno));
@ -1168,12 +1166,13 @@ static void node_initialized(void *data)
struct impl *impl = data;
struct pw_client_node0 *this = &impl->this;
struct pw_node *node = this->node;
struct spa_system *data_system = impl->node.data_system;
if (this->resource == NULL)
return;
impl->fds[0] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
impl->fds[1] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
impl->fds[0] = spa_system_eventfd_create(data_system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
impl->fds[1] = spa_system_eventfd_create(data_system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
impl->node.data_source.fd = impl->fds[0];
impl->node.writefd = impl->fds[1];
impl->other_fds[0] = impl->fds[1];
@ -1192,6 +1191,7 @@ static void node_initialized(void *data)
static void node_free(void *data)
{
struct impl *impl = data;
struct spa_system *data_system = impl->node.data_system;
pw_log_debug("client-node %p: free", &impl->this);
node_clear(&impl->node);
@ -1204,9 +1204,9 @@ static void node_free(void *data)
pw_array_clear(&impl->mems);
if (impl->fds[0] != -1)
close(impl->fds[0]);
spa_system_close(data_system, impl->fds[0]);
if (impl->fds[1] != -1)
close(impl->fds[1]);
spa_system_close(data_system, impl->fds[1]);
free(impl);
}

View file

@ -28,7 +28,6 @@
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <sys/eventfd.h>
#include <spa/monitor/device.h>
#include <spa/monitor/utils.h>

View file

@ -33,7 +33,6 @@
#include <unistd.h>
#include <pthread.h>
#include <sys/resource.h>
#include <sys/eventfd.h>
#include "config.h"
@ -52,6 +51,7 @@ struct impl {
struct pw_core *core;
struct spa_loop *loop;
struct spa_system *system;
struct spa_source source;
struct spa_hook module_listener;
@ -411,7 +411,7 @@ static void module_destroy(void *data)
0,
true,
&impl->source);
close(impl->source.fd);
spa_system_close(impl->system, impl->source.fd);
impl->source.fd = -1;
}
free(impl);
@ -432,7 +432,7 @@ static void idle_func(struct spa_source *source)
long long rttime;
uint64_t count;
read(impl->source.fd, &count, sizeof(uint64_t));
spa_system_eventfd_read(impl->system, impl->source.fd, &count);
rtprio = 20;
rttime = 20000;
@ -478,6 +478,7 @@ int pipewire__module_init(struct pw_module *module, const char *args)
struct pw_core *core = pw_module_get_core(module);
struct impl *impl;
struct spa_loop *loop;
struct spa_system *system;
const struct spa_support *support;
uint32_t n_support;
int res;
@ -488,6 +489,10 @@ int pipewire__module_init(struct pw_module *module, const char *args)
if (loop == NULL)
return -ENOTSUP;
system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem);
if (system == NULL)
return -ENOTSUP;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
return -ENOMEM;
@ -496,11 +501,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
impl->core = core;
impl->loop = loop;
impl->system = system;
impl->source.loop = loop;
impl->source.func = idle_func;
impl->source.data = impl;
impl->source.fd = eventfd(1, EFD_CLOEXEC | EFD_NONBLOCK);
impl->source.fd = spa_system_eventfd_create(system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
impl->source.mask = SPA_IO_IN;
if (impl->source.fd == -1) {
res = -errno;