]> code.delx.au - pulseaudio/blob - src/pulsecore/iochannel.h
merge 'lennart' branch back into trunk.
[pulseaudio] / src / pulsecore / iochannel.h
1 #ifndef fooiochannelhfoo
2 #define fooiochannelhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of PulseAudio.
8
9 Copyright 2004-2006 Lennart Poettering
10 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
11
12 PulseAudio is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as
14 published by the Free Software Foundation; either version 2.1 of the
15 License, or (at your option) any later version.
16
17 PulseAudio is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public
23 License along with PulseAudio; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 USA.
26 ***/
27
28 #ifndef PACKAGE
29 #error "Please include config.h before including this file!"
30 #endif
31
32 #include <sys/types.h>
33
34 #include <pulse/mainloop-api.h>
35 #include <pulsecore/creds.h>
36 #include <pulsecore/macro.h>
37
38 /* A wrapper around UNIX file descriptors for attaching them to the a
39 main event loop. Everytime new data may be read or be written to
40 the channel a callback function is called. It is safe to destroy
41 the calling iochannel object from the callback */
42
43 /* When pa_iochannel_is_readable() returns non-zero, the user has to
44 * call this function in a loop until it is no longer set or EOF
45 * reached. Otherwise strange things may happen when an EOF is
46 * reached. */
47
48 typedef struct pa_iochannel pa_iochannel;
49
50 /* Create a new IO channel for the specified file descriptors for
51 input resp. output. It is safe to pass the same file descriptor for
52 both parameters (in case of full-duplex channels). For a simplex
53 channel specify -1 for the other direction. */
54
55 pa_iochannel* pa_iochannel_new(pa_mainloop_api*m, int ifd, int ofd);
56 void pa_iochannel_free(pa_iochannel*io);
57
58 ssize_t pa_iochannel_write(pa_iochannel*io, const void*data, size_t l);
59 ssize_t pa_iochannel_read(pa_iochannel*io, void*data, size_t l);
60
61 #ifdef HAVE_CREDS
62 pa_bool_t pa_iochannel_creds_supported(pa_iochannel *io);
63 int pa_iochannel_creds_enable(pa_iochannel *io);
64
65 ssize_t pa_iochannel_write_with_creds(pa_iochannel*io, const void*data, size_t l, const pa_creds *ucred);
66 ssize_t pa_iochannel_read_with_creds(pa_iochannel*io, void*data, size_t l, pa_creds *ucred, pa_bool_t *creds_valid);
67 #endif
68
69 pa_bool_t pa_iochannel_is_readable(pa_iochannel*io);
70 pa_bool_t pa_iochannel_is_writable(pa_iochannel*io);
71 pa_bool_t pa_iochannel_is_hungup(pa_iochannel*io);
72
73 /* Don't close the file descirptors when the io channel is freed. By
74 * default the file descriptors are closed. */
75 void pa_iochannel_set_noclose(pa_iochannel*io, pa_bool_t b);
76
77 /* Set the callback function that is called whenever data becomes available for read or write */
78 typedef void (*pa_iochannel_cb_t)(pa_iochannel*io, void *userdata);
79 void pa_iochannel_set_callback(pa_iochannel*io, pa_iochannel_cb_t callback, void *userdata);
80
81 /* In case the file descriptor is a socket, return a pretty-printed string in *s which describes the peer connected */
82 void pa_iochannel_socket_peer_to_string(pa_iochannel*io, char*s, size_t l);
83
84 /* Use setsockopt() to tune the recieve and send buffers of TCP sockets */
85 int pa_iochannel_socket_set_rcvbuf(pa_iochannel*io, size_t l);
86 int pa_iochannel_socket_set_sndbuf(pa_iochannel*io, size_t l);
87
88 pa_mainloop_api* pa_iochannel_get_mainloop_api(pa_iochannel *io);
89
90 int pa_iochannel_get_recv_fd(pa_iochannel *io);
91 int pa_iochannel_get_send_fd(pa_iochannel *io);
92
93 #endif