Turn audio into a shareable video. forked from nypublicradio/audiogram

unix.h 19KB

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