File indexing completed on 2026-09-10 09:14:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #ifndef UV_UNIX_H
0023 #define UV_UNIX_H
0024
0025 #include <sys/types.h>
0026 #include <sys/stat.h>
0027 #include <fcntl.h>
0028 #include <dirent.h>
0029
0030 #include <sys/socket.h>
0031 #include <netinet/in.h>
0032 #include <netinet/tcp.h>
0033 #include <arpa/inet.h>
0034 #include <netdb.h> /* MAXHOSTNAMELEN on Solaris */
0035
0036 #include <termios.h>
0037 #include <pwd.h>
0038
0039 #if !defined(__MVS__)
0040 #include <semaphore.h>
0041 #include <sys/param.h> /* MAXHOSTNAMELEN on Linux and the BSDs */
0042 #endif
0043 #include <pthread.h>
0044 #include <signal.h>
0045
0046 #include "uv/threadpool.h"
0047
0048 #if defined(__linux__)
0049 # include "uv/linux.h"
0050 #elif defined (__MVS__)
0051 # include "uv/os390.h"
0052 #elif defined(__PASE__)
0053 # include "uv/posix.h" /* IBM i needs uv/posix.h, not uv/aix.h */
0054 #elif defined(_AIX)
0055 # include "uv/aix.h"
0056 #elif defined(__sun)
0057 # include "uv/sunos.h"
0058 #elif defined(__APPLE__)
0059 # include "uv/darwin.h"
0060 #elif defined(__DragonFly__) || \
0061 defined(__FreeBSD__) || \
0062 defined(__OpenBSD__) || \
0063 defined(__NetBSD__)
0064 # include "uv/bsd.h"
0065 #elif defined(__CYGWIN__) || \
0066 defined(__MSYS__) || \
0067 defined(__HAIKU__) || \
0068 defined(__QNX__) || \
0069 defined(__GNU__)
0070 # include "uv/posix.h"
0071 #endif
0072
0073 #ifndef NI_MAXHOST
0074 # define NI_MAXHOST 1025
0075 #endif
0076
0077 #ifndef NI_MAXSERV
0078 # define NI_MAXSERV 32
0079 #endif
0080
0081 #ifndef UV_IO_PRIVATE_PLATFORM_FIELDS
0082 # define UV_IO_PRIVATE_PLATFORM_FIELDS
0083 #endif
0084
0085 struct uv__io_s;
0086 struct uv_loop_s;
0087
0088 typedef struct uv__io_s uv__io_t;
0089
0090 struct uv__io_s {
0091 uintptr_t bits;
0092 struct uv__queue pending_queue;
0093 struct uv__queue watcher_queue;
0094 unsigned int pevents;
0095 unsigned int events;
0096 int fd;
0097 UV_IO_PRIVATE_PLATFORM_FIELDS
0098 };
0099
0100 #ifndef UV_PLATFORM_SEM_T
0101 # define UV_PLATFORM_SEM_T sem_t
0102 #endif
0103
0104 #ifndef UV_PLATFORM_LOOP_FIELDS
0105 # define UV_PLATFORM_LOOP_FIELDS
0106 #endif
0107
0108 #ifndef UV_PLATFORM_FS_EVENT_FIELDS
0109 # define UV_PLATFORM_FS_EVENT_FIELDS
0110 #endif
0111
0112 #ifndef UV_STREAM_PRIVATE_PLATFORM_FIELDS
0113 # define UV_STREAM_PRIVATE_PLATFORM_FIELDS
0114 #endif
0115
0116
0117 typedef struct uv_buf_t {
0118 char* base;
0119 size_t len;
0120 } uv_buf_t;
0121
0122 typedef int uv_file;
0123 typedef int uv_os_sock_t;
0124 typedef int uv_os_fd_t;
0125 typedef pid_t uv_pid_t;
0126
0127 #define UV_ONCE_INIT PTHREAD_ONCE_INIT
0128
0129 typedef pthread_once_t uv_once_t;
0130 typedef pthread_t uv_thread_t;
0131 typedef pthread_mutex_t uv_mutex_t;
0132 typedef pthread_rwlock_t uv_rwlock_t;
0133 typedef UV_PLATFORM_SEM_T uv_sem_t;
0134 typedef pthread_cond_t uv_cond_t;
0135 typedef pthread_key_t uv_key_t;
0136
0137
0138 #if defined(_AIX) || \
0139 defined(__OpenBSD__) || \
0140 !defined(PTHREAD_BARRIER_SERIAL_THREAD)
0141
0142 struct _uv_barrier {
0143 uv_mutex_t mutex;
0144 uv_cond_t cond;
0145 unsigned threshold;
0146 unsigned in;
0147 unsigned out;
0148 };
0149
0150 typedef struct {
0151 struct _uv_barrier* b;
0152 # if defined(PTHREAD_BARRIER_SERIAL_THREAD)
0153
0154 char pad[sizeof(pthread_barrier_t) - sizeof(struct _uv_barrier*)];
0155 # endif
0156 } uv_barrier_t;
0157 #else
0158 typedef pthread_barrier_t uv_barrier_t;
0159 #endif
0160
0161
0162 typedef gid_t uv_gid_t;
0163 typedef uid_t uv_uid_t;
0164
0165 typedef struct dirent uv__dirent_t;
0166
0167 #define UV_DIR_PRIVATE_FIELDS \
0168 DIR* dir;
0169
0170 #if defined(DT_UNKNOWN)
0171 # define HAVE_DIRENT_TYPES
0172 # if defined(DT_REG)
0173 # define UV__DT_FILE DT_REG
0174 # else
0175 # define UV__DT_FILE -1
0176 # endif
0177 # if defined(DT_DIR)
0178 # define UV__DT_DIR DT_DIR
0179 # else
0180 # define UV__DT_DIR -2
0181 # endif
0182 # if defined(DT_LNK)
0183 # define UV__DT_LINK DT_LNK
0184 # else
0185 # define UV__DT_LINK -3
0186 # endif
0187 # if defined(DT_FIFO)
0188 # define UV__DT_FIFO DT_FIFO
0189 # else
0190 # define UV__DT_FIFO -4
0191 # endif
0192 # if defined(DT_SOCK)
0193 # define UV__DT_SOCKET DT_SOCK
0194 # else
0195 # define UV__DT_SOCKET -5
0196 # endif
0197 # if defined(DT_CHR)
0198 # define UV__DT_CHAR DT_CHR
0199 # else
0200 # define UV__DT_CHAR -6
0201 # endif
0202 # if defined(DT_BLK)
0203 # define UV__DT_BLOCK DT_BLK
0204 # else
0205 # define UV__DT_BLOCK -7
0206 # endif
0207 #endif
0208
0209
0210 #define UV_DYNAMIC
0211
0212 typedef struct {
0213 void* handle;
0214 char* errmsg;
0215 } uv_lib_t;
0216
0217 #define UV_LOOP_PRIVATE_FIELDS \
0218 unsigned long flags; \
0219 int backend_fd; \
0220 struct uv__queue pending_queue; \
0221 struct uv__queue watcher_queue; \
0222 uv__io_t** watchers; \
0223 unsigned int nwatchers; \
0224 unsigned int nfds; \
0225 struct uv__queue wq; \
0226 uv_mutex_t wq_mutex; \
0227 uv_async_t wq_async; \
0228 uv_rwlock_t cloexec_lock; \
0229 uv_handle_t* closing_handles; \
0230 struct uv__queue process_handles; \
0231 struct uv__queue prepare_handles; \
0232 struct uv__queue check_handles; \
0233 struct uv__queue idle_handles; \
0234 struct uv__queue async_handles; \
0235 void (*async_unused)(void); \
0236 uv__io_t async_io_watcher; \
0237 int async_wfd; \
0238 struct { \
0239 void* min; \
0240 unsigned int nelts; \
0241 } timer_heap; \
0242 uint64_t timer_counter; \
0243 uint64_t time; \
0244 int signal_pipefd[2]; \
0245 uv__io_t signal_io_watcher; \
0246 uv_signal_t child_watcher; \
0247 int emfile_fd; \
0248 UV_PLATFORM_LOOP_FIELDS \
0249
0250 #define UV_REQ_TYPE_PRIVATE
0251
0252 #define UV_REQ_PRIVATE_FIELDS
0253
0254 #define UV_PRIVATE_REQ_TYPES
0255
0256 #define UV_WRITE_PRIVATE_FIELDS \
0257 struct uv__queue queue; \
0258 unsigned int write_index; \
0259 uv_buf_t* bufs; \
0260 unsigned int nbufs; \
0261 int error; \
0262 uv_buf_t bufsml[4]; \
0263
0264 #define UV_CONNECT_PRIVATE_FIELDS \
0265 struct uv__queue queue; \
0266
0267 #define UV_SHUTDOWN_PRIVATE_FIELDS
0268
0269 #define UV_UDP_SEND_PRIVATE_FIELDS \
0270 struct uv__queue queue; \
0271 union { \
0272 struct sockaddr addr; \
0273 struct sockaddr_storage storage; \
0274 } u; \
0275 unsigned int nbufs; \
0276 uv_buf_t* bufs; \
0277 ssize_t status; \
0278 uv_udp_send_cb send_cb; \
0279 uv_buf_t bufsml[4]; \
0280
0281 #define UV_HANDLE_PRIVATE_FIELDS \
0282 uv_handle_t* next_closing; \
0283 unsigned int flags; \
0284
0285 #define UV_STREAM_PRIVATE_FIELDS \
0286 uv_connect_t *connect_req; \
0287 uv_shutdown_t *shutdown_req; \
0288 uv__io_t io_watcher; \
0289 struct uv__queue write_queue; \
0290 struct uv__queue write_completed_queue; \
0291 uv_connection_cb connection_cb; \
0292 int delayed_error; \
0293 int accepted_fd; \
0294 void* queued_fds; \
0295 UV_STREAM_PRIVATE_PLATFORM_FIELDS \
0296
0297 #define UV_TCP_PRIVATE_FIELDS
0298
0299 #define UV_UDP_PRIVATE_FIELDS \
0300 uv_alloc_cb alloc_cb; \
0301 uv_udp_recv_cb recv_cb; \
0302 uv__io_t io_watcher; \
0303 struct uv__queue write_queue; \
0304 struct uv__queue write_completed_queue; \
0305
0306 #define UV_PIPE_PRIVATE_FIELDS \
0307 const char* pipe_fname;
0308
0309 #define UV_POLL_PRIVATE_FIELDS \
0310 uv__io_t io_watcher;
0311
0312 #define UV_PREPARE_PRIVATE_FIELDS \
0313 uv_prepare_cb prepare_cb; \
0314 struct uv__queue queue; \
0315
0316 #define UV_CHECK_PRIVATE_FIELDS \
0317 uv_check_cb check_cb; \
0318 struct uv__queue queue; \
0319
0320 #define UV_IDLE_PRIVATE_FIELDS \
0321 uv_idle_cb idle_cb; \
0322 struct uv__queue queue; \
0323
0324 #define UV_ASYNC_PRIVATE_FIELDS \
0325 uv_async_cb async_cb; \
0326 struct uv__queue queue; \
0327 int pending; \
0328
0329 #define UV_TIMER_PRIVATE_FIELDS \
0330 uv_timer_cb timer_cb; \
0331 union { \
0332 void* heap[3]; \
0333 struct uv__queue queue; \
0334 } node; \
0335 uint64_t timeout; \
0336 uint64_t repeat; \
0337 uint64_t start_id;
0338
0339 #define UV_GETADDRINFO_PRIVATE_FIELDS \
0340 struct uv__work work_req; \
0341 uv_getaddrinfo_cb cb; \
0342 struct addrinfo* hints; \
0343 char* hostname; \
0344 char* service; \
0345 struct addrinfo* addrinfo; \
0346 int retcode;
0347
0348 #define UV_GETNAMEINFO_PRIVATE_FIELDS \
0349 struct uv__work work_req; \
0350 uv_getnameinfo_cb getnameinfo_cb; \
0351 struct sockaddr_storage storage; \
0352 int flags; \
0353 char host[NI_MAXHOST]; \
0354 char service[NI_MAXSERV]; \
0355 int retcode;
0356
0357 #define UV_PROCESS_PRIVATE_FIELDS \
0358 struct uv__queue queue; \
0359 int status; \
0360
0361 #define UV_FS_PRIVATE_FIELDS \
0362 const char *new_path; \
0363 uv_file file; \
0364 int flags; \
0365 mode_t mode; \
0366 unsigned int nbufs; \
0367 uv_buf_t* bufs; \
0368 off_t off; \
0369 uv_uid_t uid; \
0370 uv_gid_t gid; \
0371 double atime; \
0372 double mtime; \
0373 struct uv__work work_req; \
0374 uv_buf_t bufsml[4]; \
0375
0376 #define UV_WORK_PRIVATE_FIELDS \
0377 struct uv__work work_req;
0378
0379 #define UV_TTY_PRIVATE_FIELDS \
0380 struct termios orig_termios; \
0381 int mode;
0382
0383 #define UV_SIGNAL_PRIVATE_FIELDS \
0384 \
0385 struct { \
0386 struct uv_signal_s* rbe_left; \
0387 struct uv_signal_s* rbe_right; \
0388 struct uv_signal_s* rbe_parent; \
0389 int rbe_color; \
0390 } tree_entry; \
0391 \
0392 unsigned int caught_signals; \
0393 unsigned int dispatched_signals;
0394
0395 #define UV_FS_EVENT_PRIVATE_FIELDS \
0396 uv_fs_event_cb cb; \
0397 UV_PLATFORM_FS_EVENT_FIELDS \
0398
0399
0400 #if defined(O_APPEND)
0401 # define UV_FS_O_APPEND O_APPEND
0402 #else
0403 # define UV_FS_O_APPEND 0
0404 #endif
0405 #if defined(O_CREAT)
0406 # define UV_FS_O_CREAT O_CREAT
0407 #else
0408 # define UV_FS_O_CREAT 0
0409 #endif
0410
0411 #if defined(__linux__) && defined(__arm__)
0412 # define UV_FS_O_DIRECT 0x10000
0413 #elif defined(__linux__) && defined(__m68k__)
0414 # define UV_FS_O_DIRECT 0x10000
0415 #elif defined(__linux__) && defined(__mips__)
0416 # define UV_FS_O_DIRECT 0x08000
0417 #elif defined(__linux__) && defined(__powerpc__)
0418 # define UV_FS_O_DIRECT 0x20000
0419 #elif defined(__linux__) && defined(__s390x__)
0420 # define UV_FS_O_DIRECT 0x04000
0421 #elif defined(__linux__) && defined(__x86_64__)
0422 # define UV_FS_O_DIRECT 0x04000
0423 #elif defined(__linux__) && defined(__loongarch__)
0424 # define UV_FS_O_DIRECT 0x04000
0425 #elif defined(O_DIRECT)
0426 # define UV_FS_O_DIRECT O_DIRECT
0427 #else
0428 # define UV_FS_O_DIRECT 0
0429 #endif
0430
0431 #if defined(O_DIRECTORY)
0432 # define UV_FS_O_DIRECTORY O_DIRECTORY
0433 #else
0434 # define UV_FS_O_DIRECTORY 0
0435 #endif
0436 #if defined(O_DSYNC)
0437 # define UV_FS_O_DSYNC O_DSYNC
0438 #else
0439 # define UV_FS_O_DSYNC 0
0440 #endif
0441 #if defined(O_EXCL)
0442 # define UV_FS_O_EXCL O_EXCL
0443 #else
0444 # define UV_FS_O_EXCL 0
0445 #endif
0446 #if defined(O_EXLOCK)
0447 # define UV_FS_O_EXLOCK O_EXLOCK
0448 #else
0449 # define UV_FS_O_EXLOCK 0
0450 #endif
0451 #if defined(O_NOATIME)
0452 # define UV_FS_O_NOATIME O_NOATIME
0453 #else
0454 # define UV_FS_O_NOATIME 0
0455 #endif
0456 #if defined(O_NOCTTY)
0457 # define UV_FS_O_NOCTTY O_NOCTTY
0458 #else
0459 # define UV_FS_O_NOCTTY 0
0460 #endif
0461 #if defined(O_NOFOLLOW)
0462 # define UV_FS_O_NOFOLLOW O_NOFOLLOW
0463 #else
0464 # define UV_FS_O_NOFOLLOW 0
0465 #endif
0466 #if defined(O_NONBLOCK)
0467 # define UV_FS_O_NONBLOCK O_NONBLOCK
0468 #else
0469 # define UV_FS_O_NONBLOCK 0
0470 #endif
0471 #if defined(O_RDONLY)
0472 # define UV_FS_O_RDONLY O_RDONLY
0473 #else
0474 # define UV_FS_O_RDONLY 0
0475 #endif
0476 #if defined(O_RDWR)
0477 # define UV_FS_O_RDWR O_RDWR
0478 #else
0479 # define UV_FS_O_RDWR 0
0480 #endif
0481 #if defined(O_SYMLINK)
0482 # define UV_FS_O_SYMLINK O_SYMLINK
0483 #else
0484 # define UV_FS_O_SYMLINK 0
0485 #endif
0486 #if defined(O_SYNC)
0487 # define UV_FS_O_SYNC O_SYNC
0488 #else
0489 # define UV_FS_O_SYNC 0
0490 #endif
0491 #if defined(O_TRUNC)
0492 # define UV_FS_O_TRUNC O_TRUNC
0493 #else
0494 # define UV_FS_O_TRUNC 0
0495 #endif
0496 #if defined(O_WRONLY)
0497 # define UV_FS_O_WRONLY O_WRONLY
0498 #else
0499 # define UV_FS_O_WRONLY 0
0500 #endif
0501
0502
0503 #define UV_FS_O_FILEMAP 0
0504 #define UV_FS_O_RANDOM 0
0505 #define UV_FS_O_SHORT_LIVED 0
0506 #define UV_FS_O_SEQUENTIAL 0
0507 #define UV_FS_O_TEMPORARY 0
0508
0509 #endif