luvref.txt (175775B)
1 *luvref.txt* Nvim 2 3 4 LUV REFERENCE MANUAL 5 6 *luvref* 7 This file documents the Lua bindings for the LibUV library which is used for 8 Nvim's event-loop and is accessible from Lua via |vim.uv| (e.g., |uv.version()| 9 is exposed as `vim.uv.version()`). 10 11 For information about this manual, see |luv-credits|. 12 13 For further examples, see https://github.com/luvit/luv/tree/master/examples. 14 15 ============================================================================== 16 INTRODUCTION *luv* *luv-intro* *uv* 17 18 The luv (https://github.com/luvit/luv) project provides access to the 19 multi-platform support library libuv (https://github.com/libuv/libuv) in Lua 20 code. It was primarily developed for the luvit 21 (https://github.com/luvit/luvit) project as the built-in `uv` module, but can 22 be used in other Lua environments. 23 24 More information about the core libuv library can be found at the original 25 libuv documentation page (https://docs.libuv.org/). 26 27 TCP Echo Server Example ~ 28 29 Here is a small example showing a TCP echo server: 30 31 >lua 32 local uv = vim.uv 33 34 local server = uv.new_tcp() 35 server:bind("127.0.0.1", 1337) 36 server:listen(128, function (err) 37 assert(not err, err) 38 local client = uv.new_tcp() 39 server:accept(client) 40 client:read_start(function (err, chunk) 41 assert(not err, err) 42 if chunk then 43 client:write(chunk) 44 else 45 client:shutdown() 46 client:close() 47 end 48 end) 49 end) 50 print("TCP server listening at 127.0.0.1 port 1337") 51 uv.run() -- an explicit run call is necessary outside of luvit 52 < 53 54 Module Layout ~ 55 56 The luv library contains a single Lua module referred to hereafter as `uv` for 57 simplicity. This module consists mostly of functions with names corresponding 58 to their original libuv versions. For example, the libuv function 59 `uv_tcp_bind` has a luv version at |uv.tcp_bind()|. Currently, only two 60 non-function fields exists: `uv.constants` and `uv.errno`, which are tables. 61 62 Functions vs Methods ~ 63 64 In addition to having simple functions, luv provides an optional method-style 65 API. For example, `uv.tcp_bind(server, host, port)` can alternatively be 66 called as `server:bind(host, port)` . Note that the first argument `server` 67 becomes the object and `tcp_` is removed from the function name. Method forms 68 are documented below where they exist. 69 70 Synchronous vs Asynchronous Functions ~ 71 72 Functions that accept a callback are asynchronous. These functions may 73 immediately return results to the caller to indicate their initial status, but 74 their final execution is deferred until at least the next libuv loop 75 iteration. After completion, their callbacks are executed with any results 76 passed to it. 77 78 Functions that do not accept a callback are synchronous. These functions 79 immediately return their results to the caller. 80 81 Some (generally FS and DNS) functions can behave either synchronously or 82 asynchronously. If a callback is provided to these functions, they behave 83 asynchronously; if no callback is provided, they behave synchronously. 84 85 Pseudo-Types ~ 86 87 Some unique types are defined. These are not actual types in Lua, but they are 88 used here to facilitate documenting consistent behavior: 89 - `fail`: an assertable `nil, string, string` tuple (see |luv-error-handling|) 90 - `callable`: a `function`; or a `table` or `userdata` with a `__call` 91 metamethod 92 - `buffer`: a `string` or a sequential `table` of `string`s 93 - `threadargs`: variable arguments (`...`) of type `nil`, `boolean`, `number`, 94 `string`, or `userdata`; number of arguments limited to 9. 95 96 ============================================================================== 97 CONTENTS *luv-contents* 98 99 This documentation is mostly a retelling of the libuv API documentation 100 (https://docs.libuv.org/en/v1.x/api.html) within the context of luv's Lua API. 101 Low-level implementation details and unexposed C functions and types are not 102 documented here except for when they are relevant to behavior seen in the Lua 103 module. 104 105 - |luv-constants| — Constants 106 - |luv-error-handling| — Error handling 107 - |luv-version-checking| — Version checking 108 - |uv_loop_t| — Event loop 109 - |uv_req_t| — Base request 110 - |uv_handle_t| — Base handle 111 - |uv_timer_t| — Timer handle 112 - |uv_prepare_t| — Prepare handle 113 - |uv_check_t| — Check handle 114 - |uv_idle_t| — Idle handle 115 - |uv_async_t| — Async handle 116 - |uv_poll_t| — Poll handle 117 - |uv_signal_t| — Signal handle 118 - |uv_process_t| — Process handle 119 - |uv_stream_t| — Stream handle 120 - |uv_tcp_t| — TCP handle 121 - |uv_pipe_t| — Pipe handle 122 - |uv_tty_t| — TTY handle 123 - |uv_udp_t| — UDP handle 124 - |uv_fs_event_t| — FS Event handle 125 - |uv_fs_poll_t| — FS Poll handle 126 - |luv-file-system-operations| — File system operations 127 - |luv-thread-pool-work-scheduling| — Thread pool work scheduling 128 - |luv-dns-utility-functions| — DNS utility functions 129 - |luv-threading-and-synchronization-utilities| — Threading and 130 synchronization utilities 131 - |luv-miscellaneous-utilities| — Miscellaneous utilities 132 - |luv-metrics-operations| — Metrics operations 133 134 ============================================================================== 135 CONSTANTS *luv-constants* 136 137 As a Lua library, luv supports and encourages the use of lowercase strings to 138 represent options. For example: 139 >lua 140 -- signal start with string input 141 uv.signal_start("sigterm", function(signame) 142 print(signame) -- string output: "sigterm" 143 end) 144 < 145 However, luv also superficially exposes libuv constants in a Lua table at 146 `uv.constants` where its keys are uppercase constant names and their associated 147 values are integers defined internally by libuv. The values from this table may 148 be supported as function arguments, but their use may not change the output 149 type. For example: 150 >lua 151 -- signal start with integer input 152 uv.signal_start(uv.constants.SIGTERM, function(signame) 153 print(signame) -- string output: "sigterm" 154 end) 155 < 156 The uppercase constants defined in `uv.constants` that have associated 157 lowercase option strings are listed below. 158 159 Address Families ~ 160 161 - `AF_UNIX`: "unix" 162 - `AF_INET`: "inet" 163 - `AF_INET6`: "inet6" 164 - `AF_IPX`: "ipx" 165 - `AF_NETLINK`: "netlink" 166 - `AF_X25`: "x25" 167 - `AF_AX25`: "as25" 168 - `AF_ATMPVC`: "atmpvc" 169 - `AF_APPLETALK`: "appletalk" 170 - `AF_PACKET`: "packet" 171 172 Signals ~ 173 174 - `SIGHUP`: "sighup" 175 - `SIGINT`: "sigint" 176 - `SIGQUIT`: "sigquit" 177 - `SIGILL`: "sigill" 178 - `SIGTRAP`: "sigtrap" 179 - `SIGABRT`: "sigabrt" 180 - `SIGIOT`: "sigiot" 181 - `SIGBUS`: "sigbus" 182 - `SIGFPE`: "sigfpe" 183 - `SIGKILL`: "sigkill" 184 - `SIGUSR1`: "sigusr1" 185 - `SIGSEGV`: "sigsegv" 186 - `SIGUSR2`: "sigusr2" 187 - `SIGPIPE`: "sigpipe" 188 - `SIGALRM`: "sigalrm" 189 - `SIGTERM`: "sigterm" 190 - `SIGCHLD`: "sigchld" 191 - `SIGSTKFLT`: "sigstkflt" 192 - `SIGCONT`: "sigcont" 193 - `SIGSTOP`: "sigstop" 194 - `SIGTSTP`: "sigtstp" 195 - `SIGBREAK`: "sigbreak" 196 - `SIGTTIN`: "sigttin" 197 - `SIGTTOU`: "sigttou" 198 - `SIGURG`: "sigurg" 199 - `SIGXCPU`: "sigxcpu" 200 - `SIGXFSZ`: "sigxfsz" 201 - `SIGVTALRM`: "sigvtalrm" 202 - `SIGPROF`: "sigprof" 203 - `SIGWINCH`: "sigwinch" 204 - `SIGIO`: "sigio" 205 - `SIGPOLL`: "sigpoll" 206 - `SIGLOST`: "siglost" 207 - `SIGPWR`: "sigpwr" 208 - `SIGSYS`: "sigsys" 209 210 Socket Types ~ 211 212 - `SOCK_STREAM`: "stream" 213 - `SOCK_DGRAM`: "dgram" 214 - `SOCK_SEQPACKET`: "seqpacket" 215 - `SOCK_RAW`: "raw" 216 - `SOCK_RDM`: "rdm" 217 218 TTY Modes ~ 219 220 - `TTY_MODE_NORMAL`: "normal" 221 - `TTY_MODE_RAW`: "raw" 222 - `TTY_MODE_IO`: "io" 223 `TTY_MODE_RAW_VT`: "raw_vt" 224 225 FS Modification Times ~ 226 227 - `FS_UTIME_NOW`: "now" 228 - `FS_UTIME_OMIT`: "omit" 229 230 ============================================================================== 231 ERROR HANDLING *luv-error-handling* 232 233 In libuv, errors are represented by negative numbered constants. While these 234 constants are made available in the `uv.errno` table, they are not returned by 235 luv functions and the libuv functions used to handle them are not exposed. 236 Instead, if an internal error is encountered, the failing luv function will 237 return to the caller an assertable `nil, err, name` tuple: 238 239 - `nil` idiomatically indicates failure 240 - `err` is a string with the format `{name}: {message}` 241 - `{name}` is the error name provided internally by `uv_err_name` 242 - `{message}` is a human-readable message provided internally by 243 `uv_strerror` 244 - `name` is the same string used to construct `err` 245 246 This tuple is referred to below as the `fail` pseudo-type. 247 248 When a function is called successfully, it will return either a value that is 249 relevant to the operation of the function, or the integer `0` to indicate 250 success, or sometimes nothing at all. These cases are documented below. 251 252 `uv.errno` *uv.errno* 253 254 Below is a list of known error names and error strings. See Libuv's "Error 255 constants" page for further details. 256 (https://docs.libuv.org/en/v1.x/errors.html#error-constants) 257 258 - `E2BIG`: argument list too long. 259 - `EACCES`: permission denied. 260 - `EADDRINUSE`: address already in use. 261 - `EADDRNOTAVAIL`: address not available. 262 - `EAFNOSUPPORT`: address family not supported. 263 - `EAGAIN`: resource temporarily unavailable. 264 - `EAI_ADDRFAMILY`: address family not supported. 265 - `EAI_AGAIN`: temporary failure. 266 - `EAI_BADFLAGS`: bad ai_flags value. 267 - `EAI_BADHINTS`: invalid value for hints. 268 - `EAI_CANCELED`: request canceled. 269 - `EAI_FAIL`: permanent failure. 270 - `EAI_FAMILY`: ai_family not supported. 271 - `EAI_MEMORY`: out of memory. 272 - `EAI_NODATA`: no address. 273 - `EAI_NONAME`: unknown node or service. 274 - `EAI_OVERFLOW`: argument buffer overflow. 275 - `EAI_PROTOCOL`: resolved protocol is unknown. 276 - `EAI_SERVICE`: service not available for socket type. 277 - `EAI_SOCKTYPE`: socket type not supported. 278 - `EALREADY`: connection already in progress. 279 - `EBADF`: bad file descriptor. 280 - `EBUSY`: resource busy or locked. 281 - `ECANCELED`: operation canceled. 282 - `ECHARSET`: invalid Unicode character. 283 - `ECONNABORTED`: software caused connection abort. 284 - `ECONNREFUSED`: connection refused. 285 - `ECONNRESET`: connection reset by peer. 286 - `EDESTADDRREQ`: destination address required. 287 - `EEXIST`: file already exists. 288 - `EFAULT`: bad address in system call argument. 289 - `EFBIG`: file too large. 290 - `EHOSTUNREACH`: host is unreachable. 291 - `EINTR`: interrupted system call. 292 - `EINVAL`: invalid argument. 293 - `EIO`: i/o error. 294 - `EISCONN`: socket is already connected. 295 - `EISDIR`: illegal operation on a directory. 296 - `ELOOP`: too many symbolic links encountered. 297 - `EMFILE`: too many open files. 298 - `EMSGSIZE`: message too long. 299 - `ENAMETOOLONG`: name too long. 300 - `ENETDOWN`: network is down. 301 - `ENETUNREACH`: network is unreachable. 302 - `ENFILE`: file table overflow. 303 - `ENOBUFS`: no buffer space available. 304 - `ENODEV`: no such device. 305 - `ENOENT`: no such file or directory. 306 - `ENOMEM`: not enough memory. 307 - `ENONET`: machine is not on the network. 308 - `ENOPROTOOPT`: protocol not available. 309 - `ENOSPC`: no space left on device. 310 - `ENOSYS`: function not implemented. 311 - `ENOTCONN`: socket is not connected. 312 - `ENOTDIR`: not a directory. 313 - `ENOTEMPTY`: directory not empty. 314 - `ENOTSOCK`: socket operation on non-socket. 315 - `ENOTSUP`: operation not supported on socket. 316 - `EOVERFLOW`: value too large for defined data type. 317 - `EPERM`: operation not permitted. 318 - `EPIPE`: broken pipe. 319 - `EPROTO`: protocol error. 320 - `EPROTONOSUPPORT`: protocol not supported. 321 - `EPROTOTYPE`: protocol wrong type for socket. 322 - `ERANGE`: result too large. 323 - `EROFS`: read-only file system. 324 - `ESHUTDOWN`: cannot send after transport endpoint shutdown. 325 - `ESPIPE`: invalid seek. 326 - `ESRCH`: no such process. 327 - `ETIMEDOUT`: connection timed out. 328 - `ETXTBSY`: text file is busy. 329 - `EXDEV`: cross-device link not permitted. 330 - `UNKNOWN`: unknown error. 331 - `EOF`: end of file. 332 - `ENXIO`: no such device or address. 333 - `EMLINK`: too many links. 334 - `ENOTTY`: inappropriate ioctl for device. 335 - `EFTYPE`: inappropriate file type or format. 336 - `EILSEQ`: illegal byte sequence. 337 - `ESOCKTNOSUPPORT`: socket type not supported. 338 339 ============================================================================== 340 VERSION CHECKING *luv-version-checking* 341 342 uv.version() *uv.version()* 343 344 Returns the libuv version packed into a single integer. 8 bits 345 are used for each component, with the patch number stored in 346 the 8 least significant bits. For example, this would be 347 0x010203 in libuv 1.2.3. 348 349 Returns: `integer` 350 351 uv.version_string() *uv.version_string()* 352 353 Returns the libuv version number as a string. For example, 354 this would be "1.2.3" in libuv 1.2.3. For non-release 355 versions, the version suffix is included. 356 357 Returns: `string` 358 359 ============================================================================== 360 `uv_loop_t` — Event loop *luv-event-loop* *uv_loop_t* 361 362 The event loop is the central part of libuv's functionality. It takes care of 363 polling for I/O and scheduling callbacks to be run based on different sources 364 of events. 365 366 In luv, there is an implicit uv loop for every Lua state that loads the 367 library. You can use this library in an multi-threaded environment as long as 368 each thread has it's own Lua state with its corresponding own uv loop. This 369 loop is not directly exposed to users in the Lua module. 370 371 uv.loop_close() *uv.loop_close()* 372 373 Closes all internal loop resources. In normal execution, the 374 loop will automatically be closed when it is garbage collected 375 by Lua, so it is not necessary to explicitly call 376 `loop_close()`. Call this function only after the loop has 377 finished executing and all open handles and requests have been 378 closed, or it will return `EBUSY`. 379 380 Returns: `0` or `fail` 381 382 uv.run([{mode}]) *uv.run()* 383 384 Parameters: 385 - `mode`: `string` or `nil` (default: `"default"`) 386 387 This function runs the event loop. It will act differently 388 depending on the specified mode: 389 390 - `"default"`: Runs the event loop until there are no more 391 active and referenced handles or requests. Returns `true` 392 if |uv.stop()| was called and there are still active 393 handles or requests. Returns `false` in all other cases. 394 395 - `"once"`: Poll for I/O once. Note that this function 396 blocks if there are no pending callbacks. Returns `false` 397 when done (no active handles or requests left), or `true` 398 if more callbacks are expected (meaning you should run the 399 event loop again sometime in the future). 400 401 - `"nowait"`: Poll for I/O once but don't block if there are 402 no pending callbacks. Returns `false` if done (no active 403 handles or requests left), or `true` if more callbacks are 404 expected (meaning you should run the event loop again 405 sometime in the future). 406 407 Returns: `boolean` or `fail` 408 409 Note: Luvit will implicitly call `uv.run()` after loading user 410 code, but if you use the luv bindings directly, you need to 411 call this after registering your initial set of event 412 callbacks to start the event loop. 413 414 uv.loop_configure({option}, {...}) *uv.loop_configure()* 415 416 Parameters: 417 - `option`: `string` 418 - `...`: depends on `option`, see below 419 420 Set additional loop options. You should normally call this 421 before the first call to uv_run() unless mentioned otherwise. 422 423 Supported options: 424 425 - `"block_signal"`: Block a signal when polling for new 426 events. The second argument to loop_configure() is the 427 signal name (as a lowercase string) or the signal number. 428 This operation is currently only implemented for 429 `"sigprof"` signals, to suppress unnecessary wakeups when 430 using a sampling profiler. Requesting other signals will 431 fail with `EINVAL`. 432 - `"metrics_idle_time"`: Accumulate the amount of idle time 433 the event loop spends in the event provider. This option 434 is necessary to use `metrics_idle_time()`. 435 436 An example of a valid call to this function is: 437 438 >lua 439 uv.loop_configure("block_signal", "sigprof") 440 < 441 442 Returns: `0` or `fail` 443 444 Note: Be prepared to handle the `ENOSYS` error; it means the 445 loop option is not supported by the platform. 446 447 uv.loop_mode() *uv.loop_mode()* 448 449 If the loop is running, returns a string indicating the mode 450 in use. If the loop is not running, `nil` is returned instead. 451 452 Returns: `string` or `nil` 453 454 uv.loop_alive() *uv.loop_alive()* 455 456 Returns `true` if there are referenced active handles, active 457 requests, or closing handles in the loop; otherwise, `false`. 458 459 Returns: `boolean` or `fail` 460 461 uv.stop() *uv.stop()* 462 463 Stop the event loop, causing |uv.run()| to end as soon as 464 possible. This will happen not sooner than the next loop 465 iteration. If this function was called before blocking for 466 I/O, the loop won't block for I/O on this iteration. 467 468 Returns: Nothing. 469 470 uv.backend_fd() *uv.backend_fd()* 471 472 Get backend file descriptor. Only kqueue, epoll, and event 473 ports are supported. 474 475 This can be used in conjunction with `uv.run("nowait")` to 476 poll in one thread and run the event loop's callbacks in 477 another 478 479 Returns: `integer` or `nil` 480 481 Note: Embedding a kqueue fd in another kqueue pollset doesn't 482 work on all platforms. It's not an error to add the fd but it 483 never generates events. 484 485 uv.backend_timeout() *uv.backend_timeout()* 486 487 Get the poll timeout. The return value is in milliseconds, or 488 -1 for no timeout. 489 490 Returns: `integer` 491 492 uv.now() *uv.now()* 493 494 Returns the current timestamp in milliseconds. The timestamp 495 is cached at the start of the event loop tick, see 496 |uv.update_time()| for details and rationale. 497 498 The timestamp increases monotonically from some arbitrary 499 point in time. Don't make assumptions about the starting 500 point, you will only get disappointed. 501 502 Returns: `integer` 503 504 Note: Use |uv.hrtime()| if you need sub-millisecond 505 granularity. 506 507 uv.update_time() *uv.update_time()* 508 509 Update the event loop's concept of "now". Libuv caches the 510 current time at the start of the event loop tick in order to 511 reduce the number of time-related system calls. 512 513 You won't normally need to call this function unless you have 514 callbacks that block the event loop for longer periods of 515 time, where "longer" is somewhat subjective but probably on 516 the order of a millisecond or more. 517 518 Returns: Nothing. 519 520 uv.walk({callback}) *uv.walk()* 521 522 Parameters: 523 - `callback`: `callable` 524 - `handle`: `userdata` for sub-type of |uv_handle_t| 525 526 Walk the list of handles: `callback` will be executed with 527 each handle. 528 529 Returns: Nothing. 530 531 >lua 532 -- Example usage of uv.walk to close all handles that 533 -- aren't already closing. 534 uv.walk(function (handle) 535 if not handle:is_closing() then 536 handle:close() 537 end 538 end) 539 < 540 541 ============================================================================== 542 `uv_req_t` — Base request *luv-base-request* *uv_req_t* 543 544 `uv_req_t` is the base type for all libuv request types. 545 546 uv.cancel({req}) *uv.cancel()* 547 548 > method form `req:cancel()` 549 550 Parameters: 551 - `req`: `userdata` for sub-type of |uv_req_t| 552 553 Cancel a pending request. Fails if the request is executing or 554 has finished executing. Only cancellation of |uv_fs_t|, 555 `uv_getaddrinfo_t`, `uv_getnameinfo_t` and `uv_work_t` 556 requests is currently supported. 557 558 Returns: `0` or `fail` 559 560 uv.req_get_type({req}) *uv.req_get_type()* 561 562 > method form `req:get_type()` 563 564 Parameters: 565 - `req`: `userdata` for sub-type of |uv_req_t| 566 567 Returns the name of the struct for a given request (e.g. 568 `"fs"` for |uv_fs_t|) and the libuv enum integer for the 569 request's type (`uv_req_type`). 570 571 Returns: `string, integer` 572 573 ============================================================================== 574 `uv_handle_t` — Base handle *luv-base-handle* *uv_handle_t* 575 576 `uv_handle_t` is the base type for all libuv handle types. All API functions 577 defined here work with any handle type. 578 579 uv.is_active({handle}) *uv.is_active()* 580 581 > method form `handle:is_active()` 582 583 Parameters: 584 - `handle`: `userdata` for sub-type of |uv_handle_t| 585 586 Returns `true` if the handle is active, `false` if it's 587 inactive. What "active” means depends on the type of handle: 588 589 - A |uv_async_t| handle is always active and cannot be 590 deactivated, except by closing it with |uv.close()|. 591 592 - A |uv_pipe_t|, |uv_tcp_t|, |uv_udp_t|, etc. 593 handle - basically any handle that deals with I/O - is 594 active when it is doing something that involves I/O, like 595 reading, writing, connecting, accepting new connections, 596 etc. 597 598 - A |uv_check_t|, |uv_idle_t|, |uv_timer_t|, 599 etc. handle is active when it has been started with a call 600 to |uv.check_start()|, |uv.idle_start()|, 601 |uv.timer_start()| etc. until it has been stopped with a 602 call to its respective stop function. 603 604 Returns: `boolean` or `fail` 605 606 uv.is_closing({handle}) *uv.is_closing()* 607 608 > method form `handle:is_closing()` 609 610 Parameters: 611 - `handle`: `userdata` for sub-type of |uv_handle_t| 612 613 Returns `true` if the handle is closing or closed, `false` 614 otherwise. 615 616 Returns: `boolean` or `fail` 617 618 Note: This function should only be used between the 619 initialization of the handle and the arrival of the close 620 callback. 621 622 uv.close({handle} [, {callback}]) *uv.close()* 623 624 > method form `handle:close([callback])` 625 626 Parameters: 627 - `handle`: `userdata` for sub-type of |uv_handle_t| 628 - `callback`: `callable` or `nil` 629 630 Request handle to be closed. `callback` will be called 631 asynchronously after this call. This MUST be called on each 632 handle before memory is released. 633 634 Handles that wrap file descriptors are closed immediately but 635 `callback` will still be deferred to the next iteration of the 636 event loop. It gives you a chance to free up any resources 637 associated with the handle. 638 639 In-progress requests, like `uv_connect_t` or `uv_write_t`, are 640 cancelled and have their callbacks called asynchronously with 641 `ECANCELED`. 642 643 Returns: Nothing. 644 645 uv.ref({handle}) *uv.ref()* 646 647 > method form `handle:ref()` 648 649 Parameters: 650 - `handle`: `userdata` for sub-type of |uv_handle_t| 651 652 Reference the given handle. References are idempotent, that 653 is, if a handle is already referenced calling this function 654 again will have no effect. 655 656 Returns: Nothing. 657 658 See |luv-reference-counting|. 659 660 uv.unref({handle}) *uv.unref()* 661 662 > method form `handle:unref()` 663 664 Parameters: 665 - `handle`: `userdata` for sub-type of |uv_handle_t| 666 667 Un-reference the given handle. References are idempotent, that 668 is, if a handle is not referenced calling this function again 669 will have no effect. 670 671 Returns: Nothing. 672 673 See |luv-reference-counting|. 674 675 uv.has_ref({handle}) *uv.has_ref()* 676 677 > method form `handle:has_ref()` 678 679 Parameters: 680 - `handle`: `userdata` for sub-type of |uv_handle_t| 681 682 Returns `true` if the handle referenced, `false` if not. 683 684 Returns: `boolean` or `fail` 685 686 See |luv-reference-counting|. 687 688 uv.send_buffer_size({handle} [, {size}]) *uv.send_buffer_size()* 689 690 > method form `handle:send_buffer_size([size])` 691 692 Parameters: 693 - `handle`: `userdata` for sub-type of |uv_handle_t| 694 - `size`: `integer` or `nil` (default: `0`) 695 696 Gets or sets the size of the send buffer that the operating 697 system uses for the socket. 698 699 If `size` is omitted (or `0`), this will return the current 700 send buffer size; otherwise, this will use `size` to set the 701 new send buffer size. 702 703 This function works for TCP, pipe and UDP handles on Unix and 704 for TCP and UDP handles on Windows. 705 706 Returns: 707 - `integer` or `fail` (if `size` is `nil` or `0`) 708 - `0` or `fail` (if `size` is not `nil` and not `0`) 709 710 Note: Linux will set double the size and return double the 711 size of the original set value. 712 713 uv.recv_buffer_size({handle} [, {size}]) *uv.recv_buffer_size()* 714 715 > method form `handle:recv_buffer_size([size])` 716 717 Parameters: 718 - `handle`: `userdata` for sub-type of |uv_handle_t| 719 - `size`: `integer` or `nil` (default: `0`) 720 721 Gets or sets the size of the receive buffer that the operating 722 system uses for the socket. 723 724 If `size` is omitted (or `0`), this will return the current 725 send buffer size; otherwise, this will use `size` to set the 726 new send buffer size. 727 728 This function works for TCP, pipe and UDP handles on Unix and 729 for TCP and UDP handles on Windows. 730 731 Returns: 732 - `integer` or `fail` (if `size` is `nil` or `0`) 733 - `0` or `fail` (if `size` is not `nil` and not `0`) 734 735 Note: Linux will set double the size and return double the 736 size of the original set value. 737 738 uv.fileno({handle}) *uv.fileno()* 739 740 > method form `handle:fileno()` 741 742 Parameters: 743 - `handle`: `userdata` for sub-type of |uv_handle_t| 744 745 Gets the platform dependent file descriptor equivalent. 746 747 The following handles are supported: TCP, pipes, TTY, UDP and 748 poll. Passing any other handle type will fail with `EINVAL`. 749 750 If a handle doesn't have an attached file descriptor yet or 751 the handle itself has been closed, this function will return 752 `EBADF`. 753 754 Returns: `integer` or `fail` 755 756 WARNING: Be very careful when using this function. libuv 757 assumes it's in control of the file descriptor so any change 758 to it may lead to malfunction. 759 760 uv.handle_get_type({handle}) *uv.handle_get_type()* 761 762 > method form `handle:get_type()` 763 764 Parameters: 765 - `handle`: `userdata` for sub-type of |uv_handle_t| 766 767 Returns the name of the struct for a given handle (e.g. 768 `"pipe"` for |uv_pipe_t|) and the libuv enum integer for the 769 handle's type (`uv_handle_type`). 770 771 Returns: `string, integer` 772 773 ============================================================================== 774 REFERENCE COUNTING *luv-reference-counting* 775 776 The libuv event loop (if run in the default mode) will run until there are no 777 active and referenced handles left. The user can force the loop to exit early 778 by unreferencing handles which are active, for example by calling |uv.unref()| 779 after calling |uv.timer_start()|. 780 781 A handle can be referenced or unreferenced, the refcounting scheme doesn't use 782 a counter, so both operations are idempotent. 783 784 All handles are referenced when active by default, see |uv.is_active()| for a 785 more detailed explanation on what being active involves. 786 787 ============================================================================== 788 `uv_timer_t` — Timer handle *luv-timer-handle* *uv_timer_t* 789 790 > |uv_handle_t| functions also apply. 791 792 Timer handles are used to schedule callbacks to be called in the future. 793 794 uv.new_timer() *uv.new_timer()* 795 796 Creates and initializes a new |uv_timer_t|. Returns the Lua 797 userdata wrapping it. 798 799 Returns: `uv_timer_t userdata` or `fail` 800 801 >lua 802 -- Creating a simple setTimeout wrapper 803 local function setTimeout(timeout, callback) 804 local timer = uv.new_timer() 805 timer:start(timeout, 0, function () 806 timer:stop() 807 timer:close() 808 callback() 809 end) 810 return timer 811 end 812 813 -- Creating a simple setInterval wrapper 814 local function setInterval(interval, callback) 815 local timer = uv.new_timer() 816 timer:start(interval, interval, function () 817 callback() 818 end) 819 return timer 820 end 821 822 -- And clearInterval 823 local function clearInterval(timer) 824 timer:stop() 825 timer:close() 826 end 827 < 828 829 uv.timer_start({timer}, {timeout}, {repeat}, {callback}) *uv.timer_start()* 830 831 > method form `timer:start(timeout, repeat, callback)` 832 833 Parameters: 834 - `timer`: `uv_timer_t userdata` 835 - `timeout`: `integer` 836 - `repeat`: `integer` 837 - `callback`: `callable` 838 839 Start the timer. `timeout` and `repeat` are in milliseconds. 840 841 If `timeout` is zero, the callback fires on the next event 842 loop iteration. If `repeat` is non-zero, the callback fires 843 first after `timeout` milliseconds and then repeatedly after 844 `repeat` milliseconds. 845 846 Returns: `0` or `fail` 847 848 uv.timer_stop({timer}) *uv.timer_stop()* 849 850 > method form `timer:stop()` 851 852 Parameters: 853 - `timer`: `uv_timer_t userdata` 854 855 Stop the timer, the callback will not be called anymore. 856 857 Returns: `0` or `fail` 858 859 uv.timer_again({timer}) *uv.timer_again()* 860 861 > method form `timer:again()` 862 863 Parameters: 864 - `timer`: `uv_timer_t userdata` 865 866 Stop the timer, and if it is repeating restart it using the 867 repeat value as the timeout. If the timer has never been 868 started before it raises `EINVAL`. 869 870 Returns: `0` or `fail` 871 872 uv.timer_set_repeat({timer}, {repeat}) *uv.timer_set_repeat()* 873 874 > method form `timer:set_repeat(repeat)` 875 876 Parameters: 877 - `timer`: `uv_timer_t userdata` 878 - `repeat`: `integer` 879 880 Set the repeat interval value in milliseconds. The timer will 881 be scheduled to run on the given interval, regardless of the 882 callback execution duration, and will follow normal timer 883 semantics in the case of a time-slice overrun. 884 885 For example, if a 50 ms repeating timer first runs for 17 ms, 886 it will be scheduled to run again 33 ms later. If other tasks 887 consume more than the 33 ms following the first timer 888 callback, then the callback will run as soon as possible. 889 890 Returns: Nothing. 891 892 uv.timer_get_repeat({timer}) *uv.timer_get_repeat()* 893 894 > method form `timer:get_repeat()` 895 896 Parameters: 897 - `timer`: `uv_timer_t userdata` 898 899 Get the timer repeat value. 900 901 Returns: `integer` 902 903 uv.timer_get_due_in({timer}) *uv.timer_get_due_in()* 904 905 > method form `timer:get_due_in()` 906 907 Parameters: 908 - `timer`: `uv_timer_t userdata` 909 910 Get the timer due value or 0 if it has expired. The time is 911 relative to |uv.now()|. 912 913 Returns: `integer` 914 915 Note: New in libuv version 1.40.0. 916 917 ============================================================================== 918 `uv_prepare_t` — Prepare handle *luv-prepare-handle* *uv_prepare_t* 919 920 > |uv_handle_t| functions also apply. 921 922 Prepare handles will run the given callback once per loop iteration, right 923 before polling for I/O. 924 925 >lua 926 local prepare = uv.new_prepare() 927 prepare:start(function() 928 print("Before I/O polling") 929 end) 930 < 931 932 uv.new_prepare() *uv.new_prepare()* 933 934 Creates and initializes a new |uv_prepare_t|. Returns the Lua 935 userdata wrapping it. 936 937 Returns: `uv_prepare_t userdata` 938 939 uv.prepare_start({prepare}, {callback}) *uv.prepare_start()* 940 941 > method form `prepare:start(callback)` 942 943 Parameters: 944 - `prepare`: `uv_prepare_t userdata` 945 - `callback`: `callable` 946 947 Start the handle with the given callback. 948 949 Returns: `0` or `fail` 950 951 uv.prepare_stop({prepare}) *uv.prepare_stop()* 952 953 > method form `prepare:stop()` 954 955 Parameters: 956 - `prepare`: `uv_prepare_t userdata` 957 958 Stop the handle, the callback will no longer be called. 959 960 Returns: `0` or `fail` 961 962 ============================================================================== 963 `uv_check_t` — Check handle *luv-check-handle* *uv_check_t* 964 965 > |uv_handle_t| functions also apply. 966 967 Check handles will run the given callback once per loop iteration, right after 968 polling for I/O. 969 970 >lua 971 local check = uv.new_check() 972 check:start(function() 973 print("After I/O polling") 974 end) 975 < 976 977 uv.new_check() *uv.new_check()* 978 979 Creates and initializes a new |uv_check_t|. Returns the Lua 980 userdata wrapping it. 981 982 Returns: `uv_check_t userdata` 983 984 uv.check_start({check}, {callback}) *uv.check_start()* 985 986 > method form `check:start(callback)` 987 988 Parameters: 989 - `check`: `uv_check_t userdata` 990 - `callback`: `callable` 991 992 Start the handle with the given callback. 993 994 Returns: `0` or `fail` 995 996 uv.check_stop({check}) *uv.check_stop()* 997 998 > method form `check:stop()` 999 1000 Parameters: 1001 - `check`: `uv_check_t userdata` 1002 1003 Stop the handle, the callback will no longer be called. 1004 1005 Returns: `0` or `fail` 1006 1007 ============================================================================== 1008 `uv_idle_t` — Idle handle *luv-idle-handle* *uv_idle_t* 1009 1010 > |uv_handle_t| functions also apply. 1011 1012 Idle handles will run the given callback once per loop iteration, right before 1013 the |uv_prepare_t| handles. 1014 1015 Note: The notable difference with prepare handles is that when there are 1016 active idle handles, the loop will perform a zero timeout poll instead of 1017 blocking for I/O. 1018 1019 WARNING: Despite the name, idle handles will get their callbacks called on 1020 every loop iteration, not when the loop is actually "idle". 1021 1022 >lua 1023 local idle = uv.new_idle() 1024 idle:start(function() 1025 print("Before I/O polling, no blocking") 1026 end) 1027 < 1028 1029 uv.new_idle() *uv.new_idle()* 1030 1031 Creates and initializes a new |uv_idle_t|. Returns the Lua 1032 userdata wrapping it. 1033 1034 Returns: `uv_idle_t userdata` 1035 1036 uv.idle_start({idle}, {callback}) *uv.idle_start()* 1037 1038 > method form `idle:start(callback)` 1039 1040 Parameters: 1041 - `idle`: `uv_idle_t userdata` 1042 - `callback`: `callable` 1043 1044 Start the handle with the given callback. 1045 1046 Returns: `0` or `fail` 1047 1048 uv.idle_stop({check}) *uv.idle_stop()* 1049 1050 > method form `idle:stop()` 1051 1052 Parameters: 1053 - `idle`: `uv_idle_t userdata` 1054 1055 Stop the handle, the callback will no longer be called. 1056 1057 Returns: `0` or `fail` 1058 1059 ============================================================================== 1060 `uv_async_t` — Async handle *luv-async-handle* *uv_async_t* 1061 1062 > |uv_handle_t| functions also apply. 1063 1064 Async handles allow the user to "wakeup" the event loop and get a callback 1065 called from another thread. 1066 1067 >lua 1068 local async 1069 async = uv.new_async(function() 1070 print("async operation ran") 1071 async:close() 1072 end) 1073 1074 async:send() 1075 < 1076 1077 uv.new_async({callback}) *uv.new_async()* 1078 1079 Parameters: 1080 - `callback`: `callable` 1081 - `...`: `threadargs` passed to/from 1082 `uv.async_send(async, ...)` 1083 1084 Creates and initializes a new |uv_async_t|. Returns the Lua 1085 userdata wrapping it. 1086 1087 Returns: `uv_async_t userdata` or `fail` 1088 1089 Note: Unlike other handle initialization functions, this 1090 immediately starts the handle. 1091 1092 uv.async_send({async}, {...}) *uv.async_send()* 1093 1094 > method form `async:send(...)` 1095 1096 Parameters: 1097 - `async`: `uv_async_t userdata` 1098 - `...`: `threadargs` 1099 1100 Wakeup the event loop and call the async handle's callback. 1101 1102 Returns: `0` or `fail` 1103 1104 Note: It's safe to call this function from any thread. The 1105 callback will be called on the loop thread. 1106 1107 WARNING: libuv will coalesce calls to `uv.async_send(async)`, 1108 that is, not every call to it will yield an execution of the 1109 callback. For example: if `uv.async_send()` is called 5 times 1110 in a row before the callback is called, the callback will only 1111 be called once. If `uv.async_send()` is called again after the 1112 callback was called, it will be called again. 1113 1114 ============================================================================== 1115 `uv_poll_t` — Poll handle *luv-poll-handle* *uv_poll_t* 1116 1117 > |uv_handle_t| functions also apply. 1118 1119 Poll handles are used to watch file descriptors for readability and 1120 writability, similar to the purpose of poll(2) 1121 (https://linux.die.net/man/2/poll). 1122 1123 The purpose of poll handles is to enable integrating external libraries that 1124 rely on the event loop to signal it about the socket status changes, like 1125 c-ares or libssh2. Using `uv_poll_t` for any other purpose is not recommended; 1126 |uv_tcp_t|, |uv_udp_t|, etc. provide an implementation that is faster and more 1127 scalable than what can be achieved with `uv_poll_t`, especially on Windows. 1128 1129 It is possible that poll handles occasionally signal that a file descriptor is 1130 readable or writable even when it isn't. The user should therefore always be 1131 prepared to handle EAGAIN or equivalent when it attempts to read from or write 1132 to the fd. 1133 1134 It is not okay to have multiple active poll handles for the same socket, this 1135 can cause libuv to busyloop or otherwise malfunction. 1136 1137 The user should not close a file descriptor while it is being polled by an 1138 active poll handle. This can cause the handle to report an error, but it might 1139 also start polling another socket. However the fd can be safely closed 1140 immediately after a call to |uv.poll_stop()| or |uv.close()|. 1141 1142 Note: On windows only sockets can be polled with poll handles. On Unix any 1143 file descriptor that would be accepted by poll(2) can be used. 1144 1145 uv.new_poll({fd}) *uv.new_poll()* 1146 1147 Parameters: 1148 - `fd`: `integer` 1149 1150 Initialize the handle using a file descriptor. 1151 1152 The file descriptor is set to non-blocking mode. 1153 1154 Returns: `uv_poll_t userdata` or `fail` 1155 1156 uv.new_socket_poll({fd}) *uv.new_socket_poll()* 1157 1158 Parameters: 1159 - `fd`: `integer` 1160 1161 Initialize the handle using a socket descriptor. On Unix this 1162 is identical to |uv.new_poll()|. On windows it takes a SOCKET 1163 handle. 1164 1165 The socket is set to non-blocking mode. 1166 1167 Returns: `uv_poll_t userdata` or `fail` 1168 1169 uv.poll_start({poll}, {events}, {callback}) *uv.poll_start()* 1170 1171 > method form `poll:start(events, callback)` 1172 1173 Parameters: 1174 - `poll`: `uv_poll_t userdata` 1175 - `events`: `string` or `nil` (default: `"rw"`) 1176 - `callback`: `callable` 1177 - `err`: `nil` or `string` 1178 - `events`: `string` or `nil` 1179 1180 Starts polling the file descriptor. `events` are: `"r"`, 1181 `"w"`, `"rw"`, `"d"`, `"rd"`, `"wd"`, `"rwd"`, `"p"`, `"rp"`, 1182 `"wp"`, `"rwp"`, `"dp"`, `"rdp"`, `"wdp"`, or `"rwdp"` where 1183 `r` is `READABLE`, `w` is `WRITABLE`, `d` is `DISCONNECT`, and 1184 `p` is `PRIORITIZED`. As soon as an event is detected the 1185 callback will be called with status set to 0, and the detected 1186 events set on the events field. 1187 1188 The user should not close the socket while the handle is 1189 active. If the user does that anyway, the callback may be 1190 called reporting an error status, but this is not guaranteed. 1191 1192 Returns: `0` or `fail` 1193 1194 Note Calling `uv.poll_start()` on a handle that is already 1195 active is fine. Doing so will update the events mask that is 1196 being watched for. 1197 1198 uv.poll_stop({poll}) *uv.poll_stop()* 1199 1200 > method form `poll:stop()` 1201 1202 Parameters: 1203 - `poll`: `uv_poll_t userdata` 1204 1205 Stop polling the file descriptor, the callback will no longer 1206 be called. 1207 1208 Returns: `0` or `fail` 1209 1210 ============================================================================== 1211 `uv_signal_t` — Signal handle *luv-signal-handle* *uv_signal_t* 1212 1213 > |uv_handle_t| functions also apply. 1214 1215 Signal handles implement Unix style signal handling on a per-event loop bases. 1216 1217 Windows Notes: 1218 1219 Reception of some signals is emulated on Windows: 1220 - SIGINT is normally delivered when the user presses CTRL+C. However, like 1221 on Unix, it is not generated when terminal raw mode is enabled. 1222 - SIGBREAK is delivered when the user pressed CTRL + BREAK. 1223 - SIGHUP is generated when the user closes the console window. On SIGHUP the 1224 program is given approximately 10 seconds to perform cleanup. After that 1225 Windows will unconditionally terminate it. 1226 - SIGWINCH is raised whenever libuv detects that the console has been 1227 resized. SIGWINCH is emulated by libuv when the program uses a uv_tty_t 1228 handle to write to the console. SIGWINCH may not always be delivered in a 1229 timely manner; libuv will only detect size changes when the cursor is 1230 being moved. When a readable |uv_tty_t| handle is used in raw mode, 1231 resizing the console buffer will also trigger a SIGWINCH signal. 1232 - Watchers for other signals can be successfully created, but these signals 1233 are never received. These signals are: SIGILL, SIGABRT, SIGFPE, SIGSEGV, 1234 SIGTERM and SIGKILL. 1235 - Calls to raise() or abort() to programmatically raise a signal are not 1236 detected by libuv; these will not trigger a signal watcher. 1237 1238 Unix Notes: 1239 1240 - SIGKILL and SIGSTOP are impossible to catch. 1241 - Handling SIGBUS, SIGFPE, SIGILL or SIGSEGV via libuv results into 1242 undefined behavior. 1243 - SIGABRT will not be caught by libuv if generated by abort(), e.g. through 1244 assert(). 1245 - On Linux SIGRT0 and SIGRT1 (signals 32 and 33) are used by the NPTL 1246 pthreads library to manage threads. Installing watchers for those signals 1247 will lead to unpredictable behavior and is strongly discouraged. Future 1248 versions of libuv may simply reject them. 1249 1250 >lua 1251 -- Create a new signal handler 1252 local signal = uv.new_signal() 1253 -- Define a handler function 1254 uv.signal_start(signal, "sigint", function(signame) 1255 print("got " .. signame .. ", shutting down") 1256 os.exit(1) 1257 end) 1258 < 1259 1260 uv.new_signal() *uv.new_signal()* 1261 1262 Creates and initializes a new |uv_signal_t|. Returns the Lua 1263 userdata wrapping it. 1264 1265 Returns: `uv_signal_t userdata` or `fail` 1266 1267 uv.signal_start({signal}, {signame}, {callback}) *uv.signal_start()* 1268 1269 > method form `signal:start(signame, callback)` 1270 1271 Parameters: 1272 - `signal`: `uv_signal_t userdata` 1273 - `signame`: `string` or `integer` 1274 - `callback`: `callable` 1275 - `signame`: `string` 1276 1277 Start the handle with the given callback, watching for the 1278 given signal. 1279 1280 See |luv-constants| for supported `signame` input and output 1281 values. 1282 1283 Returns: `0` or `fail` 1284 *uv.signal_start_oneshot()* 1285 uv.signal_start_oneshot({signal}, {signame}, {callback}) 1286 1287 > method form `signal:start_oneshot(signame, callback)` 1288 1289 Parameters: 1290 - `signal`: `uv_signal_t userdata` 1291 - `signame`: `string` or `integer` 1292 - `callback`: `callable` 1293 - `signame`: `string` 1294 1295 Same functionality as |uv.signal_start()| but the signal 1296 handler is reset the moment the signal is received. 1297 1298 See |luv-constants| for supported `signame` input and output 1299 values. 1300 1301 Returns: `0` or `fail` 1302 1303 uv.signal_stop({signal}) *uv.signal_stop()* 1304 1305 > method form `signal:stop()` 1306 1307 Parameters: 1308 - `signal`: `uv_signal_t userdata` 1309 1310 Stop the handle, the callback will no longer be called. 1311 1312 Returns: `0` or `fail` 1313 1314 ============================================================================== 1315 `uv_process_t` — Process handle *luv-process-handle* *uv_process_t* 1316 1317 > |uv_handle_t| functions also apply. 1318 1319 Process handles will spawn a new process and allow the user to control it and 1320 establish communication channels with it using streams. 1321 1322 uv.disable_stdio_inheritance() *uv.disable_stdio_inheritance()* 1323 1324 Disables inheritance for file descriptors / handles that this 1325 process inherited from its parent. The effect is that child 1326 processes spawned by this process don't accidentally inherit 1327 these handles. 1328 1329 It is recommended to call this function as early in your 1330 program as possible, before the inherited file descriptors can 1331 be closed or duplicated. 1332 1333 Returns: Nothing. 1334 1335 Note: This function works on a best-effort basis: there is no 1336 guarantee that libuv can discover all file descriptors that 1337 were inherited. In general it does a better job on Windows 1338 than it does on Unix. 1339 1340 uv.spawn({path}, {options}, {on_exit}) *uv.spawn()* 1341 1342 Parameters: 1343 - `path`: `string` 1344 - `options`: `table` (see below) 1345 - `on_exit`: `callable` 1346 - `code`: `integer` 1347 - `signal`: `integer` 1348 1349 Initializes the process handle and starts the process. If the 1350 process is successfully spawned, this function will return the 1351 handle and pid of the child process. 1352 1353 Possible reasons for failing to spawn would include (but not 1354 be limited to) the file to execute not existing, not having 1355 permissions to use the setuid or setgid specified, or not 1356 having enough memory to allocate for the new process. 1357 1358 >lua 1359 local stdin = uv.new_pipe() 1360 local stdout = uv.new_pipe() 1361 local stderr = uv.new_pipe() 1362 1363 print("stdin", stdin) 1364 print("stdout", stdout) 1365 print("stderr", stderr) 1366 1367 local handle, pid = uv.spawn("cat", { 1368 stdio = {stdin, stdout, stderr} 1369 }, function(code, signal) -- on exit 1370 print("exit code", code) 1371 print("exit signal", signal) 1372 end) 1373 1374 print("process opened", handle, pid) 1375 1376 uv.read_start(stdout, function(err, data) 1377 assert(not err, err) 1378 if data then 1379 print("stdout chunk", stdout, data) 1380 else 1381 print("stdout end", stdout) 1382 end 1383 end) 1384 1385 uv.read_start(stderr, function(err, data) 1386 assert(not err, err) 1387 if data then 1388 print("stderr chunk", stderr, data) 1389 else 1390 print("stderr end", stderr) 1391 end 1392 end) 1393 1394 uv.write(stdin, "Hello World") 1395 1396 uv.shutdown(stdin, function() 1397 print("stdin shutdown", stdin) 1398 uv.close(handle, function() 1399 print("process closed", handle, pid) 1400 end) 1401 end) 1402 < 1403 *uv.spawn-options* 1404 The `options` table accepts the following fields: 1405 1406 - `options.args` - Command line arguments as a list of 1407 strings. The first string should not be the path to the 1408 program, since that is already provided via `path`. On 1409 Windows, this uses CreateProcess which concatenates the 1410 arguments into a string. This can cause some strange 1411 errors (see `options.verbatim` below for Windows). 1412 - `options.stdio` - Set the file descriptors that will be 1413 made available to the child process. The convention is 1414 that the first entries are stdin, stdout, and stderr. 1415 (Note: On Windows, file descriptors after the third are 1416 available to the child process only if the child processes 1417 uses the MSVCRT runtime.) 1418 - `options.env` - Set environment variables for the new 1419 process. Each entry should be a string in the form of 1420 `NAME=VALUE`. 1421 - `options.cwd` - Set the current working directory for the 1422 sub-process. 1423 - `options.uid` - Set the child process' user id. 1424 - `options.gid` - Set the child process' group id. 1425 - `options.verbatim` - If true, do not wrap any arguments in 1426 quotes, or perform any other escaping, when converting the 1427 argument list into a command line string. This option is 1428 only meaningful on Windows systems. On Unix it is silently 1429 ignored. 1430 - `options.detached` - If true, spawn the child process in a 1431 detached state - this will make it a process group leader, 1432 and will effectively enable the child to keep running 1433 after the parent exits. Note that the child process will 1434 still keep the parent's event loop alive unless the parent 1435 process calls |uv.unref()| on the child's process handle. 1436 - `options.hide` - If true, hide the subprocess console 1437 window that would normally be created. This option is only 1438 meaningful on Windows systems. On Unix it is silently 1439 ignored. 1440 1441 The `options.stdio` entries can take many shapes. 1442 1443 - If they are numbers, then the child process inherits that 1444 same zero-indexed fd from the parent process. 1445 - If |uv_stream_t| handles are passed in, those are used as 1446 a read-write pipe or inherited stream depending if the 1447 stream has a valid fd. 1448 - Including `nil` placeholders means to ignore that fd in 1449 the child process. 1450 1451 When the child process exits, `on_exit` is called with an exit 1452 code and signal. 1453 1454 Returns: `uv_process_t userdata` or `nil`, `integer` or 1455 `string`, `uv.error_name` or `nil` 1456 1457 uv.process_kill({process}, {signame}) *uv.process_kill()* 1458 1459 > method form `process:kill(signame)` 1460 1461 Parameters: 1462 - `process`: `uv_process_t userdata` 1463 - `signame`: `string` or `integer` or `nil` (default: `sigterm`) 1464 1465 Sends the specified signal to the given process handle. Check 1466 the documentation on |uv_signal_t| for signal support, 1467 specially on Windows. 1468 1469 See |luv-constants| for supported `signame` input and output 1470 values. 1471 1472 Returns: `0` or `fail` 1473 1474 uv.kill({pid}, {signame}) *uv.kill()* 1475 1476 Parameters: 1477 - `pid`: `integer` 1478 - `signame`: `string` or `integer` or `nil` (default: `sigterm`) 1479 1480 Sends the specified signal to the given PID. Check the 1481 documentation on |uv_signal_t| for signal support, specially 1482 on Windows. 1483 1484 See |luv-constants| for supported `signame` input and output 1485 values. 1486 1487 Returns: `0` or `fail` 1488 1489 uv.process_get_pid({process}) *uv.process_get_pid()* 1490 1491 > method form `process:get_pid()` 1492 1493 Parameters: 1494 - `process`: `uv_process_t userdata` 1495 1496 Returns the handle's pid. 1497 1498 Returns: `integer` 1499 1500 ============================================================================== 1501 `uv_stream_t` — Stream handle *luv-stream-handle* *uv_stream_t* 1502 1503 > |uv_handle_t| functions also apply. 1504 1505 Stream handles provide an abstraction of a duplex communication channel. 1506 `uv_stream_t` is an abstract type, libuv provides 3 stream implementations 1507 in the form of |uv_tcp_t|, |uv_pipe_t| and |uv_tty_t|. 1508 1509 uv.shutdown({stream} [, {callback}]) *uv.shutdown()* 1510 1511 > method form `stream:shutdown([callback])` 1512 1513 Parameters: 1514 - `stream`: `userdata` for sub-type of |uv_stream_t| 1515 - `callback`: `callable` or `nil` 1516 - `err`: `nil` or `string` 1517 1518 Shutdown the outgoing (write) side of a duplex stream. It 1519 waits for pending write requests to complete. The callback is 1520 called after shutdown is complete. 1521 1522 Returns: `uv_shutdown_t userdata` or `fail` 1523 1524 uv.listen({stream}, {backlog}, {callback}) *uv.listen()* 1525 1526 > method form `stream:listen(backlog, callback)` 1527 1528 Parameters: 1529 - `stream`: `userdata` for sub-type of |uv_stream_t| 1530 - `backlog`: `integer` 1531 - `callback`: `callable` 1532 - `err`: `nil` or `string` 1533 1534 Start listening for incoming connections. `backlog` indicates 1535 the number of connections the kernel might queue, same as 1536 `listen(2)`. When a new incoming connection is received the 1537 callback is called. 1538 1539 Returns: `0` or `fail` 1540 1541 uv.accept({stream}, {client_stream}) *uv.accept()* 1542 1543 > method form `stream:accept(client_stream)` 1544 1545 Parameters: 1546 - `stream`: `userdata` for sub-type of |uv_stream_t| 1547 - `client_stream`: `userdata` for sub-type of |uv_stream_t| 1548 1549 This call is used in conjunction with |uv.listen()| to accept 1550 incoming connections. Call this function after receiving a 1551 callback to accept the connection. 1552 1553 When the connection callback is called it is guaranteed that 1554 this function will complete successfully the first time. If 1555 you attempt to use it more than once, it may fail. It is 1556 suggested to only call this function once per connection call. 1557 1558 Returns: `0` or `fail` 1559 1560 >lua 1561 server:listen(128, function (err) 1562 local client = uv.new_tcp() 1563 server:accept(client) 1564 end) 1565 < 1566 1567 uv.read_start({stream}, {callback}) *uv.read_start()* 1568 1569 > method form `stream:read_start(callback)` 1570 1571 Parameters: 1572 - `stream`: `userdata` for sub-type of |uv_stream_t| 1573 - `callback`: `callable` 1574 - `err`: `nil` or `string` 1575 - `data`: `string` or `nil` 1576 1577 Read data from an incoming stream. The callback will be made 1578 several times until there is no more data to read or 1579 |uv.read_stop()| is called. When we've reached EOF, `data` 1580 will be `nil`. 1581 1582 Returns: `0` or `fail` 1583 1584 >lua 1585 stream:read_start(function (err, chunk) 1586 if err then 1587 -- handle read error 1588 elseif chunk then 1589 -- handle data 1590 else 1591 -- handle disconnect 1592 end 1593 end) 1594 < 1595 1596 uv.read_stop({stream}) *uv.read_stop()* 1597 1598 > method form `stream:read_stop()` 1599 1600 Parameters: 1601 - `stream`: `userdata` for sub-type of |uv_stream_t| 1602 1603 Stop reading data from the stream. The read callback will no 1604 longer be called. 1605 1606 This function is idempotent and may be safely called on a 1607 stopped stream. 1608 1609 Returns: `0` or `fail` 1610 1611 uv.write({stream}, {data} [, {callback}]) *uv.write()* 1612 1613 > method form `stream:write(data, [callback])` 1614 1615 Parameters: 1616 - `stream`: `userdata` for sub-type of |uv_stream_t| 1617 - `data`: `buffer` 1618 - `callback`: `callable` or `nil` 1619 - `err`: `nil` or `string` 1620 1621 Write data to stream. 1622 1623 `data` can either be a Lua string or a table of strings. If a 1624 table is passed in, the C backend will use writev to send all 1625 strings in a single system call. 1626 1627 The optional `callback` is for knowing when the write is 1628 complete. 1629 1630 Returns: `uv_write_t userdata` or `fail` 1631 1632 uv.write2({stream}, {data}, {send_handle} [, {callback}]) *uv.write2()* 1633 1634 > method form `stream:write2(data, send_handle, [callback])` 1635 1636 Parameters: 1637 - `stream`: `userdata` for sub-type of |uv_stream_t| 1638 - `data`: `buffer` 1639 - `send_handle`: `userdata` for sub-type of |uv_stream_t| 1640 - `callback`: `callable` or `nil` 1641 - `err`: `nil` or `string` 1642 1643 Extended write function for sending handles over a pipe. The 1644 pipe must be initialized with `ipc` option `true`. 1645 1646 Returns: `uv_write_t userdata` or `fail` 1647 1648 Note: `send_handle` must be a TCP socket or pipe, which is a 1649 server or a connection (listening or connected state). Bound 1650 sockets or pipes will be assumed to be servers. 1651 1652 uv.try_write({stream}, {data}) *uv.try_write()* 1653 1654 > method form `stream:try_write(data)` 1655 1656 Parameters: 1657 - `stream`: `userdata` for sub-type of |uv_stream_t| 1658 - `data`: `buffer` 1659 1660 Same as |uv.write()|, but won't queue a write request if it 1661 can't be completed immediately. 1662 1663 Will return number of bytes written (can be less than the 1664 supplied buffer size). 1665 1666 Returns: `integer` or `fail` 1667 1668 uv.try_write2({stream}, {data}, {send_handle}) *uv.try_write2()* 1669 1670 > method form `stream:try_write2(data, send_handle)` 1671 1672 Parameters: 1673 - `stream`: `userdata` for sub-type of |uv_stream_t| 1674 - `data`: `buffer` 1675 - `send_handle`: `userdata` for sub-type of |uv_stream_t| 1676 1677 Like |uv.write2()|, but with the properties of 1678 |uv.try_write()|. Not supported on Windows, where it returns 1679 `UV_EAGAIN`. 1680 1681 Will return number of bytes written (can be less than the 1682 supplied buffer size). 1683 1684 Returns: `integer` or `fail` 1685 1686 uv.is_readable({stream}) *uv.is_readable()* 1687 1688 > method form `stream:is_readable()` 1689 1690 Parameters: 1691 - `stream`: `userdata` for sub-type of |uv_stream_t| 1692 1693 Returns `true` if the stream is readable, `false` otherwise. 1694 1695 Returns: `boolean` 1696 1697 uv.is_writable({stream}) *uv.is_writable()* 1698 1699 > method form `stream:is_writable()` 1700 1701 Parameters: 1702 - `stream`: `userdata` for sub-type of |uv_stream_t| 1703 1704 Returns `true` if the stream is writable, `false` otherwise. 1705 1706 Returns: `boolean` 1707 1708 uv.stream_set_blocking({stream}, {blocking}) *uv.stream_set_blocking()* 1709 1710 > method form `stream:set_blocking(blocking)` 1711 1712 Parameters: 1713 - `stream`: `userdata` for sub-type of |uv_stream_t| 1714 - `blocking`: `boolean` 1715 1716 Enable or disable blocking mode for a stream. 1717 1718 When blocking mode is enabled all writes complete 1719 synchronously. The interface remains unchanged otherwise, e.g. 1720 completion or failure of the operation will still be reported 1721 through a callback which is made asynchronously. 1722 1723 Returns: `0` or `fail` 1724 1725 WARNING: Relying too much on this API is not recommended. It 1726 is likely to change significantly in the future. Currently 1727 this only works on Windows and only for |uv_pipe_t| handles. 1728 Also libuv currently makes no ordering guarantee when the 1729 blocking mode is changed after write requests have already 1730 been submitted. Therefore it is recommended to set the 1731 blocking mode immediately after opening or creating the 1732 stream. 1733 1734 uv.stream_get_write_queue_size() *uv.stream_get_write_queue_size()* 1735 1736 > method form `stream:get_write_queue_size()` 1737 1738 Returns the stream's write queue size. 1739 1740 Returns: `integer` 1741 1742 ============================================================================== 1743 `uv_tcp_t` — TCP handle *luv-tcp-handle* *uv_tcp_t* 1744 1745 > |uv_handle_t| and |uv_stream_t| functions also apply. 1746 1747 TCP handles are used to represent both TCP streams and servers. 1748 1749 uv.new_tcp([{flags}]) *uv.new_tcp()* 1750 1751 Parameters: 1752 - `flags`: `string` or `integer` or `nil` 1753 1754 Creates and initializes a new |uv_tcp_t|. Returns the Lua 1755 userdata wrapping it. 1756 1757 If set, `flags` must be a valid address family. See 1758 |luv-constants| for supported address family input values. 1759 1760 Returns: `uv_tcp_t userdata` or `fail` 1761 1762 uv.tcp_open({tcp}, {sock}) *uv.tcp_open()* 1763 1764 > method form `tcp:open(sock)` 1765 1766 Parameters: 1767 - `tcp`: `uv_tcp_t userdata` 1768 - `sock`: `integer` 1769 1770 Open an existing file descriptor or SOCKET as a TCP handle. 1771 1772 Returns: `0` or `fail` 1773 1774 Note: The passed file descriptor or SOCKET is not checked for 1775 its type, but it's required that it represents a valid stream 1776 socket. 1777 1778 uv.tcp_nodelay({tcp}, {enable}) *uv.tcp_nodelay()* 1779 1780 > method form `tcp:nodelay(enable)` 1781 1782 Parameters: 1783 - `tcp`: `uv_tcp_t userdata` 1784 - `enable`: `boolean` 1785 1786 Enable / disable Nagle's algorithm. 1787 1788 Returns: `0` or `fail` 1789 1790 uv.tcp_keepalive({tcp}, {enable} [, {delay}]) *uv.tcp_keepalive()* 1791 1792 > method form `tcp:keepalive(enable, [delay])` 1793 1794 Parameters: 1795 - `tcp`: `uv_tcp_t userdata` 1796 - `enable`: `boolean` 1797 - `delay`: `integer` or `nil` 1798 1799 Enable / disable TCP keep-alive. `delay` is the initial delay 1800 in seconds, ignored when enable is `false`. 1801 1802 Returns: `0` or `fail` 1803 1804 uv.tcp_simultaneous_accepts({tcp}, {enable}) *uv.tcp_simultaneous_accepts()* 1805 1806 > method form `tcp:simultaneous_accepts(enable)` 1807 1808 Parameters: 1809 - `tcp`: `uv_tcp_t userdata` 1810 - `enable`: `boolean` 1811 1812 Enable / disable simultaneous asynchronous accept requests 1813 that are queued by the operating system when listening for new 1814 TCP connections. 1815 1816 This setting is used to tune a TCP server for the desired 1817 performance. Having simultaneous accepts can significantly 1818 improve the rate of accepting connections (which is why it is 1819 enabled by default) but may lead to uneven load distribution 1820 in multi-process setups. 1821 1822 Returns: `0` or `fail` 1823 1824 uv.tcp_bind({tcp}, {host}, {port} [, {flags}]) *uv.tcp_bind()* 1825 1826 > method form `tcp:bind(host, port, [flags])` 1827 1828 Parameters: 1829 - `tcp`: `uv_tcp_t userdata` 1830 - `host`: `string` 1831 - `port`: `integer` 1832 - `flags`: `table` or `nil` 1833 - `ipv6only`: `boolean` 1834 1835 Bind the handle to an host and port. `host` should be an IP 1836 address and not a domain name. Any `flags` are set with a 1837 table with field `ipv6only` equal to `true` or `false`. 1838 1839 When the port is already taken, you can expect to see an 1840 `EADDRINUSE` error from either `uv.tcp_bind()`, |uv.listen()| 1841 or |uv.tcp_connect()|. That is, a successful call to this 1842 function does not guarantee that the call to |uv.listen()| or 1843 |uv.tcp_connect()| will succeed as well. 1844 1845 Use a port of `0` to let the OS assign an ephemeral port. You 1846 can look it up later using |uv.tcp_getsockname()|. 1847 1848 Returns: `0` or `fail` 1849 1850 uv.tcp_getpeername({tcp}) *uv.tcp_getpeername()* 1851 1852 > method form `tcp:getpeername()` 1853 1854 Parameters: 1855 - `tcp`: `uv_tcp_t userdata` 1856 1857 Get the address of the peer connected to the handle. 1858 1859 See |luv-constants| for supported address `family` output values. 1860 1861 Returns: `table` or `fail` 1862 - `ip` : `string` 1863 - `family` : `string` 1864 - `port` : `integer` 1865 1866 uv.tcp_getsockname({tcp}) *uv.tcp_getsockname()* 1867 1868 > method form `tcp:getsockname()` 1869 1870 Parameters: 1871 - `tcp`: `uv_tcp_t userdata` 1872 1873 Get the current address to which the handle is bound. 1874 1875 See |luv-constants| for supported address `family` output values. 1876 1877 Returns: `table` or `fail` 1878 - `ip` : `string` 1879 - `family` : `string` 1880 - `port` : `integer` 1881 1882 uv.tcp_connect({tcp}, {host}, {port}, {callback}) *uv.tcp_connect()* 1883 1884 > method form `tcp:connect(host, port, callback)` 1885 1886 Parameters: 1887 - `tcp`: `uv_tcp_t userdata` 1888 - `host`: `string` 1889 - `port`: `integer` 1890 - `callback`: `callable` 1891 - `err`: `nil` or `string` 1892 1893 Establish an IPv4 or IPv6 TCP connection. 1894 1895 Returns: `uv_connect_t userdata` or `fail` 1896 1897 >lua 1898 local client = uv.new_tcp() 1899 client:connect("127.0.0.1", 8080, function (err) 1900 -- check error and carry on. 1901 end) 1902 < 1903 1904 uv.tcp_write_queue_size({tcp}) *uv.tcp_write_queue_size()* 1905 1906 > method form `tcp:write_queue_size()` 1907 1908 DEPRECATED: Please use |uv.stream_get_write_queue_size()| 1909 instead. 1910 1911 uv.tcp_close_reset([{callback}]) *uv.tcp_close_reset()* 1912 1913 > method form `tcp:close_reset([callback])` 1914 1915 Parameters: 1916 - `tcp`: `uv_tcp_t userdata` 1917 - `callback`: `callable` or `nil` 1918 1919 Resets a TCP connection by sending a RST packet. This is 1920 accomplished by setting the SO_LINGER socket option with a 1921 linger interval of zero and then calling |uv.close()|. Due to 1922 some platform inconsistencies, mixing of |uv.shutdown()| and 1923 `uv.tcp_close_reset()` calls is not allowed. 1924 1925 Returns: `0` or `fail` 1926 *uv.socketpair()* 1927 uv.socketpair([{socktype}, [{protocol}, [{flags1}, [{flags2}]]]]) 1928 1929 Parameters: 1930 - `socktype`: `string`, `integer` or `nil` (default: `stream`) 1931 - `protocol`: `string`, `integer` or `nil` (default: 0) 1932 - `flags1`: `table` or `nil` 1933 - `nonblock`: `boolean` (default: `false`) 1934 - `flags2`: `table` or `nil` 1935 - `nonblock`: `boolean` (default: `false`) 1936 1937 Create a pair of connected sockets with the specified 1938 properties. The resulting handles can be passed to 1939 |uv.tcp_open()|, used with |uv.spawn()|, or for any other 1940 purpose. 1941 1942 See |luv-constants| for supported `socktype` input values. 1943 1944 When `protocol` is set to 0 or nil, it will be automatically 1945 chosen based on the socket's domain and type. When `protocol` 1946 is specified as a string, it will be looked up using the 1947 `getprotobyname(3)` function (examples: `"ip"`, `"icmp"`, 1948 `"tcp"`, `"udp"`, etc). 1949 1950 Flags: 1951 - `nonblock`: Opens the specified socket handle for 1952 `OVERLAPPED` or `FIONBIO`/`O_NONBLOCK` I/O usage. This is 1953 recommended for handles that will be used by libuv, and not 1954 usually recommended otherwise. 1955 1956 Equivalent to `socketpair(2)` with a domain of `AF_UNIX`. 1957 1958 Returns: `table` or `fail` 1959 - `[1, 2]` : `integer` (file descriptor) 1960 1961 >lua 1962 -- Simple read/write with tcp 1963 local fds = uv.socketpair(nil, nil, {nonblock=true}, {nonblock=true}) 1964 1965 local sock1 = uv.new_tcp() 1966 sock1:open(fds[1]) 1967 1968 local sock2 = uv.new_tcp() 1969 sock2:open(fds[2]) 1970 1971 sock1:write("hello") 1972 sock2:read_start(function(err, chunk) 1973 assert(not err, err) 1974 print(chunk) 1975 end) 1976 < 1977 1978 ============================================================================== 1979 `uv_pipe_t` — Pipe handle *luv-pipe-handle* *uv_pipe_t* 1980 1981 > |uv_handle_t| and |uv_stream_t| functions also apply. 1982 1983 Pipe handles provide an abstraction over local domain sockets on Unix and 1984 named pipes on Windows. 1985 1986 >lua 1987 local pipe = uv.new_pipe(false) 1988 1989 pipe:bind('/tmp/sock.test') 1990 1991 pipe:listen(128, function() 1992 local client = uv.new_pipe(false) 1993 pipe:accept(client) 1994 client:write("hello!\n") 1995 client:close() 1996 end) 1997 < 1998 1999 uv.new_pipe([{ipc}]) *uv.new_pipe()* 2000 2001 Parameters: 2002 - `ipc`: `boolean` or `nil` (default: `false`) 2003 2004 Creates and initializes a new |uv_pipe_t|. Returns the Lua 2005 userdata wrapping it. The `ipc` argument is a boolean to 2006 indicate if this pipe will be used for handle passing between 2007 processes. 2008 2009 Returns: `uv_pipe_t userdata` or `fail` 2010 2011 uv.pipe_open({pipe}, {fd}) *uv.pipe_open()* 2012 2013 > method form `pipe:open(fd)` 2014 2015 Parameters: 2016 - `pipe`: `uv_pipe_t userdata` 2017 - `fd`: `integer` 2018 2019 Open an existing file descriptor or |uv_handle_t| as a 2020 pipe. 2021 2022 Returns: `0` or `fail` 2023 2024 Note: The file descriptor is set to non-blocking mode. 2025 2026 uv.pipe_bind({pipe}, {name}) *uv.pipe_bind()* 2027 2028 > method form `pipe:bind(name)` 2029 2030 Parameters: 2031 - `pipe`: `uv_pipe_t userdata` 2032 - `name`: `string` 2033 2034 Bind the pipe to a file path (Unix) or a name (Windows). 2035 2036 Returns: `0` or `fail` 2037 2038 Note: Paths on Unix get truncated to 2039 sizeof(sockaddr_un.sun_path) bytes, typically between 92 and 2040 108 bytes. 2041 2042 uv.pipe_connect({pipe}, {name} [, {callback}]) *uv.pipe_connect()* 2043 2044 > method form `pipe:connect(name, [callback])` 2045 2046 Parameters: 2047 - `pipe`: `uv_pipe_t userdata` 2048 - `name`: `string` 2049 - `callback`: `callable` or `nil` 2050 - `err`: `nil` or `string` 2051 2052 Connect to the Unix domain socket or the named pipe. 2053 2054 Returns: `uv_connect_t userdata` or `fail` 2055 2056 Note: Paths on Unix get truncated to 2057 sizeof(sockaddr_un.sun_path) bytes, typically between 92 and 2058 108 bytes. 2059 2060 uv.pipe_getsockname({pipe}) *uv.pipe_getsockname()* 2061 2062 > method form `pipe:getsockname()` 2063 2064 Parameters: 2065 - `pipe`: `uv_pipe_t userdata` 2066 2067 Get the name of the Unix domain socket or the named pipe. 2068 2069 Returns: `string` or `fail` 2070 2071 uv.pipe_getpeername({pipe}) *uv.pipe_getpeername()* 2072 2073 > method form `pipe:getpeername()` 2074 2075 Parameters: 2076 - `pipe`: `uv_pipe_t userdata` 2077 2078 Get the name of the Unix domain socket or the named pipe to 2079 which the handle is connected. 2080 2081 Returns: `string` or `fail` 2082 2083 uv.pipe_pending_instances({pipe}, {count}) *uv.pipe_pending_instances()* 2084 2085 > method form `pipe:pending_instances(count)` 2086 2087 Parameters: 2088 - `pipe`: `uv_pipe_t userdata` 2089 - `count`: `integer` 2090 2091 Set the number of pending pipe instance handles when the pipe 2092 server is waiting for connections. 2093 2094 Returns: Nothing. 2095 2096 Note: This setting applies to Windows only. 2097 2098 uv.pipe_pending_count({pipe}) *uv.pipe_pending_count()* 2099 2100 > method form `pipe:pending_count()` 2101 2102 Parameters: 2103 - `pipe`: `uv_pipe_t userdata` 2104 2105 Returns the pending pipe count for the named pipe. 2106 2107 Returns: `integer` 2108 2109 uv.pipe_pending_type({pipe}) *uv.pipe_pending_type()* 2110 2111 > method form `pipe:pending_type()` 2112 2113 Parameters: 2114 - `pipe`: `uv_pipe_t userdata` 2115 2116 Used to receive handles over IPC pipes. 2117 2118 First - call |uv.pipe_pending_count()|, if it's > 0 then 2119 initialize a handle of the given type, returned by 2120 `uv.pipe_pending_type()` and call `uv.accept(pipe, handle)` . 2121 2122 Returns: `string` 2123 2124 uv.pipe_chmod({pipe}, {flags}) *uv.pipe_chmod()* 2125 2126 > method form `pipe:chmod(flags)` 2127 2128 Parameters: 2129 - `pipe`: `uv_pipe_t userdata` 2130 - `flags`: `string` 2131 2132 Alters pipe permissions, allowing it to be accessed from 2133 processes run by different users. Makes the pipe writable or 2134 readable by all users. `flags` are: `"r"`, `"w"`, `"rw"`, or 2135 `"wr"` where `r` is `READABLE` and `w` is `WRITABLE`. This 2136 function is blocking. 2137 2138 Returns: `0` or `fail` 2139 2140 uv.pipe({read_flags}, {write_flags}) *uv.pipe()* 2141 2142 Parameters: 2143 - `read_flags`: `table` or `nil` 2144 - `nonblock`: `boolean` (default: `false`) 2145 - `write_flags`: `table` or `nil` 2146 - `nonblock`: `boolean` (default: `false`) 2147 2148 Create a pair of connected pipe handles. Data may be written 2149 to the `write` fd and read from the `read` fd. The resulting 2150 handles can be passed to `pipe_open`, used with `spawn`, or 2151 for any other purpose. 2152 2153 Flags: 2154 - `nonblock`: Opens the specified socket handle for 2155 `OVERLAPPED` or `FIONBIO`/`O_NONBLOCK` I/O usage. This is 2156 recommended for handles that will be used by libuv, and not 2157 usually recommended otherwise. 2158 2159 Equivalent to `pipe(2)` with the `O_CLOEXEC` flag set. 2160 2161 Returns: `table` or `fail` 2162 - `read` : `integer` (file descriptor) 2163 - `write` : `integer` (file descriptor) 2164 2165 >lua 2166 -- Simple read/write with pipe_open 2167 local fds = uv.pipe({nonblock=true}, {nonblock=true}) 2168 2169 local read_pipe = uv.new_pipe() 2170 read_pipe:open(fds.read) 2171 2172 local write_pipe = uv.new_pipe() 2173 write_pipe:open(fds.write) 2174 2175 write_pipe:write("hello") 2176 read_pipe:read_start(function(err, chunk) 2177 assert(not err, err) 2178 print(chunk) 2179 end) 2180 < 2181 2182 uv.pipe_bind2({pipe}, {name}, {flags}) *uv.pipe_bind2()* 2183 2184 > method form `pipe:pipe_bind(name, flags)` 2185 2186 Parameters: 2187 - `pipe`: `uv_pipe_t userdata` 2188 - `name`: `string` 2189 - `flags`: `integer` or `table` or `nil` (default: 0) 2190 2191 Flags: 2192 - If `type(flags)` is `number`, it must be `0` or 2193 `uv.constants.PIPE_NO_TRUNCATE`. 2194 - If `type(flags)` is `table`, it must be `{}` or 2195 `{ no_truncate = true|false }`. 2196 - If `type(flags)` is `nil`, it use default value `0`. 2197 - Returns `EINVAL` for unsupported flags without performing the 2198 bind. 2199 2200 Bind the pipe to a file path (Unix) or a name (Windows). 2201 2202 Supports Linux abstract namespace sockets. namelen must include 2203 the leading '\0' byte but not the trailing nul byte. 2204 2205 Returns: `0` or `fail` 2206 2207 Note: 2208 1. Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) 2209 bytes, typically between 92 and 108 bytes. 2210 2. New in version 1.46.0. 2211 2212 uv.pipe_connect2(pipe, name, [flags], [callback]) *uv.pipe_connect2()* 2213 2214 > method form `pipe:connect2(name, [flags], [callback])` 2215 2216 Parameters: 2217 - `pipe`: `uv_pipe_t userdata` 2218 - `name`: `string` 2219 - `flags`: `integer` or `table` or `nil` (default: 0) 2220 - `callback`: `callable` or `nil` 2221 - `err`: `nil` or `string` 2222 2223 `Flags`: 2224 2225 - If `type(flags)` is `number`, it must be `0` or 2226 `uv.constants.PIPE_NO_TRUNCATE`. 2227 - If `type(flags)` is `table`, it must be `{}` or 2228 `{ no_truncate = true|false }`. 2229 - If `type(flags)` is `nil`, it use default value `0`. 2230 - Returns `EINVAL` for unsupported flags without performing the 2231 bind operation. 2232 2233 Connect to the Unix domain socket or the named pipe. 2234 2235 Supports Linux abstract namespace sockets. namelen must include 2236 the leading nul byte but not the trailing nul byte. 2237 2238 Returns: `uv_connect_t userdata` or `fail` 2239 2240 Note: 2241 1. Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) 2242 bytes, typically between 92 and 108 bytes. 2243 2. New in version 1.46.0. 2244 2245 ============================================================================== 2246 `uv_tty_t` — TTY handle *luv-tty-handle* *uv_tty_t* 2247 2248 > |uv_handle_t| and |uv_stream_t| functions also apply. 2249 2250 TTY handles represent a stream for the console. 2251 2252 >lua 2253 -- Simple echo program 2254 local stdin = uv.new_tty(0, true) 2255 local stdout = uv.new_tty(1, false) 2256 2257 stdin:read_start(function (err, data) 2258 assert(not err, err) 2259 if data then 2260 stdout:write(data) 2261 else 2262 stdin:close() 2263 stdout:close() 2264 end 2265 end) 2266 < 2267 2268 uv.new_tty({fd}, {readable}) *uv.new_tty()* 2269 2270 Parameters: 2271 - `fd`: `integer` 2272 - `readable`: `boolean` 2273 2274 Initialize a new TTY stream with the given file descriptor. 2275 Usually the file descriptor will be: 2276 2277 - 0 - stdin 2278 - 1 - stdout 2279 - 2 - stderr 2280 2281 On Unix this function will determine the path of the fd of the 2282 terminal using ttyname_r(3), open it, and use it if the passed 2283 file descriptor refers to a TTY. This lets libuv put the tty 2284 in non-blocking mode without affecting other processes that 2285 share the tty. 2286 2287 This function is not thread safe on systems that don’t support 2288 ioctl TIOCGPTN or TIOCPTYGNAME, for instance OpenBSD and 2289 Solaris. 2290 2291 Returns: `uv_tty_t userdata` or `fail` 2292 2293 Note: If reopening the TTY fails, libuv falls back to blocking 2294 writes. 2295 2296 uv.tty_set_mode({tty}, {mode}) *uv.tty_set_mode()* 2297 2298 > method form `tty:set_mode(mode)` 2299 2300 Parameters: 2301 - `tty`: `uv_tty_t userdata` 2302 - `mode`: `string` or `integer` 2303 2304 Set the TTY using the specified terminal mode. 2305 2306 See |luv-constants| for supported TTY mode input values. 2307 2308 Returns: `0` or `fail` 2309 2310 uv.tty_reset_mode() *uv.tty_reset_mode()* 2311 2312 To be called when the program exits. Resets TTY settings to 2313 default values for the next process to take over. 2314 2315 This function is async signal-safe on Unix platforms but can 2316 fail with error code `EBUSY` if you call it when execution is 2317 inside |uv.tty_set_mode()|. 2318 2319 Returns: `0` or `fail` 2320 2321 uv.tty_get_winsize({tty}) *uv.tty_get_winsize()* 2322 2323 > method form `tty:get_winsize()` 2324 2325 Parameters: 2326 - `tty`: `uv_tty_t userdata` 2327 2328 Gets the current Window width and height. 2329 2330 Returns: `integer, integer` or `fail` 2331 2332 uv.tty_set_vterm_state({state}) *uv.tty_set_vterm_state()* 2333 2334 Parameters: 2335 - `state`: `string` 2336 2337 Controls whether console virtual terminal sequences are 2338 processed by libuv or console. Useful in particular for 2339 enabling ConEmu support of ANSI X3.64 and Xterm 256 colors. 2340 Otherwise Windows10 consoles are usually detected 2341 automatically. State should be one of: `"supported"` or 2342 `"unsupported"`. 2343 2344 This function is only meaningful on Windows systems. On Unix 2345 it is silently ignored. 2346 2347 Returns: none 2348 2349 uv.tty_get_vterm_state() *uv.tty_get_vterm_state()* 2350 2351 Get the current state of whether console virtual terminal 2352 sequences are handled by libuv or the console. The return 2353 value is `"supported"` or `"unsupported"`. 2354 2355 This function is not implemented on Unix, where it returns 2356 `ENOTSUP`. 2357 2358 Returns: `string` or `fail` 2359 2360 ============================================================================== 2361 `uv_udp_t` — UDP handle *luv-udp-handle* *uv_udp_t* 2362 2363 > |uv_handle_t| functions also apply. 2364 2365 UDP handles encapsulate UDP communication for both clients and servers. 2366 2367 uv.new_udp([{flags}]) *uv.new_udp()* 2368 2369 Parameters: 2370 - `flags`: `table` or `nil` 2371 - `family`: `string` or `nil` 2372 - `mmsgs`: `integer` or `nil` (default: `1`) 2373 2374 Creates and initializes a new |uv_udp_t|. Returns the Lua 2375 userdata wrapping it. The actual socket is created lazily. 2376 2377 See |luv-constants| for supported address `family` input values. 2378 2379 When specified, `mmsgs` determines the number of messages able 2380 to be received at one time via `recvmmsg(2)` (the allocated 2381 buffer will be sized to be able to fit the specified number of 2382 max size dgrams). Only has an effect on platforms that support 2383 `recvmmsg(2)`. 2384 2385 Note: For backwards compatibility reasons, `flags` can also be 2386 a string or integer. When it is a string, it will be treated 2387 like the `family` key above. When it is an integer, it will be 2388 used directly as the `flags` parameter when calling 2389 `uv_udp_init_ex`. 2390 2391 Returns: `uv_udp_t userdata` or `fail` 2392 2393 uv.udp_get_send_queue_size() *uv.udp_get_send_queue_size()* 2394 2395 > method form `udp:get_send_queue_size()` 2396 2397 Returns the handle's send queue size. 2398 2399 Returns: `integer` 2400 2401 uv.udp_get_send_queue_count() *uv.udp_get_send_queue_count()* 2402 2403 > method form `udp:get_send_queue_count()` 2404 2405 Returns the handle's send queue count. 2406 2407 Returns: `integer` 2408 2409 uv.udp_open({udp}, {fd}) *uv.udp_open()* 2410 2411 > method form `udp:open(fd)` 2412 2413 Parameters: 2414 - `udp`: `uv_udp_t userdata` 2415 - `fd`: `integer` 2416 2417 Opens an existing file descriptor or Windows SOCKET as a UDP 2418 handle. 2419 2420 Unix only: The only requirement of the sock argument is that 2421 it follows the datagram contract (works in unconnected mode, 2422 supports sendmsg()/recvmsg(), etc). In other words, other 2423 datagram-type sockets like raw sockets or netlink sockets can 2424 also be passed to this function. 2425 2426 The file descriptor is set to non-blocking mode. 2427 2428 Note: The passed file descriptor or SOCKET is not checked for 2429 its type, but it's required that it represents a valid 2430 datagram socket. 2431 2432 Returns: `0` or `fail` 2433 2434 uv.udp_bind({udp}, {host}, {port} [, {flags}]) *uv.udp_bind()* 2435 2436 > method form `udp:bind(host, port, [flags])` 2437 2438 Parameters: 2439 - `udp`: `uv_udp_t userdata` 2440 - `host`: `string` 2441 - `port`: `number` 2442 - `flags`: `table` or `nil` 2443 - `ipv6only`: `boolean` 2444 - `reuseaddr`: `boolean` 2445 2446 Bind the UDP handle to an IP address and port. Any `flags` are 2447 set with a table with fields `reuseaddr` or `ipv6only` equal 2448 to `true` or `false`. 2449 2450 Returns: `0` or `fail` 2451 2452 uv.udp_getsockname({udp}) *uv.udp_getsockname()* 2453 2454 > method form `udp:getsockname()` 2455 2456 Parameters: 2457 - `udp`: `uv_udp_t userdata` 2458 2459 Get the local IP and port of the UDP handle. 2460 2461 Returns: `table` or `fail` 2462 - `ip` : `string` 2463 - `family` : `string` 2464 - `port` : `integer` 2465 2466 uv.udp_getpeername({udp}) *uv.udp_getpeername()* 2467 2468 > method form `udp:getpeername()` 2469 2470 Parameters: 2471 - `udp`: `uv_udp_t userdata` 2472 2473 Get the remote IP and port of the UDP handle on connected UDP 2474 handles. 2475 2476 Returns: `table` or `fail` 2477 - `ip` : `string` 2478 - `family` : `string` 2479 - `port` : `integer` 2480 2481 *uv.udp_set_membership()* 2482 uv.udp_set_membership({udp}, {multicast_addr}, {interface_addr}, {membership}) 2483 2484 > method form 2485 > `udp:set_membership(multicast_addr, interface_addr, membership)` 2486 2487 Parameters: 2488 - `udp`: `uv_udp_t userdata` 2489 - `multicast_addr`: `string` 2490 - `interface_addr`: `string` or `nil` 2491 - `membership`: `string` 2492 2493 Set membership for a multicast address. `multicast_addr` is 2494 multicast address to set membership for. `interface_addr` is 2495 interface address. `membership` can be the string `"leave"` or 2496 `"join"`. 2497 2498 Returns: `0` or `fail` 2499 2500 *uv.udp_set_source_membership()* 2501 uv.udp_set_source_membership({udp}, {multicast_addr}, {interface_addr}, {source_addr}, {membership}) 2502 2503 > method form 2504 > `udp:set_source_membership(multicast_addr, interface_addr, source_addr, membership)` 2505 2506 Parameters: 2507 - `udp`: `uv_udp_t userdata` 2508 - `multicast_addr`: `string` 2509 - `interface_addr`: `string` or `nil` 2510 - `source_addr`: `string` 2511 - `membership`: `string` 2512 2513 Set membership for a source-specific multicast group. 2514 `multicast_addr` is multicast address to set membership for. 2515 `interface_addr` is interface address. `source_addr` is source 2516 address. `membership` can be the string `"leave"` or `"join"`. 2517 2518 Returns: `0` or `fail` 2519 2520 uv.udp_set_multicast_loop({udp}, {on}) *uv.udp_set_multicast_loop()* 2521 2522 > method form `udp:set_multicast_loop(on)` 2523 2524 Parameters: 2525 - `udp`: `uv_udp_t userdata` 2526 - `on`: `boolean` 2527 2528 Set IP multicast loop flag. Makes multicast packets loop back 2529 to local sockets. 2530 2531 Returns: `0` or `fail` 2532 2533 uv.udp_set_multicast_ttl({udp}, {ttl}) *uv.udp_set_multicast_ttl()* 2534 2535 > method form `udp:set_multicast_ttl(ttl)` 2536 2537 Parameters: 2538 - `udp`: `uv_udp_t userdata` 2539 - `ttl`: `integer` 2540 2541 Set the multicast ttl. 2542 2543 `ttl` is an integer 1 through 255. 2544 2545 Returns: `0` or `fail` 2546 2547 *uv.udp_set_multicast_interface()* 2548 uv.udp_set_multicast_interface({udp}, {interface_addr}) 2549 2550 > method form `udp:set_multicast_interface(interface_addr)` 2551 2552 Parameters: 2553 - `udp`: `uv_udp_t userdata` 2554 - `interface_addr`: `string` 2555 2556 Set the multicast interface to send or receive data on. 2557 2558 Returns: `0` or `fail` 2559 2560 uv.udp_set_broadcast({udp}, {on}) *uv.udp_set_broadcast()* 2561 2562 > method form `udp:set_broadcast(on)` 2563 2564 Parameters: 2565 - `udp`: `uv_udp_t userdata` 2566 - `on`: `boolean` 2567 2568 Set broadcast on or off. 2569 2570 Returns: `0` or `fail` 2571 2572 uv.udp_set_ttl({udp}, {ttl}) *uv.udp_set_ttl()* 2573 2574 > method form `udp:set_ttl(ttl)` 2575 2576 Parameters: 2577 - `udp`: `uv_udp_t userdata` 2578 - `ttl`: `integer` 2579 2580 Set the time to live. 2581 2582 `ttl` is an integer 1 through 255. 2583 2584 Returns: `0` or `fail` 2585 2586 uv.udp_send({udp}, {data}, {host}, {port}, {callback}) *uv.udp_send()* 2587 2588 > method form `udp:send(data, host, port, callback)` 2589 2590 Parameters: 2591 - `udp`: `uv_udp_t userdata` 2592 - `data`: `buffer` 2593 - `host`: `string` 2594 - `port`: `integer` 2595 - `callback`: `callable` 2596 - `err`: `nil` or `string` 2597 2598 Send data over the UDP socket. If the socket has not 2599 previously been bound with |uv.udp_bind()| it will be bound to 2600 `0.0.0.0` (the "all interfaces" IPv4 address) and a random 2601 port number. 2602 2603 Returns: `uv_udp_send_t userdata` or `fail` 2604 2605 uv.udp_try_send({udp}, {data}, {host}, {port}) *uv.udp_try_send()* 2606 2607 > method form `udp:try_send(data, host, port)` 2608 2609 Parameters: 2610 - `udp`: `uv_udp_t userdata` 2611 - `data`: `buffer` 2612 - `host`: `string` 2613 - `port`: `integer` 2614 2615 Same as |uv.udp_send()|, but won't queue a send request if it 2616 can't be completed immediately. 2617 2618 Returns: `integer` or `fail` 2619 2620 uv.udp_try_send2({udp}, {messages}, {flags}) *uv.udp_try_send2()* 2621 2622 > method form `udp:try_send2(messages, flags)` 2623 2624 Parameters: 2625 - `udp`: `uv_udp_t userdata` 2626 - `messages`: `table` 2627 - `[1, 2, 3, ..., n]` : `table` 2628 - `data` : `buffer` 2629 - `addr` : `table` 2630 - `ip` : `string` 2631 - `port` : `integer` 2632 - `flags`: `nil` (see below) 2633 - `port`: `integer` 2634 2635 Like `uv.udp_try_send()`, but can send multiple datagrams. 2636 Lightweight abstraction around `sendmmsg(2)`, with a 2637 `sendmsg(2)` fallback loop for platforms that do not support 2638 the former. The `udp` handle must be fully initialized, either 2639 from a `uv.udp_bind` call, another call that will bind 2640 automatically (`udp_send`, `udp_try_send`, etc), or from 2641 `uv.udp_connect`. `messages` should be an array-like table, 2642 where `addr` must be specified if the `udp` has not been 2643 connected via `udp_connect`. Otherwise, `addr` must be `nil`. 2644 2645 `flags` is reserved for future extension and must currently be 2646 `nil` or `0` or `{}`. 2647 2648 Returns the number of messages sent successfully. An error will only be returned 2649 if the first datagram failed to be sent. 2650 2651 Returns: `integer` or `fail` 2652 >lua 2653 -- If client:connect(...) was not called 2654 local addr = { ip = "127.0.0.1", port = 1234 } 2655 client:try_send2({ 2656 { data = "Message 1", addr = addr }, 2657 { data = "Message 2", addr = addr }, 2658 }) 2659 -- If client:connect(...) was called 2660 client:try_send2({ 2661 { data = "Message 1" }, 2662 { data = "Message 2" }, 2663 }) 2664 < 2665 uv.udp_recv_start({udp}, {callback}) *uv.udp_recv_start()* 2666 2667 > method form `udp:recv_start(callback)` 2668 2669 Parameters: 2670 - `udp`: `uv_udp_t userdata` 2671 - `callback`: `callable` 2672 - `err`: `nil` or `string` 2673 - `data`: `string` or `nil` 2674 - `addr`: `table` or `nil` 2675 - `ip`: `string` 2676 - `port`: `integer` 2677 - `family`: `string` 2678 - `flags`: `table` 2679 - `partial`: `boolean` or `nil` 2680 - `mmsg_chunk`: `boolean` or `nil` 2681 2682 Prepare for receiving data. If the socket has not previously 2683 been bound with |uv.udp_bind()| it is bound to `0.0.0.0` (the 2684 "all interfaces" IPv4 address) and a random port number. 2685 2686 See |luv-constants| for supported address `family` output values. 2687 2688 Returns: `0` or `fail` 2689 2690 uv.udp_recv_stop({udp}) *uv.udp_recv_stop()* 2691 2692 > method form `udp:recv_stop()` 2693 2694 Parameters: 2695 - `udp`: `uv_udp_t userdata` 2696 2697 Stop listening for incoming datagrams. 2698 2699 Returns: `0` or `fail` 2700 2701 uv.udp_connect({udp}, {host}, {port}) *uv.udp_connect()* 2702 2703 > method form `udp:connect(host, port)` 2704 2705 Parameters: 2706 - `udp`: `uv_udp_t userdata` 2707 - `host`: `string` 2708 - `port`: `integer` 2709 2710 Associate the UDP handle to a remote address and port, so 2711 every message sent by this handle is automatically sent to 2712 that destination. Calling this function with a NULL addr 2713 disconnects the handle. Trying to call `uv.udp_connect()` on 2714 an already connected handle will result in an `EISCONN` error. 2715 Trying to disconnect a handle that is not connected will 2716 return an `ENOTCONN` error. 2717 2718 Returns: `0` or `fail` 2719 2720 ============================================================================== 2721 `uv_fs_event_t` — FS Event handle *luv-fs-event-handle* *uv_fs_event_t* 2722 2723 > |uv_handle_t| functions also apply. 2724 2725 FS Event handles allow the user to monitor a given path for changes, for 2726 example, if the file was renamed or there was a generic change in it. This 2727 handle uses the best backend for the job on each platform. 2728 2729 uv.new_fs_event() *uv.new_fs_event()* 2730 2731 Creates and initializes a new |uv_fs_event_t|. Returns the Lua 2732 userdata wrapping it. 2733 2734 Returns: `uv_fs_event_t userdata` or `fail` 2735 2736 uv.fs_event_start({fs_event}, {path}, {flags}, {callback}) *uv.fs_event_start()* 2737 2738 > method form `fs_event:start(path, flags, callback)` 2739 2740 Parameters: 2741 - `fs_event`: `uv_fs_event_t userdata` 2742 - `path`: `string` 2743 - `flags`: `table` 2744 - `watch_entry`: `boolean` or `nil` (default: `false`) 2745 - `stat`: `boolean` or `nil` (default: `false`) 2746 - `recursive`: `boolean` or `nil` (default: `false`) 2747 - `callback`: `callable` 2748 - `err`: `nil` or `string` 2749 - `filename`: `string` 2750 - `events`: `table` 2751 - `change`: `boolean` or `nil` 2752 - `rename`: `boolean` or `nil` 2753 2754 Start the handle with the given callback, which will watch the 2755 specified path for changes. 2756 2757 Returns: `0` or `fail` 2758 2759 uv.fs_event_stop() *uv.fs_event_stop()* 2760 2761 > method form `fs_event:stop()` 2762 2763 Stop the handle, the callback will no longer be called. 2764 2765 Returns: `0` or `fail` 2766 2767 uv.fs_event_getpath() *uv.fs_event_getpath()* 2768 2769 > method form `fs_event:getpath()` 2770 2771 Get the path being monitored by the handle. 2772 2773 Returns: `string` or `fail` 2774 2775 ============================================================================== 2776 `uv_fs_poll_t` — FS Poll handle *luv-fs-poll-handle* *uv_fs_poll_t* 2777 2778 > |uv_handle_t| functions also apply. 2779 2780 FS Poll handles allow the user to monitor a given path for changes. Unlike 2781 |uv_fs_event_t|, fs poll handles use `stat` to detect when a file has changed 2782 so they can work on file systems where fs event handles can't. 2783 2784 uv.new_fs_poll() *uv.new_fs_poll()* 2785 2786 Creates and initializes a new |uv_fs_poll_t|. Returns the Lua 2787 userdata wrapping it. 2788 2789 Returns: `uv_fs_poll_t userdata` or `fail` 2790 2791 uv.fs_poll_start({fs_poll}, {path}, {interval}, {callback}) *uv.fs_poll_start()* 2792 2793 > method form `fs_poll:start(path, interval, callback)` 2794 2795 Parameters: 2796 - `fs_poll`: `uv_fs_poll_t userdata` 2797 - `path`: `string` 2798 - `interval`: `integer` 2799 - `callback`: `callable` 2800 - `err`: `nil` or `string` 2801 - `prev`: `table` or `nil` (see `uv.fs_stat`) 2802 - `curr`: `table` or `nil` (see `uv.fs_stat`) 2803 2804 Check the file at `path` for changes every `interval` 2805 milliseconds. 2806 2807 Note: For maximum portability, use multi-second intervals. 2808 Sub-second intervals will not detect all changes on many file 2809 systems. 2810 2811 Returns: `0` or `fail` 2812 2813 uv.fs_poll_stop() *uv.fs_poll_stop()* 2814 2815 > method form `fs_poll:stop()` 2816 2817 Stop the handle, the callback will no longer be called. 2818 2819 Returns: `0` or `fail` 2820 2821 uv.fs_poll_getpath() *uv.fs_poll_getpath()* 2822 2823 > method form `fs_poll:getpath()` 2824 2825 Get the path being monitored by the handle. 2826 2827 Returns: `string` or `fail` 2828 2829 ============================================================================== 2830 FILE SYSTEM OPERATIONS *luv-file-system-operations* *uv_fs_t* 2831 2832 Most file system functions can operate synchronously or asynchronously. When a 2833 synchronous version is called (by omitting a callback), the function will 2834 immediately return the results of the FS call. When an asynchronous version is 2835 called (by providing a callback), the function will immediately return a 2836 `uv_fs_t userdata` and asynchronously execute its callback; if an error is 2837 encountered, the first and only argument passed to the callback will be the 2838 `err` error string; if the operation completes successfully, the first 2839 argument will be `nil` and the remaining arguments will be the results of the 2840 FS call. 2841 2842 Synchronous and asynchronous versions of `readFile` (with naive error 2843 handling) are implemented below as an example: 2844 2845 >lua 2846 local function readFileSync(path) 2847 local fd = assert(uv.fs_open(path, "r", 438)) 2848 local stat = assert(uv.fs_fstat(fd)) 2849 local data = assert(uv.fs_read(fd, stat.size, 0)) 2850 assert(uv.fs_close(fd)) 2851 return data 2852 end 2853 2854 local data = readFileSync("main.lua") 2855 print("synchronous read", data) 2856 < 2857 2858 >lua 2859 local function readFile(path, callback) 2860 uv.fs_open(path, "r", 438, function(err, fd) 2861 assert(not err, err) 2862 uv.fs_fstat(fd, function(err, stat) 2863 assert(not err, err) 2864 uv.fs_read(fd, stat.size, 0, function(err, data) 2865 assert(not err, err) 2866 uv.fs_close(fd, function(err) 2867 assert(not err, err) 2868 return callback(data) 2869 end) 2870 end) 2871 end) 2872 end) 2873 end 2874 2875 readFile("main.lua", function(data) 2876 print("asynchronous read", data) 2877 end) 2878 < 2879 2880 uv.fs_close({fd} [, {callback}]) *uv.fs_close()* 2881 2882 Parameters: 2883 - `fd`: `integer` 2884 - `callback`: `callable` (async version) or `nil` (sync 2885 version) 2886 - `err`: `nil` or `string` 2887 - `success`: `boolean` or `nil` 2888 2889 Equivalent to `close(2)`. 2890 2891 Returns (sync version): `boolean` or `fail` 2892 2893 Returns (async version): `uv_fs_t userdata` 2894 2895 uv.fs_open({path}, {flags}, {mode} [, {callback}]) *uv.fs_open()* 2896 2897 Parameters: 2898 - `path`: `string` 2899 - `flags`: `string` or `integer` 2900 - `mode`: `integer` (octal `chmod(1)` mode, e.g. 2901 `tonumber('644', 8)`) 2902 - `callback`: `callable` (async version) or `nil` (sync 2903 version) 2904 - `err`: `nil` or `string` 2905 - `fd`: `integer` or `nil` 2906 2907 Equivalent to `open(2)`. Access `flags` may be an integer or 2908 one of: `"r"`, `"rs"`, `"sr"`, `"r+"`, `"rs+"`, `"sr+"`, 2909 `"w"`, `"wx"`, `"xw"`, `"w+"`, `"wx+"`, `"xw+"`, `"a"`, 2910 `"ax"`, `"xa"`, `"a+"`, `"ax+"`, or "`xa+`". 2911 2912 Returns (sync version): `integer` or `fail` 2913 2914 Returns (async version): `uv_fs_t userdata` 2915 2916 Note: On Windows, libuv uses `CreateFileW` and thus the file 2917 is always opened in binary mode. Because of this, the 2918 `O_BINARY` and `O_TEXT` flags are not supported. 2919 2920 uv.fs_read({fd}, {size} [, {offset} [, {callback}]]) *uv.fs_read()* 2921 2922 Parameters: 2923 - `fd`: `integer` 2924 - `size`: `integer` 2925 - `offset`: `integer` or `nil` 2926 - `callback`: `callable` (async version) or `nil` (sync 2927 version) 2928 - `err`: `nil` or `string` 2929 - `data`: `string` or `nil` 2930 2931 Equivalent to `preadv(2)`. Returns any data. An empty string 2932 indicates EOF. 2933 2934 If `offset` is nil or omitted, it will default to `-1`, which 2935 indicates "use and update the current file offset." 2936 2937 Note: When `offset` is >= 0, the current file offset will not 2938 be updated by the read. 2939 2940 Returns (sync version): `string` or `fail` 2941 2942 Returns (async version): `uv_fs_t userdata` 2943 2944 uv.fs_unlink({path} [, {callback}]) *uv.fs_unlink()* 2945 2946 Parameters: 2947 - `path`: `string` 2948 - `callback`: `callable` (async version) or `nil` (sync 2949 version) 2950 - `err`: `nil` or `string` 2951 - `success`: `boolean` or `nil` 2952 2953 Equivalent to `unlink(2)`. 2954 2955 Returns (sync version): `boolean` or `fail` 2956 2957 Returns (async version): `uv_fs_t userdata` 2958 2959 uv.fs_write({fd}, {data} [, {offset} [, {callback}]]) *uv.fs_write()* 2960 2961 Parameters: 2962 - `fd`: `integer` 2963 - `data`: `buffer` 2964 - `offset`: `integer` or `nil` 2965 - `callback`: `callable` (async version) or `nil` (sync 2966 version) 2967 - `err`: `nil` or `string` 2968 - `bytes`: `integer` or `nil` 2969 2970 Equivalent to `pwritev(2)`. Returns the number of bytes 2971 written. 2972 2973 If `offset` is nil or omitted, it will default to `-1`, which 2974 indicates "use and update the current file offset." 2975 2976 Note: When `offset` is >= 0, the current file offset will not 2977 be updated by the write. 2978 2979 Returns (sync version): `integer` or `fail` 2980 2981 Returns (async version): `uv_fs_t userdata` 2982 2983 uv.fs_mkdir({path}, {mode} [, {callback}]) *uv.fs_mkdir()* 2984 2985 Parameters: 2986 - `path`: `string` 2987 - `mode`: `integer` (octal representation of `chmod(1)` mode, 2988 e.g. `tonumber('755', 8)`) 2989 - `callback`: `callable` (async version) or `nil` (sync 2990 version) 2991 - `err`: `nil` or `string` 2992 - `success`: `boolean` or `nil` 2993 2994 Equivalent to `mkdir(2)`. 2995 2996 Returns (sync version): `boolean` or `fail` 2997 2998 Returns (async version): `uv_fs_t userdata` 2999 3000 uv.fs_mkdtemp({template} [, {callback}]) *uv.fs_mkdtemp()* 3001 3002 Parameters: 3003 - `template`: `string` 3004 - `callback`: `callable` (async version) or `nil` (sync 3005 version) 3006 - `err`: `nil` or `string` 3007 - `path`: `string` or `nil` 3008 3009 Equivalent to `mkdtemp(3)`. 3010 3011 Returns (sync version): `string` or `fail` 3012 3013 Returns (async version): `uv_fs_t userdata` 3014 3015 uv.fs_mkstemp({template} [, {callback}]) *uv.fs_mkstemp()* 3016 3017 Parameters: 3018 - `template`: `string` 3019 - `callback`: `callable` (async version) or `nil` (sync 3020 version) 3021 - `err`: `nil` or `string` 3022 - `fd`: `integer` or `nil` 3023 - `path`: `string` or `nil` 3024 3025 Equivalent to `mkstemp(3)`. Returns a temporary file handle 3026 and filename. 3027 3028 Returns (sync version): `integer, string` or `fail` 3029 3030 Returns (async version): `uv_fs_t userdata` 3031 3032 uv.fs_rmdir({path} [, {callback}]) *uv.fs_rmdir()* 3033 3034 Parameters: 3035 - `path`: `string` 3036 - `callback`: `callable` (async version) or `nil` (sync 3037 version) 3038 - `err`: `nil` or `string` 3039 - `success`: `boolean` or `nil` 3040 3041 Equivalent to `rmdir(2)`. 3042 3043 Returns (sync version): `boolean` or `fail` 3044 3045 Returns (async version): `uv_fs_t userdata` 3046 3047 uv.fs_scandir({path} [, {callback}]) *uv.fs_scandir()* 3048 3049 Parameters: 3050 - `path`: `string` 3051 - `callback`: `callable` 3052 - `err`: `nil` or `string` 3053 - `success`: `uv_fs_t userdata` or `nil` 3054 3055 Equivalent to `scandir(3)`, with a slightly different API. 3056 Returns a handle that the user can pass to 3057 |uv.fs_scandir_next()|. 3058 3059 Note: This function can be used synchronously or 3060 asynchronously. The request userdata is always synchronously 3061 returned regardless of whether a callback is provided and the 3062 same userdata is passed to the callback if it is provided. 3063 3064 Returns: `uv_fs_t userdata` or `fail` 3065 3066 uv.fs_scandir_next({fs}) *uv.fs_scandir_next()* 3067 3068 Parameters: 3069 - `fs`: `uv_fs_t userdata` 3070 3071 Called on a |uv_fs_t| returned by |uv.fs_scandir()| to get the 3072 next directory entry data as a `name, type` pair. When there 3073 are no more entries, `nil` is returned. 3074 3075 Note: This function only has a synchronous version. See 3076 |uv.fs_opendir()| and its related functions for an 3077 asynchronous version. 3078 3079 Returns: `string, string` or `nil` or `fail` 3080 3081 uv.fs_stat({path} [, {callback}]) *uv.fs_stat()* 3082 3083 Parameters: 3084 - `path`: `string` 3085 - `callback`: `callable` (async version) or `nil` (sync 3086 version) 3087 - `err`: `nil` or `string` 3088 - `stat`: `table` or `nil` (see below) 3089 3090 Equivalent to `stat(2)`. 3091 3092 Returns (sync version): `table` or `fail` 3093 - `dev` : `integer` 3094 - `mode` : `integer` 3095 - `nlink` : `integer` 3096 - `uid` : `integer` 3097 - `gid` : `integer` 3098 - `rdev` : `integer` 3099 - `ino` : `integer` 3100 - `size` : `integer` 3101 - `blksize` : `integer` 3102 - `blocks` : `integer` 3103 - `flags` : `integer` 3104 - `gen` : `integer` 3105 - `atime` : `table` 3106 - `sec` : `integer` 3107 - `nsec` : `integer` 3108 - `mtime` : `table` 3109 - `sec` : `integer` 3110 - `nsec` : `integer` 3111 - `ctime` : `table` 3112 - `sec` : `integer` 3113 - `nsec` : `integer` 3114 - `birthtime` : `table` 3115 - `sec` : `integer` 3116 - `nsec` : `integer` 3117 - `type` : `string` 3118 3119 Returns (async version): `uv_fs_t userdata` 3120 3121 uv.fs_fstat({fd} [, {callback}]) *uv.fs_fstat()* 3122 3123 Parameters: 3124 - `fd`: `integer` 3125 - `callback`: `callable` (async version) or `nil` (sync 3126 version) 3127 - `err`: `nil` or `string` 3128 - `stat`: `table` or `nil` (see `uv.fs_stat`) 3129 3130 Equivalent to `fstat(2)`. 3131 3132 Returns (sync version): `table` or `fail` (see `uv.fs_stat`) 3133 3134 Returns (async version): `uv_fs_t userdata` 3135 3136 uv.fs_lstat({path} [, {callback}]) *uv.fs_lstat()* 3137 3138 Parameters: 3139 - `path`: `string` 3140 - `callback`: `callable` (async version) or `nil` (sync 3141 version) 3142 - `err`: `nil` or `string` 3143 - `stat`: `table` or `nil` (see `uv.fs_stat`) 3144 3145 Equivalent to `lstat(2)`. 3146 3147 Returns (sync version): `table` or `fail` (see |uv.fs_stat()|) 3148 3149 Returns (async version): `uv_fs_t userdata` 3150 3151 uv.fs_rename({path}, {new_path} [, {callback}]) *uv.fs_rename()* 3152 3153 Parameters: 3154 - `path`: `string` 3155 - `new_path`: `string` 3156 - `callback`: `callable` (async version) or `nil` (sync 3157 version) 3158 - `err`: `nil` or `string` 3159 - `success`: `boolean` or `nil` 3160 3161 Equivalent to `rename(2)`. 3162 3163 Returns (sync version): `boolean` or `fail` 3164 3165 Returns (async version): `uv_fs_t userdata` 3166 3167 uv.fs_fsync({fd} [, {callback}]) *uv.fs_fsync()* 3168 3169 Parameters: 3170 - `fd`: `integer` 3171 - `callback`: `callable` (async version) or `nil` (sync 3172 version) 3173 - `err`: `nil` or `string` 3174 - `success`: `boolean` or `nil` 3175 3176 Equivalent to `fsync(2)`. 3177 3178 Returns (sync version): `boolean` or `fail` 3179 3180 Returns (async version): `uv_fs_t userdata` 3181 3182 uv.fs_fdatasync({fd} [, {callback}]) *uv.fs_fdatasync()* 3183 3184 Parameters: 3185 - `fd`: `integer` 3186 - `callback`: `callable` (async version) or `nil` (sync 3187 version) 3188 - `err`: `nil` or `string` 3189 - `success`: `boolean` or `nil` 3190 3191 Equivalent to `fdatasync(2)`. 3192 3193 Returns (sync version): `boolean` or `fail` 3194 3195 Returns (async version): `uv_fs_t userdata` 3196 3197 uv.fs_ftruncate({fd}, {offset} [, {callback}]) *uv.fs_ftruncate()* 3198 3199 Parameters: 3200 - `fd`: `integer` 3201 - `offset`: `integer` 3202 - `callback`: `callable` (async version) or `nil` (sync 3203 version) 3204 - `err`: `nil` or `string` 3205 - `success`: `boolean` or `nil` 3206 3207 Equivalent to `ftruncate(2)`. 3208 3209 Returns (sync version): `boolean` or `fail` 3210 3211 Returns (async version): `uv_fs_t userdata` 3212 3213 *uv.fs_sendfile()* 3214 uv.fs_sendfile({out_fd}, {in_fd}, {in_offset}, {size} [, {callback}]) 3215 3216 Parameters: 3217 - `out_fd`: `integer` 3218 - `in_fd`: `integer` 3219 - `in_offset`: `integer` 3220 - `size`: `integer` 3221 - `callback`: `callable` (async version) or `nil` (sync 3222 version) 3223 - `err`: `nil` or `string` 3224 - `bytes`: `integer` or `nil` 3225 3226 Limited equivalent to `sendfile(2)`. Returns the number of 3227 bytes written. 3228 3229 Returns (sync version): `integer` or `fail` 3230 3231 Returns (async version): `uv_fs_t userdata` 3232 3233 uv.fs_access({path}, {mode} [, {callback}]) *uv.fs_access()* 3234 3235 Parameters: 3236 - `path`: `string` 3237 - `mode`: `integer` `string` (a combination of the `'r'`, 3238 `'w'` and `'x'` characters denoting the symbolic mode as per 3239 `chmod(1)`) 3240 - `callback`: `callable` (async version) or `nil` (sync 3241 version) 3242 - `err`: `nil` or `string` 3243 - `permission`: `boolean` or `nil` 3244 3245 Equivalent to `access(2)` on Unix. Windows uses 3246 `GetFileAttributesW()`. Access `mode` can be an integer or a 3247 string containing `"R"` or `"W"` or `"X"`. Returns `true` or 3248 `false` indicating access permission. 3249 3250 Returns (sync version): `boolean` or `fail` 3251 3252 Returns (async version): `uv_fs_t userdata` 3253 3254 uv.fs_chmod({path}, {mode} [, {callback}]) *uv.fs_chmod()* 3255 3256 Parameters: 3257 - `path`: `string` 3258 - `mode`: `integer` (octal representation of `chmod(1)` mode, 3259 e.g. `tonumber('644', 8)`) 3260 - `callback`: `callable` (async version) or `nil` (sync 3261 version) 3262 - `err`: `nil` or `string` 3263 - `success`: `boolean` or `nil` 3264 3265 Equivalent to `chmod(2)`. 3266 3267 Returns (sync version): `boolean` or `fail` 3268 3269 Returns (async version): `uv_fs_t userdata` 3270 3271 uv.fs_fchmod({fd}, {mode} [, {callback}]) *uv.fs_fchmod()* 3272 3273 Parameters: 3274 - `fd`: `integer` 3275 - `mode`: `integer` 3276 - `callback`: `callable` (async version) or `nil` (sync 3277 version) 3278 - `err`: `nil` or `string` 3279 - `success`: `boolean` or `nil` 3280 3281 Equivalent to `fchmod(2)`. 3282 3283 Returns (sync version): `boolean` or `fail` 3284 3285 Returns (async version): `uv_fs_t userdata` 3286 3287 uv.fs_utime({path} [, {atime}, {mtime}, {callback}]) *uv.fs_utime()* 3288 3289 Parameters: 3290 - `path`: `string` 3291 - `atime`: `number` or `string` or `nil` 3292 - `mtime`: `number` or `string` or `nil` 3293 - `callback`: `callable` (async version) or `nil` (sync 3294 version) 3295 - `err`: `nil` or `string` 3296 - `success`: `boolean` or `nil` 3297 3298 Equivalent to `utime(2)`. 3299 3300 See |luv-constants| for supported FS Modification Time 3301 constants. 3302 3303 Passing `"now"` or `uv.constants.FS_UTIME_NOW` as the atime or 3304 mtime sets the timestamp to the current time. 3305 3306 Passing `nil`, `"omit"`, or `uv.constants.FS_UTIME_OMIT` as 3307 the atime or mtime leaves the timestamp untouched. 3308 3309 Returns (sync version): `boolean` or `fail` 3310 3311 Returns (async version): `uv_fs_t userdata` 3312 3313 uv.fs_futime({fd} [, {atime}, {mtime}, {callback}]) *uv.fs_futime()* 3314 3315 Parameters: 3316 - `fd`: `integer` 3317 - `atime`: `number` or `string` or `nil` 3318 - `mtime`: `number` or `string` or `nil` 3319 - `callback`: `callable` (async version) or `nil` (sync 3320 version) 3321 - `err`: `nil` or `string` 3322 - `success`: `boolean` or `nil` 3323 3324 Equivalent to `futimes(3)`. 3325 3326 See |luv-constants| for supported FS Modification Time 3327 constants. 3328 3329 Passing `"now"` or `uv.constants.FS_UTIME_NOW` as the atime or 3330 mtime sets the timestamp to the current time. 3331 3332 Passing `nil`, `"omit"`, or `uv.constants.FS_UTIME_OMIT` as 3333 the atime or mtime leaves the timestamp untouched. 3334 3335 Returns (sync version): `boolean` or `fail` 3336 3337 Returns (async version): `uv_fs_t userdata` 3338 3339 uv.fs_lutime({path} [, {atime}, {mtime}, {callback}]) *uv.fs_lutime()* 3340 3341 Parameters: 3342 - `path`: `string` 3343 - `atime`: `number` or `string` or `nil` 3344 - `mtime`: `number` or `string` or `nil` 3345 - `callback`: `callable` (async version) or `nil` (sync 3346 version) 3347 - `err`: `nil` or `string` 3348 - `success`: `boolean` or `nil` 3349 3350 Equivalent to `lutimes(3)`. 3351 3352 See |luv-constants| for supported FS Modification Time 3353 constants. 3354 3355 Passing `"now"` or `uv.constants.FS_UTIME_NOW` as the atime or 3356 mtime sets the timestamp to the current time. 3357 3358 Passing `nil`, `"omit"`, or `uv.constants.FS_UTIME_OMIT` as 3359 the atime or mtime leaves the timestamp untouched. 3360 3361 Returns (sync version): `boolean` or `fail` 3362 3363 Returns (async version): `uv_fs_t userdata` 3364 3365 uv.fs_link({path}, {new_path} [, {callback}]) *uv.fs_link()* 3366 3367 Parameters: 3368 - `path`: `string` 3369 - `new_path`: `string` 3370 - `callback`: `callable` (async version) or `nil` (sync 3371 version) 3372 - `err`: `nil` or `string` 3373 - `success`: `boolean` or `nil` 3374 3375 Equivalent to `link(2)`. 3376 3377 Returns (sync version): `boolean` or `fail` 3378 3379 Returns (async version): `uv_fs_t userdata` 3380 3381 uv.fs_symlink({path}, {new_path} [, {flags} [, {callback}]]) *uv.fs_symlink()* 3382 3383 Parameters: 3384 - `path`: `string` 3385 - `new_path`: `string` 3386 - `flags`: `table`, `integer`, or `nil` 3387 - `dir`: `boolean` 3388 - `junction`: `boolean` 3389 - `callback`: `callable` (async version) or `nil` (sync 3390 version) 3391 - `err`: `nil` or `string` 3392 - `success`: `boolean` or `nil` 3393 3394 Equivalent to `symlink(2)`. If the `flags` parameter is 3395 omitted, then the 3rd parameter will be treated as the 3396 `callback`. 3397 3398 Returns (sync version): `boolean` or `fail` 3399 3400 Returns (async version): `uv_fs_t userdata` 3401 3402 uv.fs_readlink({path} [, {callback}]) *uv.fs_readlink()* 3403 3404 Parameters: 3405 - `path`: `string` 3406 - `callback`: `callable` (async version) or `nil` (sync 3407 version) 3408 - `err`: `nil` or `string` 3409 - `path`: `string` or `nil` 3410 3411 Equivalent to `readlink(2)`. 3412 3413 Returns (sync version): `string` or `fail` 3414 3415 Returns (async version): `uv_fs_t userdata` 3416 3417 uv.fs_realpath({path} [, {callback}]) *uv.fs_realpath()* 3418 3419 Parameters: 3420 - `path`: `string` 3421 - `callback`: `callable` (async version) or `nil` (sync 3422 version) 3423 - `err`: `nil` or `string` 3424 - `path`: `string` or `nil` 3425 3426 Equivalent to `realpath(3)`. 3427 3428 Returns (sync version): `string` or `fail` 3429 3430 Returns (async version): `uv_fs_t userdata` 3431 3432 uv.fs_chown({path}, {uid}, {gid} [, {callback}]) *uv.fs_chown()* 3433 3434 Parameters: 3435 - `path`: `string` 3436 - `uid`: `integer` 3437 - `gid`: `integer` 3438 - `callback`: `callable` (async version) or `nil` (sync 3439 version) 3440 - `err`: `nil` or `string` 3441 - `success`: `boolean` or `nil` 3442 3443 Equivalent to `chown(2)`. 3444 3445 Returns (sync version): `boolean` or `fail` 3446 3447 Returns (async version): `uv_fs_t userdata` 3448 3449 uv.fs_fchown({fd}, {uid}, {gid} [, {callback}]) *uv.fs_fchown()* 3450 3451 Parameters: 3452 - `fd`: `integer` 3453 - `uid`: `integer` 3454 - `gid`: `integer` 3455 - `callback`: `callable` (async version) or `nil` (sync 3456 version) 3457 - `err`: `nil` or `string` 3458 - `success`: `boolean` or `nil` 3459 3460 Equivalent to `fchown(2)`. 3461 3462 Returns (sync version): `boolean` or `fail` 3463 3464 Returns (async version): `uv_fs_t userdata` 3465 3466 uv.fs_lchown({fd}, {uid}, {gid} [, {callback}]) *uv.fs_lchown()* 3467 3468 Parameters: 3469 - `fd`: `integer` 3470 - `uid`: `integer` 3471 - `gid`: `integer` 3472 - `callback`: `callable` (async version) or `nil` (sync 3473 version) 3474 - `err`: `nil` or `string` 3475 - `success`: `boolean` or `nil` 3476 3477 Equivalent to `lchown(2)`. 3478 3479 Returns (sync version): `boolean` or `fail` 3480 3481 Returns (async version): `uv_fs_t userdata` 3482 3483 uv.fs_copyfile({path}, {new_path} [, {flags} [, {callback}]]) *uv.fs_copyfile()* 3484 3485 Parameters: 3486 - `path`: `string` 3487 - `new_path`: `string` 3488 - `flags`: `table`, `integer`, or `nil` 3489 - `excl`: `boolean` 3490 - `ficlone`: `boolean` 3491 - `ficlone_force`: `boolean` 3492 - `callback`: `callable` (async version) or `nil` (sync 3493 version) 3494 - `err`: `nil` or `string` 3495 - `success`: `boolean` or `nil` 3496 3497 Copies a file from path to new_path. If the `flags` parameter 3498 is omitted, then the 3rd parameter will be treated as the 3499 `callback`. 3500 3501 Returns (sync version): `boolean` or `fail` 3502 3503 Returns (async version): `uv_fs_t userdata` 3504 3505 uv.fs_opendir({path} [, {callback} [, {entries}]]) *uv.fs_opendir()* 3506 3507 Parameters: 3508 - `path`: `string` 3509 - `callback`: `callable` (async version) or `nil` (sync 3510 version) 3511 - `err`: `nil` or `string` 3512 - `dir`: `luv_dir_t userdata` or `nil` 3513 - `entries`: `integer` or `nil` 3514 3515 Opens path as a directory stream. Returns a handle that the 3516 user can pass to |uv.fs_readdir()|. The `entries` parameter 3517 defines the maximum number of entries that should be returned 3518 by each call to |uv.fs_readdir()|. 3519 3520 Returns (sync version): `luv_dir_t userdata` or `fail` 3521 3522 Returns (async version): `uv_fs_t userdata` 3523 3524 uv.fs_readdir({dir} [, {callback}]) *uv.fs_readdir()* 3525 3526 > method form `dir:readdir([callback])` 3527 3528 Parameters: 3529 - `dir`: `luv_dir_t userdata` 3530 - `callback`: `callable` (async version) or `nil` (sync 3531 version) 3532 - `err`: `nil` or `string` 3533 - `entries`: `table` or `nil` (see below) 3534 3535 Iterates over the directory stream `luv_dir_t` returned by a 3536 successful |uv.fs_opendir()| call. A table of data tables is 3537 returned where the number of entries `n` is equal to or less 3538 than the `entries` parameter used in the associated 3539 |uv.fs_opendir()| call. 3540 3541 Returns (sync version): `table` or `fail` 3542 - `[1, 2, 3, ..., n]` : `table` 3543 - `name` : `string` 3544 - `type` : `string` 3545 3546 Returns (async version): `uv_fs_t userdata` 3547 3548 uv.fs_closedir({dir} [, {callback}]) *uv.fs_closedir()* 3549 3550 > method form `dir:closedir([callback])` 3551 3552 Parameters: 3553 - `dir`: `luv_dir_t userdata` 3554 - `callback`: `callable` (async version) or `nil` (sync 3555 version) 3556 - `err`: `nil` or `string` 3557 - `success`: `boolean` or `nil` 3558 3559 Closes a directory stream returned by a successful 3560 |uv.fs_opendir()| call. 3561 3562 Returns (sync version): `boolean` or `fail` 3563 3564 Returns (async version): `uv_fs_t userdata` 3565 3566 uv.fs_statfs({path} [, {callback}]) *uv.fs_statfs()* 3567 3568 Parameters: 3569 - `path`: `string` 3570 - `callback`: `callable` (async version) or `nil` (sync 3571 version) 3572 - `err`: `nil` or `string` 3573 - `table` or `nil` (see below) 3574 3575 Equivalent to `statfs(2)`. 3576 3577 Returns `table` or `nil` 3578 - `type` : `integer` 3579 - `bsize` : `integer` 3580 - `blocks` : `integer` 3581 - `bfree` : `integer` 3582 - `bavail` : `integer` 3583 - `files` : `integer` 3584 - `ffree` : `integer` 3585 3586 ============================================================================== 3587 THREAD POOL WORK SCHEDULING *luv-thread-pool-work-scheduling* 3588 3589 Libuv provides a threadpool which can be used to run user code and get 3590 notified in the loop thread. This threadpool is internally used to run all 3591 file system operations, as well as `getaddrinfo` and `getnameinfo` requests. 3592 3593 >lua 3594 local function work_callback(a, b) 3595 return a + b 3596 end 3597 3598 local function after_work_callback(c) 3599 print("The result is: " .. c) 3600 end 3601 3602 local work = uv.new_work(work_callback, after_work_callback) 3603 3604 work:queue(1, 2) 3605 3606 -- output: "The result is: 3" 3607 < 3608 3609 uv.new_work({work_callback}, {after_work_callback}) *uv.new_work()* 3610 3611 Parameters: 3612 - `work_callback`: `function` or `string` 3613 - `...`: `threadargs` passed to/from 3614 `uv.queue_work(work_ctx, ...)` 3615 - `after_work_callback`: `function` 3616 - `...`: `threadargs` returned from `work_callback` 3617 3618 Creates and initializes a new `luv_work_ctx_t` (not 3619 `uv_work_t`). 3620 `work_callback` is a Lua function or a string containing Lua 3621 code or bytecode dumped from a function. Returns the Lua 3622 userdata wrapping it. 3623 3624 Returns: `luv_work_ctx_t userdata` 3625 3626 uv.queue_work({work_ctx}, {...}) *uv.queue_work()* 3627 3628 > method form `work_ctx:queue(...)` 3629 3630 Parameters: 3631 - `work_ctx`: `luv_work_ctx_t userdata` 3632 - `...`: `threadargs` 3633 3634 Queues a work request which will run `work_callback` in a new 3635 Lua state in a thread from the threadpool with any additional 3636 arguments from `...`. Values returned from `work_callback` are 3637 passed to `after_work_callback`, which is called in the main 3638 loop thread. 3639 3640 Returns: `boolean` or `fail` 3641 3642 ============================================================================== 3643 DNS UTILITY FUNCTIONS *luv-dns-utility-functions* 3644 3645 uv.getaddrinfo({host}, {service} [, {hints} [, {callback}]]) *uv.getaddrinfo()* 3646 3647 Parameters: 3648 - `host`: `string` or `nil` 3649 - `service`: `string` or `nil` 3650 - `hints`: `table` or `nil` 3651 - `family`: `string` or `integer` or `nil` 3652 - `socktype`: `string` or `integer` or `nil` 3653 - `protocol`: `string` or `integer` or `nil` 3654 - `addrconfig`: `boolean` or `nil` 3655 - `v4mapped`: `boolean` or `nil` 3656 - `all`: `boolean` or `nil` 3657 - `numerichost`: `boolean` or `nil` 3658 - `passive`: `boolean` or `nil` 3659 - `numericserv`: `boolean` or `nil` 3660 - `canonname`: `boolean` or `nil` 3661 - `callback`: `callable` (async version) or `nil` (sync 3662 version) 3663 - `err`: `nil` or `string` 3664 - `addresses`: `table` or `nil` (see below) 3665 3666 Equivalent to `getaddrinfo(3)`. Either `node` or `service` may 3667 be `nil` but not both. 3668 3669 See |luv-constants| for supported address `family` input and 3670 output values. 3671 3672 See |luv-constants| for supported `socktype` input and 3673 output values. 3674 3675 When `protocol` is set to `0` or `nil`, it will be 3676 automatically chosen based on the socket's domain and type. 3677 When `protocol` is specified as a string, it will be looked up 3678 using the `getprotobyname(3)` function. Examples: `"ip"`, 3679 `"icmp"`, `"tcp"`, `"udp"`, etc. 3680 3681 Returns (sync version): `table` or `fail` 3682 - `[1, 2, 3, ..., n]` : `table` 3683 - `addr` : `string` 3684 - `family` : `string` 3685 - `port` : `integer` or `nil` 3686 - `socktype` : `string` 3687 - `protocol` : `string` 3688 - `canonname` : `string` or `nil` 3689 3690 Returns (async version): `uv_getaddrinfo_t userdata` or `fail` 3691 3692 uv.getnameinfo({address} [, {callback}]) *uv.getnameinfo()* 3693 3694 Parameters: 3695 - `address`: `table` 3696 - `ip`: `string` or `nil` 3697 - `port`: `integer` or `nil` 3698 - `family`: `string` or `integer` or `nil` 3699 - `callback`: `callable` (async version) or `nil` (sync 3700 version) 3701 - `err`: `nil` or `string` 3702 - `host`: `string` or `nil` 3703 - `service`: `string` or `nil` 3704 3705 Equivalent to `getnameinfo(3)`. 3706 3707 See |luv-constants| for supported address `family` input values. 3708 3709 Returns (sync version): `string, string` or `fail` 3710 3711 Returns (async version): `uv_getnameinfo_t userdata` or `fail` 3712 3713 ============================================================================== 3714 THREADING AND SYNCHRONIZATION UTILITIES *luv-threading-and-synchronization-utilities* 3715 3716 Libuv provides cross-platform implementations for multiple threading and 3717 synchronization primitives. The API largely follows the pthreads API. 3718 3719 uv.new_thread([{options}, ] {entry}, {...}) *uv.new_thread()* 3720 3721 Parameters: 3722 - `options`: `table` or `nil` 3723 - `stack_size`: `integer` or `nil` 3724 - `entry`: `function` or `string` 3725 - `...`: `threadargs` passed to `entry` 3726 3727 Creates and initializes a `luv_thread_t` (not `uv_thread_t`). 3728 Returns the Lua userdata wrapping it and asynchronously 3729 executes `entry`, which can be either a Lua function or a 3730 string containing Lua code or bytecode dumped from a function. 3731 Additional arguments `...` are passed to the `entry` function 3732 and an optional `options` table may be provided. Currently 3733 accepted `option` fields are `stack_size`. 3734 3735 Returns: `luv_thread_t userdata` or `fail` 3736 3737 Note: unsafe, please make sure that the thread's end of life 3738 is before Lua state is closed. 3739 3740 uv.thread_equal({thread}, {other_thread}) *uv.thread_equal()* 3741 3742 > method form `thread:equal(other_thread)` 3743 3744 Parameters: 3745 - `thread`: `luv_thread_t userdata` 3746 - `other_thread`: `luv_thread_t userdata` 3747 3748 Returns a boolean indicating whether two threads are the same. 3749 This function is equivalent to the `__eq` metamethod. 3750 3751 Returns: `boolean` 3752 *uv.thread_setaffinity()* 3753 uv.thread_setaffinity({thread}, {affinity} [, {get_old_affinity}]) 3754 3755 > method form `thread:setaffinity(affinity, [get_old_affinity])` 3756 3757 Parameters: 3758 - `thread`: `luv_thread_t userdata` 3759 - `affinity`: `table` 3760 - `[1, 2, 3, ..., n]` : `boolean` 3761 - `get_old_affinity`: `boolean` 3762 3763 Sets the specified thread's affinity setting. 3764 3765 `affinity` must be a table where each of the keys are a CPU 3766 number and the values are booleans that represent whether the 3767 `thread` should be eligible to run on that CPU. If the length 3768 of the `affinity` table is not greater than or equal to 3769 |uv.cpumask_size()|, any CPU numbers missing from the table 3770 will have their affinity set to `false`. If setting the 3771 affinity of more than |uv.cpumask_size()| CPUs is desired, 3772 `affinity` must be an array-like table with no gaps, since 3773 `#affinity` will be used as the `cpumask_size` if it is 3774 greater than |uv.cpumask_size()|. 3775 3776 If `get_old_affinity` is `true`, the previous affinity 3777 settings for the `thread` will be returned. Otherwise, `true` 3778 is returned after a successful call. 3779 3780 Note: Thread affinity setting is not atomic on Windows. 3781 Unsupported on macOS. 3782 3783 Returns: `table` or `boolean` or `fail` 3784 - `[1, 2, 3, ..., n]` : `boolean` 3785 3786 3787 uv.thread_getaffinity({thread} [, {mask_size}]) *uv.thread_getaffinity()* 3788 3789 > method form `thread:getaffinity([mask_size])` 3790 3791 Parameters: 3792 - `thread`: `luv_thread_t userdata` 3793 - `mask_size`: `integer` 3794 3795 Gets the specified thread's affinity setting. 3796 3797 If `mask_size` is provided, it must be greater than or equal 3798 to `uv.cpumask_size()`. If the `mask_size` parameter is 3799 omitted, then the return of `uv.cpumask_size()` will be used. 3800 Returns an array-like table where each of the keys correspond 3801 to a CPU number and the values are booleans that represent 3802 whether the `thread` is eligible to run on that CPU. 3803 3804 Note: Thread affinity getting is not atomic on Windows. 3805 Unsupported on macOS. 3806 3807 Returns: `table` or `fail` 3808 - `[1, 2, 3, ..., n]` : `boolean` 3809 3810 uv.thread_getcpu() *uv.thread_getcpu()* 3811 3812 Gets the CPU number on which the calling thread is running. 3813 3814 Note: The first CPU will be returned as the number 1, not 0. 3815 This allows for the number to correspond with the table keys 3816 used in `uv.thread_getaffinity` and `uv.thread_setaffinity`. 3817 3818 Returns: `integer` or `fail` 3819 3820 uv.thread_setpriority({thread}, {priority}) *uv.thread.setpriority()* 3821 3822 > method form `thread:setpriority(priority)` 3823 3824 Parameters: 3825 - `thread`: `luv_thread_t userdata` 3826 - `priority`: `number` 3827 3828 Sets the specified thread's scheduling priority setting. It 3829 requires elevated privilege to set specific priorities on some 3830 platforms. The priority can be set to the following constants: 3831 - `uv.constants.THREAD_PRIORITY_HIGHEST` 3832 - `uv.constants.THREAD_PRIORITY_ABOVE_NORMAL` 3833 - `uv.constants.THREAD_PRIORITY_NORMAL` 3834 - `uv.constants.THREAD_PRIORITY_BELOW_NORMAL` 3835 - `uv.constants.THREAD_PRIORITY_LOWEST` 3836 3837 Returns: `boolean` or `fail` 3838 3839 uv.thread_getpriority({thread}) *uv.thread.getpriority()* 3840 3841 > method form `thread:getpriority()` 3842 3843 Parameters: 3844 - `thread`: `luv_thread_t userdata` 3845 3846 Gets the thread's priority setting. 3847 3848 Retrieves the scheduling priority of the specified thread. The 3849 returned priority value is platform dependent. 3850 3851 For Linux, when schedule policy is SCHED_OTHER (default), 3852 priority is 0. 3853 3854 Returns: `number` or `fail` 3855 3856 uv.thread_self() *uv.thread_self()* 3857 3858 Returns the handle for the thread in which this is called. 3859 3860 Returns: `luv_thread_t` 3861 3862 uv.thread_join({thread}) *uv.thread_join()* 3863 3864 > method form `thread:join()` 3865 3866 Parameters: 3867 - `thread`: `luv_thread_t userdata` 3868 3869 Waits for the `thread` to finish executing its entry function. 3870 3871 Returns: `boolean` or `fail` 3872 3873 uv.thread_detach({thread}) *uv.thread_detach()* 3874 3875 > method form `thread:detach()` 3876 3877 Parameters: 3878 - `thread`: `luv_thread_t userdata` 3879 3880 Detaches a thread. Detached threads automatically release 3881 their resources upon termination, eliminating the need for the 3882 application to call `uv.thread_join`. 3883 3884 Returns: `boolean` or `fail` 3885 3886 uv.thread_setname({name}) *uv.thread_setname()* 3887 3888 Parameters: 3889 - `name`: `string` 3890 3891 Sets the name of the current thread. Different platforms 3892 define different limits on the max number of characters a 3893 thread name can be: Linux, IBM i (16), macOS (64), Windows 3894 (32767), and NetBSD (32), etc. The name will be truncated if 3895 `name` is larger than the limit of the platform. 3896 3897 Returns: `0` or `fail` 3898 3899 uv.thread_getname({thread}) *uv.thread_getname()* 3900 3901 > method form `thread:getname()` 3902 3903 Parameters: 3904 - `thread`: `luv_thread_t userdata` 3905 3906 Gets the name of the thread specified by `thread`. 3907 3908 Returns: `string` or `fail` 3909 3910 uv.sleep({msec}) *uv.sleep()* 3911 3912 Parameters: 3913 - `msec`: `integer` 3914 3915 Pauses the thread in which this is called for a number of 3916 milliseconds. 3917 3918 Returns: Nothing. 3919 3920 uv.new_sem([{value}]) *uv.new_sem()* 3921 3922 Parameters: 3923 - `value`: `integer` or `nil` 3924 3925 Creates a new semaphore with the specified initial value. A 3926 semaphore is safe to share across threads. It represents an 3927 unsigned integer value that can incremented and decremented 3928 atomically but any attempt to make it negative will "wait" 3929 until the value can be decremented by another thread 3930 incrementing it. 3931 3932 The initial value must be a non-negative integer. 3933 3934 Returns: `luv_sem_t userdata` or `fail` 3935 3936 Note: A semaphore must be shared between threads, any 3937 `uv.sem_wait()` on a single thread that blocks will deadlock. 3938 3939 uv.sem_post({sem}) *uv.sem_post()* 3940 3941 > method form `sem:post()` 3942 3943 Parameters: 3944 - `sem`: `luv_sem_t userdata` 3945 3946 Increments (unlocks) a semaphore, if the semaphore's value 3947 consequently becomes greater than zero then another thread 3948 blocked in a sem_wait call will be woken and proceed to 3949 decrement the semaphore. 3950 3951 Returns: Nothing. 3952 3953 uv.sem_wait({sem}) *uv.sem_wait()* 3954 3955 > method form `sem:wait()` 3956 3957 Parameters: 3958 - `sem`: `luv_sem_t userdata` 3959 3960 Decrements (locks) a semaphore, if the semaphore's value is 3961 greater than zero then the value is decremented and the call 3962 returns immediately. If the semaphore's value is zero then the 3963 call blocks until the semaphore's value rises above zero or 3964 the call is interrupted by a signal. 3965 3966 Returns: Nothing. 3967 3968 uv.sem_trywait({sem}) *uv.sem_trywait()* 3969 3970 > method form `sem:trywait()` 3971 3972 Parameters: 3973 - `sem`: `luv_sem_t userdata` 3974 3975 The same as `uv.sem_wait()` but returns immediately if the 3976 semaphore is not available. 3977 3978 If the semaphore's value was decremented then `true` is 3979 returned, otherwise the semaphore has a value of zero and 3980 `false` is returned. 3981 3982 Returns: `boolean` 3983 3984 ============================================================================== 3985 MISCELLANEOUS UTILITIES *luv-miscellaneous-utilities* 3986 3987 uv.exepath() *uv.exepath()* 3988 3989 Returns the executable path. 3990 3991 Returns: `string` or `fail` 3992 3993 uv.cwd() *uv.cwd()* 3994 3995 Returns the current working directory. 3996 3997 Returns: `string` or `fail` 3998 3999 uv.chdir({cwd}) *uv.chdir()* 4000 4001 Parameters: 4002 - `cwd`: `string` 4003 4004 Sets the current working directory with the string `cwd`. 4005 4006 Returns: `0` or `fail` 4007 4008 uv.get_process_title() *uv.get_process_title()* 4009 4010 Returns the title of the current process. 4011 4012 Returns: `string` or `fail` 4013 4014 uv.set_process_title({title}) *uv.set_process_title()* 4015 4016 Parameters: 4017 - `title`: `string` 4018 4019 Sets the title of the current process with the string `title`. 4020 4021 Returns: `0` or `fail` 4022 4023 uv.get_total_memory() *uv.get_total_memory()* 4024 4025 Returns the current total system memory in bytes. 4026 4027 Returns: `number` 4028 4029 uv.get_free_memory() *uv.get_free_memory()* 4030 4031 Returns the current free system memory in bytes. 4032 4033 Returns: `number` 4034 4035 uv.get_constrained_memory() *uv.get_constrained_memory()* 4036 4037 Gets the amount of memory available to the process in bytes 4038 based on limits imposed by the OS. If there is no such 4039 constraint, or the constraint is unknown, 0 is returned. Note 4040 that it is not unusual for this value to be less than or 4041 greater than the total system memory. 4042 4043 Returns: `number` 4044 4045 uv.get_available_memory() *uv.get_available_memory()* 4046 4047 Gets the amount of free memory that is still available to the 4048 process (in bytes). This differs from `uv.get_free_memory()` 4049 in that it takes into account any limits imposed by the OS. If 4050 there is no such constraint, or the constraint is unknown, the 4051 amount returned will be identical to `uv.get_free_memory()`. 4052 4053 Returns: `number` 4054 4055 uv.resident_set_memory() *uv.resident_set_memory()* 4056 4057 Returns the resident set size (RSS) for the current process. 4058 4059 Returns: `integer` or `fail` 4060 4061 uv.getrusage() *uv.getrusage()* 4062 4063 Returns the resource usage. 4064 4065 Returns: `table` or `fail` 4066 - `utime` : `table` (user CPU time used) 4067 - `sec` : `integer` 4068 - `usec` : `integer` 4069 - `stime` : `table` (system CPU time used) 4070 - `sec` : `integer` 4071 - `usec` : `integer` 4072 - `maxrss` : `integer` (maximum resident set size) 4073 - `ixrss` : `integer` (integral shared memory size) 4074 - `idrss` : `integer` (integral unshared data size) 4075 - `isrss` : `integer` (integral unshared stack size) 4076 - `minflt` : `integer` (page reclaims (soft page faults)) 4077 - `majflt` : `integer` (page faults (hard page faults)) 4078 - `nswap` : `integer` (swaps) 4079 - `inblock` : `integer` (block input operations) 4080 - `oublock` : `integer` (block output operations) 4081 - `msgsnd` : `integer` (IPC messages sent) 4082 - `msgrcv` : `integer` (IPC messages received) 4083 - `nsignals` : `integer` (signals received) 4084 - `nvcsw` : `integer` (voluntary context switches) 4085 - `nivcsw` : `integer` (involuntary context switches) 4086 4087 uv.getrusage_thread() *uv.getrusage_thread()* 4088 Gets the resource usage measures for the calling thread. 4089 4090 Note: Not supported on all platforms. May return `ENOTSUP`. 4091 4092 On macOS and Windows not all fields are set (the unsupported 4093 fields are filled with zeroes). 4094 4095 Returns: `table` or `fail` 4096 - `utime` : `table` (user CPU time used) 4097 - `sec` : `integer` 4098 - `usec` : `integer` 4099 - `stime` : `table` (system CPU time used) 4100 - `sec` : `integer` 4101 - `usec` : `integer` 4102 - `maxrss` : `integer` (maximum resident set size) 4103 - `ixrss` : `integer` (integral shared memory size) 4104 - `idrss` : `integer` (integral unshared data size) 4105 - `isrss` : `integer` (integral unshared stack size) 4106 - `minflt` : `integer` (page reclaims (soft page faults)) 4107 - `majflt` : `integer` (page faults (hard page faults)) 4108 - `nswap` : `integer` (swaps) 4109 - `inblock` : `integer` (block input operations) 4110 - `oublock` : `integer` (block output operations) 4111 - `msgsnd` : `integer` (IPC messages sent) 4112 - `msgrcv` : `integer` (IPC messages received) 4113 - `nsignals` : `integer` (signals received) 4114 - `nvcsw` : `integer` (voluntary context switches) 4115 - `nivcsw` : `integer` (involuntary context switches) 4116 4117 uv.available_parallelism() *uv.available_parallelism()* 4118 4119 Returns an estimate of the default amount of parallelism a 4120 program should use. Always returns a non-zero value. 4121 4122 On Linux, inspects the calling thread’s CPU affinity mask to 4123 determine if it has been pinned to specific CPUs. 4124 4125 On Windows, the available parallelism may be underreported on 4126 systems with more than 64 logical CPUs. 4127 4128 On other platforms, reports the number of CPUs that the 4129 operating system considers to be online. 4130 4131 Returns: `integer` 4132 4133 uv.cpu_info() *uv.cpu_info()* 4134 4135 Returns information about the CPU(s) on the system as a table 4136 of tables for each CPU found. 4137 4138 Returns: `table` or `fail` 4139 - `[1, 2, 3, ..., n]` : `table` 4140 - `model` : `string` 4141 - `speed` : `number` 4142 - `times` : `table` 4143 - `user` : `number` 4144 - `nice` : `number` 4145 - `sys` : `number` 4146 - `idle` : `number` 4147 - `irq` : `number` 4148 4149 uv.cpumask_size() *uv.cpumask_size()* 4150 4151 Returns the maximum size of the mask used for process/thread 4152 affinities, or `ENOTSUP` if affinities are not supported on 4153 the current platform. 4154 4155 Returns: `integer` or `fail` 4156 4157 uv.getpid() *uv.getpid()* 4158 4159 DEPRECATED: Please use |uv.os_getpid()| instead. 4160 4161 uv.getuid() *uv.getuid()* 4162 4163 Returns the user ID of the process. 4164 4165 Returns: `integer` 4166 4167 Note: This is not a libuv function and is not supported on 4168 Windows. 4169 4170 uv.getgid() *uv.getgid()* 4171 4172 Returns the group ID of the process. 4173 4174 Returns: `integer` 4175 4176 Note: This is not a libuv function and is not supported on 4177 Windows. 4178 4179 uv.setuid({id}) *uv.setuid()* 4180 4181 Parameters: 4182 - `id`: `integer` 4183 4184 Sets the user ID of the process with the integer `id`. 4185 4186 Returns: Nothing. 4187 4188 Note: This is not a libuv function and is not supported on 4189 Windows. 4190 4191 uv.setgid({id}) *uv.setgid()* 4192 4193 Parameters: 4194 - `id`: `integer` 4195 4196 Sets the group ID of the process with the integer `id`. 4197 4198 Returns: Nothing. 4199 4200 Note: This is not a libuv function and is not supported on 4201 Windows. 4202 4203 uv.hrtime() *uv.hrtime()* 4204 4205 Returns a current high-resolution time in nanoseconds as a 4206 number. This is relative to an arbitrary time in the past. It 4207 is not related to the time of day and therefore not subject to 4208 clock drift. The primary use is for measuring time between 4209 intervals. 4210 4211 Returns: `integer` 4212 4213 uv.clock_gettime({clock_id}) *uv.clock_gettime()* 4214 4215 Parameters: 4216 - `clock_id`: `string` 4217 4218 Obtain the current system time from a high-resolution 4219 real-time or monotonic clock source. `clock_id` can be the 4220 string `"monotonic"` or `"realtime"`. 4221 4222 The real-time clock counts from the UNIX epoch (1970-01-01) 4223 and is subject to time adjustments; it can jump back in time. 4224 4225 The monotonic clock counts from an arbitrary point in the past 4226 and never jumps back in time. 4227 4228 Returns: `table` or `fail` 4229 - `sec`: `integer` 4230 - `nsec`: `integer` 4231 4232 uv.uptime() *uv.uptime()* 4233 4234 Returns the current system uptime in seconds. 4235 4236 Returns: `number` or `fail` 4237 4238 uv.print_all_handles() *uv.print_all_handles()* 4239 4240 Prints all handles associated with the main loop to stderr. 4241 The format is `[flags] handle-type handle-address` . Flags are 4242 `R` for referenced, `A` for active and `I` for internal. 4243 4244 Returns: Nothing. 4245 4246 Note: This is not available on Windows. 4247 4248 WARNING: This function is meant for ad hoc debugging, there 4249 are no API/ABI stability guarantees. 4250 4251 uv.print_active_handles() *uv.print_active_handles()* 4252 4253 The same as |uv.print_all_handles()| except only active 4254 handles are printed. 4255 4256 Returns: Nothing. 4257 4258 Note: This is not available on Windows. 4259 4260 WARNING: This function is meant for ad hoc debugging, there 4261 are no API/ABI stability guarantees. 4262 4263 uv.guess_handle({fd}) *uv.guess_handle()* 4264 4265 Parameters: 4266 - `fd`: `integer` 4267 4268 Used to detect what type of stream should be used with a given 4269 file descriptor `fd`. Usually this will be used during 4270 initialization to guess the type of the stdio streams. 4271 4272 Returns: `string` 4273 4274 uv.gettimeofday() *uv.gettimeofday()* 4275 4276 Cross-platform implementation of `gettimeofday(2)`. Returns 4277 the seconds and microseconds of a unix time as a pair. 4278 4279 Returns: `integer, integer` or `fail` 4280 4281 uv.interface_addresses() *uv.interface_addresses()* 4282 4283 Returns address information about the network interfaces on 4284 the system in a table. Each table key is the name of the 4285 interface while each associated value is an array of address 4286 information where fields are `ip`, `family`, `netmask`, 4287 `internal`, and `mac`. 4288 4289 See |luv-constants| for supported address `family` output values. 4290 4291 Returns: `table` 4292 - `[name(s)]` : `table` 4293 - `ip` : `string` 4294 - `family` : `string` 4295 - `netmask` : `string` 4296 - `internal` : `boolean` 4297 - `mac` : `string` 4298 4299 uv.if_indextoname({ifindex}) *uv.if_indextoname()* 4300 4301 Parameters: 4302 - `ifindex`: `integer` 4303 4304 IPv6-capable implementation of `if_indextoname(3)`. 4305 4306 Returns: `string` or `fail` 4307 4308 uv.if_indextoiid({ifindex}) *uv.if_indextoiid()* 4309 4310 Parameters: 4311 - `ifindex`: `integer` 4312 4313 Retrieves a network interface identifier suitable for use in 4314 an IPv6 scoped address. On Windows, returns the numeric 4315 `ifindex` as a string. On all other platforms, 4316 |uv.if_indextoname()| is used. 4317 4318 Returns: `string` or `fail` 4319 4320 uv.loadavg() *uv.loadavg()* 4321 4322 Returns the load average as a triad. Not supported on Windows. 4323 4324 Returns: `number, number, number` 4325 4326 uv.os_uname() *uv.os_uname()* 4327 4328 Returns system information. 4329 4330 Returns: `table` 4331 - `sysname` : `string` 4332 - `release` : `string` 4333 - `version` : `string` 4334 - `machine` : `string` 4335 4336 uv.os_gethostname() *uv.os_gethostname()* 4337 4338 Returns the hostname. 4339 4340 Returns: `string` 4341 4342 uv.os_getenv({name} [, {size}]) *uv.os_getenv()* 4343 4344 Parameters: 4345 - `name`: `string` 4346 - `size`: `integer` (default = `LUAL_BUFFERSIZE`) 4347 4348 Returns the environment variable specified by `name` as 4349 string. The internal buffer size can be set by defining 4350 `size`. If omitted, `LUAL_BUFFERSIZE` is used. If the 4351 environment variable exceeds the storage available in the 4352 internal buffer, `ENOBUFS` is returned. If no matching 4353 environment variable exists, `ENOENT` is returned. 4354 4355 Returns: `string` or `fail` 4356 4357 WARNING: This function is not thread safe. 4358 4359 uv.os_setenv({name}, {value}) *uv.os_setenv()* 4360 4361 Parameters: 4362 - `name`: `string` 4363 - `value`: `string` 4364 4365 Sets the environmental variable specified by `name` with the 4366 string `value`. 4367 4368 Returns: `boolean` or `fail` 4369 4370 WARNING: This function is not thread safe. 4371 4372 uv.os_unsetenv({name}) *uv.os_unsetenv()* 4373 4374 Parameters: 4375 - `name`: `string` 4376 4377 Unsets the environmental variable specified by `name`. 4378 4379 Returns: `boolean` or `fail` 4380 4381 WARNING: This function is not thread safe. 4382 4383 uv.os_environ() *uv.os_environ()* 4384 4385 Returns all environmental variables as a dynamic table of 4386 names associated with their corresponding values. 4387 4388 Returns: `table` 4389 4390 WARNING: This function is not thread safe. 4391 4392 uv.os_homedir() *uv.os_homedir()* 4393 4394 Returns: `string` or `fail` 4395 4396 WARNING: This function is not thread safe. 4397 4398 uv.os_tmpdir() *uv.os_tmpdir()* 4399 4400 Returns: `string` or `fail` 4401 4402 WARNING: This function is not thread safe. 4403 4404 uv.os_get_passwd() *uv.os_get_passwd()* 4405 4406 Returns password file information. 4407 4408 Returns: `table` or `fail` 4409 - `username` : `string` 4410 - `uid` : `integer?` (`nil` on Windows) 4411 - `gid` : `integer?` (`nil` on Windows) 4412 - `shell` : `string?`` (`nil` on Windows) 4413 - `homedir` : `string` 4414 4415 uv.os_getpid() *uv.os_getpid()* 4416 4417 Returns the current process ID. 4418 4419 Returns: `number` 4420 4421 uv.os_getppid() *uv.os_getppid()* 4422 4423 Returns the parent process ID. 4424 4425 Returns: `number` 4426 4427 uv.os_getpriority({pid}) *uv.os_getpriority()* 4428 4429 Parameters: 4430 - `pid`: `integer` 4431 4432 Returns the scheduling priority of the process specified by 4433 `pid`. 4434 4435 Returns: `number` or `fail` 4436 4437 uv.os_setpriority({pid}, {priority}) *uv.os_setpriority()* 4438 4439 Parameters: 4440 - `pid`: `integer` 4441 - `priority`: `integer` 4442 4443 Sets the scheduling priority of the process specified by 4444 `pid`. The `priority` range is between -20 (high priority) and 4445 19 (low priority). 4446 4447 Returns: `boolean` or `fail` 4448 4449 uv.random({len}, {flags} [, {callback}]) *uv.random()* 4450 4451 Parameters: 4452 - `len`: `integer` 4453 - `flags`: `nil` (see below) 4454 - `callback`: `callable` (async version) or `nil` (sync 4455 version) 4456 - `err`: `nil` or `string` 4457 - `bytes`: `string` or `nil` 4458 4459 Fills a string of length `len` with cryptographically strong 4460 random bytes acquired from the system CSPRNG. `flags` is 4461 reserved for future extension and must currently be `nil` or 4462 `0` or `{}`. 4463 4464 Short reads are not possible. When less than `len` random 4465 bytes are available, a non-zero error value is returned or 4466 passed to the callback. If the callback is omitted, this 4467 function is completed synchronously. 4468 4469 The synchronous version may block indefinitely when not enough 4470 entropy is available. The asynchronous version may not ever 4471 finish when the system is low on entropy. 4472 4473 Returns (sync version): `string` or `fail` 4474 4475 Returns (async version): `0` or `fail` 4476 4477 uv.translate_sys_error({errcode}) *uv.translate_sys_error()* 4478 4479 Parameters: 4480 - `errcode`: `integer` 4481 4482 Returns the libuv error message and error name (both in string 4483 form, see `err` and `name` in |luv-error-handling|) equivalent 4484 to the given platform dependent error code: POSIX error codes 4485 on Unix (the ones stored in errno), and Win32 error codes on 4486 Windows (those returned by GetLastError() or 4487 WSAGetLastError()). 4488 4489 Returns: `string, string` or `nil` 4490 4491 ============================================================================== 4492 METRICS OPERATIONS *luv-metrics-operations* 4493 4494 uv.metrics_idle_time() *uv.metrics_idle_time()* 4495 4496 Retrieve the amount of time the event loop has been idle in 4497 the kernel’s event provider (e.g. `epoll_wait`). The call is 4498 thread safe. 4499 4500 The return value is the accumulated time spent idle in the 4501 kernel’s event provider starting from when the |uv_loop_t| was 4502 configured to collect the idle time. 4503 4504 Note: The event loop will not begin accumulating the event 4505 provider’s idle time until calling `loop_configure` with 4506 `"metrics_idle_time"`. 4507 4508 Returns: `number` 4509 4510 uv.metrics_info() *uv.metrics_info()* 4511 4512 Get the metrics table from current set of event loop metrics. 4513 It is recommended to retrieve these metrics in a `prepare` 4514 callback (see |uv.new_prepare()|, |uv.prepare_start()|) in order 4515 to make sure there are no inconsistencies with the metrics 4516 counters. 4517 4518 Returns: `table` 4519 4520 - `loop_count` : `integer` 4521 - `events` : `integer` 4522 - `events_waiting` : `integer` 4523 4524 ============================================================================== 4525 STRING MANIPULATION FUNCTIONS *luv-string-manipulation* 4526 4527 These string utilities are needed internally for dealing with Windows, and are 4528 exported to allow clients to work uniformly with this data when the libuv API 4529 is not complete. 4530 4531 Notes: 4532 1. New in luv version 1.49.0. 4533 2. See the WTF-8 spec (https://simonsapin.github.io/wtf-8/) for information 4534 about WTF-8. 4535 3. Luv uses Lua-style strings, which means that all inputs and return values 4536 (UTF-8 or UTF-16 strings) do not include a NUL terminator. 4537 4538 uv.utf16_length_as_wtf8({utf16}) *uv.utf16_length_as_wtf8()* 4539 4540 Get the length (in bytes) of a UTF-16 (or UCS-2) string 4541 `utf16` value after converting it to WTF-8. The endianness of 4542 the UTF-16 (or UCS-2) string is assumed to be the same as the 4543 native endianness of the platform. 4544 4545 Parameters: 4546 - `utf16`: `string` 4547 4548 Returns: `integer` 4549 4550 uv.utf16_to_wtf8({utf16}) *uv.utf16_to_wtf8()* 4551 4552 Convert UTF-16 (or UCS-2) string `utf16` to UTF-8 string. The 4553 endianness of the UTF-16 (or UCS-2) string is assumed to be 4554 the same as the native endianness of the platform. 4555 4556 Parameters: 4557 - `utf16`: `string` 4558 4559 Returns: `string` 4560 4561 uv.wtf8_length_as_utf16({wtf16}) *uv.wtf8_length_as_utf16()* 4562 4563 Get the length (in UTF-16 code units) of a WTF-8 `wtf8` value 4564 after converting it to UTF-16 (or UCS-2). 4565 4566 Note: The number of bytes needed for a UTF-16 (or UCS-2) 4567 string is `<number of code units> * 2`. 4568 4569 Parameters: 4570 - `wtf8`: `string` 4571 4572 Returns: `integer` 4573 4574 uv.wtf8_to_utf16({wtf16}) *uv.wtf8_to_utf16()* 4575 4576 Convert WTF-8 string in `wtf8` to UTF-16 (or UCS-2) string. 4577 The endianness of the UTF-16 (or UCS-2) string is assumed to 4578 be the same as the native endianness of the platform. 4579 4580 Parameters: 4581 - `wtf8`: `string` 4582 4583 Returns: `string` 4584 4585 ============================================================================== 4586 CREDITS *luv-credits* 4587 4588 This document is a reformatted version of the LUV documentation, up-to-date 4589 with commit dcd1a1c (23 Aug 2023) of the luv repository 4590 https://github.com/luvit/luv/commit/dcd1a1cad5b05634a7691402d6ca2f214fb4ae76. 4591 4592 Based on https://github.com/nanotee/luv-vimdocs with kind permission. 4593 4594 4595 vim:tw=78:ts=8:sw=2:et:ft=help:norl: