robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonbuild(deps): bump luv to 1.52.1-05a0a26a725

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