robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
5a0a26a725
master
1*luvref.txt* Nvim 2 3 4 LUV REFERENCE MANUAL 5 6 *luvref* 7This file documents the Lua bindings for the LibUV library which is used for 8Nvim's event-loop and is accessible from Lua via |vim.uv| (e.g., |uv.version()| 9is exposed as `vim.uv.version()`). 10 11For information about this manual, see |luv-credits|. 12 13For further examples, see https://github.com/luvit/luv/tree/master/examples. 14 15============================================================================== 16INTRODUCTION *luv* *luv-intro* *uv* 17 18The luv (https://github.com/luvit/luv) project provides access to the 19multi-platform support library libuv (https://github.com/libuv/libuv) in Lua 20code. It was primarily developed for the luvit 21(https://github.com/luvit/luvit) project as the built-in `uv` module, but can 22be used in other Lua environments. 23 24More information about the core libuv library can be found at the original 25libuv documentation page (https://docs.libuv.org/). 26 27TCP Echo Server Example ~ 28 29Here 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 assert(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 54Module Layout ~ 55 56The luv library contains a single Lua module referred to hereafter as `uv` for 57simplicity. This module consists mostly of functions with names corresponding 58to their original libuv versions. For example, the libuv function 59`uv_tcp_bind` has a luv version at |uv.tcp_bind()|. Currently, only two 60non-function fields exists: `uv.constants` and `uv.errno`, which are tables. 61 62Functions vs Methods ~ 63 64In addition to having simple functions, luv provides an optional method-style 65API. For example, `uv.tcp_bind(server, host, port)` can alternatively be 66called as `server:bind(host, port)` . Note that the first argument `server` 67becomes the object and `tcp_` is removed from the function name. Method forms 68are documented below where they exist. 69 70Synchronous vs Asynchronous Functions ~ 71 72Functions that accept a callback are asynchronous. These functions may 73immediately return results to the caller to indicate their initial status, but 74their final execution is deferred until at least the next libuv loop 75iteration. After completion, their callbacks are executed with any results 76passed to it. 77 78Functions that do not accept a callback are synchronous. These functions 79immediately return their results to the caller. 80 81Some (generally FS and DNS) functions can behave either synchronously or 82asynchronously. If a callback is provided to these functions, they behave 83asynchronously; if no callback is provided, they behave synchronously. 84 85Pseudo-Types ~ 86 87Some unique types are defined. These are not actual types in Lua, but they are 88used 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============================================================================== 97CONTENTS *luv-contents* 98 99This 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. 101Low-level implementation details and unexposed C functions and types are not 102documented here except for when they are relevant to behavior seen in the Lua 103module. 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============================================================================== 135CONSTANTS *luv-constants* 136 137As a Lua library, luv supports and encourages the use of lowercase strings to 138represent 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< 145However, luv also superficially exposes libuv constants in a Lua table at 146`uv.constants` where its keys are uppercase constant names and their associated 147values are integers defined internally by libuv. The values from this table may 148be supported as function arguments, but their use may not change the output 149type. 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< 156The uppercase constants defined in `uv.constants` that have associated 157lowercase option strings are listed below. 158 159Address 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 172Signals ~ 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 210Socket Types ~ 211 212- `SOCK_STREAM`: "stream" 213- `SOCK_DGRAM`: "dgram" 214- `SOCK_SEQPACKET`: "seqpacket" 215- `SOCK_RAW`: "raw" 216- `SOCK_RDM`: "rdm" 217 218TTY 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 225FS Modification Times ~ 226 227- `FS_UTIME_NOW`: "now" 228- `FS_UTIME_OMIT`: "omit" 229 230============================================================================== 231ERROR HANDLING *luv-error-handling* 232 233In libuv, errors are represented by negative numbered constants. While these 234constants are made available in the `uv.errno` table, they are not returned by 235luv functions and the libuv functions used to handle them are not exposed. 236Instead, if an internal error is encountered, the failing luv function will 237return 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 246This tuple is referred to below as the `fail` pseudo-type. 247 248When a function is called successfully, it will return either a value that is 249relevant to the operation of the function, or the integer `0` to indicate 250success, or sometimes nothing at all. These cases are documented below. 251 252`uv.errno` *uv.errno* 253 254Below is a list of known error names and error strings. See Libuv's "Error 255constants" 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============================================================================== 340VERSION CHECKING *luv-version-checking* 341 342uv.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 351uv.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 362The event loop is the central part of libuv's functionality. It takes care of 363polling for I/O and scheduling callbacks to be run based on different sources 364of events. 365 366In luv, there is an implicit uv loop for every Lua state that loads the 367library. You can use this library in an multi-threaded environment as long as 368each thread has it's own Lua state with its corresponding own uv loop. This 369loop is not directly exposed to users in the Lua module. 370 371uv.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 382uv.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 414uv.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 447uv.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 454uv.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 461uv.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 470uv.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 485uv.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 492uv.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 507uv.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 520uv.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 546uv.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 560uv.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 577defined here work with any handle type. 578 579uv.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 606uv.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 622uv.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 645uv.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 660uv.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 673See |luv-reference-counting|. 674 675uv.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 688uv.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 713uv.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 738uv.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 760uv.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============================================================================== 774REFERENCE COUNTING *luv-reference-counting* 775 776The libuv event loop (if run in the default mode) will run until there are no 777active and referenced handles left. The user can force the loop to exit early 778by unreferencing handles which are active, for example by calling |uv.unref()| 779after calling |uv.timer_start()|. 780 781A handle can be referenced or unreferenced, the refcounting scheme doesn't use 782a counter, so both operations are idempotent. 783 784All handles are referenced when active by default, see |uv.is_active()| for a 785more 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 792Timer handles are used to schedule callbacks to be called in the future. 793 794uv.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 829uv.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 848uv.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 859uv.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 872uv.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 892uv.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 903uv.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 922Prepare handles will run the given callback once per loop iteration, right 923before 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 932uv.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 939uv.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 951uv.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 967Check handles will run the given callback once per loop iteration, right after 968polling 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 977uv.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 984uv.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 996uv.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 1012Idle handles will run the given callback once per loop iteration, right before 1013the |uv_prepare_t| handles. 1014 1015Note: The notable difference with prepare handles is that when there are 1016active idle handles, the loop will perform a zero timeout poll instead of 1017blocking for I/O. 1018 1019WARNING: Despite the name, idle handles will get their callbacks called on 1020every 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 1029uv.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 1036uv.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 1048uv.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 1064Async handles allow the user to "wakeup" the event loop and get a callback 1065called 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 1077uv.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 1092uv.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 1119Poll handles are used to watch file descriptors for readability and 1120writability, similar to the purpose of poll(2) 1121(https://linux.die.net/man/2/poll). 1122 1123The purpose of poll handles is to enable integrating external libraries that 1124rely on the event loop to signal it about the socket status changes, like 1125c-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 1127scalable than what can be achieved with `uv_poll_t`, especially on Windows. 1128 1129It is possible that poll handles occasionally signal that a file descriptor is 1130readable or writable even when it isn't. The user should therefore always be 1131prepared to handle EAGAIN or equivalent when it attempts to read from or write 1132to the fd. 1133 1134It is not okay to have multiple active poll handles for the same socket, this 1135can cause libuv to busyloop or otherwise malfunction. 1136 1137The user should not close a file descriptor while it is being polled by an 1138active poll handle. This can cause the handle to report an error, but it might 1139also start polling another socket. However the fd can be safely closed 1140immediately after a call to |uv.poll_stop()| or |uv.close()|. 1141 1142Note: On windows only sockets can be polled with poll handles. On Unix any 1143file descriptor that would be accepted by poll(2) can be used. 1144 1145uv.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 1156uv.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 1169uv.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 1198uv.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 1215Signal handles implement Unix style signal handling on a per-event loop bases. 1216 1217Windows Notes: 1218 1219Reception 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 1238Unix 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 1260uv.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 1267uv.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()* 1285uv.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 1303uv.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 1319Process handles will spawn a new process and allow the user to control it and 1320establish communication channels with it using streams. 1321 1322uv.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 1340uv.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 1457uv.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 1474uv.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 1489uv.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 1505Stream handles provide an abstraction of a duplex communication channel. 1506`uv_stream_t` is an abstract type, libuv provides 3 stream implementations 1507in the form of |uv_tcp_t|, |uv_pipe_t| and |uv_tty_t|. 1508 1509uv.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 1524uv.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 1541uv.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 1567uv.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 1596uv.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 1611uv.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 1632uv.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 1652uv.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 1668uv.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 1686uv.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 1697uv.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 1708uv.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 1734uv.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 1747TCP handles are used to represent both TCP streams and servers. 1748 1749uv.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 1762uv.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 1778uv.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()* 1791uv.tcp_keepalive({tcp}, {enable} [, {delay}, {intvl}, {cnt}]) 1792 1793 > method form `tcp:keepalive(enable, [delay], [intvl], [cnt])` 1794 1795 Parameters: 1796 - `tcp`: `uv_tcp_t userdata` 1797 - `enable`: `boolean` 1798 - `delay`: `integer` or `nil` 1799 - `intvl`: `integer` or `nil` 1800 - `cnt`: `integer` or `nil` 1801 1802 Enable / disable TCP keep-alive. `delay` is the initial delay 1803 in seconds, `intvl` is the time in seconds between individual 1804 keep-alive probes, and `cnt` is the number of probes to send 1805 before assuming the connection is dead. 1806 Ignored when enable is `false`. 1807 1808 Returns: `0` or `fail` 1809 1810 Note: `intvl` and `cnt` are only supported with Libuv >= 1.52.0. 1811 1812uv.tcp_simultaneous_accepts({tcp}, {enable}) *uv.tcp_simultaneous_accepts()* 1813 1814 > method form `tcp:simultaneous_accepts(enable)` 1815 1816 Parameters: 1817 - `tcp`: `uv_tcp_t userdata` 1818 - `enable`: `boolean` 1819 1820 Enable / disable simultaneous asynchronous accept requests 1821 that are queued by the operating system when listening for new 1822 TCP connections. 1823 1824 This setting is used to tune a TCP server for the desired 1825 performance. Having simultaneous accepts can significantly 1826 improve the rate of accepting connections (which is why it is 1827 enabled by default) but may lead to uneven load distribution 1828 in multi-process setups. 1829 1830 Returns: `0` or `fail` 1831 1832uv.tcp_bind({tcp}, {host}, {port} [, {flags}]) *uv.tcp_bind()* 1833 1834 > method form `tcp:bind(host, port, [flags])` 1835 1836 Parameters: 1837 - `tcp`: `uv_tcp_t userdata` 1838 - `host`: `string` 1839 - `port`: `integer` 1840 - `flags`: `table` or `nil` 1841 - `ipv6only`: `boolean` 1842 1843 Bind the handle to an host and port. `host` should be an IP 1844 address and not a domain name. Any `flags` are set with a 1845 table with field `ipv6only` equal to `true` or `false`. 1846 1847 When the port is already taken, you can expect to see an 1848 `EADDRINUSE` error from either `uv.tcp_bind()`, |uv.listen()| 1849 or |uv.tcp_connect()|. That is, a successful call to this 1850 function does not guarantee that the call to |uv.listen()| or 1851 |uv.tcp_connect()| will succeed as well. 1852 1853 Use a port of `0` to let the OS assign an ephemeral port. You 1854 can look it up later using |uv.tcp_getsockname()|. 1855 1856 Returns: `0` or `fail` 1857 1858uv.tcp_getpeername({tcp}) *uv.tcp_getpeername()* 1859 1860 > method form `tcp:getpeername()` 1861 1862 Parameters: 1863 - `tcp`: `uv_tcp_t userdata` 1864 1865 Get the address of the peer connected to the handle. 1866 1867 See |luv-constants| for supported address `family` output values. 1868 1869 Returns: `table` or `fail` 1870 - `ip` : `string` 1871 - `family` : `string` 1872 - `port` : `integer` 1873 1874uv.tcp_getsockname({tcp}) *uv.tcp_getsockname()* 1875 1876 > method form `tcp:getsockname()` 1877 1878 Parameters: 1879 - `tcp`: `uv_tcp_t userdata` 1880 1881 Get the current address to which the handle is bound. 1882 1883 See |luv-constants| for supported address `family` output values. 1884 1885 Returns: `table` or `fail` 1886 - `ip` : `string` 1887 - `family` : `string` 1888 - `port` : `integer` 1889 1890uv.tcp_connect({tcp}, {host}, {port}, {callback}) *uv.tcp_connect()* 1891 1892 > method form `tcp:connect(host, port, callback)` 1893 1894 Parameters: 1895 - `tcp`: `uv_tcp_t userdata` 1896 - `host`: `string` 1897 - `port`: `integer` 1898 - `callback`: `callable` 1899 - `err`: `nil` or `string` 1900 1901 Establish an IPv4 or IPv6 TCP connection. 1902 1903 Returns: `uv_connect_t userdata` or `fail` 1904 1905 >lua 1906 local client = uv.new_tcp() 1907 client:connect("127.0.0.1", 8080, function (err) 1908 -- check error and carry on. 1909 end) 1910< 1911 1912uv.tcp_write_queue_size({tcp}) *uv.tcp_write_queue_size()* 1913 1914 > method form `tcp:write_queue_size()` 1915 1916 DEPRECATED: Please use |uv.stream_get_write_queue_size()| 1917 instead. 1918 1919uv.tcp_close_reset([{callback}]) *uv.tcp_close_reset()* 1920 1921 > method form `tcp:close_reset([callback])` 1922 1923 Parameters: 1924 - `tcp`: `uv_tcp_t userdata` 1925 - `callback`: `callable` or `nil` 1926 1927 Resets a TCP connection by sending a RST packet. This is 1928 accomplished by setting the SO_LINGER socket option with a 1929 linger interval of zero and then calling |uv.close()|. Due to 1930 some platform inconsistencies, mixing of |uv.shutdown()| and 1931 `uv.tcp_close_reset()` calls is not allowed. 1932 1933 Returns: `0` or `fail` 1934 *uv.socketpair()* 1935uv.socketpair([{socktype}, [{protocol}, [{flags1}, [{flags2}]]]]) 1936 1937 Parameters: 1938 - `socktype`: `string`, `integer` or `nil` (default: `stream`) 1939 - `protocol`: `string`, `integer` or `nil` (default: 0) 1940 - `flags1`: `table` or `nil` 1941 - `nonblock`: `boolean` (default: `false`) 1942 - `flags2`: `table` or `nil` 1943 - `nonblock`: `boolean` (default: `false`) 1944 1945 Create a pair of connected sockets with the specified 1946 properties. The resulting handles can be passed to 1947 |uv.tcp_open()|, used with |uv.spawn()|, or for any other 1948 purpose. 1949 1950 See |luv-constants| for supported `socktype` input values. 1951 1952 When `protocol` is set to 0 or nil, it will be automatically 1953 chosen based on the socket's domain and type. When `protocol` 1954 is specified as a string, it will be looked up using the 1955 `getprotobyname(3)` function (examples: `"ip"`, `"icmp"`, 1956 `"tcp"`, `"udp"`, etc). 1957 1958 Flags: 1959 - `nonblock`: Opens the specified socket handle for 1960 `OVERLAPPED` or `FIONBIO`/`O_NONBLOCK` I/O usage. This is 1961 recommended for handles that will be used by libuv, and not 1962 usually recommended otherwise. 1963 1964 Equivalent to `socketpair(2)` with a domain of `AF_UNIX`. 1965 1966 Returns: `table` or `fail` 1967 - `[1, 2]` : `integer` (file descriptor) 1968 1969 >lua 1970 -- Simple read/write with tcp 1971 local fds = uv.socketpair(nil, nil, {nonblock=true}, {nonblock=true}) 1972 1973 local sock1 = uv.new_tcp() 1974 sock1:open(fds[1]) 1975 1976 local sock2 = uv.new_tcp() 1977 sock2:open(fds[2]) 1978 1979 sock1:write("hello") 1980 sock2:read_start(function(err, chunk) 1981 assert(not err, err) 1982 print(chunk) 1983 end) 1984< 1985 1986============================================================================== 1987`uv_pipe_t` — Pipe handle *luv-pipe-handle* *uv_pipe_t* 1988 1989> |uv_handle_t| and |uv_stream_t| functions also apply. 1990 1991Pipe handles provide an abstraction over local domain sockets on Unix and 1992named pipes on Windows. 1993 1994 >lua 1995 local pipe = uv.new_pipe(false) 1996 1997 pipe:bind('/tmp/sock.test') 1998 1999 pipe:listen(128, function() 2000 local client = uv.new_pipe(false) 2001 pipe:accept(client) 2002 client:write("hello!\n") 2003 client:close() 2004 end) 2005< 2006 2007uv.new_pipe([{ipc}]) *uv.new_pipe()* 2008 2009 Parameters: 2010 - `ipc`: `boolean` or `nil` (default: `false`) 2011 2012 Creates and initializes a new |uv_pipe_t|. Returns the Lua 2013 userdata wrapping it. The `ipc` argument is a boolean to 2014 indicate if this pipe will be used for handle passing between 2015 processes. 2016 2017 Returns: `uv_pipe_t userdata` or `fail` 2018 2019uv.pipe_open({pipe}, {fd}) *uv.pipe_open()* 2020 2021 > method form `pipe:open(fd)` 2022 2023 Parameters: 2024 - `pipe`: `uv_pipe_t userdata` 2025 - `fd`: `integer` 2026 2027 Open an existing file descriptor or |uv_handle_t| as a 2028 pipe. 2029 2030 Returns: `0` or `fail` 2031 2032 Note: The file descriptor is set to non-blocking mode. 2033 2034uv.pipe_bind({pipe}, {name}) *uv.pipe_bind()* 2035 2036 > method form `pipe:bind(name)` 2037 2038 Parameters: 2039 - `pipe`: `uv_pipe_t userdata` 2040 - `name`: `string` 2041 2042 Bind the pipe to a file path (Unix) or a name (Windows). 2043 2044 Returns: `0` or `fail` 2045 2046 Note: Paths on Unix get truncated to 2047 sizeof(sockaddr_un.sun_path) bytes, typically between 92 and 2048 108 bytes. 2049 2050uv.pipe_connect({pipe}, {name} [, {callback}]) *uv.pipe_connect()* 2051 2052 > method form `pipe:connect(name, [callback])` 2053 2054 Parameters: 2055 - `pipe`: `uv_pipe_t userdata` 2056 - `name`: `string` 2057 - `callback`: `callable` or `nil` 2058 - `err`: `nil` or `string` 2059 2060 Connect to the Unix domain socket or the named pipe. 2061 2062 Returns: `uv_connect_t userdata` or `fail` 2063 2064 Note: Paths on Unix get truncated to 2065 sizeof(sockaddr_un.sun_path) bytes, typically between 92 and 2066 108 bytes. 2067 2068uv.pipe_getsockname({pipe}) *uv.pipe_getsockname()* 2069 2070 > method form `pipe:getsockname()` 2071 2072 Parameters: 2073 - `pipe`: `uv_pipe_t userdata` 2074 2075 Get the name of the Unix domain socket or the named pipe. 2076 2077 Returns: `string` or `fail` 2078 2079uv.pipe_getpeername({pipe}) *uv.pipe_getpeername()* 2080 2081 > method form `pipe:getpeername()` 2082 2083 Parameters: 2084 - `pipe`: `uv_pipe_t userdata` 2085 2086 Get the name of the Unix domain socket or the named pipe to 2087 which the handle is connected. 2088 2089 Returns: `string` or `fail` 2090 2091uv.pipe_pending_instances({pipe}, {count}) *uv.pipe_pending_instances()* 2092 2093 > method form `pipe:pending_instances(count)` 2094 2095 Parameters: 2096 - `pipe`: `uv_pipe_t userdata` 2097 - `count`: `integer` 2098 2099 Set the number of pending pipe instance handles when the pipe 2100 server is waiting for connections. 2101 2102 Returns: Nothing. 2103 2104 Note: This setting applies to Windows only. 2105 2106uv.pipe_pending_count({pipe}) *uv.pipe_pending_count()* 2107 2108 > method form `pipe:pending_count()` 2109 2110 Parameters: 2111 - `pipe`: `uv_pipe_t userdata` 2112 2113 Returns the pending pipe count for the named pipe. 2114 2115 Returns: `integer` 2116 2117uv.pipe_pending_type({pipe}) *uv.pipe_pending_type()* 2118 2119 > method form `pipe:pending_type()` 2120 2121 Parameters: 2122 - `pipe`: `uv_pipe_t userdata` 2123 2124 Used to receive handles over IPC pipes. 2125 2126 First - call |uv.pipe_pending_count()|, if it's > 0 then 2127 initialize a handle of the given type, returned by 2128 `uv.pipe_pending_type()` and call `uv.accept(pipe, handle)` . 2129 2130 Returns: `string` 2131 2132uv.pipe_chmod({pipe}, {flags}) *uv.pipe_chmod()* 2133 2134 > method form `pipe:chmod(flags)` 2135 2136 Parameters: 2137 - `pipe`: `uv_pipe_t userdata` 2138 - `flags`: `string` 2139 2140 Alters pipe permissions, allowing it to be accessed from 2141 processes run by different users. Makes the pipe writable or 2142 readable by all users. `flags` are: `"r"`, `"w"`, `"rw"`, or 2143 `"wr"` where `r` is `READABLE` and `w` is `WRITABLE`. This 2144 function is blocking. 2145 2146 Returns: `0` or `fail` 2147 2148uv.pipe({read_flags}, {write_flags}) *uv.pipe()* 2149 2150 Parameters: 2151 - `read_flags`: `table` or `nil` 2152 - `nonblock`: `boolean` (default: `false`) 2153 - `write_flags`: `table` or `nil` 2154 - `nonblock`: `boolean` (default: `false`) 2155 2156 Create a pair of connected pipe handles. Data may be written 2157 to the `write` fd and read from the `read` fd. The resulting 2158 handles can be passed to `pipe_open`, used with `spawn`, or 2159 for any other purpose. 2160 2161 Flags: 2162 - `nonblock`: Opens the specified socket handle for 2163 `OVERLAPPED` or `FIONBIO`/`O_NONBLOCK` I/O usage. This is 2164 recommended for handles that will be used by libuv, and not 2165 usually recommended otherwise. 2166 2167 Equivalent to `pipe(2)` with the `O_CLOEXEC` flag set. 2168 2169 Returns: `table` or `fail` 2170 - `read` : `integer` (file descriptor) 2171 - `write` : `integer` (file descriptor) 2172 2173 >lua 2174 -- Simple read/write with pipe_open 2175 local fds = uv.pipe({nonblock=true}, {nonblock=true}) 2176 2177 local read_pipe = uv.new_pipe() 2178 read_pipe:open(fds.read) 2179 2180 local write_pipe = uv.new_pipe() 2181 write_pipe:open(fds.write) 2182 2183 write_pipe:write("hello") 2184 read_pipe:read_start(function(err, chunk) 2185 assert(not err, err) 2186 print(chunk) 2187 end) 2188< 2189 2190uv.pipe_bind2({pipe}, {name}, {flags}) *uv.pipe_bind2()* 2191 2192 > method form `pipe:pipe_bind(name, flags)` 2193 2194 Parameters: 2195 - `pipe`: `uv_pipe_t userdata` 2196 - `name`: `string` 2197 - `flags`: `integer` or `table` or `nil` (default: 0) 2198 2199 Flags: 2200 - If `type(flags)` is `number`, it must be `0` or 2201 `uv.constants.PIPE_NO_TRUNCATE`. 2202 - If `type(flags)` is `table`, it must be `{}` or 2203 `{ no_truncate = true|false }`. 2204 - If `type(flags)` is `nil`, it use default value `0`. 2205 - Returns `EINVAL` for unsupported flags without performing the 2206 bind. 2207 2208 Bind the pipe to a file path (Unix) or a name (Windows). 2209 2210 Supports Linux abstract namespace sockets. namelen must include 2211 the leading '\0' byte but not the trailing nul byte. 2212 2213 Returns: `0` or `fail` 2214 2215 Note: 2216 1. Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) 2217 bytes, typically between 92 and 108 bytes. 2218 2. New in version 1.46.0. 2219 2220uv.pipe_connect2(pipe, name, [flags], [callback]) *uv.pipe_connect2()* 2221 2222 > method form `pipe:connect2(name, [flags], [callback])` 2223 2224 Parameters: 2225 - `pipe`: `uv_pipe_t userdata` 2226 - `name`: `string` 2227 - `flags`: `integer` or `table` or `nil` (default: 0) 2228 - `callback`: `callable` or `nil` 2229 - `err`: `nil` or `string` 2230 2231 `Flags`: 2232 2233 - If `type(flags)` is `number`, it must be `0` or 2234 `uv.constants.PIPE_NO_TRUNCATE`. 2235 - If `type(flags)` is `table`, it must be `{}` or 2236 `{ no_truncate = true|false }`. 2237 - If `type(flags)` is `nil`, it use default value `0`. 2238 - Returns `EINVAL` for unsupported flags without performing the 2239 bind operation. 2240 2241 Connect to the Unix domain socket or the named pipe. 2242 2243 Supports Linux abstract namespace sockets. namelen must include 2244 the leading nul byte but not the trailing nul byte. 2245 2246 Returns: `uv_connect_t userdata` or `fail` 2247 2248 Note: 2249 1. Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) 2250 bytes, typically between 92 and 108 bytes. 2251 2. New in version 1.46.0. 2252 2253============================================================================== 2254`uv_tty_t` — TTY handle *luv-tty-handle* *uv_tty_t* 2255 2256> |uv_handle_t| and |uv_stream_t| functions also apply. 2257 2258TTY handles represent a stream for the console. 2259 2260 >lua 2261 -- Simple echo program 2262 local stdin = uv.new_tty(0, true) 2263 local stdout = uv.new_tty(1, false) 2264 2265 stdin:read_start(function (err, data) 2266 assert(not err, err) 2267 if data then 2268 stdout:write(data) 2269 else 2270 stdin:close() 2271 stdout:close() 2272 end 2273 end) 2274< 2275 2276uv.new_tty({fd}, {readable}) *uv.new_tty()* 2277 2278 Parameters: 2279 - `fd`: `integer` 2280 - `readable`: `boolean` 2281 2282 Initialize a new TTY stream with the given file descriptor. 2283 Usually the file descriptor will be: 2284 2285 - 0 - stdin 2286 - 1 - stdout 2287 - 2 - stderr 2288 2289 On Unix this function will determine the path of the fd of the 2290 terminal using ttyname_r(3), open it, and use it if the passed 2291 file descriptor refers to a TTY. This lets libuv put the tty 2292 in non-blocking mode without affecting other processes that 2293 share the tty. 2294 2295 This function is not thread safe on systems that don’t support 2296 ioctl TIOCGPTN or TIOCPTYGNAME, for instance OpenBSD and 2297 Solaris. 2298 2299 Returns: `uv_tty_t userdata` or `fail` 2300 2301 Note: If reopening the TTY fails, libuv falls back to blocking 2302 writes. 2303 2304uv.tty_set_mode({tty}, {mode}) *uv.tty_set_mode()* 2305 2306 > method form `tty:set_mode(mode)` 2307 2308 Parameters: 2309 - `tty`: `uv_tty_t userdata` 2310 - `mode`: `string` or `integer` 2311 2312 Set the TTY using the specified terminal mode. 2313 2314 See |luv-constants| for supported TTY mode input values. 2315 2316 Returns: `0` or `fail` 2317 2318uv.tty_reset_mode() *uv.tty_reset_mode()* 2319 2320 To be called when the program exits. Resets TTY settings to 2321 default values for the next process to take over. 2322 2323 This function is async signal-safe on Unix platforms but can 2324 fail with error code `EBUSY` if you call it when execution is 2325 inside |uv.tty_set_mode()|. 2326 2327 Returns: `0` or `fail` 2328 2329uv.tty_get_winsize({tty}) *uv.tty_get_winsize()* 2330 2331 > method form `tty:get_winsize()` 2332 2333 Parameters: 2334 - `tty`: `uv_tty_t userdata` 2335 2336 Gets the current Window width and height. 2337 2338 Returns: `integer, integer` or `fail` 2339 2340uv.tty_set_vterm_state({state}) *uv.tty_set_vterm_state()* 2341 2342 Parameters: 2343 - `state`: `string` 2344 2345 Controls whether console virtual terminal sequences are 2346 processed by libuv or console. Useful in particular for 2347 enabling ConEmu support of ANSI X3.64 and Xterm 256 colors. 2348 Otherwise Windows10 consoles are usually detected 2349 automatically. State should be one of: `"supported"` or 2350 `"unsupported"`. 2351 2352 This function is only meaningful on Windows systems. On Unix 2353 it is silently ignored. 2354 2355 Returns: none 2356 2357uv.tty_get_vterm_state() *uv.tty_get_vterm_state()* 2358 2359 Get the current state of whether console virtual terminal 2360 sequences are handled by libuv or the console. The return 2361 value is `"supported"` or `"unsupported"`. 2362 2363 This function is not implemented on Unix, where it returns 2364 `ENOTSUP`. 2365 2366 Returns: `string` or `fail` 2367 2368============================================================================== 2369`uv_udp_t` — UDP handle *luv-udp-handle* *uv_udp_t* 2370 2371> |uv_handle_t| functions also apply. 2372 2373UDP handles encapsulate UDP communication for both clients and servers. 2374 2375uv.new_udp([{flags}]) *uv.new_udp()* 2376 2377 Parameters: 2378 - `flags`: `table` or `nil` 2379 - `family`: `string` or `nil` 2380 - `mmsgs`: `integer` or `nil` (default: `1`) 2381 2382 Creates and initializes a new |uv_udp_t|. Returns the Lua 2383 userdata wrapping it. The actual socket is created lazily. 2384 2385 See |luv-constants| for supported address `family` input values. 2386 2387 When specified, `mmsgs` determines the number of messages able 2388 to be received at one time via `recvmmsg(2)` (the allocated 2389 buffer will be sized to be able to fit the specified number of 2390 max size dgrams). Only has an effect on platforms that support 2391 `recvmmsg(2)`. 2392 2393 Note: For backwards compatibility reasons, `flags` can also be 2394 a string or integer. When it is a string, it will be treated 2395 like the `family` key above. When it is an integer, it will be 2396 used directly as the `flags` parameter when calling 2397 `uv_udp_init_ex`. 2398 2399 Returns: `uv_udp_t userdata` or `fail` 2400 2401uv.udp_get_send_queue_size() *uv.udp_get_send_queue_size()* 2402 2403 > method form `udp:get_send_queue_size()` 2404 2405 Returns the handle's send queue size. 2406 2407 Returns: `integer` 2408 2409uv.udp_get_send_queue_count() *uv.udp_get_send_queue_count()* 2410 2411 > method form `udp:get_send_queue_count()` 2412 2413 Returns the handle's send queue count. 2414 2415 Returns: `integer` 2416 2417uv.udp_open({udp}, {fd}, [{flags}]) *uv.udp_open()* 2418 2419 > method form `udp:open(fd, [flags])` 2420 2421 Parameters: 2422 - `udp`: `uv_udp_t userdata` 2423 - `fd`: `integer` 2424 - `flags`: `table` or `integer` or `nil` 2425 - `reuseaddr`: `boolean` or `nil` 2426 - `reuseport`: `boolean` or `nil` 2427 2428 Opens an existing file descriptor or Windows SOCKET as a UDP 2429 handle. 2430 2431 Unix only: The only requirement of the sock argument is that 2432 it follows the datagram contract (works in unconnected mode, 2433 supports sendmsg()/recvmsg(), etc). In other words, other 2434 datagram-type sockets like raw sockets or netlink sockets can 2435 also be passed to this function. 2436 2437 The file descriptor is set to non-blocking mode. 2438 2439 Note: The passed file descriptor or SOCKET is not checked for 2440 its type, but it's required that it represents a valid 2441 datagram socket. 2442 2443 Returns: `0` or `fail` 2444 2445 Note: `flags` is only supported with Libuv >= 1.52.0. 2446 2447uv.udp_bind({udp}, {host}, {port} [, {flags}]) *uv.udp_bind()* 2448 2449 > method form `udp:bind(host, port, [flags])` 2450 2451 Parameters: 2452 - `udp`: `uv_udp_t userdata` 2453 - `host`: `string` 2454 - `port`: `number` 2455 - `flags`: `table` or `nil` 2456 - `ipv6only`: `boolean` or `nil` 2457 - `reuseaddr`: `boolean` or `nil` 2458 - `linux_recverr`: `boolean` or `nil` 2459 - `reuseport`: `boolean` or `nil` 2460 2461 Bind the UDP handle to an IP address and port. Any `flags` are 2462 set with a table with fields `reuseaddr`, `ipv6only`, 2463 `linux_recverr`, `reuseport` equal to `true` or `false`. 2464 2465 - `reuseaddr`: Indicates if SO_REUSEADDR will be set when 2466 binding the handle. This sets the SO_REUSEPORT socket flag on 2467 the BSDs (except for DragonFlyBSD), OS X, and other platforms 2468 where SO_REUSEPORTs don't have the capability of load 2469 balancing, as the opposite of what `reuseport` would do. On 2470 other Unix platforms, it sets the SO_REUSEADDR flag. What that 2471 means is that multiple threads or processes can bind to the 2472 same address without error (provided they all set the flag) 2473 but only the last one to bind will receive any traffic, in 2474 effect "stealing" the port from the previous listener. 2475 - `ipv6only`: Disables dual stack mode. 2476 - `linux_recverr`: Indicates if IP_RECVERR/IPV6_RECVERR will 2477 be set when binding the handle. This sets IP_RECVERR for IPv4 2478 and IPV6_RECVERR for IPv6 UDP sockets on Linux. This stops the 2479 Linux kernel from suppressing some ICMP error messages and 2480 enables full ICMP error reporting for faster failover. This 2481 flag is no-op on platforms other than Linux. 2482 - `reuseport`: Indicates if SO_REUSEPORT will be set when 2483 binding the handle. This sets the SO_REUSEPORT socket option 2484 on supported platforms. Unlike `reuseaddr`, this flag will 2485 make multiple threads or processes that are binding to the 2486 same address and port "share" the port, which means incoming 2487 datagrams are distributed across the receiving sockets among 2488 threads or processes. This flag is available only on Linux 2489 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+, Solaris 11.4, and AIX 2490 7.2.5+ for now. 2491 2492 Returns: `0` or `fail` 2493 2494 Note: The flag `linux_recverr` is only supported with Libuv >= 2495 1.42.0. The flag `reuseport` is only supported with Libuv >= 2496 1.49.0. 2497 2498uv.udp_getsockname({udp}) *uv.udp_getsockname()* 2499 2500 > method form `udp:getsockname()` 2501 2502 Parameters: 2503 - `udp`: `uv_udp_t userdata` 2504 2505 Get the local IP and port of the UDP handle. 2506 2507 Returns: `table` or `fail` 2508 - `ip` : `string` 2509 - `family` : `string` 2510 - `port` : `integer` 2511 2512uv.udp_getpeername({udp}) *uv.udp_getpeername()* 2513 2514 > method form `udp:getpeername()` 2515 2516 Parameters: 2517 - `udp`: `uv_udp_t userdata` 2518 2519 Get the remote IP and port of the UDP handle on connected UDP 2520 handles. 2521 2522 Returns: `table` or `fail` 2523 - `ip` : `string` 2524 - `family` : `string` 2525 - `port` : `integer` 2526 2527 *uv.udp_set_membership()* 2528uv.udp_set_membership({udp}, {multicast_addr}, {interface_addr}, {membership}) 2529 2530 > method form 2531 > `udp:set_membership(multicast_addr, interface_addr, membership)` 2532 2533 Parameters: 2534 - `udp`: `uv_udp_t userdata` 2535 - `multicast_addr`: `string` 2536 - `interface_addr`: `string` or `nil` 2537 - `membership`: `string` 2538 2539 Set membership for a multicast address. `multicast_addr` is 2540 multicast address to set membership for. `interface_addr` is 2541 interface address. `membership` can be the string `"leave"` or 2542 `"join"`. 2543 2544 Returns: `0` or `fail` 2545 2546 *uv.udp_set_source_membership()* 2547uv.udp_set_source_membership({udp}, {multicast_addr}, {interface_addr}, {source_addr}, {membership}) 2548 2549 > method form 2550 > `udp:set_source_membership(multicast_addr, interface_addr, source_addr, membership)` 2551 2552 Parameters: 2553 - `udp`: `uv_udp_t userdata` 2554 - `multicast_addr`: `string` 2555 - `interface_addr`: `string` or `nil` 2556 - `source_addr`: `string` 2557 - `membership`: `string` 2558 2559 Set membership for a source-specific multicast group. 2560 `multicast_addr` is multicast address to set membership for. 2561 `interface_addr` is interface address. `source_addr` is source 2562 address. `membership` can be the string `"leave"` or `"join"`. 2563 2564 Returns: `0` or `fail` 2565 2566uv.udp_set_multicast_loop({udp}, {on}) *uv.udp_set_multicast_loop()* 2567 2568 > method form `udp:set_multicast_loop(on)` 2569 2570 Parameters: 2571 - `udp`: `uv_udp_t userdata` 2572 - `on`: `boolean` 2573 2574 Set IP multicast loop flag. Makes multicast packets loop back 2575 to local sockets. 2576 2577 Returns: `0` or `fail` 2578 2579uv.udp_set_multicast_ttl({udp}, {ttl}) *uv.udp_set_multicast_ttl()* 2580 2581 > method form `udp:set_multicast_ttl(ttl)` 2582 2583 Parameters: 2584 - `udp`: `uv_udp_t userdata` 2585 - `ttl`: `integer` 2586 2587 Set the multicast ttl. 2588 2589 `ttl` is an integer 1 through 255. 2590 2591 Returns: `0` or `fail` 2592 2593 *uv.udp_set_multicast_interface()* 2594uv.udp_set_multicast_interface({udp}, {interface_addr}) 2595 2596 > method form `udp:set_multicast_interface(interface_addr)` 2597 2598 Parameters: 2599 - `udp`: `uv_udp_t userdata` 2600 - `interface_addr`: `string` 2601 2602 Set the multicast interface to send or receive data on. 2603 2604 Returns: `0` or `fail` 2605 2606uv.udp_set_broadcast({udp}, {on}) *uv.udp_set_broadcast()* 2607 2608 > method form `udp:set_broadcast(on)` 2609 2610 Parameters: 2611 - `udp`: `uv_udp_t userdata` 2612 - `on`: `boolean` 2613 2614 Set broadcast on or off. 2615 2616 Returns: `0` or `fail` 2617 2618uv.udp_set_ttl({udp}, {ttl}) *uv.udp_set_ttl()* 2619 2620 > method form `udp:set_ttl(ttl)` 2621 2622 Parameters: 2623 - `udp`: `uv_udp_t userdata` 2624 - `ttl`: `integer` 2625 2626 Set the time to live. 2627 2628 `ttl` is an integer 1 through 255. 2629 2630 Returns: `0` or `fail` 2631 2632uv.udp_send({udp}, {data}, {host}, {port}, {callback}) *uv.udp_send()* 2633 2634 > method form `udp:send(data, host, port, callback)` 2635 2636 Parameters: 2637 - `udp`: `uv_udp_t userdata` 2638 - `data`: `buffer` 2639 - `host`: `string` 2640 - `port`: `integer` 2641 - `callback`: `callable` 2642 - `err`: `nil` or `string` 2643 2644 Send data over the UDP socket. If the socket has not 2645 previously been bound with |uv.udp_bind()| it will be bound to 2646 `0.0.0.0` (the "all interfaces" IPv4 address) and a random 2647 port number. 2648 2649 Returns: `uv_udp_send_t userdata` or `fail` 2650 2651uv.udp_try_send({udp}, {data}, {host}, {port}) *uv.udp_try_send()* 2652 2653 > method form `udp:try_send(data, host, port)` 2654 2655 Parameters: 2656 - `udp`: `uv_udp_t userdata` 2657 - `data`: `buffer` 2658 - `host`: `string` 2659 - `port`: `integer` 2660 2661 Same as |uv.udp_send()|, but won't queue a send request if it 2662 can't be completed immediately. 2663 2664 Returns: `integer` or `fail` 2665 2666uv.udp_try_send2({udp}, {messages}, {flags}) *uv.udp_try_send2()* 2667 2668 > method form `udp:try_send2(messages, flags)` 2669 2670 Parameters: 2671 - `udp`: `uv_udp_t userdata` 2672 - `messages`: `table` 2673 - `[1, 2, 3, ..., n]` : `table` 2674 - `data` : `buffer` 2675 - `addr` : `table` 2676 - `ip` : `string` 2677 - `port` : `integer` 2678 - `flags`: `nil` (see below) 2679 - `port`: `integer` 2680 2681 Like `uv.udp_try_send()`, but can send multiple datagrams. 2682 Lightweight abstraction around `sendmmsg(2)`, with a 2683 `sendmsg(2)` fallback loop for platforms that do not support 2684 the former. The `udp` handle must be fully initialized, either 2685 from a `uv.udp_bind` call, another call that will bind 2686 automatically (`udp_send`, `udp_try_send`, etc), or from 2687 `uv.udp_connect`. `messages` should be an array-like table, 2688 where `addr` must be specified if the `udp` has not been 2689 connected via `udp_connect`. Otherwise, `addr` must be `nil`. 2690 2691 `flags` is reserved for future extension and must currently be 2692 `nil` or `0` or `{}`. 2693 2694 Returns the number of messages sent successfully. An error will only be returned 2695 if the first datagram failed to be sent. 2696 2697 Returns: `integer` or `fail` 2698 >lua 2699 -- If client:connect(...) was not called 2700 local addr = { ip = "127.0.0.1", port = 1234 } 2701 client:try_send2({ 2702 { data = "Message 1", addr = addr }, 2703 { data = "Message 2", addr = addr }, 2704 }) 2705 -- If client:connect(...) was called 2706 client:try_send2({ 2707 { data = "Message 1" }, 2708 { data = "Message 2" }, 2709 }) 2710< 2711uv.udp_recv_start({udp}, {callback}) *uv.udp_recv_start()* 2712 2713 > method form `udp:recv_start(callback)` 2714 2715 Parameters: 2716 - `udp`: `uv_udp_t userdata` 2717 - `callback`: `callable` 2718 - `err`: `nil` or `string` 2719 - `data`: `string` or `nil` 2720 - `addr`: `table` or `nil` 2721 - `ip`: `string` 2722 - `port`: `integer` 2723 - `family`: `string` 2724 - `flags`: `table` 2725 - `partial`: `boolean` or `nil` 2726 - `mmsg_chunk`: `boolean` or `nil` 2727 2728 Prepare for receiving data. If the socket has not previously 2729 been bound with |uv.udp_bind()| it is bound to `0.0.0.0` (the 2730 "all interfaces" IPv4 address) and a random port number. 2731 2732 See |luv-constants| for supported address `family` output values. 2733 2734 Returns: `0` or `fail` 2735 2736uv.udp_recv_stop({udp}) *uv.udp_recv_stop()* 2737 2738 > method form `udp:recv_stop()` 2739 2740 Parameters: 2741 - `udp`: `uv_udp_t userdata` 2742 2743 Stop listening for incoming datagrams. 2744 2745 Returns: `0` or `fail` 2746 2747uv.udp_connect({udp}, {host}, {port}) *uv.udp_connect()* 2748 2749 > method form `udp:connect(host, port)` 2750 2751 Parameters: 2752 - `udp`: `uv_udp_t userdata` 2753 - `host`: `string` 2754 - `port`: `integer` 2755 2756 Associate the UDP handle to a remote address and port, so 2757 every message sent by this handle is automatically sent to 2758 that destination. Calling this function with a NULL addr 2759 disconnects the handle. Trying to call `uv.udp_connect()` on 2760 an already connected handle will result in an `EISCONN` error. 2761 Trying to disconnect a handle that is not connected will 2762 return an `ENOTCONN` error. 2763 2764 Returns: `0` or `fail` 2765 2766============================================================================== 2767`uv_fs_event_t` — FS Event handle *luv-fs-event-handle* *uv_fs_event_t* 2768 2769> |uv_handle_t| functions also apply. 2770 2771FS Event handles allow the user to monitor a given path for changes, for 2772example, if the file was renamed or there was a generic change in it. This 2773handle uses the best backend for the job on each platform. 2774 2775uv.new_fs_event() *uv.new_fs_event()* 2776 2777 Creates and initializes a new |uv_fs_event_t|. Returns the Lua 2778 userdata wrapping it. 2779 2780 Returns: `uv_fs_event_t userdata` or `fail` 2781 2782uv.fs_event_start({fs_event}, {path}, {flags}, {callback}) *uv.fs_event_start()* 2783 2784 > method form `fs_event:start(path, flags, callback)` 2785 2786 Parameters: 2787 - `fs_event`: `uv_fs_event_t userdata` 2788 - `path`: `string` 2789 - `flags`: `table` 2790 - `watch_entry`: `boolean` or `nil` (default: `false`) 2791 - `stat`: `boolean` or `nil` (default: `false`) 2792 - `recursive`: `boolean` or `nil` (default: `false`) 2793 - `callback`: `callable` 2794 - `err`: `nil` or `string` 2795 - `filename`: `string` 2796 - `events`: `table` 2797 - `change`: `boolean` or `nil` 2798 - `rename`: `boolean` or `nil` 2799 2800 Start the handle with the given callback, which will watch the 2801 specified path for changes. 2802 2803 Returns: `0` or `fail` 2804 2805uv.fs_event_stop() *uv.fs_event_stop()* 2806 2807 > method form `fs_event:stop()` 2808 2809 Stop the handle, the callback will no longer be called. 2810 2811 Returns: `0` or `fail` 2812 2813uv.fs_event_getpath() *uv.fs_event_getpath()* 2814 2815 > method form `fs_event:getpath()` 2816 2817 Get the path being monitored by the handle. 2818 2819 Returns: `string` or `fail` 2820 2821============================================================================== 2822`uv_fs_poll_t` — FS Poll handle *luv-fs-poll-handle* *uv_fs_poll_t* 2823 2824> |uv_handle_t| functions also apply. 2825 2826FS Poll handles allow the user to monitor a given path for changes. Unlike 2827|uv_fs_event_t|, fs poll handles use `stat` to detect when a file has changed 2828so they can work on file systems where fs event handles can't. 2829 2830uv.new_fs_poll() *uv.new_fs_poll()* 2831 2832 Creates and initializes a new |uv_fs_poll_t|. Returns the Lua 2833 userdata wrapping it. 2834 2835 Returns: `uv_fs_poll_t userdata` or `fail` 2836 2837uv.fs_poll_start({fs_poll}, {path}, {interval}, {callback}) *uv.fs_poll_start()* 2838 2839 > method form `fs_poll:start(path, interval, callback)` 2840 2841 Parameters: 2842 - `fs_poll`: `uv_fs_poll_t userdata` 2843 - `path`: `string` 2844 - `interval`: `integer` 2845 - `callback`: `callable` 2846 - `err`: `nil` or `string` 2847 - `prev`: `table` or `nil` (see `uv.fs_stat`) 2848 - `curr`: `table` or `nil` (see `uv.fs_stat`) 2849 2850 Check the file at `path` for changes every `interval` 2851 milliseconds. 2852 2853 Note: For maximum portability, use multi-second intervals. 2854 Sub-second intervals will not detect all changes on many file 2855 systems. 2856 2857 Returns: `0` or `fail` 2858 2859uv.fs_poll_stop() *uv.fs_poll_stop()* 2860 2861 > method form `fs_poll:stop()` 2862 2863 Stop the handle, the callback will no longer be called. 2864 2865 Returns: `0` or `fail` 2866 2867uv.fs_poll_getpath() *uv.fs_poll_getpath()* 2868 2869 > method form `fs_poll:getpath()` 2870 2871 Get the path being monitored by the handle. 2872 2873 Returns: `string` or `fail` 2874 2875============================================================================== 2876FILE SYSTEM OPERATIONS *luv-file-system-operations* *uv_fs_t* 2877 2878Most file system functions can operate synchronously or asynchronously. When a 2879synchronous version is called (by omitting a callback), the function will 2880immediately return the results of the FS call. When an asynchronous version is 2881called (by providing a callback), the function will immediately return a 2882`uv_fs_t userdata` and asynchronously execute its callback; if an error is 2883encountered, the first and only argument passed to the callback will be the 2884`err` error string; if the operation completes successfully, the first 2885argument will be `nil` and the remaining arguments will be the results of the 2886FS call. 2887 2888Synchronous and asynchronous versions of `readFile` (with naive error 2889handling) are implemented below as an example: 2890 2891 >lua 2892 local function readFileSync(path) 2893 local fd = assert(uv.fs_open(path, "r", 438)) 2894 local stat = assert(uv.fs_fstat(fd)) 2895 local data = assert(uv.fs_read(fd, stat.size, 0)) 2896 assert(uv.fs_close(fd)) 2897 return data 2898 end 2899 2900 local data = readFileSync("main.lua") 2901 print("synchronous read", data) 2902< 2903 2904 >lua 2905 local function readFile(path, callback) 2906 uv.fs_open(path, "r", 438, function(err, fd) 2907 assert(not err, err) 2908 uv.fs_fstat(fd, function(err, stat) 2909 assert(not err, err) 2910 uv.fs_read(fd, stat.size, 0, function(err, data) 2911 assert(not err, err) 2912 uv.fs_close(fd, function(err) 2913 assert(not err, err) 2914 return callback(data) 2915 end) 2916 end) 2917 end) 2918 end) 2919 end 2920 2921 readFile("main.lua", function(data) 2922 print("asynchronous read", data) 2923 end) 2924< 2925 2926uv.fs_close({fd} [, {callback}]) *uv.fs_close()* 2927 2928 Parameters: 2929 - `fd`: `integer` 2930 - `callback`: `callable` (async version) or `nil` (sync 2931 version) 2932 - `err`: `nil` or `string` 2933 - `success`: `boolean` or `nil` 2934 2935 Equivalent to `close(2)`. 2936 2937 Returns (sync version): `boolean` or `fail` 2938 2939 Returns (async version): `uv_fs_t userdata` 2940 2941uv.fs_open({path}, {flags}, {mode} [, {callback}]) *uv.fs_open()* 2942 2943 Parameters: 2944 - `path`: `string` 2945 - `flags`: `string` or `integer` 2946 - `mode`: `integer` (octal `chmod(1)` mode, e.g. 2947 `tonumber('644', 8)`) 2948 - `callback`: `callable` (async version) or `nil` (sync 2949 version) 2950 - `err`: `nil` or `string` 2951 - `fd`: `integer` or `nil` 2952 2953 Equivalent to `open(2)`. Access `flags` may be an integer or 2954 one of: `"r"`, `"rs"`, `"sr"`, `"r+"`, `"rs+"`, `"sr+"`, 2955 `"w"`, `"wx"`, `"xw"`, `"w+"`, `"wx+"`, `"xw+"`, `"a"`, 2956 `"ax"`, `"xa"`, `"a+"`, `"ax+"`, or "`xa+`". 2957 2958 Returns (sync version): `integer` or `fail` 2959 2960 Returns (async version): `uv_fs_t userdata` 2961 2962 Note: On Windows, libuv uses `CreateFileW` and thus the file 2963 is always opened in binary mode. Because of this, the 2964 `O_BINARY` and `O_TEXT` flags are not supported. 2965 2966uv.fs_read({fd}, {size} [, {offset} [, {callback}]]) *uv.fs_read()* 2967 2968 Parameters: 2969 - `fd`: `integer` 2970 - `size`: `integer` 2971 - `offset`: `integer` or `nil` 2972 - `callback`: `callable` (async version) or `nil` (sync 2973 version) 2974 - `err`: `nil` or `string` 2975 - `data`: `string` or `nil` 2976 2977 Equivalent to `preadv(2)`. Returns any data. An empty string 2978 indicates EOF. 2979 2980 If `offset` is nil or omitted, it will default to `-1`, which 2981 indicates "use and update the current file offset." 2982 2983 Note: When `offset` is >= 0, the current file offset will not 2984 be updated by the read. 2985 2986 Returns (sync version): `string` or `fail` 2987 2988 Returns (async version): `uv_fs_t userdata` 2989 2990uv.fs_unlink({path} [, {callback}]) *uv.fs_unlink()* 2991 2992 Parameters: 2993 - `path`: `string` 2994 - `callback`: `callable` (async version) or `nil` (sync 2995 version) 2996 - `err`: `nil` or `string` 2997 - `success`: `boolean` or `nil` 2998 2999 Equivalent to `unlink(2)`. 3000 3001 Returns (sync version): `boolean` or `fail` 3002 3003 Returns (async version): `uv_fs_t userdata` 3004 3005uv.fs_write({fd}, {data} [, {offset} [, {callback}]]) *uv.fs_write()* 3006 3007 Parameters: 3008 - `fd`: `integer` 3009 - `data`: `buffer` 3010 - `offset`: `integer` or `nil` 3011 - `callback`: `callable` (async version) or `nil` (sync 3012 version) 3013 - `err`: `nil` or `string` 3014 - `bytes`: `integer` or `nil` 3015 3016 Equivalent to `pwritev(2)`. Returns the number of bytes 3017 written. 3018 3019 If `offset` is nil or omitted, it will default to `-1`, which 3020 indicates "use and update the current file offset." 3021 3022 Note: When `offset` is >= 0, the current file offset will not 3023 be updated by the write. 3024 3025 Returns (sync version): `integer` or `fail` 3026 3027 Returns (async version): `uv_fs_t userdata` 3028 3029uv.fs_mkdir({path}, {mode} [, {callback}]) *uv.fs_mkdir()* 3030 3031 Parameters: 3032 - `path`: `string` 3033 - `mode`: `integer` (octal representation of `chmod(1)` mode, 3034 e.g. `tonumber('755', 8)`) 3035 - `callback`: `callable` (async version) or `nil` (sync 3036 version) 3037 - `err`: `nil` or `string` 3038 - `success`: `boolean` or `nil` 3039 3040 Equivalent to `mkdir(2)`. 3041 3042 Returns (sync version): `boolean` or `fail` 3043 3044 Returns (async version): `uv_fs_t userdata` 3045 3046uv.fs_mkdtemp({template} [, {callback}]) *uv.fs_mkdtemp()* 3047 3048 Parameters: 3049 - `template`: `string` 3050 - `callback`: `callable` (async version) or `nil` (sync 3051 version) 3052 - `err`: `nil` or `string` 3053 - `path`: `string` or `nil` 3054 3055 Equivalent to `mkdtemp(3)`. 3056 3057 Returns (sync version): `string` or `fail` 3058 3059 Returns (async version): `uv_fs_t userdata` 3060 3061uv.fs_mkstemp({template} [, {callback}]) *uv.fs_mkstemp()* 3062 3063 Parameters: 3064 - `template`: `string` 3065 - `callback`: `callable` (async version) or `nil` (sync 3066 version) 3067 - `err`: `nil` or `string` 3068 - `fd`: `integer` or `nil` 3069 - `path`: `string` or `nil` 3070 3071 Equivalent to `mkstemp(3)`. Returns a temporary file handle 3072 and filename. 3073 3074 Returns (sync version): `integer, string` or `fail` 3075 3076 Returns (async version): `uv_fs_t userdata` 3077 3078uv.fs_rmdir({path} [, {callback}]) *uv.fs_rmdir()* 3079 3080 Parameters: 3081 - `path`: `string` 3082 - `callback`: `callable` (async version) or `nil` (sync 3083 version) 3084 - `err`: `nil` or `string` 3085 - `success`: `boolean` or `nil` 3086 3087 Equivalent to `rmdir(2)`. 3088 3089 Returns (sync version): `boolean` or `fail` 3090 3091 Returns (async version): `uv_fs_t userdata` 3092 3093uv.fs_scandir({path} [, {callback}]) *uv.fs_scandir()* 3094 3095 Parameters: 3096 - `path`: `string` 3097 - `callback`: `callable` 3098 - `err`: `nil` or `string` 3099 - `success`: `uv_fs_t userdata` or `nil` 3100 3101 Equivalent to `scandir(3)`, with a slightly different API. 3102 Returns a handle that the user can pass to 3103 |uv.fs_scandir_next()|. 3104 3105 Note: This function can be used synchronously or 3106 asynchronously. The request userdata is always synchronously 3107 returned regardless of whether a callback is provided and the 3108 same userdata is passed to the callback if it is provided. 3109 3110 Returns: `uv_fs_t userdata` or `fail` 3111 3112uv.fs_scandir_next({fs}) *uv.fs_scandir_next()* 3113 3114 Parameters: 3115 - `fs`: `uv_fs_t userdata` 3116 3117 Called on a |uv_fs_t| returned by |uv.fs_scandir()| to get the 3118 next directory entry data as a `name, type` pair. When there 3119 are no more entries, `nil` is returned. 3120 3121 Note: This function only has a synchronous version. See 3122 |uv.fs_opendir()| and its related functions for an 3123 asynchronous version. 3124 3125 Returns: `string, string` or `nil` or `fail` 3126 3127uv.fs_stat({path} [, {callback}]) *uv.fs_stat()* 3128 3129 Parameters: 3130 - `path`: `string` 3131 - `callback`: `callable` (async version) or `nil` (sync 3132 version) 3133 - `err`: `nil` or `string` 3134 - `stat`: `table` or `nil` (see below) 3135 3136 Equivalent to `stat(2)`. 3137 3138 Returns (sync version): `table` or `fail` 3139 - `dev` : `integer` 3140 - `mode` : `integer` 3141 - `nlink` : `integer` 3142 - `uid` : `integer` 3143 - `gid` : `integer` 3144 - `rdev` : `integer` 3145 - `ino` : `integer` 3146 - `size` : `integer` 3147 - `blksize` : `integer` 3148 - `blocks` : `integer` 3149 - `flags` : `integer` 3150 - `gen` : `integer` 3151 - `atime` : `table` 3152 - `sec` : `integer` 3153 - `nsec` : `integer` 3154 - `mtime` : `table` 3155 - `sec` : `integer` 3156 - `nsec` : `integer` 3157 - `ctime` : `table` 3158 - `sec` : `integer` 3159 - `nsec` : `integer` 3160 - `birthtime` : `table` 3161 - `sec` : `integer` 3162 - `nsec` : `integer` 3163 - `type` : `string` 3164 3165 Returns (async version): `uv_fs_t userdata` 3166 3167uv.fs_fstat({fd} [, {callback}]) *uv.fs_fstat()* 3168 3169 Parameters: 3170 - `fd`: `integer` 3171 - `callback`: `callable` (async version) or `nil` (sync 3172 version) 3173 - `err`: `nil` or `string` 3174 - `stat`: `table` or `nil` (see `uv.fs_stat`) 3175 3176 Equivalent to `fstat(2)`. 3177 3178 Returns (sync version): `table` or `fail` (see `uv.fs_stat`) 3179 3180 Returns (async version): `uv_fs_t userdata` 3181 3182uv.fs_lstat({path} [, {callback}]) *uv.fs_lstat()* 3183 3184 Parameters: 3185 - `path`: `string` 3186 - `callback`: `callable` (async version) or `nil` (sync 3187 version) 3188 - `err`: `nil` or `string` 3189 - `stat`: `table` or `nil` (see `uv.fs_stat`) 3190 3191 Equivalent to `lstat(2)`. 3192 3193 Returns (sync version): `table` or `fail` (see |uv.fs_stat()|) 3194 3195 Returns (async version): `uv_fs_t userdata` 3196 3197uv.fs_rename({path}, {new_path} [, {callback}]) *uv.fs_rename()* 3198 3199 Parameters: 3200 - `path`: `string` 3201 - `new_path`: `string` 3202 - `callback`: `callable` (async version) or `nil` (sync 3203 version) 3204 - `err`: `nil` or `string` 3205 - `success`: `boolean` or `nil` 3206 3207 Equivalent to `rename(2)`. 3208 3209 Returns (sync version): `boolean` or `fail` 3210 3211 Returns (async version): `uv_fs_t userdata` 3212 3213uv.fs_fsync({fd} [, {callback}]) *uv.fs_fsync()* 3214 3215 Parameters: 3216 - `fd`: `integer` 3217 - `callback`: `callable` (async version) or `nil` (sync 3218 version) 3219 - `err`: `nil` or `string` 3220 - `success`: `boolean` or `nil` 3221 3222 Equivalent to `fsync(2)`. 3223 3224 Returns (sync version): `boolean` or `fail` 3225 3226 Returns (async version): `uv_fs_t userdata` 3227 3228uv.fs_fdatasync({fd} [, {callback}]) *uv.fs_fdatasync()* 3229 3230 Parameters: 3231 - `fd`: `integer` 3232 - `callback`: `callable` (async version) or `nil` (sync 3233 version) 3234 - `err`: `nil` or `string` 3235 - `success`: `boolean` or `nil` 3236 3237 Equivalent to `fdatasync(2)`. 3238 3239 Returns (sync version): `boolean` or `fail` 3240 3241 Returns (async version): `uv_fs_t userdata` 3242 3243uv.fs_ftruncate({fd}, {offset} [, {callback}]) *uv.fs_ftruncate()* 3244 3245 Parameters: 3246 - `fd`: `integer` 3247 - `offset`: `integer` 3248 - `callback`: `callable` (async version) or `nil` (sync 3249 version) 3250 - `err`: `nil` or `string` 3251 - `success`: `boolean` or `nil` 3252 3253 Equivalent to `ftruncate(2)`. 3254 3255 Returns (sync version): `boolean` or `fail` 3256 3257 Returns (async version): `uv_fs_t userdata` 3258 3259 *uv.fs_sendfile()* 3260uv.fs_sendfile({out_fd}, {in_fd}, {in_offset}, {size} [, {callback}]) 3261 3262 Parameters: 3263 - `out_fd`: `integer` 3264 - `in_fd`: `integer` 3265 - `in_offset`: `integer` 3266 - `size`: `integer` 3267 - `callback`: `callable` (async version) or `nil` (sync 3268 version) 3269 - `err`: `nil` or `string` 3270 - `bytes`: `integer` or `nil` 3271 3272 Limited equivalent to `sendfile(2)`. Returns the number of 3273 bytes written. 3274 3275 Returns (sync version): `integer` or `fail` 3276 3277 Returns (async version): `uv_fs_t userdata` 3278 3279uv.fs_access({path}, {mode} [, {callback}]) *uv.fs_access()* 3280 3281 Parameters: 3282 - `path`: `string` 3283 - `mode`: `integer` `string` (a combination of the `'r'`, 3284 `'w'` and `'x'` characters denoting the symbolic mode as per 3285 `chmod(1)`) 3286 - `callback`: `callable` (async version) or `nil` (sync 3287 version) 3288 - `err`: `nil` or `string` 3289 - `permission`: `boolean` or `nil` 3290 3291 Equivalent to `access(2)` on Unix. Windows uses 3292 `GetFileAttributesW()`. Access `mode` can be an integer or a 3293 string containing `"R"` or `"W"` or `"X"`. Returns `true` or 3294 `false` indicating access permission. 3295 3296 Returns (sync version): `boolean` or `fail` 3297 3298 Returns (async version): `uv_fs_t userdata` 3299 3300uv.fs_chmod({path}, {mode} [, {callback}]) *uv.fs_chmod()* 3301 3302 Parameters: 3303 - `path`: `string` 3304 - `mode`: `integer` (octal representation of `chmod(1)` mode, 3305 e.g. `tonumber('644', 8)`) 3306 - `callback`: `callable` (async version) or `nil` (sync 3307 version) 3308 - `err`: `nil` or `string` 3309 - `success`: `boolean` or `nil` 3310 3311 Equivalent to `chmod(2)`. 3312 3313 Returns (sync version): `boolean` or `fail` 3314 3315 Returns (async version): `uv_fs_t userdata` 3316 3317uv.fs_fchmod({fd}, {mode} [, {callback}]) *uv.fs_fchmod()* 3318 3319 Parameters: 3320 - `fd`: `integer` 3321 - `mode`: `integer` 3322 - `callback`: `callable` (async version) or `nil` (sync 3323 version) 3324 - `err`: `nil` or `string` 3325 - `success`: `boolean` or `nil` 3326 3327 Equivalent to `fchmod(2)`. 3328 3329 Returns (sync version): `boolean` or `fail` 3330 3331 Returns (async version): `uv_fs_t userdata` 3332 3333uv.fs_utime({path} [, {atime}, {mtime}, {callback}]) *uv.fs_utime()* 3334 3335 Parameters: 3336 - `path`: `string` 3337 - `atime`: `number` or `string` or `nil` 3338 - `mtime`: `number` or `string` or `nil` 3339 - `callback`: `callable` (async version) or `nil` (sync 3340 version) 3341 - `err`: `nil` or `string` 3342 - `success`: `boolean` or `nil` 3343 3344 Equivalent to `utime(2)`. 3345 3346 See |luv-constants| for supported FS Modification Time 3347 constants. 3348 3349 Passing `"now"` or `uv.constants.FS_UTIME_NOW` as the atime or 3350 mtime sets the timestamp to the current time. 3351 3352 Passing `nil`, `"omit"`, or `uv.constants.FS_UTIME_OMIT` as 3353 the atime or mtime leaves the timestamp untouched. 3354 3355 Returns (sync version): `boolean` or `fail` 3356 3357 Returns (async version): `uv_fs_t userdata` 3358 3359uv.fs_futime({fd} [, {atime}, {mtime}, {callback}]) *uv.fs_futime()* 3360 3361 Parameters: 3362 - `fd`: `integer` 3363 - `atime`: `number` or `string` or `nil` 3364 - `mtime`: `number` or `string` or `nil` 3365 - `callback`: `callable` (async version) or `nil` (sync 3366 version) 3367 - `err`: `nil` or `string` 3368 - `success`: `boolean` or `nil` 3369 3370 Equivalent to `futimes(3)`. 3371 3372 See |luv-constants| for supported FS Modification Time 3373 constants. 3374 3375 Passing `"now"` or `uv.constants.FS_UTIME_NOW` as the atime or 3376 mtime sets the timestamp to the current time. 3377 3378 Passing `nil`, `"omit"`, or `uv.constants.FS_UTIME_OMIT` as 3379 the atime or mtime leaves the timestamp untouched. 3380 3381 Returns (sync version): `boolean` or `fail` 3382 3383 Returns (async version): `uv_fs_t userdata` 3384 3385uv.fs_lutime({path} [, {atime}, {mtime}, {callback}]) *uv.fs_lutime()* 3386 3387 Parameters: 3388 - `path`: `string` 3389 - `atime`: `number` or `string` or `nil` 3390 - `mtime`: `number` or `string` or `nil` 3391 - `callback`: `callable` (async version) or `nil` (sync 3392 version) 3393 - `err`: `nil` or `string` 3394 - `success`: `boolean` or `nil` 3395 3396 Equivalent to `lutimes(3)`. 3397 3398 See |luv-constants| for supported FS Modification Time 3399 constants. 3400 3401 Passing `"now"` or `uv.constants.FS_UTIME_NOW` as the atime or 3402 mtime sets the timestamp to the current time. 3403 3404 Passing `nil`, `"omit"`, or `uv.constants.FS_UTIME_OMIT` as 3405 the atime or mtime leaves the timestamp untouched. 3406 3407 Returns (sync version): `boolean` or `fail` 3408 3409 Returns (async version): `uv_fs_t userdata` 3410 3411uv.fs_link({path}, {new_path} [, {callback}]) *uv.fs_link()* 3412 3413 Parameters: 3414 - `path`: `string` 3415 - `new_path`: `string` 3416 - `callback`: `callable` (async version) or `nil` (sync 3417 version) 3418 - `err`: `nil` or `string` 3419 - `success`: `boolean` or `nil` 3420 3421 Equivalent to `link(2)`. 3422 3423 Returns (sync version): `boolean` or `fail` 3424 3425 Returns (async version): `uv_fs_t userdata` 3426 3427uv.fs_symlink({path}, {new_path} [, {flags} [, {callback}]]) *uv.fs_symlink()* 3428 3429 Parameters: 3430 - `path`: `string` 3431 - `new_path`: `string` 3432 - `flags`: `table`, `integer`, or `nil` 3433 - `dir`: `boolean` 3434 - `junction`: `boolean` 3435 - `callback`: `callable` (async version) or `nil` (sync 3436 version) 3437 - `err`: `nil` or `string` 3438 - `success`: `boolean` or `nil` 3439 3440 Equivalent to `symlink(2)`. If the `flags` parameter is 3441 omitted, then the 3rd parameter will be treated as the 3442 `callback`. 3443 3444 Returns (sync version): `boolean` or `fail` 3445 3446 Returns (async version): `uv_fs_t userdata` 3447 3448uv.fs_readlink({path} [, {callback}]) *uv.fs_readlink()* 3449 3450 Parameters: 3451 - `path`: `string` 3452 - `callback`: `callable` (async version) or `nil` (sync 3453 version) 3454 - `err`: `nil` or `string` 3455 - `path`: `string` or `nil` 3456 3457 Equivalent to `readlink(2)`. 3458 3459 Returns (sync version): `string` or `fail` 3460 3461 Returns (async version): `uv_fs_t userdata` 3462 3463uv.fs_realpath({path} [, {callback}]) *uv.fs_realpath()* 3464 3465 Parameters: 3466 - `path`: `string` 3467 - `callback`: `callable` (async version) or `nil` (sync 3468 version) 3469 - `err`: `nil` or `string` 3470 - `path`: `string` or `nil` 3471 3472 Equivalent to `realpath(3)`. 3473 3474 Returns (sync version): `string` or `fail` 3475 3476 Returns (async version): `uv_fs_t userdata` 3477 3478uv.fs_chown({path}, {uid}, {gid} [, {callback}]) *uv.fs_chown()* 3479 3480 Parameters: 3481 - `path`: `string` 3482 - `uid`: `integer` 3483 - `gid`: `integer` 3484 - `callback`: `callable` (async version) or `nil` (sync 3485 version) 3486 - `err`: `nil` or `string` 3487 - `success`: `boolean` or `nil` 3488 3489 Equivalent to `chown(2)`. 3490 3491 Returns (sync version): `boolean` or `fail` 3492 3493 Returns (async version): `uv_fs_t userdata` 3494 3495uv.fs_fchown({fd}, {uid}, {gid} [, {callback}]) *uv.fs_fchown()* 3496 3497 Parameters: 3498 - `fd`: `integer` 3499 - `uid`: `integer` 3500 - `gid`: `integer` 3501 - `callback`: `callable` (async version) or `nil` (sync 3502 version) 3503 - `err`: `nil` or `string` 3504 - `success`: `boolean` or `nil` 3505 3506 Equivalent to `fchown(2)`. 3507 3508 Returns (sync version): `boolean` or `fail` 3509 3510 Returns (async version): `uv_fs_t userdata` 3511 3512uv.fs_lchown({fd}, {uid}, {gid} [, {callback}]) *uv.fs_lchown()* 3513 3514 Parameters: 3515 - `fd`: `integer` 3516 - `uid`: `integer` 3517 - `gid`: `integer` 3518 - `callback`: `callable` (async version) or `nil` (sync 3519 version) 3520 - `err`: `nil` or `string` 3521 - `success`: `boolean` or `nil` 3522 3523 Equivalent to `lchown(2)`. 3524 3525 Returns (sync version): `boolean` or `fail` 3526 3527 Returns (async version): `uv_fs_t userdata` 3528 3529uv.fs_copyfile({path}, {new_path} [, {flags} [, {callback}]]) *uv.fs_copyfile()* 3530 3531 Parameters: 3532 - `path`: `string` 3533 - `new_path`: `string` 3534 - `flags`: `table`, `integer`, or `nil` 3535 - `excl`: `boolean` 3536 - `ficlone`: `boolean` 3537 - `ficlone_force`: `boolean` 3538 - `callback`: `callable` (async version) or `nil` (sync 3539 version) 3540 - `err`: `nil` or `string` 3541 - `success`: `boolean` or `nil` 3542 3543 Copies a file from path to new_path. If the `flags` parameter 3544 is omitted, then the 3rd parameter will be treated as the 3545 `callback`. 3546 3547 Returns (sync version): `boolean` or `fail` 3548 3549 Returns (async version): `uv_fs_t userdata` 3550 3551uv.fs_opendir({path} [, {callback} [, {entries}]]) *uv.fs_opendir()* 3552 3553 Parameters: 3554 - `path`: `string` 3555 - `callback`: `callable` (async version) or `nil` (sync 3556 version) 3557 - `err`: `nil` or `string` 3558 - `dir`: `luv_dir_t userdata` or `nil` 3559 - `entries`: `integer` or `nil` 3560 3561 Opens path as a directory stream. Returns a handle that the 3562 user can pass to |uv.fs_readdir()|. The `entries` parameter 3563 defines the maximum number of entries that should be returned 3564 by each call to |uv.fs_readdir()|. 3565 3566 Returns (sync version): `luv_dir_t userdata` or `fail` 3567 3568 Returns (async version): `uv_fs_t userdata` 3569 3570uv.fs_readdir({dir} [, {callback}]) *uv.fs_readdir()* 3571 3572 > method form `dir:readdir([callback])` 3573 3574 Parameters: 3575 - `dir`: `luv_dir_t userdata` 3576 - `callback`: `callable` (async version) or `nil` (sync 3577 version) 3578 - `err`: `nil` or `string` 3579 - `entries`: `table` or `nil` (see below) 3580 3581 Iterates over the directory stream `luv_dir_t` returned by a 3582 successful |uv.fs_opendir()| call. A table of data tables is 3583 returned where the number of entries `n` is equal to or less 3584 than the `entries` parameter used in the associated 3585 |uv.fs_opendir()| call. 3586 3587 Returns (sync version): `table` or `fail` 3588 - `[1, 2, 3, ..., n]` : `table` 3589 - `name` : `string` 3590 - `type` : `string` 3591 3592 Returns (async version): `uv_fs_t userdata` 3593 3594uv.fs_closedir({dir} [, {callback}]) *uv.fs_closedir()* 3595 3596 > method form `dir:closedir([callback])` 3597 3598 Parameters: 3599 - `dir`: `luv_dir_t userdata` 3600 - `callback`: `callable` (async version) or `nil` (sync 3601 version) 3602 - `err`: `nil` or `string` 3603 - `success`: `boolean` or `nil` 3604 3605 Closes a directory stream returned by a successful 3606 |uv.fs_opendir()| call. 3607 3608 Returns (sync version): `boolean` or `fail` 3609 3610 Returns (async version): `uv_fs_t userdata` 3611 3612uv.fs_statfs({path} [, {callback}]) *uv.fs_statfs()* 3613 3614 Parameters: 3615 - `path`: `string` 3616 - `callback`: `callable` (async version) or `nil` (sync 3617 version) 3618 - `err`: `nil` or `string` 3619 - `table` or `nil` (see below) 3620 3621 Equivalent to `statfs(2)`. 3622 3623 Returns `table` or `nil` 3624 - `type` : `integer` 3625 - `bsize` : `integer` 3626 - `blocks` : `integer` 3627 - `bfree` : `integer` 3628 - `bavail` : `integer` 3629 - `files` : `integer` 3630 - `ffree` : `integer` 3631 - `frsize`: `integer` or `nil` 3632 3633============================================================================== 3634THREAD POOL WORK SCHEDULING *luv-thread-pool-work-scheduling* 3635 3636Libuv provides a threadpool which can be used to run user code and get 3637notified in the loop thread. This threadpool is internally used to run all 3638file system operations, as well as `getaddrinfo` and `getnameinfo` requests. 3639 3640 >lua 3641 local function work_callback(a, b) 3642 return a + b 3643 end 3644 3645 local function after_work_callback(c) 3646 print("The result is: " .. c) 3647 end 3648 3649 local work = uv.new_work(work_callback, after_work_callback) 3650 3651 work:queue(1, 2) 3652 3653 -- output: "The result is: 3" 3654< 3655 3656uv.new_work({work_callback}, {after_work_callback}) *uv.new_work()* 3657 3658 Parameters: 3659 - `work_callback`: `function` or `string` 3660 - `...`: `threadargs` passed to/from 3661 `uv.queue_work(work_ctx, ...)` 3662 - `after_work_callback`: `function` 3663 - `...`: `threadargs` returned from `work_callback` 3664 3665 Creates and initializes a new `luv_work_ctx_t` (not 3666 `uv_work_t`). 3667 `work_callback` is a Lua function or a string containing Lua 3668 code or bytecode dumped from a function. Returns the Lua 3669 userdata wrapping it. 3670 3671 Returns: `luv_work_ctx_t userdata` 3672 3673uv.queue_work({work_ctx}, {...}) *uv.queue_work()* 3674 3675 > method form `work_ctx:queue(...)` 3676 3677 Parameters: 3678 - `work_ctx`: `luv_work_ctx_t userdata` 3679 - `...`: `threadargs` 3680 3681 Queues a work request which will run `work_callback` in a new 3682 Lua state in a thread from the threadpool with any additional 3683 arguments from `...`. Values returned from `work_callback` are 3684 passed to `after_work_callback`, which is called in the main 3685 loop thread. 3686 3687 Returns: `boolean` or `fail` 3688 3689============================================================================== 3690DNS UTILITY FUNCTIONS *luv-dns-utility-functions* 3691 3692uv.getaddrinfo({host}, {service} [, {hints} [, {callback}]]) *uv.getaddrinfo()* 3693 3694 Parameters: 3695 - `host`: `string` or `nil` 3696 - `service`: `string` or `nil` 3697 - `hints`: `table` or `nil` 3698 - `family`: `string` or `integer` or `nil` 3699 - `socktype`: `string` or `integer` or `nil` 3700 - `protocol`: `string` or `integer` or `nil` 3701 - `addrconfig`: `boolean` or `nil` 3702 - `v4mapped`: `boolean` or `nil` 3703 - `all`: `boolean` or `nil` 3704 - `numerichost`: `boolean` or `nil` 3705 - `passive`: `boolean` or `nil` 3706 - `numericserv`: `boolean` or `nil` 3707 - `canonname`: `boolean` or `nil` 3708 - `callback`: `callable` (async version) or `nil` (sync 3709 version) 3710 - `err`: `nil` or `string` 3711 - `addresses`: `table` or `nil` (see below) 3712 3713 Equivalent to `getaddrinfo(3)`. Either `node` or `service` may 3714 be `nil` but not both. 3715 3716 See |luv-constants| for supported address `family` input and 3717 output values. 3718 3719 See |luv-constants| for supported `socktype` input and 3720 output values. 3721 3722 When `protocol` is set to `0` or `nil`, it will be 3723 automatically chosen based on the socket's domain and type. 3724 When `protocol` is specified as a string, it will be looked up 3725 using the `getprotobyname(3)` function. Examples: `"ip"`, 3726 `"icmp"`, `"tcp"`, `"udp"`, etc. 3727 3728 Returns (sync version): `table` or `fail` 3729 - `[1, 2, 3, ..., n]` : `table` 3730 - `addr` : `string` 3731 - `family` : `string` 3732 - `port` : `integer` or `nil` 3733 - `socktype` : `string` 3734 - `protocol` : `string` 3735 - `canonname` : `string` or `nil` 3736 3737 Returns (async version): `uv_getaddrinfo_t userdata` or `fail` 3738 3739uv.getnameinfo({address} [, {callback}]) *uv.getnameinfo()* 3740 3741 Parameters: 3742 - `address`: `table` 3743 - `ip`: `string` or `nil` 3744 - `port`: `integer` or `nil` 3745 - `family`: `string` or `integer` or `nil` 3746 - `callback`: `callable` (async version) or `nil` (sync 3747 version) 3748 - `err`: `nil` or `string` 3749 - `host`: `string` or `nil` 3750 - `service`: `string` or `nil` 3751 3752 Equivalent to `getnameinfo(3)`. 3753 3754 See |luv-constants| for supported address `family` input values. 3755 3756 Returns (sync version): `string, string` or `fail` 3757 3758 Returns (async version): `uv_getnameinfo_t userdata` or `fail` 3759 3760============================================================================== 3761THREADING AND SYNCHRONIZATION UTILITIES *luv-threading-and-synchronization-utilities* 3762 3763Libuv provides cross-platform implementations for multiple threading and 3764synchronization primitives. The API largely follows the pthreads API. 3765 3766uv.new_thread([{options}, ] {entry}, {...}) *uv.new_thread()* 3767 3768 Parameters: 3769 - `options`: `table` or `nil` 3770 - `stack_size`: `integer` or `nil` 3771 - `entry`: `function` or `string` 3772 - `...`: `threadargs` passed to `entry` 3773 3774 Creates and initializes a `luv_thread_t` (not `uv_thread_t`). 3775 Returns the Lua userdata wrapping it and asynchronously 3776 executes `entry`, which can be either a Lua function or a 3777 string containing Lua code or bytecode dumped from a function. 3778 Additional arguments `...` are passed to the `entry` function 3779 and an optional `options` table may be provided. Currently 3780 accepted `option` fields are `stack_size`. 3781 3782 Returns: `luv_thread_t userdata` or `fail` 3783 3784 Note: unsafe, please make sure that the thread's end of life 3785 is before Lua state is closed. 3786 3787uv.thread_equal({thread}, {other_thread}) *uv.thread_equal()* 3788 3789 > method form `thread:equal(other_thread)` 3790 3791 Parameters: 3792 - `thread`: `luv_thread_t userdata` 3793 - `other_thread`: `luv_thread_t userdata` 3794 3795 Returns a boolean indicating whether two threads are the same. 3796 This function is equivalent to the `__eq` metamethod. 3797 3798 Returns: `boolean` 3799 *uv.thread_setaffinity()* 3800uv.thread_setaffinity({thread}, {affinity} [, {get_old_affinity}]) 3801 3802 > method form `thread:setaffinity(affinity, [get_old_affinity])` 3803 3804 Parameters: 3805 - `thread`: `luv_thread_t userdata` 3806 - `affinity`: `table` 3807 - `[1, 2, 3, ..., n]` : `boolean` 3808 - `get_old_affinity`: `boolean` 3809 3810 Sets the specified thread's affinity setting. 3811 3812 `affinity` must be a table where each of the keys are a CPU 3813 number and the values are booleans that represent whether the 3814 `thread` should be eligible to run on that CPU. If the length 3815 of the `affinity` table is not greater than or equal to 3816 |uv.cpumask_size()|, any CPU numbers missing from the table 3817 will have their affinity set to `false`. If setting the 3818 affinity of more than |uv.cpumask_size()| CPUs is desired, 3819 `affinity` must be an array-like table with no gaps, since 3820 `#affinity` will be used as the `cpumask_size` if it is 3821 greater than |uv.cpumask_size()|. 3822 3823 If `get_old_affinity` is `true`, the previous affinity 3824 settings for the `thread` will be returned. Otherwise, `true` 3825 is returned after a successful call. 3826 3827 Note: Thread affinity setting is not atomic on Windows. 3828 Unsupported on macOS. 3829 3830 Returns: `table` or `boolean` or `fail` 3831 - `[1, 2, 3, ..., n]` : `boolean` 3832 3833 3834uv.thread_getaffinity({thread} [, {mask_size}]) *uv.thread_getaffinity()* 3835 3836 > method form `thread:getaffinity([mask_size])` 3837 3838 Parameters: 3839 - `thread`: `luv_thread_t userdata` 3840 - `mask_size`: `integer` 3841 3842 Gets the specified thread's affinity setting. 3843 3844 If `mask_size` is provided, it must be greater than or equal 3845 to `uv.cpumask_size()`. If the `mask_size` parameter is 3846 omitted, then the return of `uv.cpumask_size()` will be used. 3847 Returns an array-like table where each of the keys correspond 3848 to a CPU number and the values are booleans that represent 3849 whether the `thread` is eligible to run on that CPU. 3850 3851 Note: Thread affinity getting is not atomic on Windows. 3852 Unsupported on macOS. 3853 3854 Returns: `table` or `fail` 3855 - `[1, 2, 3, ..., n]` : `boolean` 3856 3857uv.thread_getcpu() *uv.thread_getcpu()* 3858 3859 Gets the CPU number on which the calling thread is running. 3860 3861 Note: The first CPU will be returned as the number 1, not 0. 3862 This allows for the number to correspond with the table keys 3863 used in `uv.thread_getaffinity` and `uv.thread_setaffinity`. 3864 3865 Returns: `integer` or `fail` 3866 3867uv.thread_setpriority({thread}, {priority}) *uv.thread.setpriority()* 3868 3869 > method form `thread:setpriority(priority)` 3870 3871 Parameters: 3872 - `thread`: `luv_thread_t userdata` 3873 - `priority`: `number` 3874 3875 Sets the specified thread's scheduling priority setting. It 3876 requires elevated privilege to set specific priorities on some 3877 platforms. The priority can be set to the following constants: 3878 - `uv.constants.THREAD_PRIORITY_HIGHEST` 3879 - `uv.constants.THREAD_PRIORITY_ABOVE_NORMAL` 3880 - `uv.constants.THREAD_PRIORITY_NORMAL` 3881 - `uv.constants.THREAD_PRIORITY_BELOW_NORMAL` 3882 - `uv.constants.THREAD_PRIORITY_LOWEST` 3883 3884 Returns: `boolean` or `fail` 3885 3886uv.thread_getpriority({thread}) *uv.thread.getpriority()* 3887 3888 > method form `thread:getpriority()` 3889 3890 Parameters: 3891 - `thread`: `luv_thread_t userdata` 3892 3893 Gets the thread's priority setting. 3894 3895 Retrieves the scheduling priority of the specified thread. The 3896 returned priority value is platform dependent. 3897 3898 For Linux, when schedule policy is SCHED_OTHER (default), 3899 priority is 0. 3900 3901 Returns: `number` or `fail` 3902 3903uv.thread_self() *uv.thread_self()* 3904 3905 Returns the handle for the thread in which this is called. 3906 3907 Returns: `luv_thread_t` 3908 3909uv.thread_join({thread}) *uv.thread_join()* 3910 3911 > method form `thread:join()` 3912 3913 Parameters: 3914 - `thread`: `luv_thread_t userdata` 3915 3916 Waits for the `thread` to finish executing its entry function. 3917 3918 Returns: `boolean` or `fail` 3919 3920uv.thread_detach({thread}) *uv.thread_detach()* 3921 3922 > method form `thread:detach()` 3923 3924 Parameters: 3925 - `thread`: `luv_thread_t userdata` 3926 3927 Detaches a thread. Detached threads automatically release 3928 their resources upon termination, eliminating the need for the 3929 application to call `uv.thread_join`. 3930 3931 Returns: `boolean` or `fail` 3932 3933uv.thread_setname({name}) *uv.thread_setname()* 3934 3935 Parameters: 3936 - `name`: `string` 3937 3938 Sets the name of the current thread. Different platforms 3939 define different limits on the max number of characters a 3940 thread name can be: Linux, IBM i (16), macOS (64), Windows 3941 (32767), and NetBSD (32), etc. The name will be truncated if 3942 `name` is larger than the limit of the platform. 3943 3944 Returns: `0` or `fail` 3945 3946uv.thread_getname({thread}) *uv.thread_getname()* 3947 3948 > method form `thread:getname()` 3949 3950 Parameters: 3951 - `thread`: `luv_thread_t userdata` 3952 3953 Gets the name of the thread specified by `thread`. 3954 3955 Returns: `string` or `fail` 3956 3957uv.sleep({msec}) *uv.sleep()* 3958 3959 Parameters: 3960 - `msec`: `integer` 3961 3962 Pauses the thread in which this is called for a number of 3963 milliseconds. 3964 3965 Returns: Nothing. 3966 3967uv.new_sem([{value}]) *uv.new_sem()* 3968 3969 Parameters: 3970 - `value`: `integer` or `nil` 3971 3972 Creates a new semaphore with the specified initial value. A 3973 semaphore is safe to share across threads. It represents an 3974 unsigned integer value that can incremented and decremented 3975 atomically but any attempt to make it negative will "wait" 3976 until the value can be decremented by another thread 3977 incrementing it. 3978 3979 The initial value must be a non-negative integer. 3980 3981 Returns: `luv_sem_t userdata` or `fail` 3982 3983 Note: A semaphore must be shared between threads, any 3984 `uv.sem_wait()` on a single thread that blocks will deadlock. 3985 3986uv.sem_post({sem}) *uv.sem_post()* 3987 3988 > method form `sem:post()` 3989 3990 Parameters: 3991 - `sem`: `luv_sem_t userdata` 3992 3993 Increments (unlocks) a semaphore, if the semaphore's value 3994 consequently becomes greater than zero then another thread 3995 blocked in a sem_wait call will be woken and proceed to 3996 decrement the semaphore. 3997 3998 Returns: Nothing. 3999 4000uv.sem_wait({sem}) *uv.sem_wait()* 4001 4002 > method form `sem:wait()` 4003 4004 Parameters: 4005 - `sem`: `luv_sem_t userdata` 4006 4007 Decrements (locks) a semaphore, if the semaphore's value is 4008 greater than zero then the value is decremented and the call 4009 returns immediately. If the semaphore's value is zero then the 4010 call blocks until the semaphore's value rises above zero or 4011 the call is interrupted by a signal. 4012 4013 Returns: Nothing. 4014 4015uv.sem_trywait({sem}) *uv.sem_trywait()* 4016 4017 > method form `sem:trywait()` 4018 4019 Parameters: 4020 - `sem`: `luv_sem_t userdata` 4021 4022 The same as `uv.sem_wait()` but returns immediately if the 4023 semaphore is not available. 4024 4025 If the semaphore's value was decremented then `true` is 4026 returned, otherwise the semaphore has a value of zero and 4027 `false` is returned. 4028 4029 Returns: `boolean` 4030 4031============================================================================== 4032MISCELLANEOUS UTILITIES *luv-miscellaneous-utilities* 4033 4034uv.exepath() *uv.exepath()* 4035 4036 Returns the executable path. 4037 4038 Returns: `string` or `fail` 4039 4040uv.cwd() *uv.cwd()* 4041 4042 Returns the current working directory. 4043 4044 Returns: `string` or `fail` 4045 4046uv.chdir({cwd}) *uv.chdir()* 4047 4048 Parameters: 4049 - `cwd`: `string` 4050 4051 Sets the current working directory with the string `cwd`. 4052 4053 Returns: `0` or `fail` 4054 4055uv.get_process_title() *uv.get_process_title()* 4056 4057 Returns the title of the current process. 4058 4059 Returns: `string` or `fail` 4060 4061uv.set_process_title({title}) *uv.set_process_title()* 4062 4063 Parameters: 4064 - `title`: `string` 4065 4066 Sets the title of the current process with the string `title`. 4067 4068 Returns: `0` or `fail` 4069 4070uv.get_total_memory() *uv.get_total_memory()* 4071 4072 Returns the current total system memory in bytes. 4073 4074 Returns: `number` 4075 4076uv.get_free_memory() *uv.get_free_memory()* 4077 4078 Returns the current free system memory in bytes. 4079 4080 Returns: `number` 4081 4082uv.get_constrained_memory() *uv.get_constrained_memory()* 4083 4084 Gets the amount of memory available to the process in bytes 4085 based on limits imposed by the OS. If there is no such 4086 constraint, or the constraint is unknown, 0 is returned. Note 4087 that it is not unusual for this value to be less than or 4088 greater than the total system memory. 4089 4090 Returns: `number` 4091 4092uv.get_available_memory() *uv.get_available_memory()* 4093 4094 Gets the amount of free memory that is still available to the 4095 process (in bytes). This differs from `uv.get_free_memory()` 4096 in that it takes into account any limits imposed by the OS. If 4097 there is no such constraint, or the constraint is unknown, the 4098 amount returned will be identical to `uv.get_free_memory()`. 4099 4100 Returns: `number` 4101 4102uv.resident_set_memory() *uv.resident_set_memory()* 4103 4104 Returns the resident set size (RSS) for the current process. 4105 4106 Returns: `integer` or `fail` 4107 4108uv.getrusage() *uv.getrusage()* 4109 4110 Returns the resource usage. 4111 4112 Returns: `table` or `fail` 4113 - `utime` : `table` (user CPU time used) 4114 - `sec` : `integer` 4115 - `usec` : `integer` 4116 - `stime` : `table` (system CPU time used) 4117 - `sec` : `integer` 4118 - `usec` : `integer` 4119 - `maxrss` : `integer` (maximum resident set size) 4120 - `ixrss` : `integer` (integral shared memory size) 4121 - `idrss` : `integer` (integral unshared data size) 4122 - `isrss` : `integer` (integral unshared stack size) 4123 - `minflt` : `integer` (page reclaims (soft page faults)) 4124 - `majflt` : `integer` (page faults (hard page faults)) 4125 - `nswap` : `integer` (swaps) 4126 - `inblock` : `integer` (block input operations) 4127 - `oublock` : `integer` (block output operations) 4128 - `msgsnd` : `integer` (IPC messages sent) 4129 - `msgrcv` : `integer` (IPC messages received) 4130 - `nsignals` : `integer` (signals received) 4131 - `nvcsw` : `integer` (voluntary context switches) 4132 - `nivcsw` : `integer` (involuntary context switches) 4133 4134uv.getrusage_thread() *uv.getrusage_thread()* 4135 Gets the resource usage measures for the calling thread. 4136 4137 Note: Not supported on all platforms. May return `ENOTSUP`. 4138 4139 On macOS and Windows not all fields are set (the unsupported 4140 fields are filled with zeroes). 4141 4142 Returns: `table` or `fail` 4143 - `utime` : `table` (user CPU time used) 4144 - `sec` : `integer` 4145 - `usec` : `integer` 4146 - `stime` : `table` (system CPU time used) 4147 - `sec` : `integer` 4148 - `usec` : `integer` 4149 - `maxrss` : `integer` (maximum resident set size) 4150 - `ixrss` : `integer` (integral shared memory size) 4151 - `idrss` : `integer` (integral unshared data size) 4152 - `isrss` : `integer` (integral unshared stack size) 4153 - `minflt` : `integer` (page reclaims (soft page faults)) 4154 - `majflt` : `integer` (page faults (hard page faults)) 4155 - `nswap` : `integer` (swaps) 4156 - `inblock` : `integer` (block input operations) 4157 - `oublock` : `integer` (block output operations) 4158 - `msgsnd` : `integer` (IPC messages sent) 4159 - `msgrcv` : `integer` (IPC messages received) 4160 - `nsignals` : `integer` (signals received) 4161 - `nvcsw` : `integer` (voluntary context switches) 4162 - `nivcsw` : `integer` (involuntary context switches) 4163 4164uv.available_parallelism() *uv.available_parallelism()* 4165 4166 Returns an estimate of the default amount of parallelism a 4167 program should use. Always returns a non-zero value. 4168 4169 On Linux, inspects the calling thread’s CPU affinity mask to 4170 determine if it has been pinned to specific CPUs. 4171 4172 On Windows, the available parallelism may be underreported on 4173 systems with more than 64 logical CPUs. 4174 4175 On other platforms, reports the number of CPUs that the 4176 operating system considers to be online. 4177 4178 Returns: `integer` 4179 4180uv.cpu_info() *uv.cpu_info()* 4181 4182 Returns information about the CPU(s) on the system as a table 4183 of tables for each CPU found. 4184 4185 Returns: `table` or `fail` 4186 - `[1, 2, 3, ..., n]` : `table` 4187 - `model` : `string` 4188 - `speed` : `number` 4189 - `times` : `table` 4190 - `user` : `number` 4191 - `nice` : `number` 4192 - `sys` : `number` 4193 - `idle` : `number` 4194 - `irq` : `number` 4195 4196uv.cpumask_size() *uv.cpumask_size()* 4197 4198 Returns the maximum size of the mask used for process/thread 4199 affinities, or `ENOTSUP` if affinities are not supported on 4200 the current platform. 4201 4202 Returns: `integer` or `fail` 4203 4204uv.getpid() *uv.getpid()* 4205 4206 DEPRECATED: Please use |uv.os_getpid()| instead. 4207 4208uv.getuid() *uv.getuid()* 4209 4210 Returns the user ID of the process. 4211 4212 Returns: `integer` 4213 4214 Note: This is not a libuv function and is not supported on 4215 Windows. 4216 4217uv.getgid() *uv.getgid()* 4218 4219 Returns the group ID of the process. 4220 4221 Returns: `integer` 4222 4223 Note: This is not a libuv function and is not supported on 4224 Windows. 4225 4226uv.setuid({id}) *uv.setuid()* 4227 4228 Parameters: 4229 - `id`: `integer` 4230 4231 Sets the user ID of the process with the integer `id`. 4232 4233 Returns: Nothing. 4234 4235 Note: This is not a libuv function and is not supported on 4236 Windows. 4237 4238uv.setgid({id}) *uv.setgid()* 4239 4240 Parameters: 4241 - `id`: `integer` 4242 4243 Sets the group ID of the process with the integer `id`. 4244 4245 Returns: Nothing. 4246 4247 Note: This is not a libuv function and is not supported on 4248 Windows. 4249 4250uv.hrtime() *uv.hrtime()* 4251 4252 Returns a current high-resolution time in nanoseconds as a 4253 number. This is relative to an arbitrary time in the past. It 4254 is not related to the time of day and therefore not subject to 4255 clock drift. The primary use is for measuring time between 4256 intervals. 4257 4258 Returns: `integer` 4259 4260uv.clock_gettime({clock_id}) *uv.clock_gettime()* 4261 4262 Parameters: 4263 - `clock_id`: `string` 4264 4265 Obtain the current system time from a high-resolution 4266 real-time or monotonic clock source. `clock_id` can be the 4267 string `"monotonic"` or `"realtime"`. 4268 4269 The real-time clock counts from the UNIX epoch (1970-01-01) 4270 and is subject to time adjustments; it can jump back in time. 4271 4272 The monotonic clock counts from an arbitrary point in the past 4273 and never jumps back in time. 4274 4275 Returns: `table` or `fail` 4276 - `sec`: `integer` 4277 - `nsec`: `integer` 4278 4279uv.uptime() *uv.uptime()* 4280 4281 Returns the current system uptime in seconds. 4282 4283 Returns: `number` or `fail` 4284 4285uv.print_all_handles() *uv.print_all_handles()* 4286 4287 Prints all handles associated with the main loop to stderr. 4288 The format is `[flags] handle-type handle-address` . Flags are 4289 `R` for referenced, `A` for active and `I` for internal. 4290 4291 Returns: Nothing. 4292 4293 Note: This is not available on Windows. 4294 4295 WARNING: This function is meant for ad hoc debugging, there 4296 are no API/ABI stability guarantees. 4297 4298uv.print_active_handles() *uv.print_active_handles()* 4299 4300 The same as |uv.print_all_handles()| except only active 4301 handles are printed. 4302 4303 Returns: Nothing. 4304 4305 Note: This is not available on Windows. 4306 4307 WARNING: This function is meant for ad hoc debugging, there 4308 are no API/ABI stability guarantees. 4309 4310uv.guess_handle({fd}) *uv.guess_handle()* 4311 4312 Parameters: 4313 - `fd`: `integer` 4314 4315 Used to detect what type of stream should be used with a given 4316 file descriptor `fd`. Usually this will be used during 4317 initialization to guess the type of the stdio streams. 4318 4319 Returns: `string` 4320 4321uv.gettimeofday() *uv.gettimeofday()* 4322 4323 Cross-platform implementation of `gettimeofday(2)`. Returns 4324 the seconds and microseconds of a unix time as a pair. 4325 4326 Returns: `integer, integer` or `fail` 4327 4328uv.interface_addresses() *uv.interface_addresses()* 4329 4330 Returns address information about the network interfaces on 4331 the system in a table. Each table key is the name of the 4332 interface while each associated value is an array of address 4333 information where fields are `ip`, `family`, `netmask`, 4334 `internal`, and `mac`. 4335 4336 See |luv-constants| for supported address `family` output values. 4337 4338 Returns: `table` or `fail` 4339 - `[name(s)]` : `table` 4340 - `ip` : `string` 4341 - `family` : `string` 4342 - `netmask` : `string` 4343 - `internal` : `boolean` 4344 - `mac` : `string` 4345 4346uv.if_indextoname({ifindex}) *uv.if_indextoname()* 4347 4348 Parameters: 4349 - `ifindex`: `integer` 4350 4351 IPv6-capable implementation of `if_indextoname(3)`. 4352 4353 Returns: `string` or `fail` 4354 4355uv.if_indextoiid({ifindex}) *uv.if_indextoiid()* 4356 4357 Parameters: 4358 - `ifindex`: `integer` 4359 4360 Retrieves a network interface identifier suitable for use in 4361 an IPv6 scoped address. On Windows, returns the numeric 4362 `ifindex` as a string. On all other platforms, 4363 |uv.if_indextoname()| is used. 4364 4365 Returns: `string` or `fail` 4366 4367uv.loadavg() *uv.loadavg()* 4368 4369 Returns the load average as a triad. Not supported on Windows. 4370 4371 Returns: `number, number, number` 4372 4373uv.os_uname() *uv.os_uname()* 4374 4375 Returns system information. 4376 4377 Returns: `table` 4378 - `sysname` : `string` 4379 - `release` : `string` 4380 - `version` : `string` 4381 - `machine` : `string` 4382 4383uv.os_gethostname() *uv.os_gethostname()* 4384 4385 Returns the hostname. 4386 4387 Returns: `string` 4388 4389uv.os_getenv({name} [, {size}]) *uv.os_getenv()* 4390 4391 Parameters: 4392 - `name`: `string` 4393 - `size`: `integer` (default = `LUAL_BUFFERSIZE`) 4394 4395 Returns the environment variable specified by `name` as 4396 string. The internal buffer size can be set by defining 4397 `size`. If omitted, `LUAL_BUFFERSIZE` is used. If the 4398 environment variable exceeds the storage available in the 4399 internal buffer, `ENOBUFS` is returned. If no matching 4400 environment variable exists, `ENOENT` is returned. 4401 4402 Returns: `string` or `fail` 4403 4404 WARNING: This function is not thread safe. 4405 4406uv.os_setenv({name}, {value}) *uv.os_setenv()* 4407 4408 Parameters: 4409 - `name`: `string` 4410 - `value`: `string` 4411 4412 Sets the environmental variable specified by `name` with the 4413 string `value`. 4414 4415 Returns: `boolean` or `fail` 4416 4417 WARNING: This function is not thread safe. 4418 4419uv.os_unsetenv({name}) *uv.os_unsetenv()* 4420 4421 Parameters: 4422 - `name`: `string` 4423 4424 Unsets the environmental variable specified by `name`. 4425 4426 Returns: `boolean` or `fail` 4427 4428 WARNING: This function is not thread safe. 4429 4430uv.os_environ() *uv.os_environ()* 4431 4432 Returns all environmental variables as a dynamic table of 4433 names associated with their corresponding values. 4434 4435 Returns: `table` 4436 4437 WARNING: This function is not thread safe. 4438 4439uv.os_homedir() *uv.os_homedir()* 4440 4441 Returns: `string` or `fail` 4442 4443 WARNING: This function is not thread safe. 4444 4445uv.os_tmpdir() *uv.os_tmpdir()* 4446 4447 Returns: `string` or `fail` 4448 4449 WARNING: This function is not thread safe. 4450 4451uv.os_get_passwd() *uv.os_get_passwd()* 4452 4453 Returns password file information. 4454 4455 Returns: `table` or `fail` 4456 - `username` : `string` 4457 - `uid` : `integer?` (`nil` on Windows) 4458 - `gid` : `integer?` (`nil` on Windows) 4459 - `shell` : `string?`` (`nil` on Windows) 4460 - `homedir` : `string` 4461 4462uv.os_getpid() *uv.os_getpid()* 4463 4464 Returns the current process ID. 4465 4466 Returns: `number` 4467 4468uv.os_getppid() *uv.os_getppid()* 4469 4470 Returns the parent process ID. 4471 4472 Returns: `number` 4473 4474uv.os_getpriority({pid}) *uv.os_getpriority()* 4475 4476 Parameters: 4477 - `pid`: `integer` 4478 4479 Returns the scheduling priority of the process specified by 4480 `pid`. 4481 4482 Returns: `number` or `fail` 4483 4484uv.os_setpriority({pid}, {priority}) *uv.os_setpriority()* 4485 4486 Parameters: 4487 - `pid`: `integer` 4488 - `priority`: `integer` 4489 4490 Sets the scheduling priority of the process specified by 4491 `pid`. The `priority` range is between -20 (high priority) and 4492 19 (low priority). 4493 4494 Returns: `boolean` or `fail` 4495 4496uv.random({len}, {flags} [, {callback}]) *uv.random()* 4497 4498 Parameters: 4499 - `len`: `integer` 4500 - `flags`: `nil` (see below) 4501 - `callback`: `callable` (async version) or `nil` (sync 4502 version) 4503 - `err`: `nil` or `string` 4504 - `bytes`: `string` or `nil` 4505 4506 Fills a string of length `len` with cryptographically strong 4507 random bytes acquired from the system CSPRNG. `flags` is 4508 reserved for future extension and must currently be `nil` or 4509 `0` or `{}`. 4510 4511 Short reads are not possible. When less than `len` random 4512 bytes are available, a non-zero error value is returned or 4513 passed to the callback. If the callback is omitted, this 4514 function is completed synchronously. 4515 4516 The synchronous version may block indefinitely when not enough 4517 entropy is available. The asynchronous version may not ever 4518 finish when the system is low on entropy. 4519 4520 Returns (sync version): `string` or `fail` 4521 4522 Returns (async version): `0` or `fail` 4523 4524uv.translate_sys_error({errcode}) *uv.translate_sys_error()* 4525 4526 Parameters: 4527 - `errcode`: `integer` 4528 4529 Returns the libuv error message and error name (both in string 4530 form, see `err` and `name` in |luv-error-handling|) equivalent 4531 to the given platform dependent error code: POSIX error codes 4532 on Unix (the ones stored in errno), and Win32 error codes on 4533 Windows (those returned by GetLastError() or 4534 WSAGetLastError()). 4535 4536 Returns: `string, string` or `nil` 4537 4538============================================================================== 4539METRICS OPERATIONS *luv-metrics-operations* 4540 4541uv.metrics_idle_time() *uv.metrics_idle_time()* 4542 4543 Retrieve the amount of time the event loop has been idle in 4544 the kernel’s event provider (e.g. `epoll_wait`). The call is 4545 thread safe. 4546 4547 The return value is the accumulated time spent idle in the 4548 kernel’s event provider starting from when the |uv_loop_t| was 4549 configured to collect the idle time. 4550 4551 Note: The event loop will not begin accumulating the event 4552 provider’s idle time until calling `loop_configure` with 4553 `"metrics_idle_time"`. 4554 4555 Returns: `number` 4556 4557uv.metrics_info() *uv.metrics_info()* 4558 4559 Get the metrics table from current set of event loop metrics. 4560 It is recommended to retrieve these metrics in a `prepare` 4561 callback (see |uv.new_prepare()|, |uv.prepare_start()|) in order 4562 to make sure there are no inconsistencies with the metrics 4563 counters. 4564 4565 Returns: `table` 4566 4567 - `loop_count` : `integer` 4568 - `events` : `integer` 4569 - `events_waiting` : `integer` 4570 4571============================================================================== 4572STRING MANIPULATION FUNCTIONS *luv-string-manipulation* 4573 4574These string utilities are needed internally for dealing with Windows, and are 4575exported to allow clients to work uniformly with this data when the libuv API 4576is not complete. 4577 4578Notes: 45791. New in luv version 1.49.0. 45802. See the WTF-8 spec (https://simonsapin.github.io/wtf-8/) for information 4581 about WTF-8. 45823. Luv uses Lua-style strings, which means that all inputs and return values 4583 (UTF-8 or UTF-16 strings) do not include a NUL terminator. 4584 4585uv.utf16_length_as_wtf8({utf16}) *uv.utf16_length_as_wtf8()* 4586 4587 Get the length (in bytes) of a UTF-16 (or UCS-2) string 4588 `utf16` value after converting it to WTF-8. The endianness of 4589 the UTF-16 (or UCS-2) string is assumed to be the same as the 4590 native endianness of the platform. 4591 4592 Parameters: 4593 - `utf16`: `string` 4594 4595 Returns: `integer` 4596 4597uv.utf16_to_wtf8({utf16}) *uv.utf16_to_wtf8()* 4598 4599 Convert UTF-16 (or UCS-2) string `utf16` to UTF-8 string. The 4600 endianness of the UTF-16 (or UCS-2) string is assumed to be 4601 the same as the native endianness of the platform. 4602 4603 Parameters: 4604 - `utf16`: `string` 4605 4606 Returns: `string` 4607 4608uv.wtf8_length_as_utf16({wtf16}) *uv.wtf8_length_as_utf16()* 4609 4610 Get the length (in UTF-16 code units) of a WTF-8 `wtf8` value 4611 after converting it to UTF-16 (or UCS-2). 4612 4613 Note: The number of bytes needed for a UTF-16 (or UCS-2) 4614 string is `<number of code units> * 2`. 4615 4616 Parameters: 4617 - `wtf8`: `string` 4618 4619 Returns: `integer` 4620 4621uv.wtf8_to_utf16({wtf16}) *uv.wtf8_to_utf16()* 4622 4623 Convert WTF-8 string in `wtf8` to UTF-16 (or UCS-2) string. 4624 The endianness of the UTF-16 (or UCS-2) string is assumed to 4625 be the same as the native endianness of the platform. 4626 4627 Parameters: 4628 - `wtf8`: `string` 4629 4630 Returns: `string` 4631 4632============================================================================== 4633CREDITS *luv-credits* 4634 4635This document is a reformatted version of the LUV documentation, up-to-date 4636with commit dcd1a1c (23 Aug 2023) of the luv repository 4637https://github.com/luvit/luv/commit/dcd1a1cad5b05634a7691402d6ca2f214fb4ae76. 4638 4639Based on https://github.com/nanotee/luv-vimdocs with kind permission. 4640 4641 4642vim:tw=78:ts=8:sw=2:et:ft=help:norl: