1 module deimos.uv.unix; 2 public import deimos.uv._d; 3 version(Posix): 4 extern(C): 5 pure: 6 nothrow: 7 @nogc: 8 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining a copy 11 * of this software and associated documentation files (the "Software"), to 12 * deal in the Software without restriction, including without limitation the 13 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 14 * sell copies of the Software, and to permit persons to whom the Software is 15 * furnished to do so, subject to the following conditions: 16 * 17 * The above copyright notice and this permission notice shall be included in 18 * all copies or substantial portions of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 26 * IN THE SOFTWARE. 27 */ 28 /* UV_UNIX_H */ 29 /* include(sys/types.h); */ 30 /* include(sys/stat.h); */ 31 /* include(fcntl.h); */ 32 /* include(dirent.h); */ 33 /* include(sys/socket.h); */ 34 /* include(netinet/in.h); */ 35 /* include(netinet/tcp.h); */ 36 /* include(arpa/inet.h); */ 37 /* include(netdb.h); */ 38 /* MAXHOSTNAMELEN on Solaris */ 39 /* include(termios.h); */ 40 /* include(pwd.h); */ 41 static if( isOS390 ) { 42 /* include(semaphore.h); */ 43 /* include(sys/param.h); */ 44 /* MAXHOSTNAMELEN on Linux and the BSDs */ 45 } 46 /* include(pthread.h); */ 47 /* include(signal.h); */ 48 package import deimos.uv.threadpool; /* include(uv/threadpool.h); */ 49 static if( isLinuxOS ) { 50 package import deimos.uv.linux; /* include(uv/linux.h); */ 51 } else static if( isOS390 ) { 52 package import deimos.uv.os390; /* include(uv/os390.h); */ 53 } else static if( isOS400 ) { 54 package import deimos.uv.posix; /* include(uv/posix.h); */ 55 /* IBM i needs uv/posix.h, not uv/aix.h */ 56 } else static if( isAixOS ) { 57 package import deimos.uv.aix; /* include(uv/aix.h); */ 58 } else static if( isSunOS ) { 59 package import deimos.uv.sunos; /* include(uv/sunos.h); */ 60 } else static if( isMacOS ) { 61 package import deimos.uv.darwin; /* include(uv/darwin.h); */ 62 } else static if( isBsdOS ) { 63 package import deimos.uv.bsd; /* include(uv/bsd.h); */ 64 } else static if( isCygWin ) { 65 package import deimos.uv.posix; /* include(uv/posix.h); */ 66 } else static if( isHaiKuOS ) { 67 package import deimos.uv.posix; /* include(uv/posix.h); */ 68 } else static if( isQNX ) { 69 package import deimos.uv.posix; /* include(uv/posix.h); */ 70 } 71 enum NI_MAXSERV = 32; 72 static if( isLinuxOS || isAixOS || isSunOS ) { 73 template UV_IO_PRIVATE_PLATFORM_FIELDS() {}; 74 } 75 alias uv__io_cb = ExternC!(void function(uv_loop_s* loop, uv__io_s* w, uint events)); 76 alias uv__io_t = uv__io_s ; 77 struct uv__io_s { 78 uv__io_cb cb; 79 void*[2] pending_queue; 80 void*[2] watcher_queue; 81 uint pevents; 82 /* Pending event mask i.e. mask at next tick. */ 83 uint events; 84 /* Current event mask. */ 85 int fd; 86 mixin UV_IO_PRIVATE_PLATFORM_FIELDS; 87 }; 88 static if( !isMacOS ) { 89 alias UV_PLATFORM_SEM_T = sem_t; 90 } 91 static if( isBsdOS ) { 92 template UV_PLATFORM_LOOP_FIELDS() {}; 93 } 94 static if( !isMacOS ) { 95 template UV_STREAM_PRIVATE_PLATFORM_FIELDS() {}; 96 } 97 /* Note: May be cast to struct iovec. See writev(2). */ 98 struct uv_buf_t { 99 char* base; 100 size_t len; 101 }; 102 alias uv_file = int ; 103 alias uv_os_sock_t = int ; 104 alias uv_os_fd_t = int ; 105 alias uv_pid_t = pid_t ; 106 alias uv_once_t = pthread_once_t ; 107 alias uv_thread_t = pthread_t ; 108 alias uv_mutex_t = pthread_mutex_t ; 109 alias uv_rwlock_t = pthread_rwlock_t_ ; 110 alias uv_sem_t = UV_PLATFORM_SEM_T ; 111 alias uv_cond_t = pthread_cond_t ; 112 alias uv_key_t = pthread_key_t ; 113 /* Note: guard clauses should match uv_barrier_init's in src/unix/thread.c. */ 114 static if( isAixOS ) { 115 /* TODO(bnoordhuis) Merge into uv_barrier_t in v2. */ 116 struct _uv_barrier { 117 uv_mutex_t mutex; 118 uv_cond_t cond; 119 uint threshold; 120 uint in_; 121 uint out_; 122 }; 123 struct uv_barrier_t { 124 _uv_barrier* b; 125 static if( hasPTHREAD_BARRIER ) { 126 /* TODO(bnoordhuis) Remove padding in v2. */ 127 char[pthread_barrier_t.sizeof-(_uv_barrier*).sizeof] pad; 128 } 129 }; 130 } else { 131 alias uv_barrier_t = pthread_barrier_t ; 132 } 133 /* Platform-specific definitions for uv_spawn support. */ 134 alias uv_gid_t = gid_t ; 135 alias uv_uid_t = uid_t ; 136 alias uv__dirent_t = dirent ; 137 template UV_DIR_PRIVATE_FIELDS() { 138 DIR* dir; 139 } 140 static if( isDtUnknow ) { 141 template HAVE_DIRENT_TYPES() {}; 142 enum UV__DT_FILE = -1 ; 143 enum UV__DT_DIR = -2 ; 144 enum UV__DT_LINK = -3 ; 145 enum UV__DT_FIFO = -4 ; 146 enum UV__DT_SOCKET = -5 ; 147 enum UV__DT_CHAR = -6 ; 148 enum UV__DT_BLOCK = -7 ; 149 } 150 /* Platform-specific definitions for uv_dlopen support. */ 151 struct uv_lib_t { 152 void* handle; 153 char* errmsg; 154 }; 155 template UV_LOOP_PRIVATE_FIELDS() { 156 c_ulong flags; 157 int backend_fd; 158 void*[2] pending_queue; 159 void*[2] watcher_queue; 160 uv__io_t** watchers; 161 uint nwatchers; 162 uint nfds; 163 void*[2] wq; 164 uv_mutex_t wq_mutex; 165 uv_async_t wq_async; 166 uv_rwlock_t cloexec_lock; 167 uv_handle_t* closing_handles; 168 void*[2] process_handles; 169 void*[2] prepare_handles; 170 void*[2] check_handles; 171 void*[2] idle_handles; 172 void*[2] async_handles; 173 void function() async_unused; 174 uv__io_t async_io_watcher; 175 int async_wfd; 176 struct timer_heap_s { 177 void* min; 178 uint nelts; 179 }; 180 timer_heap_s timer_heap; 181 uint64_t timer_counter; 182 uint64_t time; 183 int[2] signal_pipefd; 184 uv__io_t signal_io_watcher; 185 uv_signal_t child_watcher; 186 int emfile_fd; 187 mixin UV_PLATFORM_LOOP_FIELDS; 188 } 189 enum UV_REQ_TYPE_PRIVATE = ``; 190 template UV_REQ_PRIVATE_FIELDS() {}; 191 template UV_PRIVATE_REQ_TYPES() {}; 192 template UV_WRITE_PRIVATE_FIELDS() { 193 void*[2] queue; 194 uint write_index; 195 uv_buf_t* bufs; 196 uint nbufs; 197 int error; 198 uv_buf_t[4] bufsml; 199 } 200 template UV_CONNECT_PRIVATE_FIELDS() { 201 void*[2] queue; 202 } 203 template UV_SHUTDOWN_PRIVATE_FIELDS() {}; 204 template UV_UDP_SEND_PRIVATE_FIELDS() { 205 void*[2] queue; 206 sockaddr_storage addr; 207 uint nbufs; 208 uv_buf_t* bufs; 209 ssize_t status; 210 uv_udp_send_cb send_cb; 211 uv_buf_t[4] bufsml; 212 } 213 template UV_HANDLE_PRIVATE_FIELDS() { 214 uv_handle_t* next_closing; 215 uint flags; 216 } 217 template UV_STREAM_PRIVATE_FIELDS() { 218 uv_connect_t* connect_req; 219 uv_shutdown_t* shutdown_req; 220 uv__io_t io_watcher; 221 void*[2] write_queue; 222 void*[2] write_completed_queue; 223 uv_connection_cb connection_cb; 224 int delayed_error; 225 int accepted_fd; 226 void* queued_fds; 227 mixin UV_STREAM_PRIVATE_PLATFORM_FIELDS; 228 } 229 template UV_TCP_PRIVATE_FIELDS() {}; 230 template UV_UDP_PRIVATE_FIELDS() { 231 uv_alloc_cb alloc_cb; 232 uv_udp_recv_cb recv_cb; 233 uv__io_t io_watcher; 234 void*[2] write_queue; 235 void*[2] write_completed_queue; 236 } 237 template UV_PIPE_PRIVATE_FIELDS() { 238 const(char)* pipe_fname; 239 } 240 template UV_POLL_PRIVATE_FIELDS() { 241 uv__io_t io_watcher; 242 } 243 template UV_PREPARE_PRIVATE_FIELDS() { 244 uv_prepare_cb prepare_cb; 245 void*[2] queue; 246 } 247 template UV_CHECK_PRIVATE_FIELDS() { 248 uv_check_cb check_cb; 249 void*[2] queue; 250 } 251 template UV_IDLE_PRIVATE_FIELDS() { 252 uv_idle_cb idle_cb; 253 void*[2] queue; 254 } 255 template UV_ASYNC_PRIVATE_FIELDS() { 256 uv_async_cb async_cb; 257 void*[2] queue; 258 int pending; 259 } 260 template UV_TIMER_PRIVATE_FIELDS() { 261 uv_timer_cb timer_cb; 262 void*[3] heap_node; 263 uint64_t timeout; 264 uint64_t repeat; 265 uint64_t start_id; 266 } 267 template UV_GETADDRINFO_PRIVATE_FIELDS() { 268 uv__work work_req; 269 uv_getaddrinfo_cb cb; 270 addrinfo* hints; 271 char* hostname; 272 char* service; 273 addrinfo* addrinfo_; 274 int retcode; 275 } 276 template UV_GETNAMEINFO_PRIVATE_FIELDS() { 277 uv__work work_req; 278 uv_getnameinfo_cb getnameinfo_cb; 279 sockaddr_storage storage; 280 int flags; 281 char[NI_MAXHOST] host; 282 char[NI_MAXSERV] service; 283 int retcode; 284 } 285 template UV_PROCESS_PRIVATE_FIELDS() { 286 void*[2] queue; 287 int status; 288 } 289 template UV_FS_PRIVATE_FIELDS() { 290 const(char)* new_path; 291 uv_file file; 292 int flags; 293 mode_t mode; 294 uint nbufs; 295 uv_buf_t* bufs; 296 ptrdiff_t off; 297 uv_uid_t uid; 298 uv_gid_t gid; 299 double atime; 300 double mtime; 301 uv__work work_req; 302 uv_buf_t[4] bufsml; 303 } 304 template UV_WORK_PRIVATE_FIELDS() { 305 uv__work work_req; 306 } 307 template UV_TTY_PRIVATE_FIELDS() { 308 termios orig_termios; 309 int mode; 310 } 311 template UV_SIGNAL_PRIVATE_FIELDS() { 312 struct tree_entry_s { 313 uv_signal_s* rbe_left; 314 uv_signal_s* rbe_right; 315 uv_signal_s* rbe_parent; 316 int rbe_color; 317 }; 318 tree_entry_s tree_entry; 319 /* Use two counters here so we don have to fiddle with atomics. */ 320 uint caught_signals; 321 uint dispatched_signals; 322 } 323 template UV_FS_EVENT_PRIVATE_FIELDS() { 324 uv_fs_event_cb cb; 325 mixin UV_PLATFORM_FS_EVENT_FIELDS; 326 } 327 /* fs open() flags supported on this platform: */ 328 /* fs open() flags supported on other platforms: */ 329 enum UV_FS_O_FILEMAP = 0 ; 330 enum UV_FS_O_RANDOM = 0 ; 331 enum UV_FS_O_SHORT_LIVED = 0 ; 332 enum UV_FS_O_SEQUENTIAL = 0 ; 333 enum UV_FS_O_TEMPORARY = 0 ;