本文整理汇总了C++中pa_close函数的典型用法代码示例。如果您正苦于以下问题:C++ pa_close函数的具体用法?C++ pa_close怎么用?C++ pa_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pa_close函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: open_pid_file
static int open_pid_file(const char *fn, int mode) {
int fd;
pa_assert(fn);
for (;;) {
struct stat st;
if ((fd = pa_open_cloexec(fn, mode
#ifdef O_NOFOLLOW
|O_NOFOLLOW
#endif
, S_IRUSR|S_IWUSR
)) < 0) {
if (mode != O_RDONLY || errno != ENOENT)
pa_log_warn("Failed to open PID file '%s': %s", fn, pa_cstrerror(errno));
goto fail;
}
/* Try to lock the file. If that fails, go without */
if (pa_lock_fd(fd, 1) < 0)
goto fail;
if (fstat(fd, &st) < 0) {
pa_log_warn("Failed to fstat() PID file '%s': %s", fn, pa_cstrerror(errno));
goto fail;
}
/* Does the file still exist in the file system? When yes, we're done, otherwise restart */
if (st.st_nlink >= 1)
break;
if (pa_lock_fd(fd, 0) < 0)
goto fail;
if (pa_close(fd) < 0) {
pa_log_warn("Failed to close file '%s': %s", fn, pa_cstrerror(errno));
fd = -1;
goto fail;
}
}
return fd;
fail:
if (fd >= 0) {
int saved_errno = errno;
pa_lock_fd(fd, 0);
pa_close(fd);
errno = saved_errno;
}
return -1;
}
开发者ID:KimT,项目名称:pulseaudio_kt,代码行数:55,代码来源:pid.c
示例2: callback
static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
pa_socket_server *s = userdata;
pa_iochannel *io;
int nfd;
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
pa_assert(s->mainloop == mainloop);
pa_assert(s->io_event == e);
pa_assert(e);
pa_assert(fd >= 0);
pa_assert(fd == s->fd);
pa_socket_server_ref(s);
if ((nfd = pa_accept_cloexec(fd, NULL, NULL)) < 0) {
pa_log("accept(): %s", pa_cstrerror(errno));
goto finish;
}
if (!s->on_connection) {
pa_close(nfd);
goto finish;
}
#ifdef HAVE_LIBWRAP
if (s->tcpwrap_service) {
struct request_info req;
request_init(&req, RQ_DAEMON, s->tcpwrap_service, RQ_FILE, nfd, NULL);
fromhost(&req);
if (!hosts_access(&req)) {
pa_log_warn("TCP connection refused by tcpwrap.");
pa_close(nfd);
goto finish;
}
pa_log_info("TCP connection accepted by tcpwrap.");
}
#endif
/* There should be a check for socket type here */
if (s->type == SOCKET_SERVER_IPV4)
pa_make_tcp_socket_low_delay(fd);
else
pa_make_socket_low_delay(fd);
pa_assert_se(io = pa_iochannel_new(s->mainloop, nfd, nfd));
s->on_connection(s, io, s->userdata);
finish:
pa_socket_server_unref(s);
}
开发者ID:BYSTROSTREL,项目名称:pulseaudio,代码行数:54,代码来源:socket-server.c
示例3: pa_iochannel_free
void pa_iochannel_free(pa_iochannel*io) {
pa_assert(io);
delete_events(io);
if (!io->no_close) {
if (io->ifd >= 0)
pa_close(io->ifd);
if (io->ofd >= 0 && io->ofd != io->ifd)
pa_close(io->ofd);
}
pa_xfree(io);
}
开发者ID:plbossart,项目名称:pulseaudio,代码行数:14,代码来源:iochannel.c
示例4: unref
static void unref(pa_bool_t after_fork) {
pa_assert(n_ref > 0);
pa_assert(pipe_fd[0] >= 0);
pa_assert(pipe_fd[1] >= 0);
pa_assert(lock_fd_mutex);
n_ref--;
if (n_ref > 0)
return;
if (thread) {
pa_thread_free(thread);
thread = NULL;
}
pa_mutex_lock(lock_fd_mutex);
pa_assert(state != STATE_TAKEN);
if (state == STATE_OWNING) {
pa_assert(lock_fd >= 0);
if (after_fork)
pa_close(lock_fd);
else {
char *lf;
if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK)))
pa_log_warn(_("Cannot access autospawn lock."));
pa_unlock_lockfile(lf, lock_fd);
pa_xfree(lf);
}
}
lock_fd = -1;
state = STATE_IDLE;
pa_mutex_unlock(lock_fd_mutex);
pa_mutex_free(lock_fd_mutex);
lock_fd_mutex = NULL;
pa_close(pipe_fd[0]);
pa_close(pipe_fd[1]);
pipe_fd[0] = pipe_fd[1] = -1;
}
开发者ID:KimT,项目名称:pulseaudio_kt,代码行数:50,代码来源:lock-autospawn.c
示例5: pa_shm_attach
int pa_shm_attach(pa_shm *m, unsigned id, bool writable) {
char fn[32];
int fd = -1;
int prot;
struct stat st;
pa_assert(m);
segment_name(fn, sizeof(fn), m->id = id);
if ((fd = shm_open(fn, writable ? O_RDWR : O_RDONLY, 0)) < 0) {
if (errno != EACCES && errno != ENOENT)
pa_log("shm_open() failed: %s", pa_cstrerror(errno));
goto fail;
}
if (fstat(fd, &st) < 0) {
pa_log("fstat() failed: %s", pa_cstrerror(errno));
goto fail;
}
if (st.st_size <= 0 ||
st.st_size > (off_t) (MAX_SHM_SIZE+SHM_MARKER_SIZE) ||
PA_ALIGN((size_t) st.st_size) != (size_t) st.st_size) {
pa_log("Invalid shared memory segment size");
goto fail;
}
m->size = (size_t) st.st_size;
prot = writable ? PROT_READ | PROT_WRITE : PROT_READ;
if ((m->ptr = mmap(NULL, PA_PAGE_ALIGN(m->size), prot, MAP_SHARED, fd, (off_t) 0)) == MAP_FAILED) {
pa_log("mmap() failed: %s", pa_cstrerror(errno));
goto fail;
}
m->do_unlink = false;
m->shared = true;
pa_assert_se(pa_close(fd) == 0);
return 0;
fail:
if (fd >= 0)
pa_close(fd);
return -1;
}
开发者ID:Elemecca,项目名称:pulseaudio,代码行数:49,代码来源:shm.c
示例6: pa__init
int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
int ret = -1;
int32_t fd = -1;
char x = 1;
pa_assert(m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs)) ||
pa_modargs_get_value_s32(ma, "fd", &fd) < 0 ||
fd < 0) {
pa_log("Failed to parse module arguments");
goto finish;
}
if (pa_loop_write(fd, &x, sizeof(x), NULL) != sizeof(x))
pa_log_warn("write(%u, 1, 1) failed: %s", fd, pa_cstrerror(errno));
pa_assert_se(pa_close(fd) == 0);
pa_module_unload_request(m, true);
ret = 0;
finish:
if (ma)
pa_modargs_free(ma);
return ret;
}
开发者ID:lebauce,项目名称:pulseaudio,代码行数:31,代码来源:module-esound-compat-spawnfd.c
示例7: pa__done
void pa__done(pa_module *m) {
struct userdata *u;
pa_assert(m);
if (!(u = m->userdata))
return;
if (u->udev_io)
m->core->mainloop->io_free(u->udev_io);
if (u->monitor)
udev_monitor_unref(u->monitor);
if (u->udev)
udev_unref(u->udev);
if (u->inotify_io)
m->core->mainloop->io_free(u->inotify_io);
if (u->inotify_fd >= 0)
pa_close(u->inotify_fd);
if (u->devices) {
struct device *d;
while ((d = pa_hashmap_steal_first(u->devices)))
device_free(d);
pa_hashmap_free(u->devices, NULL, NULL);
}
pa_xfree(u);
}
开发者ID:BYSTROSTREL,项目名称:pulseaudio,代码行数:34,代码来源:module-udev-detect.c
示例8: pa__done
void pa__done(pa_module *m) {
struct userdata *u;
pa_assert(m);
if (!(u = m->userdata))
return;
if (u->udev_io)
m->core->mainloop->io_free(u->udev_io);
if (u->monitor)
udev_monitor_unref(u->monitor);
if (u->udev)
udev_unref(u->udev);
if (u->inotify_io)
m->core->mainloop->io_free(u->inotify_io);
if (u->inotify_fd >= 0)
pa_close(u->inotify_fd);
if (u->devices)
pa_hashmap_free(u->devices);
pa_xfree(u);
}
开发者ID:DryakhlyyZlodey,项目名称:pulseaudio,代码行数:28,代码来源:module-udev-detect.c
示例9: inotify_cb
static void inotify_cb(
pa_mainloop_api *a,
pa_io_event *e,
int fd,
pa_io_event_flags_t events,
void *userdata) {
struct {
struct inotify_event event;
char name[NAME_MAX+1];
} buf;
pa_inotify *i = userdata;
int pid_fd;
pa_assert(i);
if (pa_read(fd, &buf, sizeof(buf), NULL) < (int) sizeof(buf.event))
pa_log_warn("inotify did not read a full event.");
else
pa_log_debug("inotify callback, event mask: 0x%x", (int) buf.event.mask);
pid_fd = pa_open_cloexec(i->filename, O_RDONLY
#ifdef O_NOFOLLOW
|O_NOFOLLOW
#endif
, S_IRUSR);
if (pid_fd < 0) {
if (i->callback)
i->callback(i->callback_data);
} else
pa_close(pid_fd);
}
开发者ID:morphis,项目名称:pulseaudio,代码行数:34,代码来源:inotify-wrapper.c
示例10: pa_socket_server_new_ipv4
pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address, uint16_t port, pa_bool_t fallback, const char *tcpwrap_service) {
pa_socket_server *ss;
int fd = -1;
struct sockaddr_in sa;
int on = 1;
pa_assert(m);
pa_assert(port);
if ((fd = pa_socket_cloexec(PF_INET, SOCK_STREAM, 0)) < 0) {
pa_log("socket(PF_INET): %s", pa_cstrerror(errno));
goto fail;
}
#ifdef SO_REUSEADDR
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(on)) < 0)
pa_log("setsockopt(): %s", pa_cstrerror(errno));
#endif
pa_make_tcp_socket_low_delay(fd);
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
sa.sin_addr.s_addr = htonl(address);
if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
if (errno == EADDRINUSE && fallback) {
sa.sin_port = 0;
if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) >= 0)
goto good;
}
pa_log("bind(): %s", pa_cstrerror(errno));
goto fail;
good:
;
}
if (listen(fd, 5) < 0) {
pa_log("listen(): %s", pa_cstrerror(errno));
goto fail;
}
if ((ss = pa_socket_server_new(m, fd))) {
ss->type = SOCKET_SERVER_IPV4;
ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
}
return ss;
fail:
if (fd >= 0)
pa_close(fd);
return NULL;
}
开发者ID:BYSTROSTREL,项目名称:pulseaudio,代码行数:60,代码来源:socket-server.c
示例11: pa_shm_attach_ro
int pa_shm_attach_ro(pa_shm *m, unsigned id) {
char fn[32];
int fd = -1;
struct stat st;
pa_assert(m);
segment_name(fn, sizeof(fn), m->id = id);
if ((fd = shm_open(fn, O_RDONLY, 0)) < 0) {
if (errno != EACCES)
pa_log("shm_open() failed: %s", pa_cstrerror(errno));
goto fail;
}
if (fstat(fd, &st) < 0) {
pa_log("fstat() failed: %s", pa_cstrerror(errno));
goto fail;
}
if (st.st_size <= 0 ||
st.st_size > (off_t) (MAX_SHM_SIZE+SHM_MARKER_SIZE) ||
PA_ALIGN((size_t) st.st_size) != (size_t) st.st_size) {
pa_log("Invalid shared memory segment size");
goto fail;
}
m->size = (size_t) st.st_size;
if ((m->ptr = mmap(NULL, PA_PAGE_ALIGN(m->size), PROT_READ, MAP_SHARED, fd, (off_t) 0)) == MAP_FAILED) {
pa_log("mmap() failed: %s", pa_cstrerror(errno));
goto fail;
}
m->do_unlink = FALSE;
m->shared = TRUE;
pa_assert_se(pa_close(fd) == 0);
return 0;
fail:
if (fd >= 0)
pa_close(fd);
return -1;
}
开发者ID:almosthappy4u,项目名称:PulseAudio-UCM,代码行数:47,代码来源:shm.c
示例12: pa_log_set_fd
void pa_log_set_fd(int fd) {
if (fd >= 0)
log_fd = fd;
else if (log_fd >= 0) {
pa_close(log_fd);
log_fd = -1;
}
}
开发者ID:OS2World,项目名称:MM-SOUND-PM123,代码行数:8,代码来源:log.c
示例13: pa_pid_file_kill
/* Kill a current running daemon. Return non-zero on success, -1
* otherwise. If successful *pid contains the PID of the daemon
* process. */
int pa_pid_file_kill(int sig, pid_t *pid, const char *procname) {
int fd = -1;
char *fn;
int ret = -1;
pid_t _pid;
#ifdef __linux__
char *e = NULL;
#endif
if (!pid)
pid = &_pid;
if (!(fn = pa_runtime_path("pid")))
goto fail;
if ((fd = open_pid_file(fn, O_RDONLY)) < 0) {
if (errno == ENOENT)
errno = ESRCH;
goto fail;
}
if ((*pid = read_pid(fn, fd)) == (pid_t) -1)
goto fail;
if (procname) {
int ours;
if ((ours = proc_name_ours(*pid, procname)) < 0)
goto fail;
if (!ours) {
errno = ESRCH;
goto fail;
}
}
ret = kill(*pid, sig);
fail:
if (fd >= 0) {
int saved_errno = errno;
pa_lock_fd(fd, 0);
pa_close(fd);
errno = saved_errno;
}
#ifdef __linux__
pa_xfree(e);
#endif
pa_xfree(fn);
return ret;
}
开发者ID:KimT,项目名称:pulseaudio_kt,代码行数:61,代码来源:pid.c
示例14: main
int main(int argc, const char * argv[])
{
plotter_init();
pa_init();
getchar();
pa_close();
plotter_close();
return 0;
}
开发者ID:EQ4,项目名称:WaveformPlot,代码行数:9,代码来源:main.c
示例15: load
/* Load an authorization cookie from file fn and store it in data. If
* the cookie file doesn't exist, create it */
static int load(const char *fn, void *data, size_t length) {
int fd = -1;
int writable = 1;
int unlock = 0, ret = -1;
ssize_t r;
pa_assert(fn);
pa_assert(data);
pa_assert(length > 0);
if ((fd = pa_open_cloexec(fn, O_RDWR|O_CREAT|O_BINARY, S_IRUSR|S_IWUSR)) < 0) {
if (errno != EACCES || (fd = open(fn, O_RDONLY|O_BINARY)) < 0) {
pa_log_warn("Failed to open cookie file '%s': %s", fn, pa_cstrerror(errno));
goto finish;
} else
writable = 0;
}
unlock = pa_lock_fd(fd, 1) >= 0;
if ((r = pa_loop_read(fd, data, length, NULL)) < 0) {
pa_log("Failed to read cookie file '%s': %s", fn, pa_cstrerror(errno));
goto finish;
}
if ((size_t) r != length) {
pa_log_debug("Got %d bytes from cookie file '%s', expected %d", (int) r, fn, (int) length);
if (!writable) {
pa_log_warn("Unable to write cookie to read-only file");
goto finish;
}
if (generate(fd, data, length) < 0)
goto finish;
}
ret = 0;
finish:
if (fd >= 0) {
if (unlock)
pa_lock_fd(fd, 0);
if (pa_close(fd) < 0) {
pa_log_warn("Failed to close cookie file: %s", pa_cstrerror(errno));
ret = -1;
}
}
return ret;
}
开发者ID:BYSTROSTREL,项目名称:pulseaudio,代码行数:57,代码来源:authkey.c
示例16: pa_fdsem_free
void pa_fdsem_free(pa_fdsem *f) {
pa_assert(f);
#ifdef HAVE_SYS_EVENTFD_H
if (f->efd >= 0)
pa_close(f->efd);
#endif
pa_close_pipe(f->fds);
pa_xfree(f);
}
开发者ID:felfert,项目名称:pulseaudio,代码行数:11,代码来源:fdsem.c
示例17: pa_xmalloc
static char *get_cpuinfo(void) {
char *cpuinfo;
int n, fd;
cpuinfo = pa_xmalloc(MAX_BUFFER);
if ((fd = pa_open_cloexec("/proc/cpuinfo", O_RDONLY, 0)) < 0) {
pa_xfree(cpuinfo);
return NULL;
}
if ((n = pa_read(fd, cpuinfo, MAX_BUFFER-1, NULL)) < 0) {
pa_xfree(cpuinfo);
pa_close(fd);
return NULL;
}
cpuinfo[n] = 0;
pa_close(fd);
return cpuinfo;
}
开发者ID:Oboyma,项目名称:pulseaudio,代码行数:21,代码来源:cpu-arm.c
示例18: pa_inotify_stop
void pa_inotify_stop(pa_inotify *i) {
pa_assert(i);
if (i->io_event)
i->core->mainloop->io_free(i->io_event);
if (i->fd)
pa_close(i->fd);
pa_xfree(i->filename);
if (i->core)
pa_core_unref(i->core);
pa_xfree(i);
}
开发者ID:morphis,项目名称:pulseaudio,代码行数:13,代码来源:inotify-wrapper.c
示例19: socket_server_free
static void socket_server_free(pa_socket_server*s) {
pa_assert(s);
if (s->filename) {
unlink(s->filename);
pa_xfree(s->filename);
}
pa_close(s->fd);
pa_xfree(s->tcpwrap_service);
s->mainloop->io_free(s->io_event);
pa_xfree(s);
}
开发者ID:BYSTROSTREL,项目名称:pulseaudio,代码行数:15,代码来源:socket-server.c
示例20: pa_socket_server_new_unix
pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *filename) {
int fd = -1;
struct sockaddr_un sa;
pa_socket_server *s;
pa_assert(m);
pa_assert(filename);
if ((fd = pa_socket_cloexec(PF_UNIX, SOCK_STREAM, 0)) < 0) {
pa_log("socket(): %s", pa_cstrerror(errno));
goto fail;
}
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
pa_strlcpy(sa.sun_path, filename, sizeof(sa.sun_path));
pa_make_socket_low_delay(fd);
if (bind(fd, (struct sockaddr*) &sa, (socklen_t) SUN_LEN(&sa)) < 0) {
pa_log("bind(): %s", pa_cstrerror(errno));
goto fail;
}
/* Allow access from all clients. Sockets like this one should
* always be put inside a directory with proper access rights,
* 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;
}
pa_assert_se(s = pa_socket_server_new(m, fd));
s->filename = pa_xstrdup(filename);
s->type = SOCKET_SERVER_UNIX;
return s;
fail:
if (fd >= 0)
pa_close(fd);
return NULL;
}
开发者ID:BYSTROSTREL,项目名称:pulseaudio,代码行数:48,代码来源:socket-server.c
注:本文中的pa_close函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论