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