forked from luvit/luv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeta.lua
More file actions
4608 lines (4146 loc) · 168 KB
/
meta.lua
File metadata and controls
4608 lines (4146 loc) · 168 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--- @meta
--- @class uv
local uv = {}
uv.constants = {}
--- # LibUV in Lua
---
--- The [luv][] project provides access to the multi-platform support library
--- [libuv][] in Lua code. It was primarily developed for the [luvit][] project as
--- the built-in `uv` module, but can be used in other Lua environments.
---
--- More information about the core libuv library can be found at the original
--- [libuv documentation page][].
--- # TCP Echo Server Example
---
--- Here is a small example showing a TCP echo server:
---
--- ```lua
--- local uv = require("luv") -- "luv" when stand-alone, "uv" in luvi apps
---
--- local server = uv.new_tcp()
--- server:bind("127.0.0.1", 1337)
--- server:listen(128, function (err)
--- assert(not err, err)
--- local client = uv.new_tcp()
--- server:accept(client)
--- client:read_start(function (err, chunk)
--- assert(not err, err)
--- if chunk then
--- client:write(chunk)
--- else
--- client:shutdown()
--- client:close()
--- end
--- end)
--- end)
--- print("TCP server listening at 127.0.0.1 port 1337")
--- uv.run() -- an explicit run call is necessary outside of luvit
--- ```
--- # Module Layout
---
--- The luv library contains a single Lua module referred to hereafter as `uv` for
--- simplicity. This module consists mostly of functions with names corresponding to
--- their original libuv versions. For example, the libuv function `uv_tcp_bind` has
--- a luv version at `uv.tcp_bind`. Currently, only two non-function fields exists:
--- `uv.constants` and `uv.errno`, which are tables.
--- # Functions vs Methods
---
--- In addition to having simple functions, luv provides an optional method-style
--- API. For example, `uv.tcp_bind(server, host, port)` can alternatively be called
--- as `server:bind(host, port)`. Note that the first argument `server` becomes the
--- object and `tcp_` is removed from the function name. Method forms are
--- documented below where they exist.
--- # Synchronous vs Asynchronous Functions
---
--- Functions that accept a callback are asynchronous. These functions may
--- immediately return results to the caller to indicate their initial status, but
--- their final execution is deferred until at least the next libuv loop iteration.
--- After completion, their callbacks are executed with any results passed to it.
---
--- Functions that do not accept a callback are synchronous. These functions
--- immediately return their results to the caller.
---
--- Some (generally FS and DNS) functions can behave either synchronously or
--- asynchronously. If a callback is provided to these functions, they behave
--- asynchronously; if no callback is provided, they behave synchronously.
--- # Pseudo-Types
---
--- Some unique types are defined. These are not actual types in Lua, but they are
--- used here to facilitate documenting consistent behavior:
--- - `fail`: an assertable `nil, string, string` tuple (see [Error Handling][])
--- - `callable`: a `function`; or a `table` or `userdata` with a `__call`
--- metamethod
--- - `buffer`: a `string` or a sequential `table` of `string`s
--- - `threadargs`: variable arguments (`...`) of type `nil`, `boolean`, `number`,
--- `string`, or `userdata`, numbers of argument limited to 9.
--- # Contents
---
--- This documentation is mostly a retelling of the [libuv API documentation][]
--- within the context of luv's Lua API. Low-level implementation details and
--- unexposed C functions and types are not documented here except for when they
--- are relevant to behavior seen in the Lua module.
---
--- - [Constants][]
--- - [Error Handling][]
--- - [Version Checking][]
--- - [`uv_loop_t`][] — Event loop
--- - [`uv_req_t`][] — Base request
--- - [`uv_handle_t`][] — Base handle
--- - [`uv_timer_t`][] — Timer handle
--- - [`uv_prepare_t`][] — Prepare handle
--- - [`uv_check_t`][] — Check handle
--- - [`uv_idle_t`][] — Idle handle
--- - [`uv_async_t`][] — Async handle
--- - [`uv_poll_t`][] — Poll handle
--- - [`uv_signal_t`][] — Signal handle
--- - [`uv_process_t`][] — Process handle
--- - [`uv_stream_t`][] — Stream handle
--- - [`uv_tcp_t`][] — TCP handle
--- - [`uv_pipe_t`][] — Pipe handle
--- - [`uv_tty_t`][] — TTY handle
--- - [`uv_udp_t`][] — UDP handle
--- - [`uv_fs_event_t`][] — FS Event handle
--- - [`uv_fs_poll_t`][] — FS Poll handle
--- - [File system operations][]
--- - [Thread pool work scheduling][]
--- - [DNS utility functions][]
--- - [Threading and synchronization utilities][]
--- - [Miscellaneous utilities][]
--- - [Metrics operations][]
--- # Constants
---
--- As a Lua library, luv supports and encourages the use of lowercase strings to
--- represent options. For example:
--- ```lua
--- -- signal start with string input
--- uv.signal_start("sigterm", function(signame)
--- print(signame) -- string output: "sigterm"
--- end)
--- ```
---
--- However, luv also superficially exposes libuv constants in a Lua table at
--- `uv.constants` where its keys are uppercase constant names and their associated
--- values are integers defined internally by libuv. The values from this table may
--- be supported as function arguments, but their use may not change the output
--- type. For example:
---
--- ```lua
--- -- signal start with integer input
--- uv.signal_start(uv.constants.SIGTERM, function(signame)
--- print(signame) -- string output: "sigterm"
--- end)
--- ```
---
--- The uppercase constants defined in `uv.constants` that have associated
--- lowercase option strings are listed below.
--- # Address Families
uv.constants.AF_UNIX = 'unix'
uv.constants.AF_INET = 'inet'
uv.constants.AF_INET6 = 'inet6'
uv.constants.AF_IPX = 'ipx'
uv.constants.AF_NETLINK = 'netlink'
uv.constants.AF_X25 = 'x25'
uv.constants.AF_AX25 = 'as25'
uv.constants.AF_ATMPVC = 'atmpvc'
uv.constants.AF_APPLETALK = 'appletalk'
uv.constants.AF_PACKET = 'packet'
--- # Signals
uv.constants.SIGHUP = 'sighup'
uv.constants.SIGINT = 'sigint'
uv.constants.SIGQUIT = 'sigquit'
uv.constants.SIGILL = 'sigill'
uv.constants.SIGTRAP = 'sigtrap'
uv.constants.SIGABRT = 'sigabrt'
uv.constants.SIGIOT = 'sigiot'
uv.constants.SIGBUS = 'sigbus'
uv.constants.SIGFPE = 'sigfpe'
uv.constants.SIGKILL = 'sigkill'
uv.constants.SIGUSR1 = 'sigusr1'
uv.constants.SIGSEGV = 'sigsegv'
uv.constants.SIGUSR2 = 'sigusr2'
uv.constants.SIGPIPE = 'sigpipe'
uv.constants.SIGALRM = 'sigalrm'
uv.constants.SIGTERM = 'sigterm'
uv.constants.SIGCHLD = 'sigchld'
uv.constants.SIGSTKFLT = 'sigstkflt'
uv.constants.SIGCONT = 'sigcont'
uv.constants.SIGSTOP = 'sigstop'
uv.constants.SIGTSTP = 'sigtstp'
uv.constants.SIGBREAK = 'sigbreak'
uv.constants.SIGTTIN = 'sigttin'
uv.constants.SIGTTOU = 'sigttou'
uv.constants.SIGURG = 'sigurg'
uv.constants.SIGXCPU = 'sigxcpu'
uv.constants.SIGXFSZ = 'sigxfsz'
uv.constants.SIGVTALRM = 'sigvtalrm'
uv.constants.SIGPROF = 'sigprof'
uv.constants.SIGWINCH = 'sigwinch'
uv.constants.SIGIO = 'sigio'
uv.constants.SIGPOLL = 'sigpoll'
uv.constants.SIGLOST = 'siglost'
uv.constants.SIGPWR = 'sigpwr'
uv.constants.SIGSYS = 'sigsys'
--- # Socket Types
uv.constants.SOCK_STREAM = 'stream'
uv.constants.SOCK_DGRAM = 'dgram'
uv.constants.SOCK_SEQPACKET = 'seqpacket'
uv.constants.SOCK_RAW = 'raw'
uv.constants.SOCK_RDM = 'rdm'
--- # TTY Modes
uv.constants.TTY_MODE_NORMAL = 'normal'
uv.constants.TTY_MODE_RAW = 'raw'
uv.constants.TTY_MODE_IO = 'io'
uv.constants.TTY_MODE_RAW_VT = 'raw_vt'
--- # FS Modification Times
uv.constants.FS_UTIME_NOW = 'now'
uv.constants.FS_UTIME_OMIT = 'omit'
--- # Error Handling
---
--- In libuv, errors are represented by negative numbered constants. While these
--- constants are made available in the `uv.errno` table, they are not returned by
--- luv functions and the libuv functions used to handle them are not exposed.
--- Instead, if an internal error is encountered, the failing luv function will
--- return to the caller an assertable `nil, err, name` tuple:
---
--- - `nil` idiomatically indicates failure
--- - `err` is a string with the format `{name}: {message}`
--- - `{name}` is the error name provided internally by `uv_err_name`
--- - `{message}` is a human-readable message provided internally by `uv_strerror`
--- - `name` is the same string used to construct `err`
---
--- This tuple is referred to below as the `fail` pseudo-type.
---
--- When a function is called successfully, it will return either a value that is
--- relevant to the operation of the function, or the integer `0` to indicate
--- success, or sometimes nothing at all. These cases are documented below.
---
--- Below is a list of known error names and error strings. See libuv's
--- [error constants][] page for an original source.
--- @alias uv.error_name
--- | 'E2BIG' # argument list too long.
--- | 'EACCES' # permission denied.
--- | 'EADDRINUSE' # address already in use.
--- | 'EADDRNOTAVAIL' # address not available.
--- | 'EAFNOSUPPORT' # address family not supported.
--- | 'EAGAIN' # resource temporarily unavailable.
--- | 'EAI_ADDRFAMILY' # address family not supported.
--- | 'EAI_AGAIN' # temporary failure.
--- | 'EAI_BADFLAGS' # bad ai_flags value.
--- | 'EAI_BADHINTS' # invalid value for hints.
--- | 'EAI_CANCELED' # request canceled.
--- | 'EAI_FAIL' # permanent failure.
--- | 'EAI_FAMILY' # ai_family not supported.
--- | 'EAI_MEMORY' # out of memory.
--- | 'EAI_NODATA' # no address.
--- | 'EAI_NONAME' # unknown node or service.
--- | 'EAI_OVERFLOW' # argument buffer overflow.
--- | 'EAI_PROTOCOL' # resolved protocol is unknown.
--- | 'EAI_SERVICE' # service not available for socket type.
--- | 'EAI_SOCKTYPE' # socket type not supported.
--- | 'EALREADY' # connection already in progress.
--- | 'EBADF' # bad file descriptor.
--- | 'EBUSY' # resource busy or locked.
--- | 'ECANCELED' # operation canceled.
--- | 'ECHARSET' # invalid Unicode character.
--- | 'ECONNABORTED' # software caused connection abort.
--- | 'ECONNREFUSED' # connection refused.
--- | 'ECONNRESET' # connection reset by peer.
--- | 'EDESTADDRREQ' # destination address required.
--- | 'EEXIST' # file already exists.
--- | 'EFAULT' # bad address in system call argument.
--- | 'EFBIG' # file too large.
--- | 'EHOSTUNREACH' # host is unreachable.
--- | 'EINTR' # interrupted system call.
--- | 'EINVAL' # invalid argument.
--- | 'EIO' # i/o error.
--- | 'EISCONN' # socket is already connected.
--- | 'EISDIR' # illegal operation on a directory.
--- | 'ELOOP' # too many symbolic links encountered.
--- | 'EMFILE' # too many open files.
--- | 'EMSGSIZE' # message too long.
--- | 'ENAMETOOLONG' # name too long.
--- | 'ENETDOWN' # network is down.
--- | 'ENETUNREACH' # network is unreachable.
--- | 'ENFILE' # file table overflow.
--- | 'ENOBUFS' # no buffer space available.
--- | 'ENODEV' # no such device.
--- | 'ENOENT' # no such file or directory.
--- | 'ENOMEM' # not enough memory.
--- | 'ENONET' # machine is not on the network.
--- | 'ENOPROTOOPT' # protocol not available.
--- | 'ENOSPC' # no space left on device.
--- | 'ENOSYS' # function not implemented.
--- | 'ENOTCONN' # socket is not connected.
--- | 'ENOTDIR' # not a directory.
--- | 'ENOTEMPTY' # directory not empty.
--- | 'ENOTSOCK' # socket operation on non-socket.
--- | 'ENOTSUP' # operation not supported on socket.
--- | 'EOVERFLOW' # value too large for defined data type.
--- | 'EPERM' # operation not permitted.
--- | 'EPIPE' # broken pipe.
--- | 'EPROTO' # protocol error.
--- | 'EPROTONOSUPPORT' # protocol not supported.
--- | 'EPROTOTYPE' # protocol wrong type for socket.
--- | 'ERANGE' # result too large.
--- | 'EROFS' # read-only file system.
--- | 'ESHUTDOWN' # cannot send after transport endpoint shutdown.
--- | 'ESPIPE' # invalid seek.
--- | 'ESRCH' # no such process.
--- | 'ETIMEDOUT' # connection timed out.
--- | 'ETXTBSY' # text file is busy.
--- | 'EXDEV' # cross-device link not permitted.
--- | 'UNKNOWN' # unknown error.
--- | 'EOF' # end of file.
--- | 'ENXIO' # no such device or address.
--- | 'EMLINK' # too many links.
--- | 'ENOTTY' # inappropriate ioctl for device.
--- | 'EFTYPE' # inappropriate file type or format.
--- | 'EILSEQ' # illegal byte sequence.
--- | 'ESOCKTNOSUPPORT' # socket type not supported.
--- # Version Checking
--- Returns the libuv version packed into a single integer. 8 bits are used for each
--- component, with the patch number stored in the 8 least significant bits. For
--- example, this would be 0x010203 in libuv 1.2.3.
--- @return integer
function uv.version() end
--- Returns the libuv version number as a string. For example, this would be "1.2.3"
--- in libuv 1.2.3. For non-release versions, the version suffix is included.
--- @return string
function uv.version_string() end
--- # `uv_loop_t` - Event loop
---
--- The event loop is the central part of libuv's functionality. It takes care of
--- polling for I/O and scheduling callbacks to be run based on different sources of
--- events.
---
--- In luv, there is an implicit uv loop for every Lua state that loads the library.
--- You can use this library in an multi-threaded environment as long as each thread
--- has it's own Lua state with its corresponding own uv loop. This loop is not
--- directly exposed to users in the Lua module.
--- Closes all internal loop resources. In normal execution, the loop will
--- automatically be closed when it is garbage collected by Lua, so it is not
--- necessary to explicitly call `loop_close()`. Call this function only after the
--- loop has finished executing and all open handles and requests have been closed,
--- or it will return `EBUSY`.
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.loop_close() end
--- This function runs the event loop. It will act differently depending on the
--- specified mode:
---
--- - `"default"`: Runs the event loop until there are no more active and
--- referenced handles or requests. Returns `true` if `uv.stop()` was called and
--- there are still active handles or requests. Returns `false` in all other
--- cases.
---
--- - `"once"`: Poll for I/O once. Note that this function blocks if there are no
--- pending callbacks. Returns `false` when done (no active handles or requests
--- left), or `true` if more callbacks are expected (meaning you should run the
--- event loop again sometime in the future).
---
--- - `"nowait"`: Poll for I/O once but don't block if there are no pending
--- callbacks. Returns `false` if done (no active handles or requests left),
--- or `true` if more callbacks are expected (meaning you should run the event
--- loop again sometime in the future).
--- **Note**:
--- Luvit will implicitly call `uv.run()` after loading user code, but if
--- you use the luv bindings directly, you need to call this after registering
--- your initial set of event callbacks to start the event loop.
--- @param mode string?
--- @return boolean? running
--- @return string? err
--- @return uv.error_name? err_name
function uv.run(mode) end
--- Set additional loop options. You should normally call this before the first call
--- to uv_run() unless mentioned otherwise.
---
--- Supported options:
---
--- - `"block_signal"`: Block a signal when polling for new events. The second argument
--- to loop_configure() is the signal name (as a lowercase string) or the signal number.
--- This operation is currently only implemented for `"sigprof"` signals, to suppress
--- unnecessary wakeups when using a sampling profiler. Requesting other signals will
--- fail with `EINVAL`.
--- - `"metrics_idle_time"`: Accumulate the amount of idle time the event loop spends
--- in the event provider. This option is necessary to use `metrics_idle_time()`.
---
--- An example of a valid call to this function is:
---
--- ```lua
--- uv.loop_configure("block_signal", "sigprof")
--- ```
--- **Note**:
--- Be prepared to handle the `ENOSYS` error; it means the loop option is
--- not supported by the platform.
--- @param option string
--- @param ... any depends on `option`
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.loop_configure(option, ...) end
--- If the loop is running, returns a string indicating the mode in use. If the loop
--- is not running, `nil` is returned instead.
--- @return string?
function uv.loop_mode() end
--- Returns `true` if there are referenced active handles, active requests, or
--- closing handles in the loop; otherwise, `false`.
--- @return boolean? alive
--- @return string? err
--- @return uv.error_name? err_name
function uv.loop_alive() end
--- Stop the event loop, causing `uv.run()` to end as soon as possible. This
--- will happen not sooner than the next loop iteration. If this function was called
--- before blocking for I/O, the loop won't block for I/O on this iteration.
function uv.stop() end
--- Get backend file descriptor. Only kqueue, epoll, and event ports are supported.
---
--- This can be used in conjunction with `uv.run("nowait")` to poll in one thread
--- and run the event loop's callbacks in another
--- **Note**:
--- Embedding a kqueue fd in another kqueue pollset doesn't work on all
--- platforms. It's not an error to add the fd but it never generates events.
--- @return integer?
function uv.backend_fd() end
--- Get the poll timeout. The return value is in milliseconds, or -1 for no timeout.
--- @return integer
function uv.backend_timeout() end
--- Returns the current timestamp in milliseconds. The timestamp is cached at the
--- start of the event loop tick, see `uv.update_time()` for details and rationale.
---
--- The timestamp increases monotonically from some arbitrary point in time. Don't
--- make assumptions about the starting point, you will only get disappointed.
--- **Note**:
--- Use `uv.hrtime()` if you need sub-millisecond granularity.
--- @return integer
function uv.now() end
--- Update the event loop's concept of "now". Libuv caches the current time at the
--- start of the event loop tick in order to reduce the number of time-related
--- system calls.
---
--- You won't normally need to call this function unless you have callbacks that
--- block the event loop for longer periods of time, where "longer" is somewhat
--- subjective but probably on the order of a millisecond or more.
function uv.update_time() end
--- Walk the list of handles: `callback` will be executed with each handle.
--- Example
--- ```lua
--- -- Example usage of uv.walk to close all handles that aren't already closing.
--- uv.walk(function (handle)
--- if not handle:is_closing() then
--- handle:close()
--- end
--- end)
--- ```
--- @param callback fun(handle: uv.uv_handle_t)
function uv.walk(callback) end
--- # `uv_req_t` - Base request
---
--- `uv_req_t` is the base type for all libuv request types.
--- @class uv.uv_req_t : userdata
local uv_req_t = {}
--- Cancel a pending request. Fails if the request is executing or has finished
--- executing. Only cancellation of `uv_fs_t`, `uv_getaddrinfo_t`,
--- `uv_getnameinfo_t` and `uv_work_t` requests is currently supported.
--- @param req uv.uv_req_t
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.cancel(req) end
--- Cancel a pending request. Fails if the request is executing or has finished
--- executing. Only cancellation of `uv_fs_t`, `uv_getaddrinfo_t`,
--- `uv_getnameinfo_t` and `uv_work_t` requests is currently supported.
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_req_t:cancel() end
--- Returns the name of the struct for a given request (e.g. `"fs"` for `uv_fs_t`)
--- and the libuv enum integer for the request's type (`uv_req_type`).
--- @param req uv.uv_req_t
--- @return string type
--- @return integer enum
function uv.req_get_type(req) end
--- Returns the name of the struct for a given request (e.g. `"fs"` for `uv_fs_t`)
--- and the libuv enum integer for the request's type (`uv_req_type`).
--- @return string type
--- @return integer enum
function uv_req_t:get_type() end
--- # `uv_handle_t` - Base handle
---
--- `uv_handle_t` is the base type for all libuv handle types. All API functions
--- defined here work with any handle type.
--- @class uv.uv_handle_t : userdata
local uv_handle_t = {}
--- Returns `true` if the handle is active, `false` if it's inactive. What "active”
--- means depends on the type of handle:
---
--- - A [`uv_async_t`][] handle is always active and cannot be deactivated, except
--- by closing it with `uv.close()`.
---
--- - A [`uv_pipe_t`][], [`uv_tcp_t`][], [`uv_udp_t`][], etc. handle - basically
--- any handle that deals with I/O - is active when it is doing something that
--- involves I/O, like reading, writing, connecting, accepting new connections,
--- etc.
---
--- - A [`uv_check_t`][], [`uv_idle_t`][], [`uv_timer_t`][], etc. handle is active
--- when it has been started with a call to `uv.check_start()`, `uv.idle_start()`,
--- `uv.timer_start()` etc. until it has been stopped with a call to its
--- respective stop function.
--- @param handle uv.uv_handle_t
--- @return boolean? active
--- @return string? err
--- @return uv.error_name? err_name
function uv.is_active(handle) end
--- Returns `true` if the handle is active, `false` if it's inactive. What "active”
--- means depends on the type of handle:
---
--- - A [`uv_async_t`][] handle is always active and cannot be deactivated, except
--- by closing it with `uv.close()`.
---
--- - A [`uv_pipe_t`][], [`uv_tcp_t`][], [`uv_udp_t`][], etc. handle - basically
--- any handle that deals with I/O - is active when it is doing something that
--- involves I/O, like reading, writing, connecting, accepting new connections,
--- etc.
---
--- - A [`uv_check_t`][], [`uv_idle_t`][], [`uv_timer_t`][], etc. handle is active
--- when it has been started with a call to `uv.check_start()`, `uv.idle_start()`,
--- `uv.timer_start()` etc. until it has been stopped with a call to its
--- respective stop function.
--- @return boolean? active
--- @return string? err
--- @return uv.error_name? err_name
function uv_handle_t:is_active() end
--- Returns `true` if the handle is closing or closed, `false` otherwise.
--- **Note**:
--- This function should only be used between the initialization of the
--- handle and the arrival of the close callback.
--- @param handle uv.uv_handle_t
--- @return boolean? closing
--- @return string? err
--- @return uv.error_name? err_name
function uv.is_closing(handle) end
--- Returns `true` if the handle is closing or closed, `false` otherwise.
--- **Note**:
--- This function should only be used between the initialization of the
--- handle and the arrival of the close callback.
--- @return boolean? closing
--- @return string? err
--- @return uv.error_name? err_name
function uv_handle_t:is_closing() end
--- Request handle to be closed. `callback` will be called asynchronously after this
--- call. This MUST be called on each handle before memory is released.
---
--- Handles that wrap file descriptors are closed immediately but `callback` will
--- still be deferred to the next iteration of the event loop. It gives you a chance
--- to free up any resources associated with the handle.
---
--- In-progress requests, like `uv_connect_t` or `uv_write_t`, are cancelled and
--- have their callbacks called asynchronously with `ECANCELED`.
--- @param handle uv.uv_handle_t
--- @param callback fun()?
function uv.close(handle, callback) end
--- Request handle to be closed. `callback` will be called asynchronously after this
--- call. This MUST be called on each handle before memory is released.
---
--- Handles that wrap file descriptors are closed immediately but `callback` will
--- still be deferred to the next iteration of the event loop. It gives you a chance
--- to free up any resources associated with the handle.
---
--- In-progress requests, like `uv_connect_t` or `uv_write_t`, are cancelled and
--- have their callbacks called asynchronously with `ECANCELED`.
--- @param callback fun()?
function uv_handle_t:close(callback) end
--- Reference the given handle. References are idempotent, that is, if a handle is
--- already referenced calling this function again will have no effect.
--- @param handle uv.uv_handle_t
function uv.ref(handle) end
--- Reference the given handle. References are idempotent, that is, if a handle is
--- already referenced calling this function again will have no effect.
function uv_handle_t:ref() end
--- Un-reference the given handle. References are idempotent, that is, if a handle
--- is not referenced calling this function again will have no effect.
--- @param handle uv.uv_handle_t
function uv.unref(handle) end
--- Un-reference the given handle. References are idempotent, that is, if a handle
--- is not referenced calling this function again will have no effect.
function uv_handle_t:unref() end
--- Returns `true` if the handle referenced, `false` if not.
--- @param handle uv.uv_handle_t
--- @return boolean? has_ref
--- @return string? err
--- @return uv.error_name? err_name
function uv.has_ref(handle) end
--- Returns `true` if the handle referenced, `false` if not.
--- @return boolean? has_ref
--- @return string? err
--- @return uv.error_name? err_name
function uv_handle_t:has_ref() end
--- Gets or sets the size of the send buffer that the operating system uses for the
--- socket.
---
--- 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.
---
--- This function works for TCP, pipe and UDP handles on Unix and for TCP and UDP
--- handles on Windows.
--- **Note**:
--- Linux will set double the size and return double the size of the
--- original set value.
--- @param handle uv.uv_handle_t
--- @param size integer?
--- @return integer? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.send_buffer_size(handle, size) end
--- Gets or sets the size of the send buffer that the operating system uses for the
--- socket.
---
--- 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.
---
--- This function works for TCP, pipe and UDP handles on Unix and for TCP and UDP
--- handles on Windows.
--- **Note**:
--- Linux will set double the size and return double the size of the
--- original set value.
--- @param size integer?
--- @return integer? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_handle_t:send_buffer_size(size) end
--- Gets or sets the size of the receive buffer that the operating system uses for
--- the socket.
---
--- 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.
---
--- This function works for TCP, pipe and UDP handles on Unix and for TCP and UDP
--- handles on Windows.
--- **Note**:
--- Linux will set double the size and return double the size of the
--- original set value.
--- @param handle uv.uv_handle_t
--- @param size integer?
--- @return integer? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.recv_buffer_size(handle, size) end
--- Gets or sets the size of the receive buffer that the operating system uses for
--- the socket.
---
--- 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.
---
--- This function works for TCP, pipe and UDP handles on Unix and for TCP and UDP
--- handles on Windows.
--- **Note**:
--- Linux will set double the size and return double the size of the
--- original set value.
--- @param size integer?
--- @return integer? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_handle_t:recv_buffer_size(size) end
--- Gets the platform dependent file descriptor equivalent.
---
--- The following handles are supported: TCP, pipes, TTY, UDP and poll. Passing any
--- other handle type will fail with `EINVAL`.
---
--- If a handle doesn't have an attached file descriptor yet or the handle itself
--- has been closed, this function will return `EBADF`.
--- **Warning**:
--- Be very careful when using this function. libuv assumes it's in
--- control of the file descriptor so any change to it may lead to malfunction.
--- @param handle uv.uv_handle_t
--- @return integer? fileno
--- @return string? err
--- @return uv.error_name? err_name
function uv.fileno(handle) end
--- Gets the platform dependent file descriptor equivalent.
---
--- The following handles are supported: TCP, pipes, TTY, UDP and poll. Passing any
--- other handle type will fail with `EINVAL`.
---
--- If a handle doesn't have an attached file descriptor yet or the handle itself
--- has been closed, this function will return `EBADF`.
--- **Warning**:
--- Be very careful when using this function. libuv assumes it's in
--- control of the file descriptor so any change to it may lead to malfunction.
--- @return integer? fileno
--- @return string? err
--- @return uv.error_name? err_name
function uv_handle_t:fileno() end
--- Returns the name of the struct for a given handle (e.g. `"pipe"` for `uv_pipe_t`)
--- and the libuv enum integer for the handle's type (`uv_handle_type`).
--- @param handle uv.uv_handle_t
--- @return string type
--- @return integer enum
function uv.handle_get_type(handle) end
--- Returns the name of the struct for a given handle (e.g. `"pipe"` for `uv_pipe_t`)
--- and the libuv enum integer for the handle's type (`uv_handle_type`).
--- @return string type
--- @return integer enum
function uv_handle_t:get_type() end
--- # Reference counting
---
--- The libuv event loop (if run in the default mode) will run until there are no
--- active and referenced handles left. The user can force the loop to exit early by
--- unreferencing handles which are active, for example by calling `uv.unref()`
--- after calling `uv.timer_start()`.
---
--- A handle can be referenced or unreferenced, the refcounting scheme doesn't use a
--- counter, so both operations are idempotent.
---
--- All handles are referenced when active by default, see `uv.is_active()` for a
--- more detailed explanation on what being active involves.
--- # `uv_timer_t` - Timer handle
---
--- > [`uv_handle_t`][] functions also apply.
---
--- Timer handles are used to schedule callbacks to be called in the future.
--- @class uv.uv_timer_t : uv.uv_handle_t
local uv_timer_t = {}
--- Creates and initializes a new `uv_timer_t`. Returns the Lua userdata wrapping
--- it.
--- Example
--- ```lua
--- -- Creating a simple setTimeout wrapper
--- local function setTimeout(timeout, callback)
--- local timer = uv.new_timer()
--- timer:start(timeout, 0, function ()
--- timer:stop()
--- timer:close()
--- callback()
--- end)
--- return timer
--- end
---
--- -- Creating a simple setInterval wrapper
--- local function setInterval(interval, callback)
--- local timer = uv.new_timer()
--- timer:start(interval, interval, function ()
--- callback()
--- end)
--- return timer
--- end
---
--- -- And clearInterval
--- local function clearInterval(timer)
--- timer:stop()
--- timer:close()
--- end
--- ```
--- @return uv.uv_timer_t? timer
--- @return string? err
--- @return uv.error_name? err_name
function uv.new_timer() end
--- Start the timer. `timeout` and `repeat` are in milliseconds.
---
--- If `timeout` is zero, the callback fires on the next event loop iteration. If
--- `repeat` is non-zero, the callback fires first after `timeout` milliseconds and
--- then repeatedly after `repeat` milliseconds.
--- @param timer uv.uv_timer_t
--- @param timeout integer
--- @param repeat_ integer
--- @param callback fun()
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.timer_start(timer, timeout, repeat_, callback) end
--- Start the timer. `timeout` and `repeat` are in milliseconds.
---
--- If `timeout` is zero, the callback fires on the next event loop iteration. If
--- `repeat` is non-zero, the callback fires first after `timeout` milliseconds and
--- then repeatedly after `repeat` milliseconds.
--- @param timeout integer
--- @param repeat_ integer
--- @param callback fun()
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_timer_t:start(timeout, repeat_, callback) end
--- Stop the timer, the callback will not be called anymore.
--- @param timer uv.uv_timer_t
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.timer_stop(timer) end
--- Stop the timer, the callback will not be called anymore.
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_timer_t:stop() end
--- Stop the timer, and if it is repeating restart it using the repeat value as the
--- timeout. If the timer has never been started before it raises `EINVAL`.
--- @param timer uv.uv_timer_t
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.timer_again(timer) end
--- Stop the timer, and if it is repeating restart it using the repeat value as the
--- timeout. If the timer has never been started before it raises `EINVAL`.
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_timer_t:again() end
--- Set the repeat interval value in milliseconds. The timer will be scheduled to
--- run on the given interval, regardless of the callback execution duration, and
--- will follow normal timer semantics in the case of a time-slice overrun.
---
--- For example, if a 50 ms repeating timer first runs for 17 ms, it will be
--- scheduled to run again 33 ms later. If other tasks consume more than the 33 ms
--- following the first timer callback, then the callback will run as soon as
--- possible.
--- @param timer uv.uv_timer_t
--- @param repeat_ integer
function uv.timer_set_repeat(timer, repeat_) end
--- Set the repeat interval value in milliseconds. The timer will be scheduled to
--- run on the given interval, regardless of the callback execution duration, and
--- will follow normal timer semantics in the case of a time-slice overrun.
---
--- For example, if a 50 ms repeating timer first runs for 17 ms, it will be
--- scheduled to run again 33 ms later. If other tasks consume more than the 33 ms
--- following the first timer callback, then the callback will run as soon as
--- possible.
--- @param repeat_ integer
function uv_timer_t:set_repeat(repeat_) end
--- Get the timer repeat value.
--- @param timer uv.uv_timer_t
--- @return integer repeat_
function uv.timer_get_repeat(timer) end
--- Get the timer repeat value.
--- @return integer repeat_
function uv_timer_t:get_repeat() end
--- Get the timer due value or 0 if it has expired. The time is relative to `uv.now()`.
--- @param timer uv.uv_timer_t
--- @return integer due_in
function uv.timer_get_due_in(timer) end
--- Get the timer due value or 0 if it has expired. The time is relative to `uv.now()`.
--- @return integer due_in
function uv_timer_t:get_due_in() end
--- # `uv_prepare_t` - Prepare handle
---
--- > [`uv_handle_t`][] functions also apply.
---
--- Prepare handles will run the given callback once per loop iteration, right
--- before polling for I/O.
---
--- ```lua
--- local prepare = uv.new_prepare()
--- prepare:start(function()
--- print("Before I/O polling")
--- end)
--- ```
--- @class uv.uv_prepare_t : uv.uv_handle_t
local uv_prepare_t = {}
--- Creates and initializes a new `uv_prepare_t`. Returns the Lua userdata wrapping
--- it.
--- @return uv.uv_prepare_t
function uv.new_prepare() end
--- Start the handle with the given callback.
--- @param prepare uv.uv_prepare_t
--- @param callback fun()
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.prepare_start(prepare, callback) end
--- Start the handle with the given callback.
--- @param callback fun()
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_prepare_t:start(callback) end
--- Stop the handle, the callback will no longer be called.
--- @param prepare uv.uv_prepare_t
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.prepare_stop(prepare) end
--- Stop the handle, the callback will no longer be called.
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_prepare_t:stop() end
--- # `uv_check_t` - Check handle
---
--- > [`uv_handle_t`][] functions also apply.
---
--- Check handles will run the given callback once per loop iteration, right after
--- polling for I/O.
---
--- ```lua
--- local check = uv.new_check()
--- check:start(function()
--- print("After I/O polling")
--- end)
--- ```
--- @class uv.uv_check_t : uv.uv_handle_t
local uv_check_t = {}
--- Creates and initializes a new `uv_check_t`. Returns the Lua userdata wrapping
--- it.
--- @return uv.uv_check_t
function uv.new_check() end
--- Start the handle with the given callback.
--- @param check uv.uv_check_t
--- @param callback fun()
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.check_start(check, callback) end
--- Start the handle with the given callback.
--- @param callback fun()
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_check_t:start(callback) end
--- Stop the handle, the callback will no longer be called.
--- @param check uv.uv_check_t
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv.check_stop(check) end
--- Stop the handle, the callback will no longer be called.
--- @return 0? success
--- @return string? err
--- @return uv.error_name? err_name
function uv_check_t:stop() end
--- # `uv_idle_t` - Idle handle
---
--- > [`uv_handle_t`][] functions also apply.
---