WPILibC++ 2023.4.3
unix.h
Go to the documentation of this file.
1/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21
22#ifndef UV_UNIX_H
23#define UV_UNIX_H
24
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <fcntl.h>
28#include <dirent.h>
29
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <netinet/tcp.h>
33#include <arpa/inet.h>
34#include <netdb.h> /* MAXHOSTNAMELEN on Solaris */
35
36#include <termios.h>
37#include <pwd.h>
38
39#if !defined(__MVS__)
40#include <semaphore.h>
41#include <sys/param.h> /* MAXHOSTNAMELEN on Linux and the BSDs */
42#endif
43#include <pthread.h>
44#include <signal.h>
45
46#include "uv/threadpool.h"
47
48#if defined(__linux__)
49# include "uv/linux.h"
50#elif defined(__APPLE__)
51# include "uv/darwin.h"
52#elif defined(__DragonFly__) || \
53 defined(__FreeBSD__) || \
54 defined(__FreeBSD_kernel__) || \
55 defined(__OpenBSD__) || \
56 defined(__NetBSD__)
57# include "uv/bsd.h"
58#elif defined(__CYGWIN__) || \
59 defined(__MSYS__) || \
60 defined(__HAIKU__) || \
61 defined(__QNX__) || \
62 defined(__GNU__)
63# include "uv/posix.h"
64#endif
65
66#ifndef NI_MAXHOST
67# define NI_MAXHOST 1025
68#endif
69
70#ifndef NI_MAXSERV
71# define NI_MAXSERV 32
72#endif
73
74#ifndef UV_IO_PRIVATE_PLATFORM_FIELDS
75# define UV_IO_PRIVATE_PLATFORM_FIELDS /* empty */
76#endif
77
78struct uv__io_s;
79struct uv_loop_s;
80
81typedef void (*uv__io_cb)(struct uv_loop_s* loop,
82 struct uv__io_s* w,
83 unsigned int events);
84typedef struct uv__io_s uv__io_t;
85
86struct uv__io_s {
88 void* pending_queue[2];
89 void* watcher_queue[2];
90 unsigned int pevents; /* Pending event mask i.e. mask at next tick. */
91 unsigned int events; /* Current event mask. */
92 int fd;
94};
95
96#ifndef UV_PLATFORM_SEM_T
97# define UV_PLATFORM_SEM_T sem_t
98#endif
99
100#ifndef UV_PLATFORM_LOOP_FIELDS
101# define UV_PLATFORM_LOOP_FIELDS /* empty */
102#endif
103
104#ifndef UV_PLATFORM_FS_EVENT_FIELDS
105# define UV_PLATFORM_FS_EVENT_FIELDS /* empty */
106#endif
107
108#ifndef UV_STREAM_PRIVATE_PLATFORM_FIELDS
109# define UV_STREAM_PRIVATE_PLATFORM_FIELDS /* empty */
110#endif
111
112/* Note: May be cast to struct iovec. See writev(2). */
113typedef struct uv_buf_t {
114 char* base;
115 size_t len;
117
118typedef int uv_file;
119typedef int uv_os_sock_t;
120typedef int uv_os_fd_t;
121typedef pid_t uv_pid_t;
122
123#define UV_ONCE_INIT PTHREAD_ONCE_INIT
124
125typedef pthread_once_t uv_once_t;
126typedef pthread_t uv_thread_t;
127typedef pthread_mutex_t uv_mutex_t;
128typedef pthread_rwlock_t uv_rwlock_t;
130typedef pthread_cond_t uv_cond_t;
131typedef pthread_key_t uv_key_t;
132
133/* Note: guard clauses should match uv_barrier_init's in src/unix/thread.c. */
134#if defined(_AIX) || \
135 defined(__OpenBSD__) || \
136 !defined(PTHREAD_BARRIER_SERIAL_THREAD)
137/* TODO(bnoordhuis) Merge into uv_barrier_t in v2. */
141 unsigned threshold;
142 unsigned in;
143 unsigned out;
144};
145
146typedef struct {
147 struct _uv_barrier* b;
148# if defined(PTHREAD_BARRIER_SERIAL_THREAD)
149 /* TODO(bnoordhuis) Remove padding in v2. */
150 char pad[sizeof(pthread_barrier_t) - sizeof(struct _uv_barrier*)];
151# endif
153#else
154typedef pthread_barrier_t uv_barrier_t;
155#endif
156
157/* Platform-specific definitions for uv_spawn support. */
158typedef gid_t uv_gid_t;
159typedef uid_t uv_uid_t;
160
161typedef struct dirent uv__dirent_t;
162
163#define UV_DIR_PRIVATE_FIELDS \
164 DIR* dir;
165
166#if defined(DT_UNKNOWN)
167# define HAVE_DIRENT_TYPES
168# if defined(DT_REG)
169# define UV__DT_FILE DT_REG
170# else
171# define UV__DT_FILE -1
172# endif
173# if defined(DT_DIR)
174# define UV__DT_DIR DT_DIR
175# else
176# define UV__DT_DIR -2
177# endif
178# if defined(DT_LNK)
179# define UV__DT_LINK DT_LNK
180# else
181# define UV__DT_LINK -3
182# endif
183# if defined(DT_FIFO)
184# define UV__DT_FIFO DT_FIFO
185# else
186# define UV__DT_FIFO -4
187# endif
188# if defined(DT_SOCK)
189# define UV__DT_SOCKET DT_SOCK
190# else
191# define UV__DT_SOCKET -5
192# endif
193# if defined(DT_CHR)
194# define UV__DT_CHAR DT_CHR
195# else
196# define UV__DT_CHAR -6
197# endif
198# if defined(DT_BLK)
199# define UV__DT_BLOCK DT_BLK
200# else
201# define UV__DT_BLOCK -7
202# endif
203#endif
204
205/* Platform-specific definitions for uv_dlopen support. */
206#define UV_DYNAMIC /* empty */
207
208typedef struct {
209 void* handle;
210 char* errmsg;
211} uv_lib_t;
212
213#define UV_LOOP_PRIVATE_FIELDS \
214 unsigned long flags; \
215 int backend_fd; \
216 void* pending_queue[2]; \
217 void* watcher_queue[2]; \
218 void** watchers; \
219 unsigned int nwatchers; \
220 unsigned int nfds; \
221 void* wq[2]; \
222 uv_mutex_t wq_mutex; \
223 uv_async_t wq_async; \
224 uv_rwlock_t cloexec_lock; \
225 uv_handle_t* closing_handles; \
226 void* process_handles[2]; \
227 void* prepare_handles[2]; \
228 void* check_handles[2]; \
229 void* idle_handles[2]; \
230 void* async_handles[2]; \
231 void (*async_unused)(void); /* TODO(bnoordhuis) Remove in libuv v2. */ \
232 uv__io_t async_io_watcher; \
233 int async_wfd; \
234 struct { \
235 void* min; \
236 unsigned int nelts; \
237 } timer_heap; \
238 uint64_t timer_counter; \
239 uint64_t time; \
240 int signal_pipefd[2]; \
241 uv__io_t signal_io_watcher; \
242 uv_signal_t child_watcher; \
243 int emfile_fd; \
244 UV_PLATFORM_LOOP_FIELDS \
245
246#define UV_REQ_TYPE_PRIVATE /* empty */
247
248#define UV_REQ_PRIVATE_FIELDS /* empty */
249
250#define UV_PRIVATE_REQ_TYPES /* empty */
251
252#define UV_WRITE_PRIVATE_FIELDS \
253 void* queue[2]; \
254 unsigned int write_index; \
255 uv_buf_t* bufs; \
256 unsigned int nbufs; \
257 int error; \
258 uv_buf_t bufsml[4]; \
259
260#define UV_CONNECT_PRIVATE_FIELDS \
261 void* queue[2]; \
262
263#define UV_SHUTDOWN_PRIVATE_FIELDS /* empty */
264
265#define UV_UDP_SEND_PRIVATE_FIELDS \
266 void* queue[2]; \
267 struct sockaddr_storage addr; \
268 unsigned int nbufs; \
269 uv_buf_t* bufs; \
270 ssize_t status; \
271 uv_udp_send_cb send_cb; \
272 uv_buf_t bufsml[4]; \
273
274#define UV_HANDLE_PRIVATE_FIELDS \
275 uv_handle_t* next_closing; \
276 unsigned int flags; \
277
278#define UV_STREAM_PRIVATE_FIELDS \
279 uv_connect_t *connect_req; \
280 uv_shutdown_t *shutdown_req; \
281 uv__io_t io_watcher; \
282 void* write_queue[2]; \
283 void* write_completed_queue[2]; \
284 uv_connection_cb connection_cb; \
285 int delayed_error; \
286 int accepted_fd; \
287 void* queued_fds; \
288 UV_STREAM_PRIVATE_PLATFORM_FIELDS \
289
290#define UV_TCP_PRIVATE_FIELDS /* empty */
291
292#define UV_UDP_PRIVATE_FIELDS \
293 uv_alloc_cb alloc_cb; \
294 uv_udp_recv_cb recv_cb; \
295 uv__io_t io_watcher; \
296 void* write_queue[2]; \
297 void* write_completed_queue[2]; \
298
299#define UV_PIPE_PRIVATE_FIELDS \
300 const char* pipe_fname; /* strdup'ed */
301
302#define UV_POLL_PRIVATE_FIELDS \
303 uv__io_t io_watcher;
304
305#define UV_PREPARE_PRIVATE_FIELDS \
306 uv_prepare_cb prepare_cb; \
307 void* queue[2]; \
308
309#define UV_CHECK_PRIVATE_FIELDS \
310 uv_check_cb check_cb; \
311 void* queue[2]; \
312
313#define UV_IDLE_PRIVATE_FIELDS \
314 uv_idle_cb idle_cb; \
315 void* queue[2]; \
316
317#define UV_ASYNC_PRIVATE_FIELDS \
318 uv_async_cb async_cb; \
319 void* queue[2]; \
320 int pending; \
321
322#define UV_TIMER_PRIVATE_FIELDS \
323 uv_timer_cb timer_cb; \
324 void* heap_node[3]; \
325 uint64_t timeout; \
326 uint64_t repeat; \
327 uint64_t start_id;
328
329#define UV_GETADDRINFO_PRIVATE_FIELDS \
330 struct uv__work work_req; \
331 uv_getaddrinfo_cb cb; \
332 struct addrinfo* hints; \
333 char* hostname; \
334 char* service; \
335 struct addrinfo* addrinfo; \
336 int retcode;
337
338#define UV_GETNAMEINFO_PRIVATE_FIELDS \
339 struct uv__work work_req; \
340 uv_getnameinfo_cb getnameinfo_cb; \
341 struct sockaddr_storage storage; \
342 int flags; \
343 char host[NI_MAXHOST]; \
344 char service[NI_MAXSERV]; \
345 int retcode;
346
347#define UV_PROCESS_PRIVATE_FIELDS \
348 void* queue[2]; \
349 int status; \
350
351#define UV_FS_PRIVATE_FIELDS \
352 const char *new_path; \
353 uv_file file; \
354 int flags; \
355 mode_t mode; \
356 unsigned int nbufs; \
357 uv_buf_t* bufs; \
358 off_t off; \
359 uv_uid_t uid; \
360 uv_gid_t gid; \
361 double atime; \
362 double mtime; \
363 struct uv__work work_req; \
364 uv_buf_t bufsml[4]; \
365
366#define UV_WORK_PRIVATE_FIELDS \
367 struct uv__work work_req;
368
369#define UV_TTY_PRIVATE_FIELDS \
370 struct termios orig_termios; \
371 int mode;
372
373#define UV_SIGNAL_PRIVATE_FIELDS \
374 /* RB_ENTRY(uv_signal_s) tree_entry; */ \
375 struct { \
376 struct uv_signal_s* rbe_left; \
377 struct uv_signal_s* rbe_right; \
378 struct uv_signal_s* rbe_parent; \
379 int rbe_color; \
380 } tree_entry; \
381 /* Use two counters here so we don have to fiddle with atomics. */ \
382 unsigned int caught_signals; \
383 unsigned int dispatched_signals;
384
385#define UV_FS_EVENT_PRIVATE_FIELDS \
386 uv_fs_event_cb cb; \
387 UV_PLATFORM_FS_EVENT_FIELDS \
388
389/* fs open() flags supported on this platform: */
390#if defined(O_APPEND)
391# define UV_FS_O_APPEND O_APPEND
392#else
393# define UV_FS_O_APPEND 0
394#endif
395#if defined(O_CREAT)
396# define UV_FS_O_CREAT O_CREAT
397#else
398# define UV_FS_O_CREAT 0
399#endif
400
401#if defined(__linux__) && defined(__arm__)
402# define UV_FS_O_DIRECT 0x10000
403#elif defined(__linux__) && defined(__m68k__)
404# define UV_FS_O_DIRECT 0x10000
405#elif defined(__linux__) && defined(__mips__)
406# define UV_FS_O_DIRECT 0x08000
407#elif defined(__linux__) && defined(__powerpc__)
408# define UV_FS_O_DIRECT 0x20000
409#elif defined(__linux__) && defined(__s390x__)
410# define UV_FS_O_DIRECT 0x04000
411#elif defined(__linux__) && defined(__x86_64__)
412# define UV_FS_O_DIRECT 0x04000
413#elif defined(O_DIRECT)
414# define UV_FS_O_DIRECT O_DIRECT
415#else
416# define UV_FS_O_DIRECT 0
417#endif
418
419#if defined(O_DIRECTORY)
420# define UV_FS_O_DIRECTORY O_DIRECTORY
421#else
422# define UV_FS_O_DIRECTORY 0
423#endif
424#if defined(O_DSYNC)
425# define UV_FS_O_DSYNC O_DSYNC
426#else
427# define UV_FS_O_DSYNC 0
428#endif
429#if defined(O_EXCL)
430# define UV_FS_O_EXCL O_EXCL
431#else
432# define UV_FS_O_EXCL 0
433#endif
434#if defined(O_EXLOCK)
435# define UV_FS_O_EXLOCK O_EXLOCK
436#else
437# define UV_FS_O_EXLOCK 0
438#endif
439#if defined(O_NOATIME)
440# define UV_FS_O_NOATIME O_NOATIME
441#else
442# define UV_FS_O_NOATIME 0
443#endif
444#if defined(O_NOCTTY)
445# define UV_FS_O_NOCTTY O_NOCTTY
446#else
447# define UV_FS_O_NOCTTY 0
448#endif
449#if defined(O_NOFOLLOW)
450# define UV_FS_O_NOFOLLOW O_NOFOLLOW
451#else
452# define UV_FS_O_NOFOLLOW 0
453#endif
454#if defined(O_NONBLOCK)
455# define UV_FS_O_NONBLOCK O_NONBLOCK
456#else
457# define UV_FS_O_NONBLOCK 0
458#endif
459#if defined(O_RDONLY)
460# define UV_FS_O_RDONLY O_RDONLY
461#else
462# define UV_FS_O_RDONLY 0
463#endif
464#if defined(O_RDWR)
465# define UV_FS_O_RDWR O_RDWR
466#else
467# define UV_FS_O_RDWR 0
468#endif
469#if defined(O_SYMLINK)
470# define UV_FS_O_SYMLINK O_SYMLINK
471#else
472# define UV_FS_O_SYMLINK 0
473#endif
474#if defined(O_SYNC)
475# define UV_FS_O_SYNC O_SYNC
476#else
477# define UV_FS_O_SYNC 0
478#endif
479#if defined(O_TRUNC)
480# define UV_FS_O_TRUNC O_TRUNC
481#else
482# define UV_FS_O_TRUNC 0
483#endif
484#if defined(O_WRONLY)
485# define UV_FS_O_WRONLY O_WRONLY
486#else
487# define UV_FS_O_WRONLY 0
488#endif
489
490/* fs open() flags supported on other platforms: */
491#define UV_FS_O_FILEMAP 0
492#define UV_FS_O_RANDOM 0
493#define UV_FS_O_SHORT_LIVED 0
494#define UV_FS_O_SEQUENTIAL 0
495#define UV_FS_O_TEMPORARY 0
496
497#endif /* UV_UNIX_H */
Definition: unix.h:138
unsigned out
Definition: unix.h:143
unsigned threshold
Definition: unix.h:141
uv_mutex_t mutex
Definition: unix.h:139
uv_cond_t cond
Definition: unix.h:140
unsigned in
Definition: unix.h:142
Definition: win.h:300
Definition: unix.h:86
uv__io_cb cb
Definition: unix.h:87
void * watcher_queue[2]
Definition: unix.h:89
unsigned int events
Definition: unix.h:91
unsigned int pevents
Definition: unix.h:90
void * pending_queue[2]
Definition: unix.h:88
int fd
Definition: unix.h:92
Definition: win.h:277
struct _uv_barrier * b
Definition: unix.h:147
It should be possible to cast uv_buf_t[] to WSABUF[] see http://msdn.microsoft.com/en-us/library/ms74...
Definition: win.h:234
size_t len
Definition: unix.h:115
char * base
Definition: win.h:236
Definition: win.h:321
void * handle
Definition: unix.h:209
Definition: uv.h:1793
Definition: win.h:257
pthread_cond_t uv_cond_t
Definition: unix.h:130
uid_t uv_uid_t
Definition: unix.h:159
UV_PLATFORM_SEM_T uv_sem_t
Definition: unix.h:129
struct uv_buf_t uv_buf_t
int uv_file
Definition: unix.h:118
pid_t uv_pid_t
Definition: unix.h:121
pthread_rwlock_t uv_rwlock_t
Definition: unix.h:128
pthread_key_t uv_key_t
Definition: unix.h:131
#define UV_IO_PRIVATE_PLATFORM_FIELDS
Definition: unix.h:75
pthread_mutex_t uv_mutex_t
Definition: unix.h:127
pthread_t uv_thread_t
Definition: unix.h:126
void(* uv__io_cb)(struct uv_loop_s *loop, struct uv__io_s *w, unsigned int events)
Definition: unix.h:81
pthread_once_t uv_once_t
Definition: unix.h:125
int uv_os_fd_t
Definition: unix.h:120
gid_t uv_gid_t
Definition: unix.h:158
int uv_os_sock_t
Definition: unix.h:119
#define UV_PLATFORM_SEM_T
Definition: unix.h:97
CRITICAL_SECTION uv_mutex_t
Definition: win.h:248