~raof/mir/platform-eglstream

« back to all changes in this revision

Viewing changes to 3rd_party/libancillary/ancillary.h

  • Committer: Alan Griffiths
  • Date: 2012-09-03 11:49:23 UTC
  • mto: This revision was merged to the branch mainline in revision 114.
  • Revision ID: alan@octopull.co.uk-20120903114923-na70zt8h5s6gnnkj
Add 3rd party including libancillary

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 * libancillary - black magic on Unix domain sockets
 
3
 * (C) Nicolas George
 
4
 * ancillary.h - public header
 
5
 ***************************************************************************/
 
6
 
 
7
/*
 
8
 * Redistribution and use in source and binary forms, with or without
 
9
 * modification, are permitted provided that the following conditions are met:
 
10
 * 
 
11
 *  1. Redistributions of source code must retain the above copyright notice,
 
12
 *     this list of conditions and the following disclaimer.
 
13
 *  2. Redistributions in binary form must reproduce the above copyright
 
14
 *     notice, this list of conditions and the following disclaimer in the
 
15
 *     documentation and/or other materials provided with the distribution.
 
16
 *  3. The name of the author may not be used to endorse or promote products
 
17
 *     derived from this software without specific prior written permission.
 
18
 * 
 
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
22
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
23
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
27
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
28
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 */
 
30
 
 
31
#ifndef ANCILLARY_H__
 
32
#define ANCILLARY_H__
 
33
 
 
34
/***************************************************************************
 
35
 * Start of the readable part.
 
36
 ***************************************************************************/
 
37
 
 
38
#define ANCIL_MAX_N_FDS 960
 
39
/*
 
40
 * Maximum number of fds that can be sent or received using the "esay"
 
41
 * functions; this is so that all can fit in one page.
 
42
 */
 
43
 
 
44
extern int
 
45
ancil_send_fds_with_buffer(int, const int *, unsigned, void *);
 
46
/*
 
47
 * ancil_send_fds_with_buffer(sock, n_fds, fds, buffer)
 
48
 *
 
49
 * Sends the file descriptors in the array pointed by fds, of length n_fds
 
50
 * on the socket sock.
 
51
 * buffer is a writeable memory area large enough to hold the required data
 
52
 * structures.
 
53
 * Returns: -1 and errno in case of error, 0 in case of success.
 
54
 */
 
55
 
 
56
extern int
 
57
ancil_recv_fds_with_buffer(int, int *, unsigned, void *);
 
58
/*
 
59
 * ancil_recv_fds_with_buffer(sock, n_fds, fds, buffer)
 
60
 *
 
61
 * Receives *n_fds file descriptors into the array pointed by fds
 
62
 * from the socket sock.
 
63
 * buffer is a writeable memory area large enough to hold the required data
 
64
 * structures.
 
65
 * Returns: -1 and errno in case of error, the actual number of received fd
 
66
 * in case of success
 
67
 */
 
68
 
 
69
#define ANCIL_FD_BUFFER(n) \
 
70
    struct { \
 
71
        struct cmsghdr h; \
 
72
        int fd[n]; \
 
73
    }
 
74
/* ANCIL_FD_BUFFER(n)
 
75
 *
 
76
 * A structure type suitable to be used as buffer for n file descriptors.
 
77
 * Requires <sys/socket.h>.
 
78
 * Example:
 
79
 * ANCIL_FD_BUFFER(42) buffer;
 
80
 * ancil_recv_fds_with_buffer(sock, 42, my_fds, &buffer);
 
81
 */
 
82
 
 
83
extern int
 
84
ancil_send_fds(int, const int *, unsigned);
 
85
/*
 
86
 * ancil_send_fds(sock, n_fds, fds)
 
87
 *
 
88
 * Sends the file descriptors in the array pointed by fds, of length n_fds
 
89
 * on the socket sock.
 
90
 * n_fds must not be greater than ANCIL_MAX_N_FDS.
 
91
 * Returns: -1 and errno in case of error, 0 in case of success.
 
92
 */
 
93
 
 
94
extern int
 
95
ancil_recv_fds(int, int *, unsigned);
 
96
/*
 
97
 * ancil_recv_fds(sock, n_fds, fds)
 
98
 *
 
99
 * Receives *n_fds file descriptors into the array pointed by fds
 
100
 * from the socket sock.
 
101
 * *n_fds must not be greater than ANCIL_MAX_N_FDS.
 
102
 * Returns: -1 and errno in case of error, the actual number of received fd
 
103
 * in case of success.
 
104
 */
 
105
 
 
106
 
 
107
extern int
 
108
ancil_send_fd(int, int);
 
109
/* ancil_recv_fd(sock, fd);
 
110
 *
 
111
 * Sends the file descriptor fd on the socket sock.
 
112
 * Returns : -1 and errno in case of error, 0 in case of success.
 
113
 */
 
114
 
 
115
extern int
 
116
ancil_recv_fd(int, int *);
 
117
/* ancil_send_fd(sock, &fd);
 
118
 *
 
119
 * Receives the file descriptor fd from the socket sock.
 
120
 * Returns : -1 and errno in case of error, 0 in case of success.
 
121
 */
 
122
 
 
123
#endif /* ANCILLARY_H__ */