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