xref: /unit/src/nxt_test_build.h (revision 0:a63ceefd6ab0)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 
8 #ifndef _NXT_UNIX_TEST_BUILD_H_INCLUDED_
9 #define _NXT_UNIX_TEST_BUILD_H_INCLUDED_
10 
11 
12 #if (NXT_TEST_BUILD_EPOLL)
13 
14 #define NXT_HAVE_EPOLL       1
15 #define NXT_HAVE_EPOLL_EDGE  1
16 #define NXT_HAVE_EVENTFD     1
17 #define NXT_HAVE_SIGNALFD    1
18 #define NXT_HAVE_ACCEPT4     1
19 
20 /* Linux epoll declarations */
21 
22 #define EPOLLIN        0x00000001
23 #define EPOLLPRI       0x00000002
24 #define EPOLLOUT       0x00000004
25 #define EPOLLERR       0x00000008
26 #define EPOLLHUP       0x00000010
27 #define EPOLLRDNORM    0x00000040
28 #define EPOLLRDBAND    0x00000080
29 #define EPOLLWRNORM    00000x0100
30 #define EPOLLWRBAND    0x00000200
31 #define EPOLLMSG       0x00000400
32 #define EPOLLRDHUP     0x00002000
33 
34 #define EPOLLET        0x80000000
35 #define EPOLLONESHOT   0x40000000
36 
37 #define EPOLL_CTL_ADD  1
38 #define EPOLL_CTL_DEL  2
39 #define EPOLL_CTL_MOD  3
40 
41 #define EFD_SEMAPHORE  1
42 #define EFD_NONBLOCK   04000
43 
44 
45 typedef union epoll_data {
46     void               *ptr;
47     int                fd;
48     uint32_t           u32;
49     uint64_t           u64;
50 } epoll_data_t;
51 
52 
53 struct epoll_event {
54     uint32_t           events;
55     epoll_data_t       data;
56 };
57 
58 
59 struct signalfd_siginfo {
60     uint32_t           ssi_signo;   /* Signal number */
61     int32_t            ssi_errno;   /* Error number (unused) */
62     int32_t            ssi_code;    /* Signal code */
63     uint32_t           ssi_pid;     /* PID of sender */
64     uint32_t           ssi_uid;     /* Real UID of sender */
65     int32_t            ssi_fd;      /* File descriptor (SIGIO) */
66     uint32_t           ssi_tid;     /* Kernel timer ID (POSIX timers) */
67     uint32_t           ssi_band;    /* Band event (SIGIO) */
68     uint32_t           ssi_overrun; /* POSIX timer overrun count */
69     uint32_t           ssi_trapno;  /* Trap number that caused signal */
70     int32_t            ssi_status;  /* Exit status or signal (SIGCHLD) */
71     int32_t            ssi_int;     /* Integer sent by sigqueue(2) */
72     uint64_t           ssi_ptr;     /* Pointer sent by sigqueue(2) */
73     uint64_t           ssi_utime;   /* User CPU time consumed (SIGCHLD) */
74     uint64_t           ssi_stime;   /* System CPU time consumed (SIGCHLD) */
75     uint64_t           ssi_addr;    /* Address that generated signal
76                                        (for hardware-generated signals) */
77     uint8_t            pad[8];      /* Pad size to 128 bytes (allow for
78                                        additional fields in the future) */
79 };
80 
81 
82 int epoll_create(int size);
83 int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
84 int epoll_wait(int epfd, struct epoll_event *events, int nevents, int timeout);
85 
86 int eventfd(u_int initval, int flags);
87 int signalfd(int fd, const sigset_t *mask, int flags);
88 
89 #define SOCK_NONBLOCK  04000
90 
91 int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
92 
93 #endif
94 
95 
96 #if (NXT_TEST_BUILD_EVENTPORT)
97 
98 #include <poll.h>
99 
100 #define NXT_HAVE_EVENTPORT  1
101 
102 #define ushort_t  u_short
103 #define uint_t    u_int
104 
105 /* Solaris eventport declarations */
106 
107 #define PORT_SOURCE_AIO    1
108 #define PORT_SOURCE_TIMER  2
109 #define PORT_SOURCE_USER   3
110 #define PORT_SOURCE_FD     4
111 #define PORT_SOURCE_ALERT  5
112 #define PORT_SOURCE_MQ     6
113 #define PORT_SOURCE_FILE   7
114 
115 #ifndef ETIME
116 #define ETIME              62
117 #endif
118 
119 
120 typedef struct {
121     int                    portev_events;  /* event data is source specific */
122     ushort_t               portev_source;  /* event source */
123     ushort_t               portev_pad;     /* port internal use */
124     uintptr_t              portev_object;  /* source specific object */
125     void                   *portev_user;   /* user cookie */
126 } port_event_t;
127 
128 
129 typedef struct timespec  timespec_t;
130 typedef struct timespec  timestruc_t;
131 
132 
133 typedef struct file_obj {
134     timestruc_t            fo_atime;       /* Access time from stat(2) */
135     timestruc_t            fo_mtime;       /* Modification time from stat(2) */
136     timestruc_t            fo_ctime;       /* Change time from stat(2) */
137     uintptr_t              fo_pad[3];      /* For future expansion */
138     char                   *fo_name;       /* Null terminated file name */
139 } file_obj_t;
140 
141 
142 int port_create(void);
143 int port_associate(int port, int source, uintptr_t object, int events,
144     void *user);
145 int port_dissociate(int port, int source, uintptr_t object);
146 int port_send(int port, int events, void *user);
147 int port_getn(int port, port_event_t list[], uint_t max, uint_t *nget,
148     const timespec_t *timeout);
149 
150 #endif
151 
152 
153 #if (NXT_TEST_BUILD_DEVPOLL)
154 
155 #define NXT_HAVE_DEVPOLL  1
156 
157 #include <poll.h>
158 #include <sys/ioctl.h>
159 
160 /* Solaris /dev/poll declarations */
161 
162 #define POLLREMOVE      0x0800
163 #define DP_POLL         0xD001
164 #define DP_ISPOLLED     0xD002
165 
166 
167 struct dvpoll {
168     struct pollfd       *dp_fds;
169     int                 dp_nfds;
170     int                 dp_timeout;
171 };
172 
173 #endif
174 
175 
176 #if (NXT_TEST_BUILD_POLLSET)
177 
178 #define NXT_HAVE_POLLSET  1
179 
180 #include <poll.h>
181 
182 /* AIX pollset declarations */
183 
184 #define PS_ADD          0x0
185 #define PS_MOD          0x1
186 #define PS_DELETE       0x2
187 
188 
189 typedef int             pollset_t;
190 
191 struct poll_ctl {
192     short               cmd;
193     short               events;
194     int                 fd;
195 };
196 
197 
198 pollset_t pollset_create(int maxfd);
199 int pollset_destroy(pollset_t ps);
200 int pollset_query(pollset_t ps, struct pollfd *pollfd_query);
201 int pollset_ctl(pollset_t ps, struct poll_ctl *pollctl_array, int array_length);
202 int pollset_poll(pollset_t ps, struct pollfd *polldata_array, int array_length,
203     int timeout);
204 
205 #endif
206 
207 
208 #if (NXT_TEST_BUILD_FREEBSD_SENDFILE || NXT_TEST_BUILD_MACOSX_SENDFILE)
209 
210 #if !(NXT_FREEBSD) && !(NXT_MACOSX)
211 
212 struct sf_hdtr {
213     struct iovec  *headers;
214     int           hdr_cnt;
215     struct iovec  *trailers;
216     int           trl_cnt;
217 };
218 
219 #endif
220 
221 #endif
222 
223 
224 #if (NXT_TEST_BUILD_SOLARIS_SENDFILEV)
225 
226 /* Solaris declarations */
227 
228 typedef struct sendfilevec {
229     int     sfv_fd;
230     u_int   sfv_flag;
231     off_t   sfv_off;
232     size_t  sfv_len;
233 } sendfilevec_t;
234 
235 #define SFV_FD_SELF  -2
236 
237 ssize_t sendfilev(int fd, const struct sendfilevec *vec, int sfvcnt,
238     size_t *xferred);
239 
240 #endif
241 
242 
243 #if (NXT_TEST_BUILD_AIX_SEND_FILE)
244 
245 #ifndef uint_t
246 #define uint_t    u_int
247 #endif
248 
249 struct sf_parms {
250     void      *header_data;
251     uint_t    header_length;
252 
253     int       file_descriptor;
254     uint64_t  file_size;
255     uint64_t  file_offset;
256     int64_t   file_bytes;
257 
258     void      *trailer_data;
259     uint_t    trailer_length;
260 
261     uint64_t  bytes_sent;
262 };
263 
264 #define SF_CLOSE       0x00000001  /* close the socket after completion */
265 #define SF_REUSE       0x00000002  /* reuse socket. not supported */
266 #define SF_DONT_CACHE  0x00000004  /* don't apply network buffer cache */
267 #define SF_SYNC_CACHE  0x00000008  /* sync/update network buffer cache */
268 
269 ssize_t send_file(int *s, struct sf_parms *sf_iobuf, uint_t flags);
270 
271 #endif
272 
273 
274 #endif /* _NXT_UNIX_TEST_BUILD_H_INCLUDED_ */
275