153a5a1b3Sopenharmony_ci#ifndef fooiochannelhfoo
253a5a1b3Sopenharmony_ci#define fooiochannelhfoo
353a5a1b3Sopenharmony_ci
453a5a1b3Sopenharmony_ci/***
553a5a1b3Sopenharmony_ci  This file is part of PulseAudio.
653a5a1b3Sopenharmony_ci
753a5a1b3Sopenharmony_ci  Copyright 2004-2006 Lennart Poettering
853a5a1b3Sopenharmony_ci  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
953a5a1b3Sopenharmony_ci
1053a5a1b3Sopenharmony_ci  PulseAudio is free software; you can redistribute it and/or modify
1153a5a1b3Sopenharmony_ci  it under the terms of the GNU Lesser General Public License as
1253a5a1b3Sopenharmony_ci  published by the Free Software Foundation; either version 2.1 of the
1353a5a1b3Sopenharmony_ci  License, or (at your option) any later version.
1453a5a1b3Sopenharmony_ci
1553a5a1b3Sopenharmony_ci  PulseAudio is distributed in the hope that it will be useful, but
1653a5a1b3Sopenharmony_ci  WITHOUT ANY WARRANTY; without even the implied warranty of
1753a5a1b3Sopenharmony_ci  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1853a5a1b3Sopenharmony_ci  Lesser General Public License for more details.
1953a5a1b3Sopenharmony_ci
2053a5a1b3Sopenharmony_ci  You should have received a copy of the GNU Lesser General Public
2153a5a1b3Sopenharmony_ci  License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
2253a5a1b3Sopenharmony_ci***/
2353a5a1b3Sopenharmony_ci
2453a5a1b3Sopenharmony_ci#ifndef PACKAGE
2553a5a1b3Sopenharmony_ci#error "Please include config.h before including this file!"
2653a5a1b3Sopenharmony_ci#endif
2753a5a1b3Sopenharmony_ci
2853a5a1b3Sopenharmony_ci#include <sys/types.h>
2953a5a1b3Sopenharmony_ci
3053a5a1b3Sopenharmony_ci#include <pulse/mainloop-api.h>
3153a5a1b3Sopenharmony_ci#include <pulsecore/creds.h>
3253a5a1b3Sopenharmony_ci#include <pulsecore/macro.h>
3353a5a1b3Sopenharmony_ci
3453a5a1b3Sopenharmony_ci/* A wrapper around UNIX file descriptors for attaching them to the a
3553a5a1b3Sopenharmony_ci   main event loop. Every time new data may be read or be written to
3653a5a1b3Sopenharmony_ci   the channel a callback function is called. It is safe to destroy
3753a5a1b3Sopenharmony_ci   the calling iochannel object from the callback */
3853a5a1b3Sopenharmony_ci
3953a5a1b3Sopenharmony_citypedef struct pa_iochannel pa_iochannel;
4053a5a1b3Sopenharmony_ci
4153a5a1b3Sopenharmony_ci/* Create a new IO channel for the specified file descriptors for
4253a5a1b3Sopenharmony_ciinput resp. output. It is safe to pass the same file descriptor for
4353a5a1b3Sopenharmony_ciboth parameters (in case of full-duplex channels). For a simplex
4453a5a1b3Sopenharmony_cichannel specify -1 for the other direction. */
4553a5a1b3Sopenharmony_ci
4653a5a1b3Sopenharmony_cipa_iochannel* pa_iochannel_new(pa_mainloop_api*m, int ifd, int ofd);
4753a5a1b3Sopenharmony_civoid pa_iochannel_free(pa_iochannel*io);
4853a5a1b3Sopenharmony_ci
4953a5a1b3Sopenharmony_ci/* Returns: length written on success, 0 if a retry is needed, negative value
5053a5a1b3Sopenharmony_ci * on error. */
5153a5a1b3Sopenharmony_cissize_t pa_iochannel_write(pa_iochannel*io, const void*data, size_t l);
5253a5a1b3Sopenharmony_cissize_t pa_iochannel_read(pa_iochannel*io, void*data, size_t l);
5353a5a1b3Sopenharmony_ci
5453a5a1b3Sopenharmony_ci#ifdef HAVE_CREDS
5553a5a1b3Sopenharmony_cibool pa_iochannel_creds_supported(pa_iochannel *io);
5653a5a1b3Sopenharmony_ciint pa_iochannel_creds_enable(pa_iochannel *io);
5753a5a1b3Sopenharmony_ci
5853a5a1b3Sopenharmony_cissize_t pa_iochannel_write_with_fds(pa_iochannel*io, const void*data, size_t l, int nfd, const int *fds);
5953a5a1b3Sopenharmony_cissize_t pa_iochannel_write_with_creds(pa_iochannel*io, const void*data, size_t l, const pa_creds *ucred);
6053a5a1b3Sopenharmony_cissize_t pa_iochannel_read_with_ancil_data(pa_iochannel*io, void*data, size_t l, pa_cmsg_ancil_data *ancil_data);
6153a5a1b3Sopenharmony_ci#endif
6253a5a1b3Sopenharmony_ci
6353a5a1b3Sopenharmony_cibool pa_iochannel_is_readable(pa_iochannel*io);
6453a5a1b3Sopenharmony_cibool pa_iochannel_is_writable(pa_iochannel*io);
6553a5a1b3Sopenharmony_cibool pa_iochannel_is_hungup(pa_iochannel*io);
6653a5a1b3Sopenharmony_ci
6753a5a1b3Sopenharmony_ci/* Don't close the file descriptors when the io channel is freed. By
6853a5a1b3Sopenharmony_ci * default the file descriptors are closed. */
6953a5a1b3Sopenharmony_civoid pa_iochannel_set_noclose(pa_iochannel*io, bool b);
7053a5a1b3Sopenharmony_ci
7153a5a1b3Sopenharmony_ci/* Set the callback function that is called whenever data becomes available for read or write */
7253a5a1b3Sopenharmony_citypedef void (*pa_iochannel_cb_t)(pa_iochannel*io, void *userdata);
7353a5a1b3Sopenharmony_civoid pa_iochannel_set_callback(pa_iochannel*io, pa_iochannel_cb_t callback, void *userdata);
7453a5a1b3Sopenharmony_ci
7553a5a1b3Sopenharmony_ci/* In case the file descriptor is a socket, return a pretty-printed string in *s which describes the peer connected */
7653a5a1b3Sopenharmony_civoid pa_iochannel_socket_peer_to_string(pa_iochannel*io, char*s, size_t l);
7753a5a1b3Sopenharmony_ci
7853a5a1b3Sopenharmony_ci/* Use setsockopt() to tune the receive and send buffers of TCP sockets */
7953a5a1b3Sopenharmony_ciint pa_iochannel_socket_set_rcvbuf(pa_iochannel*io, size_t l);
8053a5a1b3Sopenharmony_ciint pa_iochannel_socket_set_sndbuf(pa_iochannel*io, size_t l);
8153a5a1b3Sopenharmony_ci
8253a5a1b3Sopenharmony_cibool pa_iochannel_socket_is_local(pa_iochannel *io);
8353a5a1b3Sopenharmony_ci
8453a5a1b3Sopenharmony_cipa_mainloop_api* pa_iochannel_get_mainloop_api(pa_iochannel *io);
8553a5a1b3Sopenharmony_ci
8653a5a1b3Sopenharmony_ciint pa_iochannel_get_recv_fd(pa_iochannel *io);
8753a5a1b3Sopenharmony_ciint pa_iochannel_get_send_fd(pa_iochannel *io);
8853a5a1b3Sopenharmony_ci
8953a5a1b3Sopenharmony_ci#endif
90