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