-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.html
More file actions
1170 lines (1126 loc) · 371 KB
/
docs.html
File metadata and controls
1170 lines (1126 loc) · 371 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
<!doctype html>
<html>
<head>
<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'><style type='text/css'>html {overflow-x: initial !important;}</style>
<style type='text/css' id="style-base">:root { --bg-color: #ffffff; --text-color: #333333; --select-text-bg-color: #B5D6FC; --select-text-font-color: auto; --monospace: "Lucida Console",Consolas,"Courier",monospace; --title-bar-height: 20px; }
.mac-os-11 { --title-bar-height: 28px; }
html { font-size: 14px; background-color: var(--bg-color); color: var(--text-color); font-family: "Helvetica Neue", Helvetica, Arial, "Segoe UI Emoji", "SF Pro", sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, h5 { white-space: pre-wrap; }
body { margin: 0px; padding: 0px; height: auto; inset: 0px; font-size: 1rem; line-height: 1.42857; overflow-x: hidden; background: inherit; }
iframe { margin: auto; }
a.url { word-break: break-all; }
a:active, a:hover { outline: 0px; }
.in-text-selection, ::selection { text-shadow: none; background: var(--select-text-bg-color); color: var(--select-text-font-color); }
#write { margin: 0px auto; height: auto; width: inherit; word-break: normal; overflow-wrap: break-word; position: relative; white-space: normal; overflow-x: visible; padding-top: 36px; }
#write.first-line-indent p { text-indent: 2em; }
#write.first-line-indent li p, #write.first-line-indent p *, #write.first-line-indent svg * { text-indent: 0px; }
#write.first-line-indent li { margin-left: 2em; }
.for-image #write { padding-left: 8px; padding-right: 8px; }
body.typora-export { padding-left: 30px; padding-right: 30px; }
.typora-export .footnote-line, .typora-export li, .typora-export p { white-space: pre-wrap; }
.typora-export .task-list-item input { pointer-events: none; }
@media screen and (max-width: 500px) {
body.typora-export { padding-left: 0px; padding-right: 0px; }
#write { padding-left: 20px; padding-right: 20px; }
}
#write li > figure:last-child { margin-bottom: 0.5rem; }
#write ol, #write ul { position: relative; }
img { max-width: 100%; vertical-align: middle; image-orientation: from-image; }
button, input, select, textarea { color: inherit; font: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
*, ::after, ::before { box-sizing: border-box; }
#write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p, #write pre { width: inherit; position: relative; }
#write svg h1, #write svg h2, #write svg h3, #write svg h4, #write svg h5, #write svg h6, #write svg p { position: static; }
.nodeLabel p { padding-right: 2px; padding-left: 2px; }
.typora-export .nodeLabel p { padding-right: 0px; padding-left: 0px; }
foreignobject { overflow: visible; }
p { line-height: inherit; }
h1, h2, h3, h4, h5, h6 { break-after: avoid-page; break-inside: avoid; orphans: 4; }
p { orphans: 4; }
li p { orphans: 1; }
h1 { font-size: 2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.6rem; }
h4 { font-size: 1.4rem; }
h5 { font-size: 1.2rem; }
h6 { font-size: 1rem; }
.md-math-block, .md-rawblock, h1, h2, h3, h4, h5, h6, p { margin-top: 1rem; margin-bottom: 1rem; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: 700; font-style: italic; }
a { cursor: pointer; }
sup.md-footnote { padding: 2px 4px; background-color: rgba(238, 238, 238, 0.7); color: rgb(85, 85, 85); border-radius: 4px; cursor: pointer; }
sup.md-footnote a, sup.md-footnote a:hover { color: inherit; text-transform: inherit; text-decoration: inherit; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; }
figure { overflow-x: auto; margin: 1.2em 0px; max-width: calc(100% + 16px); padding: 0px; }
figure > table { margin: 0px; }
thead, tr { break-inside: avoid; break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; break-inside: auto; text-align: left; }
table.md-table td { min-width: 32px; }
.CodeMirror-gutters { border-right: 0px; background-color: inherit; }
.CodeMirror-linenumber { user-select: none; }
.CodeMirror { text-align: left; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror pre { padding: 0px 4px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
#write pre { white-space: pre-wrap; }
#write.fences-no-line-wrapping pre { white-space: pre; }
#write pre.ty-contain-cm { white-space: normal; }
.CodeMirror-gutters { margin-right: 4px; }
.md-fences { font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; overflow: visible; white-space: pre; background: inherit; position: relative !important; }
.md-fences-adv-panel { width: 100%; margin-top: 10px; text-align: center; padding-top: 0px; padding-bottom: 8px; overflow-x: auto; }
#write .md-fences.mock-cm { white-space: pre-wrap; }
.md-fences.md-fences-with-lineno { padding-left: 0px; }
#write.fences-no-line-wrapping .md-fences.mock-cm { white-space: pre; overflow-x: auto; }
.md-fences.mock-cm.md-fences-with-lineno { padding-left: 8px; }
.CodeMirror-line, twitterwidget { break-inside: avoid; }
svg { break-inside: avoid; }
.footnotes { opacity: 0.8; font-size: 0.9rem; margin-top: 1em; margin-bottom: 1em; }
.footnotes + .footnotes { margin-top: 0px; }
.md-reset { margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: top; background: 0px 0px; text-decoration: none; text-shadow: none; float: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; -webkit-tap-highlight-color: transparent; line-height: normal; font-weight: 400; text-align: left; box-sizing: content-box; direction: ltr; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li .mathjax-block, li p { margin: 0.5rem 0px; }
li blockquote { margin: 1rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child, li > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; white-space: normal; }
#write .footnote-line { white-space: pre-wrap; }
@media print {
body, html { border: 1px solid transparent; height: 99%; break-after: avoid; break-before: avoid; font-variant-ligatures: no-common-ligatures; }
#write { margin-top: 0px; border-color: transparent !important; padding-top: 0px !important; padding-bottom: 0px !important; }
.typora-export * { -webkit-print-color-adjust: exact; }
.typora-export #write { break-after: avoid; }
.typora-export #write::after { height: 0px; }
.is-mac table { break-inside: avoid; }
#write > p:nth-child(1) { margin-top: 0px; }
.typora-export-show-outline .typora-export-sidebar { display: none; }
figure { overflow-x: visible; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
a img, img a { cursor: pointer; }
pre.md-meta-block { font-size: 0.8rem; min-height: 0.8rem; white-space: pre-wrap; background: rgb(204, 204, 204); display: block; overflow-x: hidden; }
p > .md-image:only-child:not(.md-img-error) img, p > img:only-child { display: block; margin: auto; }
#write.first-line-indent p > .md-image:only-child:not(.md-img-error) img { left: -2em; position: relative; }
p > .md-image:only-child { display: inline-block; width: 100%; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.md-math-block { width: 100%; }
.md-math-block:not(:empty)::after { display: none; }
.MathJax_ref { fill: currentcolor; }
[contenteditable="true"]:active, [contenteditable="true"]:focus, [contenteditable="false"]:active, [contenteditable="false"]:focus { outline: 0px; box-shadow: none; }
.md-task-list-item { position: relative; list-style-type: none; }
.task-list-item.md-task-list-item { padding-left: 0px; }
.md-task-list-item > input { position: absolute; top: 0px; left: 0px; margin-left: -1.2em; margin-top: calc(1em - 10px); border: none; }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-radius: 10px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc-content::after, .md-toc::after { display: none; }
.md-toc-item { display: block; color: rgb(65, 131, 196); }
.md-toc-item a { text-decoration: none; }
.md-toc-inner:hover { text-decoration: underline; }
.md-toc-inner { display: inline-block; cursor: pointer; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: 700; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
@media screen and (max-width: 48em) {
.md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
.md-toc-h4 .md-toc-inner { margin-left: 5em; }
.md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
.md-toc-h6 .md-toc-inner { margin-left: 8em; }
}
a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.reversefootnote { font-family: ui-monospace, sans-serif; }
.md-attr { display: none; }
.md-fn-count::after { content: "."; }
code, pre, samp, tt { font-family: var(--monospace); }
kbd { margin: 0px 0.1em; padding: 0.1em 0.6em; font-size: 0.8em; color: rgb(36, 39, 41); background: rgb(255, 255, 255); border: 1px solid rgb(173, 179, 185); border-radius: 3px; box-shadow: rgba(12, 13, 14, 0.2) 0px 1px 0px, rgb(255, 255, 255) 0px 0px 0px 2px inset; white-space: nowrap; vertical-align: middle; }
.md-comment { color: rgb(162, 127, 3); opacity: 0.6; font-family: var(--monospace); }
code { text-align: left; vertical-align: initial; }
a.md-print-anchor { white-space: pre !important; border-width: initial !important; border-style: none !important; border-color: initial !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: 0px !important; background: 0px 0px !important; text-decoration: initial !important; text-shadow: initial !important; }
.os-windows.monocolor-emoji .md-emoji { font-family: "Segoe UI Symbol", sans-serif; }
.md-diagram-panel > svg { max-width: 100%; }
[lang="flow"] svg, [lang="mermaid"] svg { max-width: 100%; height: auto; }
[lang="mermaid"] .node text { font-size: 1rem; }
table tr th { border-bottom: 0px; }
video { max-width: 100%; display: block; margin: 0px auto; }
iframe { max-width: 100%; width: 100%; border: none; }
.highlight td, .highlight tr { border: 0px; }
mark { background: rgb(255, 255, 0); color: rgb(0, 0, 0); }
.md-html-inline .md-plain, .md-html-inline strong, mark .md-inline-math, mark strong { color: inherit; }
.md-expand mark .md-meta { opacity: 0.3 !important; }
mark .md-meta { color: rgb(0, 0, 0); }
@media print {
.typora-export h1, .typora-export h2, .typora-export h3, .typora-export h4, .typora-export h5, .typora-export h6 { break-inside: avoid; }
}
.md-diagram-panel .messageText { stroke: none !important; }
.md-diagram-panel .start-state { fill: var(--node-fill); }
.md-diagram-panel .edgeLabel rect { opacity: 1 !important; }
.md-fences.md-fences-math { font-size: 1em; }
.md-fences-advanced:not(.md-focus) { padding: 0px; white-space: nowrap; border: 0px; }
.md-fences-advanced:not(.md-focus) { background: inherit; }
.mermaid-svg { margin: auto; }
.typora-export-show-outline .typora-export-content { max-width: 1440px; margin: auto; display: flex; flex-direction: row; }
.typora-export-sidebar { width: 300px; font-size: 0.8rem; margin-top: 80px; margin-right: 18px; }
.typora-export-show-outline #write { --webkit-flex: 2; flex: 2 1 0%; }
.typora-export-sidebar .outline-content { position: fixed; top: 0px; max-height: 100%; overflow: hidden auto; padding-bottom: 30px; padding-top: 60px; width: 300px; }
@media screen and (max-width: 1024px) {
.typora-export-sidebar, .typora-export-sidebar .outline-content { width: 240px; }
}
@media screen and (max-width: 800px) {
.typora-export-sidebar { display: none; }
}
.outline-content li, .outline-content ul { margin-left: 0px; margin-right: 0px; padding-left: 0px; padding-right: 0px; list-style: none; overflow-wrap: anywhere; }
.outline-content ul { margin-top: 0px; margin-bottom: 0px; }
.outline-content strong { font-weight: 400; }
.outline-expander { width: 1rem; height: 1.42857rem; position: relative; display: table-cell; vertical-align: middle; cursor: pointer; padding-left: 4px; }
.outline-expander::before { content: ""; position: relative; font-family: Ionicons; display: inline-block; font-size: 8px; vertical-align: middle; }
.outline-item { padding-top: 3px; padding-bottom: 3px; cursor: pointer; }
.outline-expander:hover::before { content: ""; }
.outline-h1 > .outline-item { padding-left: 0px; }
.outline-h2 > .outline-item { padding-left: 1em; }
.outline-h3 > .outline-item { padding-left: 2em; }
.outline-h4 > .outline-item { padding-left: 3em; }
.outline-h5 > .outline-item { padding-left: 4em; }
.outline-h6 > .outline-item { padding-left: 5em; }
.outline-label { cursor: pointer; display: table-cell; vertical-align: middle; text-decoration: none; color: inherit; }
.outline-label:hover { text-decoration: underline; }
.outline-item:hover { border-color: rgb(245, 245, 245); background-color: var(--item-hover-bg-color); }
.outline-item:hover { margin-left: -28px; margin-right: -28px; border-left: 28px solid transparent; border-right: 28px solid transparent; }
.outline-item-single .outline-expander::before, .outline-item-single .outline-expander:hover::before { display: none; }
.outline-item-open > .outline-item > .outline-expander::before { content: ""; }
.outline-children { display: none; }
.info-panel-tab-wrapper { display: none; }
.outline-item-open > .outline-children { display: block; }
.typora-export .outline-item { padding-top: 1px; padding-bottom: 1px; }
.typora-export .outline-item:hover { margin-right: -8px; border-right: 8px solid transparent; }
.typora-export .outline-expander::before { content: "+"; font-family: inherit; top: -1px; }
.typora-export .outline-expander:hover::before, .typora-export .outline-item-open > .outline-item > .outline-expander::before { content: "−"; }
.typora-export-collapse-outline .outline-children { display: none; }
.typora-export-collapse-outline .outline-item-open > .outline-children, .typora-export-no-collapse-outline .outline-children { display: block; }
.typora-export-no-collapse-outline .outline-expander::before { content: "" !important; }
.typora-export-show-outline .outline-item-active > .outline-item .outline-label { font-weight: 700; }
.md-inline-math-container mjx-container { zoom: 0.95; }
mjx-container { break-inside: avoid; }
.md-alert.md-alert-note { border-left-color: rgb(9, 105, 218); }
.md-alert.md-alert-important { border-left-color: rgb(130, 80, 223); }
.md-alert.md-alert-warning { border-left-color: rgb(154, 103, 0); }
.md-alert.md-alert-tip { border-left-color: rgb(31, 136, 61); }
.md-alert.md-alert-caution { border-left-color: rgb(207, 34, 46); }
.md-alert { padding: 0px 1em; margin-bottom: 16px; color: inherit; border-left: 0.25em solid rgb(0, 0, 0); }
.md-alert-text-note { color: rgb(9, 105, 218); }
.md-alert-text-important { color: rgb(130, 80, 223); }
.md-alert-text-warning { color: rgb(154, 103, 0); }
.md-alert-text-tip { color: rgb(31, 136, 61); }
.md-alert-text-caution { color: rgb(207, 34, 46); }
.md-alert-text { font-size: 0.9rem; font-weight: 700; }
.md-alert-text svg { fill: currentcolor; position: relative; top: 0.125em; margin-right: 1ch; overflow: visible; }
.md-alert-text-container::after { content: attr(data-text); text-transform: capitalize; pointer-events: none; margin-right: 1ch; }
</style>
<style type='text/css' id="style-codemirror">.CodeMirror { height: auto; }
.CodeMirror.cm-s-inner { background: inherit; }
.CodeMirror-scroll { overflow: auto hidden; z-index: 3; }
.CodeMirror-gutter-filler, .CodeMirror-scrollbar-filler { background-color: rgb(255, 255, 255); }
.CodeMirror-gutters { border-right: 1px solid rgb(221, 221, 221); background: inherit; white-space: nowrap; }
.CodeMirror-linenumber { padding: 0px 3px 0px 5px; text-align: right; color: rgb(153, 153, 153); }
.cm-s-inner .cm-keyword { color: rgb(119, 0, 136); }
.cm-s-inner .cm-atom, .cm-s-inner.cm-atom { color: rgb(34, 17, 153); }
.cm-s-inner .cm-number { color: rgb(17, 102, 68); }
.cm-s-inner .cm-def { color: rgb(0, 0, 255); }
.cm-s-inner .cm-variable { color: rgb(0, 0, 0); }
.cm-s-inner .cm-variable-2 { color: rgb(0, 85, 170); }
.cm-s-inner .cm-variable-3 { color: rgb(0, 136, 85); }
.cm-s-inner .cm-string { color: rgb(170, 17, 17); }
.cm-s-inner .cm-property { color: rgb(0, 0, 0); }
.cm-s-inner .cm-operator { color: rgb(152, 26, 26); }
.cm-s-inner .cm-comment, .cm-s-inner.cm-comment { color: rgb(170, 85, 0); }
.cm-s-inner .cm-string-2 { color: rgb(255, 85, 0); }
.cm-s-inner .cm-meta { color: rgb(85, 85, 85); }
.cm-s-inner .cm-qualifier { color: rgb(85, 85, 85); }
.cm-s-inner .cm-builtin { color: rgb(51, 0, 170); }
.cm-s-inner .cm-bracket { color: rgb(153, 153, 119); }
.cm-s-inner .cm-tag { color: rgb(17, 119, 0); }
.cm-s-inner .cm-attribute { color: rgb(0, 0, 204); }
.cm-s-inner .cm-header, .cm-s-inner.cm-header { color: rgb(0, 0, 255); }
.cm-s-inner .cm-quote, .cm-s-inner.cm-quote { color: rgb(0, 153, 0); }
.cm-s-inner .cm-hr, .cm-s-inner.cm-hr { color: rgb(153, 153, 153); }
.cm-s-inner .cm-link, .cm-s-inner.cm-link { color: rgb(0, 0, 204); }
.cm-negative { color: rgb(221, 68, 68); }
.cm-positive { color: rgb(34, 153, 34); }
.cm-header, .cm-strong { font-weight: 700; }
.cm-del { text-decoration: line-through; }
.cm-em { font-style: italic; }
.cm-link { text-decoration: underline; }
.cm-error { color: red; }
.cm-invalidchar { color: red; }
.cm-constant { color: rgb(38, 139, 210); }
.cm-defined { color: rgb(181, 137, 0); }
div.CodeMirror span.CodeMirror-matchingbracket { color: rgb(0, 255, 0); }
div.CodeMirror span.CodeMirror-nonmatchingbracket { color: rgb(255, 34, 34); }
.cm-s-inner .CodeMirror-activeline-background { background: inherit; }
.CodeMirror { position: relative; overflow: hidden; }
.CodeMirror-scroll { height: 100%; outline: 0px; position: relative; box-sizing: content-box; background: inherit; }
.CodeMirror-sizer { position: relative; }
.CodeMirror-gutter-filler, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-vscrollbar { position: absolute; z-index: 6; display: none; outline: 0px; }
.CodeMirror-vscrollbar { right: 0px; top: 0px; overflow: hidden; }
.CodeMirror-hscrollbar { bottom: 0px; left: 0px; overflow: auto hidden; }
.CodeMirror-scrollbar-filler { right: 0px; bottom: 0px; }
.CodeMirror-gutter-filler { left: 0px; bottom: 0px; }
.CodeMirror-gutters { position: absolute; left: 0px; top: 0px; padding-bottom: 10px; z-index: 3; overflow-y: hidden; }
.CodeMirror-gutter { white-space: normal; height: 100%; box-sizing: content-box; padding-bottom: 30px; margin-bottom: -32px; display: inline-block; }
.CodeMirror-gutter-wrapper { position: absolute; z-index: 4; background: 0px 0px !important; border: none !important; }
.CodeMirror-gutter-background { position: absolute; top: 0px; bottom: 0px; z-index: 4; }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; }
.CodeMirror-lines { cursor: text; }
.CodeMirror pre { border-radius: 0px; border-width: 0px; background: 0px 0px; font-family: inherit; font-size: inherit; margin: 0px; white-space: pre; overflow-wrap: normal; color: inherit; z-index: 2; position: relative; overflow: visible; }
.CodeMirror-wrap pre { overflow-wrap: break-word; white-space: pre-wrap; word-break: normal; }
.CodeMirror-code pre { border-right: 30px solid transparent; width: fit-content; }
.CodeMirror-wrap .CodeMirror-code pre { border-right: none; width: auto; }
.CodeMirror-linebackground { position: absolute; inset: 0px; z-index: 0; }
.CodeMirror-linewidget { position: relative; z-index: 2; overflow: auto; }
.CodeMirror-wrap .CodeMirror-scroll { overflow-x: hidden; }
.CodeMirror-measure { position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden; }
.CodeMirror-measure pre { position: static; }
.CodeMirror div.CodeMirror-cursor { position: absolute; visibility: hidden; border-right: none; width: 0px; }
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
.CodeMirror-focused div.CodeMirror-cursor { visibility: inherit; }
.cm-searching { background: rgba(255, 255, 0, 0.4); }
span.cm-underlined { text-decoration: underline; }
span.cm-strikethrough { text-decoration: line-through; }
.cm-tw-syntaxerror { color: rgb(255, 255, 255); background-color: rgb(153, 0, 0); }
.cm-tw-deleted { text-decoration: line-through; }
.cm-tw-header5 { font-weight: 700; }
.cm-tw-listitem:first-child { padding-left: 10px; }
.cm-tw-box { border-style: solid; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-color: inherit; border-top-width: 0px !important; }
.cm-tw-underline { text-decoration: underline; }
@media print {
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
}
</style>
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext' type='text/css' />
<style type='text/css' id="style-theme_css">:root {
--side-bar-bg-color: #fafafa;
--control-text-color: #777;
}
@include-when-export url(https://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
/* open-sans-regular - latin-ext_latin */
/* open-sans-italic - latin-ext_latin */
/* open-sans-700 - latin-ext_latin */
/* open-sans-700italic - latin-ext_latin */
html {
font-size: 16px;
-webkit-font-smoothing: antialiased;
}
body {
font-family: "Open Sans","Clear Sans", "Helvetica Neue", Helvetica, Arial, 'Segoe UI Emoji', 'SF Pro', sans-serif;
color: rgb(51, 51, 51);
line-height: 1.6;
}
#write {
max-width: 860px;
margin: 0 auto;
padding: 30px;
padding-bottom: 100px;
}
@media only screen and (min-width: 1400px) {
#write {
max-width: 1024px;
}
}
@media only screen and (min-width: 1800px) {
#write {
max-width: 1200px;
}
}
#write > ul:first-child,
#write > ol:first-child{
margin-top: 30px;
}
a {
color: #4183C4;
}
h1,
h2,
h3,
h4,
h5,
h6 {
position: relative;
margin-top: 1rem;
margin-bottom: 1rem;
font-weight: bold;
line-height: 1.4;
cursor: text;
}
h1:hover a.anchor,
h2:hover a.anchor,
h3:hover a.anchor,
h4:hover a.anchor,
h5:hover a.anchor,
h6:hover a.anchor {
text-decoration: none;
}
h1 tt,
h1 code {
font-size: inherit;
}
h2 tt,
h2 code {
font-size: inherit;
}
h3 tt,
h3 code {
font-size: inherit;
}
h4 tt,
h4 code {
font-size: inherit;
}
h5 tt,
h5 code {
font-size: inherit;
}
h6 tt,
h6 code {
font-size: inherit;
}
h1 {
font-size: 2.25em;
line-height: 1.2;
border-bottom: 1px solid #eee;
}
h2 {
font-size: 1.75em;
line-height: 1.225;
border-bottom: 1px solid #eee;
}
/*@media print {
.typora-export h1,
.typora-export h2 {
border-bottom: none;
padding-bottom: initial;
}
.typora-export h1::after,
.typora-export h2::after {
content: "";
display: block;
height: 100px;
margin-top: -96px;
border-top: 1px solid #eee;
}
}*/
h3 {
font-size: 1.5em;
line-height: 1.43;
}
h4 {
font-size: 1.25em;
}
h5 {
font-size: 1em;
}
h6 {
font-size: 1em;
color: #777;
}
p,
blockquote,
ul,
ol,
dl,
table{
margin: 0.8em 0;
}
li>ol,
li>ul {
margin: 0 0;
}
hr {
height: 2px;
padding: 0;
margin: 16px 0;
background-color: #e7e7e7;
border: 0 none;
overflow: hidden;
box-sizing: content-box;
}
li p.first {
display: inline-block;
}
ul,
ol {
padding-left: 30px;
}
ul:first-child,
ol:first-child {
margin-top: 0;
}
ul:last-child,
ol:last-child {
margin-bottom: 0;
}
blockquote {
border-left: 4px solid #dfe2e5;
padding: 0 15px;
color: #777777;
}
blockquote blockquote {
padding-right: 0;
}
table {
padding: 0;
word-break: initial;
}
table tr {
border: 1px solid #dfe2e5;
margin: 0;
padding: 0;
}
table tr:nth-child(2n),
thead {
background-color: #f8f8f8;
}
table th {
font-weight: bold;
border: 1px solid #dfe2e5;
border-bottom: 0;
margin: 0;
padding: 6px 13px;
}
table td {
border: 1px solid #dfe2e5;
margin: 0;
padding: 6px 13px;
}
table th:first-child,
table td:first-child {
margin-top: 0;
}
table th:last-child,
table td:last-child {
margin-bottom: 0;
}
.CodeMirror-lines {
padding-left: 4px;
}
.code-tooltip {
box-shadow: 0 1px 1px 0 rgba(0,28,36,.3);
border-top: 1px solid #eef2f2;
}
.md-fences,
code,
tt {
border: 1px solid #e7eaed;
background-color: #f8f8f8;
border-radius: 3px;
padding: 0;
padding: 2px 4px 0px 4px;
font-size: 0.9em;
}
code {
background-color: #f3f4f4;
padding: 0 2px 0 2px;
}
.md-fences {
margin-bottom: 15px;
margin-top: 15px;
padding-top: 8px;
padding-bottom: 6px;
}
.md-task-list-item > input {
margin-left: -1.3em;
}
@media print {
html {
font-size: 13px;
}
pre {
page-break-inside: avoid;
word-wrap: break-word;
}
}
.md-fences {
background-color: #f8f8f8;
}
#write pre.md-meta-block {
padding: 1rem;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border: 0;
border-radius: 3px;
color: #777777;
margin-top: 0 !important;
}
.mathjax-block>.code-tooltip {
bottom: .375rem;
}
.md-mathjax-midline {
background: #fafafa;
}
#write>h3.md-focus:before{
left: -1.5625rem;
top: .375rem;
}
#write>h4.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
#write>h5.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
#write>h6.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
.md-image>.md-meta {
/*border: 1px solid #ddd;*/
border-radius: 3px;
padding: 2px 0px 0px 4px;
font-size: 0.9em;
color: inherit;
}
.md-tag {
color: #a7a7a7;
opacity: 1;
}
.md-toc {
margin-top:20px;
padding-bottom:20px;
}
.sidebar-tabs {
border-bottom: none;
}
#typora-quick-open {
border: 1px solid #ddd;
background-color: #f8f8f8;
}
#typora-quick-open-item {
background-color: #FAFAFA;
border-color: #FEFEFE #e5e5e5 #e5e5e5 #eee;
border-style: solid;
border-width: 1px;
}
/** focus mode */
.on-focus-mode blockquote {
border-left-color: rgba(85, 85, 85, 0.12);
}
header, .context-menu, .megamenu-content, footer{
font-family: "Segoe UI", "Arial", sans-serif;
}
.file-node-content:hover .file-node-icon,
.file-node-content:hover .file-node-open-state{
visibility: visible;
}
.mac-seamless-mode #typora-sidebar {
background-color: #fafafa;
background-color: var(--side-bar-bg-color);
}
.mac-os #write{
caret-color: AccentColor;
}
.md-lang {
color: #b4654d;
}
/*.html-for-mac {
--item-hover-bg-color: #E6F0FE;
}*/
#md-notification .btn {
border: 0;
}
.dropdown-menu .divider {
border-color: #e5e5e5;
opacity: 0.4;
}
.ty-preferences .window-content {
background-color: #fafafa;
}
.ty-preferences .nav-group-item.active {
color: white;
background: #999;
}
.menu-item-container a.menu-style-btn {
background-color: #f5f8fa;
background-image: linear-gradient( 180deg , hsla(0, 0%, 100%, 0.8), hsla(0, 0%, 100%, 0));
}
</style>
<style type='text/css' id="style-lp">ol, ul {padding-left: 40px}</style>
<title>docs</title>
</head>
<body class='typora-export os-windows'><div class='typora-export-content'>
<div id='write' class=''><h1 id='libuv-in-lua'><span>LibUV in Lua</span></h1><p><span>The </span><a href='https://github.com/luvit/luv' target='_blank'><span>luv</span></a><span> project provides access to the multi-platform support library</span>
<a href='https://github.com/libuv/libuv' target='_blank'><span>libuv</span></a><span> in Lua code. It was primarily developed for the </span><a href='https://github.com/luvit/luvit' target='_blank'><span>luvit</span></a><span> project as</span>
<span>the built-in </span><code>uv</code><span> module, but can be used in other Lua environments.</span></p><p><span>More information about the core libuv library can be found at the original</span>
<a href='http://docs.libuv.org/' target='_blank'><span>libuv documentation page</span></a><span>.</span></p><h3 id='tcp-echo-server-example'><span>TCP Echo Server Example</span></h3><p><span>Here is a small example showing a TCP echo server:</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><span><span></span>x</span></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">uv</span> = <span class="cm-builtin">require</span>(<span class="cm-string">"luv"</span>) <span class="cm-comment">-- "luv" when stand-alone, "uv" in luvi apps</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">server</span> = <span class="cm-variable">uv.new_tcp</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">server</span>:<span class="cm-variable">bind</span>(<span class="cm-string">"127.0.0.1"</span>, <span class="cm-number">1337</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">server</span>:<span class="cm-variable">listen</span>(<span class="cm-number">128</span>, <span class="cm-keyword">function</span> (<span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">assert</span>(<span class="cm-keyword">not</span> <span class="cm-variable">err</span>, <span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">local</span> <span class="cm-variable">client</span> = <span class="cm-variable">uv.new_tcp</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">server</span>:<span class="cm-variable">accept</span>(<span class="cm-variable">client</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">client</span>:<span class="cm-variable">read_start</span>(<span class="cm-keyword">function</span> (<span class="cm-variable">err</span>, <span class="cm-variable">chunk</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">assert</span>(<span class="cm-keyword">not</span> <span class="cm-variable">err</span>, <span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> <span class="cm-variable">chunk</span> <span class="cm-keyword">then</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">client</span>:<span class="cm-builtin">write</span>(<span class="cm-variable">chunk</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">else</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">client</span>:<span class="cm-variable">shutdown</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">client</span>:<span class="cm-builtin">close</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">print</span>(<span class="cm-string">"TCP server listening at 127.0.0.1 port 1337"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.run</span>() <span class="cm-comment">-- an explicit run call is necessary outside of luvit</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 461px;"></div><div class="CodeMirror-gutters" style="display: none; height: 461px;"></div></div></div></pre><h3 id='module-layout'><span>Module Layout</span></h3><p><span>The luv library contains a single Lua module referred to hereafter as </span><code>uv</code><span> for</span>
<span>simplicity. This module consists mostly of functions with names corresponding to</span>
<span>their original libuv versions. For example, the libuv function </span><code>uv_tcp_bind</code><span> has</span>
<span>a luv version at </span><code>uv.tcp_bind</code><span>. Currently, only two non-function fields exists:</span>
<code>uv.constants</code><span> and </span><code>uv.errno</code><span>, which are tables.</span></p><h3 id='functions-vs-methods'><span>Functions vs Methods</span></h3><p><span>In addition to having simple functions, luv provides an optional method-style</span>
<span>API. For example, </span><code>uv.tcp_bind(server, host, port)</code><span> can alternatively be called</span>
<span>as </span><code>server:bind(host, port)</code><span>. Note that the first argument </span><code>server</code><span> becomes the</span>
<span>object and </span><code>tcp_</code><span> is removed from the function name. Method forms are</span>
<span>documented below where they exist.</span></p><h3 id='synchronous-vs-asynchronous-functions'><span>Synchronous vs Asynchronous Functions</span></h3><p><span>Functions that accept a callback are asynchronous. These functions may</span>
<span>immediately return results to the caller to indicate their initial status, but</span>
<span>their final execution is deferred until at least the next libuv loop iteration.</span>
<span>After completion, their callbacks are executed with any results passed to it.</span></p><p><span>Functions that do not accept a callback are synchronous. These functions</span>
<span>immediately return their results to the caller.</span></p><p><span>Some (generally FS and DNS) functions can behave either synchronously or</span>
<span>asynchronously. If a callback is provided to these functions, they behave</span>
<span>asynchronously; if no callback is provided, they behave synchronously.</span></p><h3 id='pseudo-types'><span>Pseudo-Types</span></h3><p><span>Some unique types are defined. These are not actual types in Lua, but they are</span>
<span>used here to facilitate documenting consistent behavior:</span></p><ul><li><p><code>fail</code><span>: an assertable </span><code>nil, string, string</code><span> tuple (see </span><a href='#error-handling' target='_blank'><span>Error Handling</span></a><span>)</span></p></li><li><p><code>callable</code><span>: a </span><code>function</code><span>; or a </span><code>table</code><span> or </span><code>userdata</code><span> with a </span><code>__call</code>
<span>metamethod</span></p></li><li><p><code>buffer</code><span>: a </span><code>string</code><span> or a sequential </span><code>table</code><span> of </span><code>string</code><span>s</span></p></li><li><p><code>threadargs</code><span>: variable arguments (</span><code>...</code><span>) of type </span><code>nil</code><span>, </span><code>boolean</code><span>, </span><code>number</code><span>,</span>
<code>string</code><span>, or </span><code>userdata</code><span>, numbers of argument limited to 9.</span></p></li></ul><h2 id='contents'><span>Contents</span></h2><p><span>This documentation is mostly a retelling of the </span><a href='http://docs.libuv.org/en/v1.x/api.html' target='_blank'><span>libuv API documentation</span></a>
<span>within the context of luv's Lua API. Low-level implementation details and</span>
<span>unexposed C functions and types are not documented here except for when they</span>
<span>are relevant to behavior seen in the Lua module.</span></p><ul><li><p><a href='#constants' target='_blank'><span>Constants</span></a></p></li><li><p><a href='#error-handling' target='_blank'><span>Error Handling</span></a></p></li><li><p><a href='#version-checking' target='_blank'><span>Version Checking</span></a></p></li><li><p><a href='#uv_loop_t--event-loop' target='_blank'><code>uv_loop_t</code></a><span> — Event loop</span></p></li><li><p><a href='#uv_req_t--base-request' target='_blank'><code>uv_req_t</code></a><span> — Base request</span></p></li><li><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> — Base handle</span></p><ul><li><p><a href='#uv_timer_t--timer-handle' target='_blank'><code>uv_timer_t</code></a><span> — Timer handle</span></p></li><li><p><a href='#uv_prepare_t--prepare-handle' target='_blank'><code>uv_prepare_t</code></a><span> — Prepare handle</span></p></li><li><p><a href='#uv_check_t--check-handle' target='_blank'><code>uv_check_t</code></a><span> — Check handle</span></p></li><li><p><a href='#uv_idle_t--idle-handle' target='_blank'><code>uv_idle_t</code></a><span> — Idle handle</span></p></li><li><p><a href='#uv_async_t--async-handle' target='_blank'><code>uv_async_t</code></a><span> — Async handle</span></p></li><li><p><a href='#uv_poll_t--poll-handle' target='_blank'><code>uv_poll_t</code></a><span> — Poll handle</span></p></li><li><p><a href='#uv_signal_t--signal-handle' target='_blank'><code>uv_signal_t</code></a><span> — Signal handle</span></p></li><li><p><a href='#uv_process_t--process-handle' target='_blank'><code>uv_process_t</code></a><span> — Process handle</span></p></li><li><p><a href='#uv_stream_t--stream-handle' target='_blank'><code>uv_stream_t</code></a><span> — Stream handle</span></p><ul><li><p><a href='#uv_tcp_t--tcp-handle' target='_blank'><code>uv_tcp_t</code></a><span> — TCP handle</span></p></li><li><p><a href='#uv_pipe_t--pipe-handle' target='_blank'><code>uv_pipe_t</code></a><span> — Pipe handle</span></p></li><li><p><a href='#uv_tty_t--tty-handle' target='_blank'><code>uv_tty_t</code></a><span> — TTY handle</span></p></li></ul></li><li><p><a href='#uv_udp_t--udp-handle' target='_blank'><code>uv_udp_t</code></a><span> — UDP handle</span></p></li><li><p><a href='#uv_fs_event_t--fs-event-handle' target='_blank'><code>uv_fs_event_t</code></a><span> — FS Event handle</span></p></li><li><p><a href='#uv_fs_poll_t--fs-poll-handle' target='_blank'><code>uv_fs_poll_t</code></a><span> — FS Poll handle</span></p></li></ul></li><li><p><a href='#file-system-operations' target='_blank'><span>File system operations</span></a></p></li><li><p><a href='#thread-pool-work-scheduling' target='_blank'><span>Thread pool work scheduling</span></a></p></li><li><p><a href='#dns-utility-functions' target='_blank'><span>DNS utility functions</span></a></p></li><li><p><a href='#threading-and-synchronization-utilities' target='_blank'><span>Threading and synchronization utilities</span></a></p></li><li><p><a href='#miscellaneous-utilities' target='_blank'><span>Miscellaneous utilities</span></a></p></li><li><p><a href='#metrics-operations' target='_blank'><span>Metrics operations</span></a></p></li></ul><h2 id='constants'><span>Constants</span></h2><p><span>As a Lua library, luv supports and encourages the use of lowercase strings to</span>
<span>represent options. For example:</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- signal start with string input</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.signal_start</span>(<span class="cm-string">"sigterm"</span>, <span class="cm-keyword">function</span>(<span class="cm-variable">signame</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-variable">signame</span>) <span class="cm-comment">-- string output: "sigterm"</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="display: none; height: 92px;"></div></div></div></pre><p><span>However, luv also superficially exposes libuv constants in a Lua table at</span>
<code>uv.constants</code><span> where its keys are uppercase constant names and their associated</span>
<span>values are integers defined internally by libuv. The values from this table may</span>
<span>be supported as function arguments, but their use may not change the output</span>
<span>type. For example:</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- signal start with integer input</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.signal_start</span>(<span class="cm-variable">uv.constants.SIGTERM</span>, <span class="cm-keyword">function</span>(<span class="cm-variable">signame</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-variable">signame</span>) <span class="cm-comment">-- string output: "sigterm"</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="display: none; height: 92px;"></div></div></div></pre><p><span>The uppercase constants defined in </span><code>uv.constants</code><span> that have associated</span>
<span>lowercase option strings are listed below.</span></p><h3 id='address-families'><span>Address Families</span></h3><ul><li><p><code>AF_UNIX</code><span>: "unix"</span></p></li><li><p><code>AF_INET</code><span>: "inet"</span></p></li><li><p><code>AF_INET6</code><span>: "inet6"</span></p></li><li><p><code>AF_IPX</code><span>: "ipx"</span></p></li><li><p><code>AF_NETLINK</code><span>: "netlink"</span></p></li><li><p><code>AF_X25</code><span>: "x25"</span></p></li><li><p><code>AF_AX25</code><span>: "as25"</span></p></li><li><p><code>AF_ATMPVC</code><span>: "atmpvc"</span></p></li><li><p><code>AF_APPLETALK</code><span>: "appletalk"</span></p></li><li><p><code>AF_PACKET</code><span>: "packet"</span></p></li></ul><h3 id='signals'><span>Signals</span></h3><ul><li><p><code>SIGHUP</code><span>: "sighup"</span></p></li><li><p><code>SIGINT</code><span>: "sigint"</span></p></li><li><p><code>SIGQUIT</code><span>: "sigquit"</span></p></li><li><p><code>SIGILL</code><span>: "sigill"</span></p></li><li><p><code>SIGTRAP</code><span>: "sigtrap"</span></p></li><li><p><code>SIGABRT</code><span>: "sigabrt"</span></p></li><li><p><code>SIGIOT</code><span>: "sigiot"</span></p></li><li><p><code>SIGBUS</code><span>: "sigbus"</span></p></li><li><p><code>SIGFPE</code><span>: "sigfpe"</span></p></li><li><p><code>SIGKILL</code><span>: "sigkill"</span></p></li><li><p><code>SIGUSR1</code><span>: "sigusr1"</span></p></li><li><p><code>SIGSEGV</code><span>: "sigsegv"</span></p></li><li><p><code>SIGUSR2</code><span>: "sigusr2"</span></p></li><li><p><code>SIGPIPE</code><span>: "sigpipe"</span></p></li><li><p><code>SIGALRM</code><span>: "sigalrm"</span></p></li><li><p><code>SIGTERM</code><span>: "sigterm"</span></p></li><li><p><code>SIGCHLD</code><span>: "sigchld"</span></p></li><li><p><code>SIGSTKFLT</code><span>: "sigstkflt"</span></p></li><li><p><code>SIGCONT</code><span>: "sigcont"</span></p></li><li><p><code>SIGSTOP</code><span>: "sigstop"</span></p></li><li><p><code>SIGTSTP</code><span>: "sigtstp"</span></p></li><li><p><code>SIGBREAK</code><span>: "sigbreak"</span></p></li><li><p><code>SIGTTIN</code><span>: "sigttin"</span></p></li><li><p><code>SIGTTOU</code><span>: "sigttou"</span></p></li><li><p><code>SIGURG</code><span>: "sigurg"</span></p></li><li><p><code>SIGXCPU</code><span>: "sigxcpu"</span></p></li><li><p><code>SIGXFSZ</code><span>: "sigxfsz"</span></p></li><li><p><code>SIGVTALRM</code><span>: "sigvtalrm"</span></p></li><li><p><code>SIGPROF</code><span>: "sigprof"</span></p></li><li><p><code>SIGWINCH</code><span>: "sigwinch"</span></p></li><li><p><code>SIGIO</code><span>: "sigio"</span></p></li><li><p><code>SIGPOLL</code><span>: "sigpoll"</span></p></li><li><p><code>SIGLOST</code><span>: "siglost"</span></p></li><li><p><code>SIGPWR</code><span>: "sigpwr"</span></p></li><li><p><code>SIGSYS</code><span>: "sigsys"</span></p></li></ul><h3 id='socket-types'><span>Socket Types</span></h3><ul><li><p><code>SOCK_STREAM</code><span>: "stream"</span></p></li><li><p><code>SOCK_DGRAM</code><span>: "dgram"</span></p></li><li><p><code>SOCK_SEQPACKET</code><span>: "seqpacket"</span></p></li><li><p><code>SOCK_RAW</code><span>: "raw"</span></p></li><li><p><code>SOCK_RDM</code><span>: "rdm"</span></p></li></ul><h3 id='tty-modes'><span>TTY Modes</span></h3><ul><li><p><code>TTY_MODE_NORMAL</code><span>: "normal"</span></p></li><li><p><code>TTY_MODE_RAW</code><span>: "raw"</span></p></li><li><p><code>TTY_MODE_IO</code><span>: "io"</span></p></li><li><p><code>TTY_MODE_RAW_VT</code><span>: "raw_vt"</span></p></li></ul><h3 id='fs-modification-times'><span>FS Modification Times</span></h3><ul><li><p><code>FS_UTIME_NOW</code><span>: "now"</span></p></li><li><p><code>FS_UTIME_OMIT</code><span>: "omit"</span></p></li></ul><h2 id='error-handling'><span>Error Handling</span></h2><p><span>In libuv, errors are represented by negative numbered constants. While these</span>
<span>constants are made available in the </span><code>uv.errno</code><span> table, they are not returned by</span>
<span>luv functions and the libuv functions used to handle them are not exposed.</span>
<span>Instead, if an internal error is encountered, the failing luv function will</span>
<span>return to the caller an assertable </span><code>nil, err, name</code><span> tuple:</span></p><ul><li><p><code>nil</code><span> idiomatically indicates failure</span></p></li><li><p><code>err</code><span> is a string with the format </span><code>{name}: {message}</code></p><ul><li><p><code>{name}</code><span> is the error name provided internally by </span><code>uv_err_name</code></p></li><li><p><code>{message}</code><span> is a human-readable message provided internally by </span><code>uv_strerror</code></p></li></ul></li><li><p><code>name</code><span> is the same string used to construct </span><code>err</code></p></li></ul><p><span>This tuple is referred to below as the </span><code>fail</code><span> pseudo-type.</span></p><p><span>When a function is called successfully, it will return either a value that is</span>
<span>relevant to the operation of the function, or the integer </span><code>0</code><span> to indicate</span>
<span>success, or sometimes nothing at all. These cases are documented below.</span></p><p><span>Below is a list of known error names and error strings. See libuv's</span>
<a href='https://docs.libuv.org/en/v1.x/errors.html#error-constants' target='_blank'><span>error constants</span></a><span> page for an original source.</span></p><ul><li><p><code>E2BIG</code><span>: argument list too long.</span></p></li><li><p><code>EACCES</code><span>: permission denied.</span></p></li><li><p><code>EADDRINUSE</code><span>: address already in use.</span></p></li><li><p><code>EADDRNOTAVAIL</code><span>: address not available.</span></p></li><li><p><code>EAFNOSUPPORT</code><span>: address family not supported.</span></p></li><li><p><code>EAGAIN</code><span>: resource temporarily unavailable.</span></p></li><li><p><code>EAI_ADDRFAMILY</code><span>: address family not supported.</span></p></li><li><p><code>EAI_AGAIN</code><span>: temporary failure.</span></p></li><li><p><code>EAI_BADFLAGS</code><span>: bad ai_flags value.</span></p></li><li><p><code>EAI_BADHINTS</code><span>: invalid value for hints.</span></p></li><li><p><code>EAI_CANCELED</code><span>: request canceled.</span></p></li><li><p><code>EAI_FAIL</code><span>: permanent failure.</span></p></li><li><p><code>EAI_FAMILY</code><span>: ai_family not supported.</span></p></li><li><p><code>EAI_MEMORY</code><span>: out of memory.</span></p></li><li><p><code>EAI_NODATA</code><span>: no address.</span></p></li><li><p><code>EAI_NONAME</code><span>: unknown node or service.</span></p></li><li><p><code>EAI_OVERFLOW</code><span>: argument buffer overflow.</span></p></li><li><p><code>EAI_PROTOCOL</code><span>: resolved protocol is unknown.</span></p></li><li><p><code>EAI_SERVICE</code><span>: service not available for socket type.</span></p></li><li><p><code>EAI_SOCKTYPE</code><span>: socket type not supported.</span></p></li><li><p><code>EALREADY</code><span>: connection already in progress.</span></p></li><li><p><code>EBADF</code><span>: bad file descriptor.</span></p></li><li><p><code>EBUSY</code><span>: resource busy or locked.</span></p></li><li><p><code>ECANCELED</code><span>: operation canceled.</span></p></li><li><p><code>ECHARSET</code><span>: invalid Unicode character.</span></p></li><li><p><code>ECONNABORTED</code><span>: software caused connection abort.</span></p></li><li><p><code>ECONNREFUSED</code><span>: connection refused.</span></p></li><li><p><code>ECONNRESET</code><span>: connection reset by peer.</span></p></li><li><p><code>EDESTADDRREQ</code><span>: destination address required.</span></p></li><li><p><code>EEXIST</code><span>: file already exists.</span></p></li><li><p><code>EFAULT</code><span>: bad address in system call argument.</span></p></li><li><p><code>EFBIG</code><span>: file too large.</span></p></li><li><p><code>EHOSTUNREACH</code><span>: host is unreachable.</span></p></li><li><p><code>EINTR</code><span>: interrupted system call.</span></p></li><li><p><code>EINVAL</code><span>: invalid argument.</span></p></li><li><p><code>EIO</code><span>: i/o error.</span></p></li><li><p><code>EISCONN</code><span>: socket is already connected.</span></p></li><li><p><code>EISDIR</code><span>: illegal operation on a directory.</span></p></li><li><p><code>ELOOP</code><span>: too many symbolic links encountered.</span></p></li><li><p><code>EMFILE</code><span>: too many open files.</span></p></li><li><p><code>EMSGSIZE</code><span>: message too long.</span></p></li><li><p><code>ENAMETOOLONG</code><span>: name too long.</span></p></li><li><p><code>ENETDOWN</code><span>: network is down.</span></p></li><li><p><code>ENETUNREACH</code><span>: network is unreachable.</span></p></li><li><p><code>ENFILE</code><span>: file table overflow.</span></p></li><li><p><code>ENOBUFS</code><span>: no buffer space available.</span></p></li><li><p><code>ENODEV</code><span>: no such device.</span></p></li><li><p><code>ENOENT</code><span>: no such file or directory.</span></p></li><li><p><code>ENOMEM</code><span>: not enough memory.</span></p></li><li><p><code>ENONET</code><span>: machine is not on the network.</span></p></li><li><p><code>ENOPROTOOPT</code><span>: protocol not available.</span></p></li><li><p><code>ENOSPC</code><span>: no space left on device.</span></p></li><li><p><code>ENOSYS</code><span>: function not implemented.</span></p></li><li><p><code>ENOTCONN</code><span>: socket is not connected.</span></p></li><li><p><code>ENOTDIR</code><span>: not a directory.</span></p></li><li><p><code>ENOTEMPTY</code><span>: directory not empty.</span></p></li><li><p><code>ENOTSOCK</code><span>: socket operation on non-socket.</span></p></li><li><p><code>ENOTSUP</code><span>: operation not supported on socket.</span></p></li><li><p><code>EOVERFLOW</code><span>: value too large for defined data type.</span></p></li><li><p><code>EPERM</code><span>: operation not permitted.</span></p></li><li><p><code>EPIPE</code><span>: broken pipe.</span></p></li><li><p><code>EPROTO</code><span>: protocol error.</span></p></li><li><p><code>EPROTONOSUPPORT</code><span>: protocol not supported.</span></p></li><li><p><code>EPROTOTYPE</code><span>: protocol wrong type for socket.</span></p></li><li><p><code>ERANGE</code><span>: result too large.</span></p></li><li><p><code>EROFS</code><span>: read-only file system.</span></p></li><li><p><code>ESHUTDOWN</code><span>: cannot send after transport endpoint shutdown.</span></p></li><li><p><code>ESPIPE</code><span>: invalid seek.</span></p></li><li><p><code>ESRCH</code><span>: no such process.</span></p></li><li><p><code>ETIMEDOUT</code><span>: connection timed out.</span></p></li><li><p><code>ETXTBSY</code><span>: text file is busy.</span></p></li><li><p><code>EXDEV</code><span>: cross-device link not permitted.</span></p></li><li><p><code>UNKNOWN</code><span>: unknown error.</span></p></li><li><p><code>EOF</code><span>: end of file.</span></p></li><li><p><code>ENXIO</code><span>: no such device or address.</span></p></li><li><p><code>EMLINK</code><span>: too many links.</span></p></li><li><p><code>ENOTTY</code><span>: inappropriate ioctl for device.</span></p></li><li><p><code>EFTYPE</code><span>: inappropriate file type or format.</span></p></li><li><p><code>EILSEQ</code><span>: illegal byte sequence.</span></p></li><li><p><code>ESOCKTNOSUPPORT</code><span>: socket type not supported.</span></p></li></ul><h2 id='version-checking'><span>Version Checking</span></h2><h3 id='uvversion'><code>uv.version()</code></h3><p><span>Returns the libuv version packed into a single integer. 8 bits are used for each</span>
<span>component, with the patch number stored in the 8 least significant bits. For</span>
<span>example, this would be 0x010203 in libuv 1.2.3.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code></p><h3 id='uvversionstring'><code>uv.version_string()</code></h3><p><span>Returns the libuv version number as a string. For example, this would be "1.2.3"</span>
<span>in libuv 1.2.3. For non-release versions, the version suffix is included.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>string</code></p><h2 id='uvloopt-----event-loop'><code>uv_loop_t</code><span> — Event loop</span></h2><p><span>The event loop is the central part of libuv's functionality. It takes care of</span>
<span>polling for I/O and scheduling callbacks to be run based on different sources of</span>
<span>events.</span></p><p><span>In luv, there is an implicit uv loop for every Lua state that loads the library.</span>
<span>You can use this library in an multi-threaded environment as long as each thread</span>
<span>has it's own Lua state with its corresponding own uv loop. This loop is not</span>
<span>directly exposed to users in the Lua module.</span></p><h3 id='uvloopclose'><code>uv.loop_close()</code></h3><p><span>Closes all internal loop resources. In normal execution, the loop will</span>
<span>automatically be closed when it is garbage collected by Lua, so it is not</span>
<span>necessary to explicitly call </span><code>loop_close()</code><span>. Call this function only after the</span>
<span>loop has finished executing and all open handles and requests have been closed,</span>
<span>or it will return </span><code>EBUSY</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvrunmode'><code>uv.run([mode])</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>mode</code><span>: </span><code>string</code><span> or </span><code>nil</code><span> (default: </span><code>"default"</code><span>)</span></p></li></ul><p><span>This function runs the event loop. It will act differently depending on the</span>
<span>specified mode:</span></p><ul><li><p><code>"default"</code><span>: Runs the event loop until there are no more active and</span>
<span>referenced handles or requests. Returns </span><code>true</code><span> if </span><code>uv.stop()</code><span> was called and</span>
<span> there are still active handles or requests. Returns </span><code>false</code><span> in all other</span>
<span> cases.</span></p></li><li><p><code>"once"</code><span>: Poll for I/O once. Note that this function blocks if there are no</span>
<span>pending callbacks. Returns </span><code>false</code><span> when done (no active handles or requests</span>
<span> left), or </span><code>true</code><span> if more callbacks are expected (meaning you should run the</span>
<span> event loop again sometime in the future).</span></p></li><li><p><code>"nowait"</code><span>: Poll for I/O once but don't block if there are no pending</span>
<span>callbacks. Returns </span><code>false</code><span> if done (no active handles or requests left),</span>
<span> or </span><code>true</code><span> if more callbacks are expected (meaning you should run the event</span>
<span> loop again sometime in the future).</span></p></li></ul><p><strong><span>Returns:</span></strong><span> </span><code>boolean</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: Luvit will implicitly call </span><code>uv.run()</code><span> after loading user code, but if</span>
<span>you use the luv bindings directly, you need to call this after registering</span>
<span>your initial set of event callbacks to start the event loop.</span></p><h3 id='uvloopconfigureoption-'><code>uv.loop_configure(option, ...)</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>option</code><span>: </span><code>string</code></p></li><li><p><code>...</code><span>: </span><code>any</code><span> depends on </span><code>option</code></p></li></ul><p><span>Set additional loop options. You should normally call this before the first call</span>
<span>to uv_run() unless mentioned otherwise.</span></p><p><span>Supported options:</span></p><ul><li><p><code>"block_signal"</code><span>: Block a signal when polling for new events. The second argument</span>
<span>to loop_configure() is the signal name (as a lowercase string) or the signal number.</span>
<span> This operation is currently only implemented for </span><code>"sigprof"</code><span> signals, to suppress</span>
<span> unnecessary wakeups when using a sampling profiler. Requesting other signals will</span>
<span> fail with </span><code>EINVAL</code><span>.</span></p></li><li><p><code>"metrics_idle_time"</code><span>: Accumulate the amount of idle time the event loop spends</span>
<span>in the event provider. This option is necessary to use </span><code>metrics_idle_time()</code><span>.</span></p></li></ul><p><span>An example of a valid call to this function is:</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.loop_configure</span>(<span class="cm-string">"block_signal"</span>, <span class="cm-string">"sigprof"</span>)</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 23px;"></div><div class="CodeMirror-gutters" style="display: none; height: 23px;"></div></div></div></pre><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: Be prepared to handle the </span><code>ENOSYS</code><span> error; it means the loop option is</span>
<span>not supported by the platform.</span></p><h3 id='uvloopmode'><code>uv.loop_mode()</code></h3><p><span>If the loop is running, returns a string indicating the mode in use. If the loop</span>
<span>is not running, </span><code>nil</code><span> is returned instead.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>string</code><span> or </span><code>nil</code></p><h3 id='uvloopalive'><code>uv.loop_alive()</code></h3><p><span>Returns </span><code>true</code><span> if there are referenced active handles, active requests, or</span>
<span>closing handles in the loop; otherwise, </span><code>false</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>boolean</code><span> or </span><code>fail</code></p><h3 id='uvstop'><code>uv.stop()</code></h3><p><span>Stop the event loop, causing </span><code>uv.run()</code><span> to end as soon as possible. This</span>
<span>will happen not sooner than the next loop iteration. If this function was called</span>
<span>before blocking for I/O, the loop won't block for I/O on this iteration.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><h3 id='uvbackendfd'><code>uv.backend_fd()</code></h3><p><span>Get backend file descriptor. Only kqueue, epoll, and event ports are supported.</span></p><p><span>This can be used in conjunction with </span><code>uv.run("nowait")</code><span> to poll in one thread</span>
<span>and run the event loop's callbacks in another</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code><span> or </span><code>nil</code></p><p><strong><span>Note</span></strong><span>: Embedding a kqueue fd in another kqueue pollset doesn't work on all</span>
<span>platforms. It's not an error to add the fd but it never generates events.</span></p><h3 id='uvbackendtimeout'><code>uv.backend_timeout()</code></h3><p><span>Get the poll timeout. The return value is in milliseconds, or -1 for no timeout.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code></p><h3 id='uvnow'><code>uv.now()</code></h3><p><span>Returns the current timestamp in milliseconds. The timestamp is cached at the</span>
<span>start of the event loop tick, see </span><code>uv.update_time()</code><span> for details and rationale.</span></p><p><span>The timestamp increases monotonically from some arbitrary point in time. Don't</span>
<span>make assumptions about the starting point, you will only get disappointed.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code></p><p><strong><span>Note</span></strong><span>: Use </span><code>uv.hrtime()</code><span> if you need sub-millisecond granularity.</span></p><h3 id='uvupdatetime'><code>uv.update_time()</code></h3><p><span>Update the event loop's concept of "now". Libuv caches the current time at the</span>
<span>start of the event loop tick in order to reduce the number of time-related</span>
<span>system calls.</span></p><p><span>You won't normally need to call this function unless you have callbacks that</span>
<span>block the event loop for longer periods of time, where "longer" is somewhat</span>
<span>subjective but probably on the order of a millisecond or more.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><h3 id='uvwalkcallback'><code>uv.walk(callback)</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>callback</code><span>: </span><code>callable</code></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li></ul></li></ul><p><span>Walk the list of handles: </span><code>callback</code><span> will be executed with each handle.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Example usage of uv.walk to close all handles that aren't already closing.</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.walk</span>(<span class="cm-keyword">function</span> (<span class="cm-variable">handle</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> <span class="cm-keyword">not</span> <span class="cm-variable">handle</span>:<span class="cm-variable">is_closing</span>() <span class="cm-keyword">then</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">handle</span>:<span class="cm-builtin">close</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 138px;"></div><div class="CodeMirror-gutters" style="display: none; height: 138px;"></div></div></div></pre><h2 id='uvreqt-----base-request'><code>uv_req_t</code><span> — Base request</span></h2><p><code>uv_req_t</code><span> is the base type for all libuv request types.</span></p><h3 id='uvcancelreq'><code>uv.cancel(req)</code></h3><blockquote><p><span>method form </span><code>req:cancel()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>req</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_req_t</code></p></li></ul><p><span>Cancel a pending request. Fails if the request is executing or has finished</span>
<span>executing. Only cancellation of </span><code>uv_fs_t</code><span>, </span><code>uv_getaddrinfo_t</code><span>,</span>
<code>uv_getnameinfo_t</code><span> and </span><code>uv_work_t</code><span> requests is currently supported.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvreqgettypereq'><code>uv.req_get_type(req)</code></h3><blockquote><p><span>method form </span><code>req:get_type()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>req</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_req_t</code></p></li></ul><p><span>Returns the name of the struct for a given request (e.g. </span><code>"fs"</code><span> for </span><code>uv_fs_t</code><span>)</span>
<span>and the libuv enum integer for the request's type (</span><code>uv_req_type</code><span>).</span></p><p><strong><span>Returns:</span></strong><span> </span><code>string</code><span>, </span><code>integer</code></p><h2 id='uvhandlet-----base-handle'><code>uv_handle_t</code><span> — Base handle</span></h2><p><code>uv_handle_t</code><span> is the base type for all libuv handle types. All API functions</span>
<span>defined here work with any handle type.</span></p><h3 id='uvisactivehandle'><code>uv.is_active(handle)</code></h3><blockquote><p><span>method form </span><code>handle:is_active()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li></ul><p><span>Returns </span><code>true</code><span> if the handle is active, </span><code>false</code><span> if it's inactive. What "active”</span>
<span>means depends on the type of handle:</span></p><ul><li><p><span>A </span><a href='#uv_async_t--async-handle' target='_blank'><code>uv_async_t</code></a><span> handle is always active and cannot be deactivated, except</span>
<span>by closing it with </span><code>uv.close()</code><span>.</span></p></li><li><p><span>A </span><a href='#uv_pipe_t--pipe-handle' target='_blank'><code>uv_pipe_t</code></a><span>, </span><a href='#uv_tcp_t--tcp-handle' target='_blank'><code>uv_tcp_t</code></a><span>, </span><a href='#uv_udp_t--udp-handle' target='_blank'><code>uv_udp_t</code></a><span>, etc. handle - basically</span>
<span>any handle that deals with I/O - is active when it is doing something that</span>
<span> involves I/O, like reading, writing, connecting, accepting new connections,</span>
<span> etc.</span></p></li><li><p><span>A </span><a href='#uv_check_t--check-handle' target='_blank'><code>uv_check_t</code></a><span>, </span><a href='#uv_idle_t--idle-handle' target='_blank'><code>uv_idle_t</code></a><span>, </span><a href='#uv_timer_t--timer-handle' target='_blank'><code>uv_timer_t</code></a><span>, etc. handle is active</span>
<span>when it has been started with a call to </span><code>uv.check_start()</code><span>, </span><code>uv.idle_start()</code><span>,</span>
<span> </span><code>uv.timer_start()</code><span> etc. until it has been stopped with a call to its</span>
<span> respective stop function.</span></p></li></ul><p><strong><span>Returns:</span></strong><span> </span><code>boolean</code><span> or </span><code>fail</code></p><h3 id='uvisclosinghandle'><code>uv.is_closing(handle)</code></h3><blockquote><p><span>method form </span><code>handle:is_closing()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li></ul><p><span>Returns </span><code>true</code><span> if the handle is closing or closed, </span><code>false</code><span> otherwise.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>boolean</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: This function should only be used between the initialization of the</span>
<span>handle and the arrival of the close callback.</span></p><h3 id='uvclosehandle-callback'><code>uv.close(handle, [callback])</code></h3><blockquote><p><span>method form </span><code>handle:close([callback])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code><span> or </span><code>nil</code></p></li></ul><p><span>Request handle to be closed. </span><code>callback</code><span> will be called asynchronously after this</span>
<span>call. This MUST be called on each handle before memory is released.</span></p><p><span>Handles that wrap file descriptors are closed immediately but </span><code>callback</code><span> will</span>
<span>still be deferred to the next iteration of the event loop. It gives you a chance</span>
<span>to free up any resources associated with the handle.</span></p><p><span>In-progress requests, like </span><code>uv_connect_t</code><span> or </span><code>uv_write_t</code><span>, are cancelled and</span>
<span>have their callbacks called asynchronously with </span><code>ECANCELED</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><h3 id='uvrefhandle'><code>uv.ref(handle)</code></h3><blockquote><p><span>method form </span><code>handle:ref()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li></ul><p><span>Reference the given handle. References are idempotent, that is, if a handle is</span>
<span>already referenced calling this function again will have no effect.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><p><span>See </span><a href='#reference-counting' target='_blank'><span>Reference counting</span></a><span>.</span></p><h3 id='uvunrefhandle'><code>uv.unref(handle)</code></h3><blockquote><p><span>method form </span><code>handle:unref()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li></ul><p><span>Un-reference the given handle. References are idempotent, that is, if a handle</span>
<span>is not referenced calling this function again will have no effect.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><p><span>See </span><a href='#reference-counting' target='_blank'><span>Reference counting</span></a><span>.</span></p><h3 id='uvhasrefhandle'><code>uv.has_ref(handle)</code></h3><blockquote><p><span>method form </span><code>handle:has_ref()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li></ul><p><span>Returns </span><code>true</code><span> if the handle referenced, </span><code>false</code><span> if not.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>boolean</code><span> or </span><code>fail</code></p><p><span>See </span><a href='#reference-counting' target='_blank'><span>Reference counting</span></a><span>.</span></p><h3 id='uvsendbuffersizehandle-size'><code>uv.send_buffer_size(handle, [size])</code></h3><blockquote><p><span>method form </span><code>handle:send_buffer_size([size])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li><li><p><code>size</code><span>: </span><code>integer</code><span> or </span><code>nil</code><span> (default: </span><code>0</code><span>)</span></p></li></ul><p><span>Gets or sets the size of the send buffer that the operating system uses for the</span>
<span>socket.</span></p><p><span>If </span><code>size</code><span> is omitted (or </span><code>0</code><span>), this will return the current send buffer size; otherwise, this will use </span><code>size</code><span> to set the new send buffer size.</span></p><p><span>This function works for TCP, pipe and UDP handles on Unix and for TCP and UDP</span>
<span>handles on Windows.</span></p><p><strong><span>Returns:</span></strong></p><ul><li><p><code>integer</code><span> or </span><code>fail</code><span> (if </span><code>size</code><span> is </span><code>nil</code><span> or </span><code>0</code><span>)</span></p></li><li><p><code>0</code><span> or </span><code>fail</code><span> (if </span><code>size</code><span> is not </span><code>nil</code><span> and not </span><code>0</code><span>)</span></p></li></ul><p><strong><span>Note</span></strong><span>: Linux will set double the size and return double the size of the</span>
<span>original set value.</span></p><h3 id='uvrecvbuffersizehandle-size'><code>uv.recv_buffer_size(handle, [size])</code></h3><blockquote><p><span>method form </span><code>handle:recv_buffer_size([size])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li><li><p><code>size</code><span>: </span><code>integer</code><span> or </span><code>nil</code><span> (default: </span><code>0</code><span>)</span></p></li></ul><p><span>Gets or sets the size of the receive buffer that the operating system uses for</span>
<span>the socket.</span></p><p><span>If </span><code>size</code><span> is omitted (or </span><code>0</code><span>), this will return the current send buffer size; otherwise, this will use </span><code>size</code><span> to set the new send buffer size.</span></p><p><span>This function works for TCP, pipe and UDP handles on Unix and for TCP and UDP</span>
<span>handles on Windows.</span></p><p><strong><span>Returns:</span></strong></p><ul><li><p><code>integer</code><span> or </span><code>fail</code><span> (if </span><code>size</code><span> is </span><code>nil</code><span> or </span><code>0</code><span>)</span></p></li><li><p><code>0</code><span> or </span><code>fail</code><span> (if </span><code>size</code><span> is not </span><code>nil</code><span> and not </span><code>0</code><span>)</span></p></li></ul><p><strong><span>Note</span></strong><span>: Linux will set double the size and return double the size of the</span>
<span>original set value.</span></p><h3 id='uvfilenohandle'><code>uv.fileno(handle)</code></h3><blockquote><p><span>method form </span><code>handle:fileno()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li></ul><p><span>Gets the platform dependent file descriptor equivalent.</span></p><p><span>The following handles are supported: TCP, pipes, TTY, UDP and poll. Passing any</span>
<span>other handle type will fail with </span><code>EINVAL</code><span>.</span></p><p><span>If a handle doesn't have an attached file descriptor yet or the handle itself</span>
<span>has been closed, this function will return </span><code>EBADF</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code><span> or </span><code>fail</code></p><p><strong><span>Warning</span></strong><span>: Be very careful when using this function. libuv assumes it's in</span>
<span>control of the file descriptor so any change to it may lead to malfunction.</span></p><h3 id='uvhandlegettypehandle'><code>uv.handle_get_type(handle)</code></h3><blockquote><p><span>method form </span><code>handle:get_type()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_handle_t</code></p></li></ul><p><span>Returns the name of the struct for a given handle (e.g. </span><code>"pipe"</code><span> for </span><code>uv_pipe_t</code><span>)</span>
<span>and the libuv enum integer for the handle's type (</span><code>uv_handle_type</code><span>).</span></p><p><strong><span>Returns:</span></strong><span> </span><code>string</code><span>, </span><code>integer</code></p><h2 id='reference-counting'><span>Reference counting</span></h2><p><span>The libuv event loop (if run in the default mode) will run until there are no</span>
<span>active and referenced handles left. The user can force the loop to exit early by</span>
<span>unreferencing handles which are active, for example by calling </span><code>uv.unref()</code>
<span>after calling </span><code>uv.timer_start()</code><span>.</span></p><p><span>A handle can be referenced or unreferenced, the refcounting scheme doesn't use a</span>
<span>counter, so both operations are idempotent.</span></p><p><span>All handles are referenced when active by default, see </span><code>uv.is_active()</code><span> for a</span>
<span>more detailed explanation on what being active involves.</span></p><h2 id='uvtimert-----timer-handle'><code>uv_timer_t</code><span> — Timer handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Timer handles are used to schedule callbacks to be called in the future.</span></p><h3 id='uvnewtimer'><code>uv.new_timer()</code></h3><p><span>Creates and initializes a new </span><code>uv_timer_t</code><span>. Returns the Lua userdata wrapping</span>
<span>it.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_timer_t userdata</code><span> or </span><code>fail</code></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Creating a simple setTimeout wrapper</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-keyword">function</span> <span class="cm-variable">setTimeout</span>(<span class="cm-variable">timeout</span>, <span class="cm-variable">callback</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">local</span> <span class="cm-variable">timer</span> = <span class="cm-variable">uv.new_timer</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">timer</span>:<span class="cm-variable">start</span>(<span class="cm-variable">timeout</span>, <span class="cm-number">0</span>, <span class="cm-keyword">function</span> ()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">timer</span>:<span class="cm-variable">stop</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">timer</span>:<span class="cm-builtin">close</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">callback</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">timer</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Creating a simple setInterval wrapper</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-keyword">function</span> <span class="cm-variable">setInterval</span>(<span class="cm-variable">interval</span>, <span class="cm-variable">callback</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">local</span> <span class="cm-variable">timer</span> = <span class="cm-variable">uv.new_timer</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">timer</span>:<span class="cm-variable">start</span>(<span class="cm-variable">interval</span>, <span class="cm-variable">interval</span>, <span class="cm-keyword">function</span> ()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">callback</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">timer</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- And clearInterval</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-keyword">function</span> <span class="cm-variable">clearInterval</span>(<span class="cm-variable">timer</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">timer</span>:<span class="cm-variable">stop</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">timer</span>:<span class="cm-builtin">close</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 576px;"></div><div class="CodeMirror-gutters" style="display: none; height: 576px;"></div></div></div></pre><h3 id='uvtimerstarttimer-timeout-repeat-callback'><code>uv.timer_start(timer, timeout, repeat, callback)</code></h3><blockquote><p><span>method form </span><code>timer:start(timeout, repeat, callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>timer</code><span>: </span><code>uv_timer_t userdata</code></p></li><li><p><code>timeout</code><span>: </span><code>integer</code></p></li><li><p><code>repeat</code><span>: </span><code>integer</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p></li></ul><p><span>Start the timer. </span><code>timeout</code><span> and </span><code>repeat</code><span> are in milliseconds.</span></p><p><span>If </span><code>timeout</code><span> is zero, the callback fires on the next event loop iteration. If</span>
<code>repeat</code><span> is non-zero, the callback fires first after </span><code>timeout</code><span> milliseconds and</span>
<span>then repeatedly after </span><code>repeat</code><span> milliseconds.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvtimerstoptimer'><code>uv.timer_stop(timer)</code></h3><blockquote><p><span>method form </span><code>timer:stop()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>timer</code><span>: </span><code>uv_timer_t userdata</code></p></li></ul><p><span>Stop the timer, the callback will not be called anymore.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvtimeragaintimer'><code>uv.timer_again(timer)</code></h3><blockquote><p><span>method form </span><code>timer:again()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>timer</code><span>: </span><code>uv_timer_t userdata</code></p></li></ul><p><span>Stop the timer, and if it is repeating restart it using the repeat value as the</span>
<span>timeout. If the timer has never been started before it raises </span><code>EINVAL</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvtimersetrepeattimer-repeat'><code>uv.timer_set_repeat(timer, repeat)</code></h3><blockquote><p><span>method form </span><code>timer:set_repeat(repeat)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>timer</code><span>: </span><code>uv_timer_t userdata</code></p></li><li><p><code>repeat</code><span>: </span><code>integer</code></p></li></ul><p><span>Set the repeat interval value in milliseconds. The timer will be scheduled to</span>
<span>run on the given interval, regardless of the callback execution duration, and</span>
<span>will follow normal timer semantics in the case of a time-slice overrun.</span></p><p><span>For example, if a 50 ms repeating timer first runs for 17 ms, it will be</span>
<span>scheduled to run again 33 ms later. If other tasks consume more than the 33 ms</span>
<span>following the first timer callback, then the callback will run as soon as</span>
<span>possible.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><h3 id='uvtimergetrepeattimer'><code>uv.timer_get_repeat(timer)</code></h3><blockquote><p><span>method form </span><code>timer:get_repeat()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>timer</code><span>: </span><code>uv_timer_t userdata</code></p></li></ul><p><span>Get the timer repeat value.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code></p><h3 id='uvtimergetdueintimer'><code>uv.timer_get_due_in(timer)</code></h3><blockquote><p><span>method form </span><code>timer:get_due_in()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>timer</code><span>: </span><code>uv_timer_t userdata</code></p></li></ul><p><span>Get the timer due value or 0 if it has expired. The time is relative to </span><code>uv.now()</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code></p><p><strong><span>Note</span></strong><span>: New in libuv version 1.40.0.</span></p><h2 id='uvpreparet-----prepare-handle'><code>uv_prepare_t</code><span> — Prepare handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Prepare handles will run the given callback once per loop iteration, right</span>
<span>before polling for I/O.</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">prepare</span> = <span class="cm-variable">uv.new_prepare</span>()</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">prepare</span>:<span class="cm-variable">start</span>(<span class="cm-keyword">function</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"Before I/O polling"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="display: none; height: 92px;"></div></div></div></pre><h3 id='uvnewprepare'><code>uv.new_prepare()</code></h3><p><span>Creates and initializes a new </span><code>uv_prepare_t</code><span>. Returns the Lua userdata wrapping</span>
<span>it.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_prepare_t userdata</code></p><h3 id='uvpreparestartprepare-callback'><code>uv.prepare_start(prepare, callback)</code></h3><blockquote><p><span>method form </span><code>prepare:start(callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>prepare</code><span>: </span><code>uv_prepare_t userdata</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p></li></ul><p><span>Start the handle with the given callback.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvpreparestopprepare'><code>uv.prepare_stop(prepare)</code></h3><blockquote><p><span>method form </span><code>prepare:stop()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>prepare</code><span>: </span><code>uv_prepare_t userdata</code></p></li></ul><p><span>Stop the handle, the callback will no longer be called.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h2 id='uvcheckt-----check-handle'><code>uv_check_t</code><span> — Check handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Check handles will run the given callback once per loop iteration, right after</span>
<span>polling for I/O.</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">check</span> = <span class="cm-variable">uv.new_check</span>()</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">check</span>:<span class="cm-variable">start</span>(<span class="cm-keyword">function</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"After I/O polling"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="display: none; height: 92px;"></div></div></div></pre><h3 id='uvnewcheck'><code>uv.new_check()</code></h3><p><span>Creates and initializes a new </span><code>uv_check_t</code><span>. Returns the Lua userdata wrapping</span>
<span>it.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_check_t userdata</code></p><h3 id='uvcheckstartcheck-callback'><code>uv.check_start(check, callback)</code></h3><blockquote><p><span>method form </span><code>check:start(callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>check</code><span>: </span><code>uv_check_t userdata</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p></li></ul><p><span>Start the handle with the given callback.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvcheckstopcheck'><code>uv.check_stop(check)</code></h3><blockquote><p><span>method form </span><code>check:stop()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>check</code><span>: </span><code>uv_check_t userdata</code></p></li></ul><p><span>Stop the handle, the callback will no longer be called.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h2 id='uvidlet-----idle-handle'><code>uv_idle_t</code><span> — Idle handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Idle handles will run the given callback once per loop iteration, right before</span>
<span>the </span><a href='#uv_prepare_t--prepare-handle' target='_blank'><code>uv_prepare_t</code></a><span> handles.</span></p><p><strong><span>Note</span></strong><span>: The notable difference with prepare handles is that when there are</span>
<span>active idle handles, the loop will perform a zero timeout poll instead of</span>
<span>blocking for I/O.</span></p><p><strong><span>Warning</span></strong><span>: Despite the name, idle handles will get their callbacks called on</span>
<span>every loop iteration, not when the loop is actually "idle".</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">idle</span> = <span class="cm-variable">uv.new_idle</span>()</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">idle</span>:<span class="cm-variable">start</span>(<span class="cm-keyword">function</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"Before I/O polling, no blocking"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="display: none; height: 92px;"></div></div></div></pre><h3 id='uvnewidle'><code>uv.new_idle()</code></h3><p><span>Creates and initializes a new </span><code>uv_idle_t</code><span>. Returns the Lua userdata wrapping</span>
<span>it.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_idle_t userdata</code></p><h3 id='uvidlestartidle-callback'><code>uv.idle_start(idle, callback)</code></h3><blockquote><p><span>method form </span><code>idle:start(callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>idle</code><span>: </span><code>uv_idle_t userdata</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p></li></ul><p><span>Start the handle with the given callback.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvidlestopidle'><code>uv.idle_stop(idle)</code></h3><blockquote><p><span>method form </span><code>idle:stop()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>idle</code><span>: </span><code>uv_idle_t userdata</code></p></li></ul><p><span>Stop the handle, the callback will no longer be called.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h2 id='uvasynct-----async-handle'><code>uv_async_t</code><span> — Async handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Async handles allow the user to "wakeup" the event loop and get a callback</span>
<span>called from another thread.</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">async</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">async</span> = <span class="cm-variable">uv.new_async</span>(<span class="cm-keyword">function</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"async operation ran"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">async</span>:<span class="cm-builtin">close</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">async</span>:<span class="cm-variable">send</span>()</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 161px;"></div><div class="CodeMirror-gutters" style="display: none; height: 161px;"></div></div></div></pre><h3 id='uvnewasynccallback'><code>uv.new_async(callback)</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>callback</code><span>: </span><code>callable</code></p><ul><li><p><code>...</code><span>: </span><code>threadargs</code><span> passed to/from </span><code>uv.async_send(async, ...)</code></p></li></ul></li></ul><p><span>Creates and initializes a new </span><code>uv_async_t</code><span>. Returns the Lua userdata wrapping</span>
<span>it.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_async_t userdata</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: Unlike other handle initialization functions, this immediately starts</span>
<span>the handle.</span></p><h3 id='uvasyncsendasync-'><code>uv.async_send(async, ...)</code></h3><blockquote><p><span>method form </span><code>async:send(...)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>async</code><span>: </span><code>uv_async_t userdata</code></p></li><li><p><code>...</code><span>: </span><code>threadargs</code></p></li></ul><p><span>Wakeup the event loop and call the async handle's callback.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: It's safe to call this function from any thread. The callback will be</span>
<span>called on the loop thread.</span></p><p><strong><span>Warning</span></strong><span>: libuv will coalesce calls to </span><code>uv.async_send(async)</code><span>, that is, not</span>
<span>every call to it will yield an execution of the callback. For example: if</span>
<code>uv.async_send()</code><span> is called 5 times in a row before the callback is called, the</span>
<span>callback will only be called once. If </span><code>uv.async_send()</code><span> is called again after</span>
<span>the callback was called, it will be called again.</span></p><h2 id='uvpollt-----poll-handle'><code>uv_poll_t</code><span> — Poll handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Poll handles are used to watch file descriptors for readability and writability,</span>
<span>similar to the purpose of </span><a href='http://linux.die.net/man/2/poll'><span>poll(2)</span></a><span>.</span></p><p><span>The purpose of poll handles is to enable integrating external libraries that</span>
<span>rely on the event loop to signal it about the socket status changes, like c-ares</span>
<span>or libssh2. Using </span><code>uv_poll_t</code><span> for any other purpose is not recommended;</span>
<code>uv_tcp_t</code><span>, </span><code>uv_udp_t</code><span>, etc. provide an implementation that is faster and more</span>
<span>scalable than what can be achieved with </span><code>uv_poll_t</code><span>, especially on Windows.</span></p><p><span>It is possible that poll handles occasionally signal that a file descriptor is</span>
<span>readable or writable even when it isn't. The user should therefore always be</span>
<span>prepared to handle EAGAIN or equivalent when it attempts to read from or write</span>
<span>to the fd.</span></p><p><span>It is not okay to have multiple active poll handles for the same socket, this</span>
<span>can cause libuv to busyloop or otherwise malfunction.</span></p><p><span>The user should not close a file descriptor while it is being polled by an</span>
<span>active poll handle. This can cause the handle to report an error, but it might</span>
<span>also start polling another socket. However the fd can be safely closed</span>
<span>immediately after a call to </span><code>uv.poll_stop()</code><span> or </span><code>uv.close()</code><span>.</span></p><p><strong><span>Note</span></strong><span>: On windows only sockets can be polled with poll handles. On Unix any</span>
<span>file descriptor that would be accepted by poll(2) can be used.</span></p><h3 id='uvnewpollfd'><code>uv.new_poll(fd)</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>fd</code><span>: </span><code>integer</code></p></li></ul><p><span>Initialize the handle using a file descriptor.</span></p><p><span>The file descriptor is set to non-blocking mode.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_poll_t userdata</code><span> or </span><code>fail</code></p><h3 id='uvnewsocketpollfd'><code>uv.new_socket_poll(fd)</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>fd</code><span>: </span><code>integer</code></p></li></ul><p><span>Initialize the handle using a socket descriptor. On Unix this is identical to</span>
<code>uv.new_poll()</code><span>. On windows it takes a SOCKET handle.</span></p><p><span>The socket is set to non-blocking mode.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_poll_t userdata</code><span> or </span><code>fail</code></p><h3 id='uvpollstartpoll-events-callback'><code>uv.poll_start(poll, [events], callback)</code></h3><blockquote><p><span>method form </span><code>poll:start(events, callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>poll</code><span>: </span><code>uv_poll_t userdata</code></p></li><li><p><code>events</code><span>: </span><code>string</code><span> or </span><code>nil</code><span> (default: </span><code>"rw"</code><span>)</span></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li><li><p><code>events</code><span>: </span><code>string</code><span> or </span><code>nil</code></p></li></ul></li></ul><p><span>Starts polling the file descriptor. </span><code>events</code><span> are: </span><code>"r"</code><span>, </span><code>"w"</code><span>, </span><code>"rw"</code><span>, </span><code>"d"</code><span>,</span>
<code>"rd"</code><span>, </span><code>"wd"</code><span>, </span><code>"rwd"</code><span>, </span><code>"p"</code><span>, </span><code>"rp"</code><span>, </span><code>"wp"</code><span>, </span><code>"rwp"</code><span>, </span><code>"dp"</code><span>, </span><code>"rdp"</code><span>,</span>
<code>"wdp"</code><span>, or </span><code>"rwdp"</code><span> where </span><code>r</code><span> is </span><code>READABLE</code><span>, </span><code>w</code><span> is </span><code>WRITABLE</code><span>, </span><code>d</code><span> is</span>
<code>DISCONNECT</code><span>, and </span><code>p</code><span> is </span><code>PRIORITIZED</code><span>. As soon as an event is detected</span>
<span>the callback will be called with status set to 0, and the detected events set on</span>
<span>the events field.</span></p><p><span>The user should not close the socket while the handle is active. If the user</span>
<span>does that anyway, the callback may be called reporting an error status, but this</span>
<span>is not guaranteed.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: Calling </span><code>uv.poll_start()</code><span> on a handle that is already active is fine.</span>
<span>Doing so will update the events mask that is being watched for.</span></p><h3 id='uvpollstoppoll'><code>uv.poll_stop(poll)</code></h3><blockquote><p><span>method form </span><code>poll:stop()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>poll</code><span>: </span><code>uv_poll_t userdata</code></p></li></ul><p><span>Stop polling the file descriptor, the callback will no longer be called.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h2 id='uvsignalt-----signal-handle'><code>uv_signal_t</code><span> — Signal handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Signal handles implement Unix style signal handling on a per-event loop bases.</span></p><p><strong><span>Windows Notes:</span></strong></p><p><span>Reception of some signals is emulated on Windows:</span></p><ul><li><p><span>SIGINT is normally delivered when the user presses CTRL+C. However, like on</span>
<span>Unix, it is not generated when terminal raw mode is enabled.</span></p></li><li><p><span>SIGBREAK is delivered when the user pressed CTRL + BREAK.</span></p></li><li><p><span>SIGHUP is generated when the user closes the console window. On SIGHUP the</span>
<span>program is given approximately 10 seconds to perform cleanup. After that</span>
<span> Windows will unconditionally terminate it.</span></p></li><li><p><span>SIGWINCH is raised whenever libuv detects that the console has been resized.</span>
<span>SIGWINCH is emulated by libuv when the program uses a uv_tty_t handle to write</span>
<span> to the console. SIGWINCH may not always be delivered in a timely manner; libuv</span>
<span> will only detect size changes when the cursor is being moved. When a readable</span>
<span> </span><a href='#uv_tty_t--tty-handle' target='_blank'><code>uv_tty_t</code></a><span> handle is used in raw mode, resizing the console buffer will</span>
<span> also trigger a SIGWINCH signal.</span></p></li><li><p><span>Watchers for other signals can be successfully created, but these signals</span>
<span>are never received. These signals are: SIGILL, SIGABRT, SIGFPE, SIGSEGV,</span>
<span> SIGTERM and SIGKILL.</span></p></li><li><p><span>Calls to raise() or abort() to programmatically raise a signal are not</span>
<span>detected by libuv; these will not trigger a signal watcher.</span></p></li></ul><p><strong><span>Unix Notes:</span></strong></p><ul><li><p><span>SIGKILL and SIGSTOP are impossible to catch.</span></p></li><li><p><span>Handling SIGBUS, SIGFPE, SIGILL or SIGSEGV via libuv results into undefined</span>
<span>behavior.</span></p></li><li><p><span>SIGABRT will not be caught by libuv if generated by abort(), e.g. through</span>
<span>assert().</span></p></li><li><p><span>On Linux SIGRT0 and SIGRT1 (signals 32 and 33) are used by the NPTL pthreads</span>
<span>library to manage threads. Installing watchers for those signals will lead to</span>
<span> unpredictable behavior and is strongly discouraged. Future versions of libuv</span>
<span> may simply reject them.</span></p></li></ul><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Create a new signal handler</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">signal</span> = <span class="cm-variable">uv.new_signal</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Define a handler function</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.signal_start</span>(<span class="cm-variable">signal</span>, <span class="cm-string">"sigint"</span>, <span class="cm-keyword">function</span>(<span class="cm-variable">signame</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"got "</span> .. <span class="cm-variable">signame</span> .. <span class="cm-string">", shutting down"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">os.exit</span>(<span class="cm-number">1</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 161px;"></div><div class="CodeMirror-gutters" style="display: none; height: 161px;"></div></div></div></pre><h3 id='uvnewsignal'><code>uv.new_signal()</code></h3><p><span>Creates and initializes a new </span><code>uv_signal_t</code><span>. Returns the Lua userdata wrapping</span>
<span>it.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_signal_t userdata</code><span> or </span><code>fail</code></p><h3 id='uvsignalstartsignal-signame-callback'><code>uv.signal_start(signal, signame, callback)</code></h3><blockquote><p><span>method form </span><code>signal:start(signame, callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>signal</code><span>: </span><code>uv_signal_t userdata</code></p></li><li><p><code>signame</code><span>: </span><code>string</code><span> or </span><code>integer</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p><ul><li><p><code>signame</code><span>: </span><code>string</code></p></li></ul></li></ul><p><span>Start the handle with the given callback, watching for the given signal.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported </span><code>signame</code><span> input and output values.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvsignalstartoneshotsignal-signame-callback'><code>uv.signal_start_oneshot(signal, signame, callback)</code></h3><blockquote><p><span>method form </span><code>signal:start_oneshot(signame, callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>signal</code><span>: </span><code>uv_signal_t userdata</code></p></li><li><p><code>signame</code><span>: </span><code>string</code><span> or </span><code>integer</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p><ul><li><p><code>signame</code><span>: </span><code>string</code></p></li></ul></li></ul><p><span>Same functionality as </span><code>uv.signal_start()</code><span> but the signal handler is reset the moment the signal is received.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported </span><code>signame</code><span> input and output values.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvsignalstopsignal'><code>uv.signal_stop(signal)</code></h3><blockquote><p><span>method form </span><code>signal:stop()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>signal</code><span>: </span><code>uv_signal_t userdata</code></p></li></ul><p><span>Stop the handle, the callback will no longer be called.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h2 id='uvprocesst-----process-handle'><code>uv_process_t</code><span> — Process handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Process handles will spawn a new process and allow the user to control it and</span>
<span>establish communication channels with it using streams.</span></p><h3 id='uvdisablestdioinheritance'><code>uv.disable_stdio_inheritance()</code></h3><p><span>Disables inheritance for file descriptors / handles that this process inherited</span>
<span>from its parent. The effect is that child processes spawned by this process</span>
<span>don't accidentally inherit these handles.</span></p><p><span>It is recommended to call this function as early in your program as possible,</span>
<span>before the inherited file descriptors can be closed or duplicated.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><p><strong><span>Note</span></strong><span>: This function works on a best-effort basis: there is no guarantee that</span>
<span>libuv can discover all file descriptors that were inherited. In general it does</span>
<span>a better job on Windows than it does on Unix.</span></p><h3 id='uvspawnpath-options-onexit'><code>uv.spawn(path, options, on_exit)</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>path</code><span>: </span><code>string</code></p></li><li><p><code>options</code><span>: </span><code>table</code></p><ul><li><p><code>args</code><span>: </span><code>string[]</code><span> or </span><code>nil</code>
<span>Command line arguments as a list of strings. The first</span>
<span>string should </span><em><span>not</span></em><span> be the path to the program, since that is already</span>
<span>provided via </span><code>path</code><span>. On Windows, this uses CreateProcess which concatenates</span>
<span>the arguments into a string. This can cause some strange errors</span>
<span>(see </span><code>options.verbatim</code><span> below for Windows).</span></p></li><li><p><code>stdio</code><span>: </span><code>table</code><span> or </span><code>nil</code>
<span>Set the file descriptors that will be made available to</span>
<span>the child process. The convention is that the first entries are stdin, stdout,</span>
<span>and stderr.</span></p><p><span>The entries can take many shapes.</span></p><ul><li><p><span>If </span><code>integer</code><span>, then the child process inherits that same zero-indexed</span>
<span>fd from the parent process.</span></p></li><li><p><span>If </span><code>uv_stream_t</code><span> handles are passed in, those are used as a read-write pipe</span>
<span>or inherited stream depending if the stream has a valid fd.</span></p></li><li><p><span>If </span><code>nil</code><span>, means to ignore that fd in the child process.</span></p></li></ul><p><strong><span>Note</span></strong><span>: On Windows, file descriptors after the third are</span>
<span>available to the child process only if the child processes uses the MSVCRT</span>
<span>runtime.</span></p><ul><li><p><code>[1, 2, 3, ..., n]</code><span>: </span><code>integer</code><span> or </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code><span> or </span><code>nil</code></p></li></ul></li><li><p><code>env</code><span>: </span><code>string[]</code><span> or </span><code>nil</code>
<span>Set environment variables for the new process.</span>
<span>Each entry should be a string in the form of </span><code>NAME=VALUE</code><span>.</span></p></li><li><p><code>cwd</code><span>: </span><code>string</code><span> or </span><code>nil</code><span> Set the current working directory for the sub-process.</span></p></li><li><p><code>uid</code><span>: </span><code>string</code><span> or </span><code>nil</code><span> Set the child process' user id.</span></p></li><li><p><code>gid</code><span>: </span><code>string</code><span> or </span><code>nil</code><span> Set the child process' group id.</span></p></li><li><p><code>verbatim</code><span>: </span><code>boolean</code><span> or </span><code>nil</code>
<span>If true, do not wrap any arguments in quotes, or</span>
<span>perform any other escaping, when converting the argument list into a command</span>
<span>line string. This option is only meaningful on Windows systems. On Unix it is</span>
<span>silently ignored.</span></p></li><li><p><code>detached</code><span>: </span><code>boolean</code><span> or </span><code>nil</code>
<span>If true, spawn the child process in a detached state -</span>
<span>this will make it a process group leader, and will effectively enable the</span>
<span>child to keep running after the parent exits. Note that the child process</span>
<span>will still keep the parent's event loop alive unless the parent process calls</span>
<code>uv.unref()</code><span> on the child's process handle.</span></p></li><li><p><code>hide</code><span>: </span><code>boolean</code><span> or </span><code>nil</code>
<span>If true, hide the subprocess console window that would</span>
<span>normally be created. This option is only meaningful on Windows systems. On</span>
<span>Unix it is silently ignored.</span></p></li></ul></li><li><p><code>on_exit</code><span>: </span><code>callable</code></p><ul><li><p><code>code</code><span>: </span><code>integer</code></p></li><li><p><code>signal</code><span>: </span><code>integer</code></p></li></ul></li></ul><p><span>Initializes the process handle and starts the process. If the process is</span>
<span>successfully spawned, this function will return the handle and pid of the child</span>
<span>process.</span></p><p><span>Possible reasons for failing to spawn would include (but not be limited to) the</span>
<span>file to execute not existing, not having permissions to use the setuid or setgid</span>
<span>specified, or not having enough memory to allocate for the new process.</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">stdin</span> = <span class="cm-variable">uv.new_pipe</span>()</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">stdout</span> = <span class="cm-variable">uv.new_pipe</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">stderr</span> = <span class="cm-variable">uv.new_pipe</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">print</span>(<span class="cm-string">"stdin"</span>, <span class="cm-variable">stdin</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">print</span>(<span class="cm-string">"stdout"</span>, <span class="cm-variable">stdout</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">print</span>(<span class="cm-string">"stderr"</span>, <span class="cm-variable">stderr</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">handle</span>, <span class="cm-variable">pid</span> = <span class="cm-variable">uv.spawn</span>(<span class="cm-string">"cat"</span>, {</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">stdio</span> = {<span class="cm-variable">stdin</span>, <span class="cm-variable">stdout</span>, <span class="cm-variable">stderr</span>}</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}, <span class="cm-keyword">function</span>(<span class="cm-variable">code</span>, <span class="cm-variable">signal</span>) <span class="cm-comment">-- on exit</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"exit code"</span>, <span class="cm-variable">code</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"exit signal"</span>, <span class="cm-variable">signal</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-builtin">print</span>(<span class="cm-string">"process opened"</span>, <span class="cm-variable">handle</span>, <span class="cm-variable">pid</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.read_start</span>(<span class="cm-variable">stdout</span>, <span class="cm-keyword">function</span>(<span class="cm-variable">err</span>, <span class="cm-variable">data</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">assert</span>(<span class="cm-keyword">not</span> <span class="cm-variable">err</span>, <span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> <span class="cm-variable">data</span> <span class="cm-keyword">then</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"stdout chunk"</span>, <span class="cm-variable">stdout</span>, <span class="cm-variable">data</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">else</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"stdout end"</span>, <span class="cm-variable">stdout</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.read_start</span>(<span class="cm-variable">stderr</span>, <span class="cm-keyword">function</span>(<span class="cm-variable">err</span>, <span class="cm-variable">data</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">assert</span>(<span class="cm-keyword">not</span> <span class="cm-variable">err</span>, <span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> <span class="cm-variable">data</span> <span class="cm-keyword">then</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"stderr chunk"</span>, <span class="cm-variable">stderr</span>, <span class="cm-variable">data</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">else</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"stderr end"</span>, <span class="cm-variable">stderr</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.write</span>(<span class="cm-variable">stdin</span>, <span class="cm-string">"Hello World"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">uv.shutdown</span>(<span class="cm-variable">stdin</span>, <span class="cm-keyword">function</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"stdin shutdown"</span>, <span class="cm-variable">stdin</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">uv.close</span>(<span class="cm-variable">handle</span>, <span class="cm-keyword">function</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-string">"process closed"</span>, <span class="cm-variable">handle</span>, <span class="cm-variable">pid</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 991px;"></div><div class="CodeMirror-gutters" style="display: none; height: 991px;"></div></div></div></pre><p><span>When the child process exits, </span><code>on_exit</code><span> is called with an exit code and signal.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_process_t userdata</code><span> or </span><code>nil</code><span>, </span><code>integer</code><span> or </span><code>string</code><span>, </span><code>uv.error_name</code><span> or </span><code>nil</code></p><h3 id='uvprocesskillprocess-signame'><code>uv.process_kill(process, [signame])</code></h3><blockquote><p><span>method form </span><code>process:kill(signame)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>process</code><span>: </span><code>uv_process_t userdata</code></p></li><li><p><code>signame</code><span>: </span><code>string</code><span> or </span><code>integer</code><span> or </span><code>nil</code><span> (default: </span><code>sigterm</code><span>)</span></p></li></ul><p><span>Sends the specified signal to the given process handle. Check the documentation</span>
<span>on </span><code>uv_signal_t</code><span> for signal support, specially on Windows.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported </span><code>signame</code><span> input values.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvkillpid-signame'><code>uv.kill(pid, [signame])</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pid</code><span>: </span><code>integer</code></p></li><li><p><code>signame</code><span>: </span><code>string</code><span> or </span><code>integer</code><span> or </span><code>nil</code><span> (default: </span><code>sigterm</code><span>)</span></p></li></ul><p><span>Sends the specified signal to the given PID. Check the documentation on</span>
<code>uv_signal_t</code><span> for signal support, specially on Windows.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported </span><code>signame</code><span> input values.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvprocessgetpidprocess'><code>uv.process_get_pid(process)</code></h3><blockquote><p><span>method form </span><code>process:get_pid()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>process</code><span>: </span><code>uv_process_t userdata</code></p></li></ul><p><span>Returns the handle's pid.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code></p><h2 id='uvstreamt-----stream-handle'><code>uv_stream_t</code><span> — Stream handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Stream handles provide an abstraction of a duplex communication channel.</span>
<a href='#uv_stream_t--stream-handle' target='_blank'><code>uv_stream_t</code></a><span> is an abstract type, libuv provides 3 stream implementations</span>
<span>in the form of </span><a href='#uv_tcp_t--tcp-handle' target='_blank'><code>uv_tcp_t</code></a><span>, </span><a href='#uv_pipe_t--pipe-handle' target='_blank'><code>uv_pipe_t</code></a><span> and </span><a href='#uv_tty_t--tty-handle' target='_blank'><code>uv_tty_t</code></a><span>.</span></p><h3 id='uvshutdownstream-callback'><code>uv.shutdown(stream, [callback])</code></h3><blockquote><p><span>method form </span><code>stream:shutdown([callback])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code><span> or </span><code>nil</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li></ul></li></ul><p><span>Shutdown the outgoing (write) side of a duplex stream. It waits for pending</span>
<span>write requests to complete. The callback is called after shutdown is complete.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_shutdown_t userdata</code><span> or </span><code>fail</code></p><h3 id='uvlistenstream-backlog-callback'><code>uv.listen(stream, backlog, callback)</code></h3><blockquote><p><span>method form </span><code>stream:listen(backlog, callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>backlog</code><span>: </span><code>integer</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li></ul></li></ul><p><span>Start listening for incoming connections. </span><code>backlog</code><span> indicates the number of</span>
<span>connections the kernel might queue, same as </span><code>listen(2)</code><span>. When a new incoming</span>
<span>connection is received the callback is called.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvacceptstream-clientstream'><code>uv.accept(stream, client_stream)</code></h3><blockquote><p><span>method form </span><code>stream:accept(client_stream)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>client_stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li></ul><p><span>This call is used in conjunction with </span><code>uv.listen()</code><span> to accept incoming</span>
<span>connections. Call this function after receiving a callback to accept the</span>
<span>connection.</span></p><p><span>When the connection callback is called it is guaranteed that this function</span>
<span>will complete successfully the first time. If you attempt to use it more than</span>
<span>once, it may fail. It is suggested to only call this function once per</span>
<span>connection call.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">server</span>:<span class="cm-variable">listen</span>(<span class="cm-number">128</span>, <span class="cm-keyword">function</span> (<span class="cm-variable">err</span>)</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">local</span> <span class="cm-variable">client</span> = <span class="cm-variable">uv.new_tcp</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">server</span>:<span class="cm-variable">accept</span>(<span class="cm-variable">client</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="display: none; height: 92px;"></div></div></div></pre><h3 id='uvreadstartstream-callback'><code>uv.read_start(stream, callback)</code></h3><blockquote><p><span>method form </span><code>stream:read_start(callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li><li><p><code>data</code><span>: </span><code>string</code><span> or </span><code>nil</code></p></li></ul></li></ul><p><span>Read data from an incoming stream. The callback will be made several times until</span>
<span>there is no more data to read or </span><code>uv.read_stop()</code><span> is called. When we've reached</span>
<span>EOF, </span><code>data</code><span> will be </span><code>nil</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">stream</span>:<span class="cm-variable">read_start</span>(<span class="cm-keyword">function</span> (<span class="cm-variable">err</span>, <span class="cm-variable">chunk</span>)</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> <span class="cm-variable">err</span> <span class="cm-keyword">then</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">-- handle read error</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">elseif</span> <span class="cm-variable">chunk</span> <span class="cm-keyword">then</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">-- handle data</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">else</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">-- handle disconnect</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 207px;"></div><div class="CodeMirror-gutters" style="display: none; height: 207px;"></div></div></div></pre><h3 id='uvreadstopstream'><code>uv.read_stop(stream)</code></h3><blockquote><p><span>method form </span><code>stream:read_stop()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li></ul><p><span>Stop reading data from the stream. The read callback will no longer be called.</span></p><p><span>This function is idempotent and may be safely called on a stopped stream.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvwritestream-data-callback'><code>uv.write(stream, data, [callback])</code></h3><blockquote><p><span>method form </span><code>stream:write(data, [callback])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>data</code><span>: </span><code>buffer</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code><span> or </span><code>nil</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li></ul></li></ul><p><span>Write data to stream.</span></p><p><code>data</code><span> can either be a Lua string or a table of strings. If a table is passed</span>
<span>in, the C backend will use writev to send all strings in a single system call.</span></p><p><span>The optional </span><code>callback</code><span> is for knowing when the write is complete.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_write_t userdata</code><span> or </span><code>fail</code></p><h3 id='uvwrite2stream-data-sendhandle-callback'><code>uv.write2(stream, data, send_handle, [callback])</code></h3><blockquote><p><span>method form </span><code>stream:write2(data, send_handle, [callback])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>data</code><span>: </span><code>buffer</code></p></li><li><p><code>send_handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code><span> or </span><code>nil</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li></ul></li></ul><p><span>Extended write function for sending handles over a pipe. The pipe must be</span>
<span>initialized with </span><code>ipc</code><span> option </span><code>true</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_write_t userdata</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: </span><code>send_handle</code><span> must be a TCP socket or pipe, which is a server or a</span>
<span>connection (listening or connected state). Bound sockets or pipes will be</span>
<span>assumed to be servers.</span></p><h3 id='uvtrywritestream-data'><code>uv.try_write(stream, data)</code></h3><blockquote><p><span>method form </span><code>stream:try_write(data)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>data</code><span>: </span><code>buffer</code></p></li></ul><p><span>Same as </span><code>uv.write()</code><span>, but won't queue a write request if it can't be completed</span>
<span>immediately.</span></p><p><span>Will return number of bytes written (can be less than the supplied buffer size).</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code><span> or </span><code>fail</code></p><h3 id='uvtrywrite2stream-data-sendhandle'><code>uv.try_write2(stream, data, send_handle)</code></h3><blockquote><p><span>method form </span><code>stream:try_write2(data, send_handle)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>data</code><span>: </span><code>buffer</code></p></li><li><p><code>send_handle</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li></ul><p><span>Like </span><code>uv.write2()</code><span>, but with the properties of </span><code>uv.try_write()</code><span>. Not supported on Windows, where it returns </span><code>UV_EAGAIN</code><span>.</span></p><p><span>Will return number of bytes written (can be less than the supplied buffer size).</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code><span> or </span><code>fail</code></p><h3 id='uvisreadablestream'><code>uv.is_readable(stream)</code></h3><blockquote><p><span>method form </span><code>stream:is_readable()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li></ul><p><span>Returns </span><code>true</code><span> if the stream is readable, </span><code>false</code><span> otherwise.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>boolean</code></p><h3 id='uviswritablestream'><code>uv.is_writable(stream)</code></h3><blockquote><p><span>method form </span><code>stream:is_writable()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li></ul><p><span>Returns </span><code>true</code><span> if the stream is writable, </span><code>false</code><span> otherwise.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>boolean</code></p><h3 id='uvstreamsetblockingstream-blocking'><code>uv.stream_set_blocking(stream, blocking)</code></h3><blockquote><p><span>method form </span><code>stream:set_blocking(blocking)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li><li><p><code>blocking</code><span>: </span><code>boolean</code></p></li></ul><p><span>Enable or disable blocking mode for a stream.</span></p><p><span>When blocking mode is enabled all writes complete synchronously. The interface</span>
<span>remains unchanged otherwise, e.g. completion or failure of the operation will</span>
<span>still be reported through a callback which is made asynchronously.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><p><strong><span>Warning</span></strong><span>: Relying too much on this API is not recommended. It is likely to</span>
<span>change significantly in the future. Currently this only works on Windows and</span>
<span>only for </span><code>uv_pipe_t</code><span> handles. Also libuv currently makes no ordering guarantee</span>
<span>when the blocking mode is changed after write requests have already been</span>
<span>submitted. Therefore it is recommended to set the blocking mode immediately</span>
<span>after opening or creating the stream.</span></p><h3 id='uvstreamgetwritequeuesizestream'><code>uv.stream_get_write_queue_size(stream)</code></h3><blockquote><p><span>method form </span><code>stream:get_write_queue_size()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>stream</code><span>: </span><code>userdata</code><span> for sub-type of </span><code>uv_stream_t</code></p></li></ul><p><span>Returns the stream's write queue size.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code></p><h2 id='uvtcpt-----tcp-handle'><code>uv_tcp_t</code><span> — TCP handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> and </span><a href='#uv_stream_t--stream-handle' target='_blank'><code>uv_stream_t</code></a><span> functions also apply.</span></p></blockquote><p><span>TCP handles are used to represent both TCP streams and servers.</span></p><h3 id='uvnewtcpflags'><code>uv.new_tcp([flags])</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>flags</code><span>: </span><code>string</code><span> or </span><code>integer</code><span> or </span><code>nil</code></p></li></ul><p><span>Creates and initializes a new </span><code>uv_tcp_t</code><span>. Returns the Lua userdata wrapping it.</span></p><p><span>If set, </span><code>flags</code><span> must be a valid address family. See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported</span>
<span>address family input values.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_tcp_t userdata</code><span> or </span><code>fail</code></p><h3 id='uvtcpopentcp-sock'><code>uv.tcp_open(tcp, sock)</code></h3><blockquote><p><span>method form </span><code>tcp:open(sock)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li><li><p><code>sock</code><span>: </span><code>integer</code></p></li></ul><p><span>Open an existing file descriptor or SOCKET as a TCP handle.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: The passed file descriptor or SOCKET is not checked for its type, but it's required that it represents a valid stream socket.</span></p><h3 id='uvtcpnodelaytcp-enable'><code>uv.tcp_nodelay(tcp, enable)</code></h3><blockquote><p><span>method form </span><code>tcp:nodelay(enable)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li><li><p><code>enable</code><span>: </span><code>boolean</code></p></li></ul><p><span>Enable / disable Nagle's algorithm.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvtcpkeepalivetcp-enable-delay'><code>uv.tcp_keepalive(tcp, enable, [delay])</code></h3><blockquote><p><span>method form </span><code>tcp:keepalive(enable, [delay])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li><li><p><code>enable</code><span>: </span><code>boolean</code></p></li><li><p><code>delay</code><span>: </span><code>integer</code><span> or </span><code>nil</code></p></li></ul><p><span>Enable / disable TCP keep-alive. </span><code>delay</code><span> is the initial delay in seconds,</span>
<span>ignored when enable is </span><code>false</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvtcpsimultaneousacceptstcp-enable'><code>uv.tcp_simultaneous_accepts(tcp, enable)</code></h3><blockquote><p><span>method form </span><code>tcp:simultaneous_accepts(enable)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li><li><p><code>enable</code><span>: </span><code>boolean</code></p></li></ul><p><span>Enable / disable simultaneous asynchronous accept requests that are queued by</span>
<span>the operating system when listening for new TCP connections.</span></p><p><span>This setting is used to tune a TCP server for the desired performance. Having</span>
<span>simultaneous accepts can significantly improve the rate of accepting connections</span>
<span>(which is why it is enabled by default) but may lead to uneven load distribution</span>
<span>in multi-process setups.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvtcpbindtcp-host-port-flags'><code>uv.tcp_bind(tcp, host, port, [flags])</code></h3><blockquote><p><span>method form </span><code>tcp:bind(host, port, [flags])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li><li><p><code>host</code><span>: </span><code>string</code></p></li><li><p><code>port</code><span>: </span><code>integer</code></p></li><li><p><code>flags</code><span>: </span><code>table</code><span> or </span><code>nil</code></p><ul><li><p><code>ipv6only</code><span>: </span><code>boolean</code></p></li></ul></li></ul><p><span>Bind the handle to an host and port. </span><code>host</code><span> should be an IP address and</span>
<span>not a domain name. Any </span><code>flags</code><span> are set with a table with field </span><code>ipv6only</code>
<span>equal to </span><code>true</code><span> or </span><code>false</code><span>.</span></p><p><span>When the port is already taken, you can expect to see an </span><code>EADDRINUSE</code><span> error</span>
<span>from either </span><code>uv.tcp_bind()</code><span>, </span><code>uv.listen()</code><span> or </span><code>uv.tcp_connect()</code><span>. That is, a</span>
<span>successful call to this function does not guarantee that the call to </span><code>uv.listen()</code>
<span>or </span><code>uv.tcp_connect()</code><span> will succeed as well.</span></p><p><span>Use a port of </span><code>0</code><span> to let the OS assign an ephemeral port. You can look it up</span>
<span>later using </span><code>uv.tcp_getsockname()</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvtcpgetpeernametcp'><code>uv.tcp_getpeername(tcp)</code></h3><blockquote><p><span>method form </span><code>tcp:getpeername()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li></ul><p><span>Get the address of the peer connected to the handle.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported address </span><code>family</code><span> output values.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>table</code><span> or </span><code>fail</code></p><ul><li><p><code>ip</code><span>: </span><code>string</code></p></li><li><p><code>family</code><span>: </span><code>string</code></p></li><li><p><code>port</code><span>: </span><code>integer</code></p></li></ul><h3 id='uvtcpgetsocknametcp'><code>uv.tcp_getsockname(tcp)</code></h3><blockquote><p><span>method form </span><code>tcp:getsockname()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li></ul><p><span>Get the current address to which the handle is bound.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported address </span><code>family</code><span> output values.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>table</code><span> or </span><code>fail</code></p><ul><li><p><code>ip</code><span>: </span><code>string</code></p></li><li><p><code>family</code><span>: </span><code>string</code></p></li><li><p><code>port</code><span>: </span><code>integer</code></p></li></ul><h3 id='uvtcpconnecttcp-host-port-callback'><code>uv.tcp_connect(tcp, host, port, callback)</code></h3><blockquote><p><span>method form </span><code>tcp:connect(host, port, callback)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li><li><p><code>host</code><span>: </span><code>string</code></p></li><li><p><code>port</code><span>: </span><code>integer</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li></ul></li></ul><p><span>Establish an IPv4 or IPv6 TCP connection.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_connect_t userdata</code><span> or </span><code>fail</code></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">client</span> = <span class="cm-variable">uv.new_tcp</span>()</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">client</span>:<span class="cm-variable">connect</span>(<span class="cm-string">"127.0.0.1"</span>, <span class="cm-number">8080</span>, <span class="cm-keyword">function</span> (<span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">-- check error and carry on.</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 92px;"></div><div class="CodeMirror-gutters" style="display: none; height: 92px;"></div></div></div></pre><h3 id='uvtcpwritequeuesizetcp'><code>uv.tcp_write_queue_size(tcp)</code></h3><blockquote><p><span>method form </span><code>tcp:write_queue_size()</code></p></blockquote><p><strong><span>Deprecated:</span></strong><span> Please use </span><code>uv.stream_get_write_queue_size()</code><span> instead.</span></p><h3 id='uvtcpcloseresettcp-callback'><code>uv.tcp_close_reset(tcp, [callback])</code></h3><blockquote><p><span>method form </span><code>tcp:close_reset([callback])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tcp</code><span>: </span><code>uv_tcp_t userdata</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code><span> or </span><code>nil</code></p></li></ul><p><span>Resets a TCP connection by sending a RST packet. This is accomplished by setting</span>
<span>the SO_LINGER socket option with a linger interval of zero and then calling</span>
<code>uv.close()</code><span>. Due to some platform inconsistencies, mixing of </span><code>uv.shutdown()</code>
<span>and </span><code>uv.tcp_close_reset()</code><span> calls is not allowed.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvsocketpairsocktype-protocol-flags1-flags2'><code>uv.socketpair([socktype], [protocol], [flags1], [flags2])</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>socktype</code><span>: </span><code>string</code><span> or </span><code>integer</code><span> or </span><code>nil</code><span> (default: </span><code>stream</code><span>)</span></p></li><li><p><code>protocol</code><span>: </span><code>string</code><span> or </span><code>integer</code><span> or </span><code>nil</code><span> (default: </span><code>0</code><span>)</span></p></li><li><p><code>flags1</code><span>: </span><code>table</code><span> or </span><code>nil</code></p><ul><li><p><code>nonblock</code><span>: </span><code>boolean</code><span> (default: </span><code>false</code><span>)</span></p></li></ul></li><li><p><code>flags2</code><span>: </span><code>table</code><span> or </span><code>nil</code></p><ul><li><p><code>nonblock</code><span>: </span><code>boolean</code><span> (default: </span><code>false</code><span>)</span></p></li></ul></li></ul><p><span>Create a pair of connected sockets with the specified properties. The resulting handles can be passed to </span><code>uv.tcp_open</code><span>, used with </span><code>uv.spawn</code><span>, or for any other purpose.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported </span><code>socktype</code><span> input values.</span></p><p><span>When </span><code>protocol</code><span> is set to 0 or nil, it will be automatically chosen based on the socket's domain and type. When </span><code>protocol</code><span> is specified as a string, it will be looked up using the </span><code>getprotobyname(3)</code><span> function (examples: </span><code>"ip"</code><span>, </span><code>"icmp"</code><span>, </span><code>"tcp"</code><span>, </span><code>"udp"</code><span>, etc).</span></p><p><span>Flags:</span></p><ul><li><p><code>nonblock</code><span>: Opens the specified socket handle for </span><code>OVERLAPPED</code><span> or </span><code>FIONBIO</code><span>/</span><code>O_NONBLOCK</code><span> I/O usage. This is recommended for handles that will be used by libuv, and not usually recommended otherwise.</span></p></li></ul><p><span>Equivalent to </span><code>socketpair(2)</code><span> with a domain of </span><code>AF_UNIX</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>[integer, integer]</code><span> or </span><code>fail</code></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Simple read/write with tcp</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">fds</span> = <span class="cm-variable">uv.socketpair</span>(<span class="cm-keyword">nil</span>, <span class="cm-keyword">nil</span>, {<span class="cm-variable">nonblock</span>=<span class="cm-keyword">true</span>}, {<span class="cm-variable">nonblock</span>=<span class="cm-keyword">true</span>})</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">sock1</span> = <span class="cm-variable">uv.new_tcp</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">sock1</span>:<span class="cm-variable">open</span>(<span class="cm-variable">fds</span>[<span class="cm-number">1</span>])</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">sock2</span> = <span class="cm-variable">uv.new_tcp</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">sock2</span>:<span class="cm-variable">open</span>(<span class="cm-variable">fds</span>[<span class="cm-number">2</span>])</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">sock1</span>:<span class="cm-builtin">write</span>(<span class="cm-string">"hello"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">sock2</span>:<span class="cm-variable">read_start</span>(<span class="cm-keyword">function</span>(<span class="cm-variable">err</span>, <span class="cm-variable">chunk</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">assert</span>(<span class="cm-keyword">not</span> <span class="cm-variable">err</span>, <span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-variable">chunk</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 323px;"></div><div class="CodeMirror-gutters" style="display: none; height: 323px;"></div></div></div></pre><h2 id='uvpipet-----pipe-handle'><code>uv_pipe_t</code><span> — Pipe handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> and </span><a href='#uv_stream_t--stream-handle' target='_blank'><code>uv_stream_t</code></a><span> functions also apply.</span></p></blockquote><p><span>Pipe handles provide an abstraction over local domain sockets on Unix and named pipes on Windows.</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">pipe</span> = <span class="cm-variable">uv.new_pipe</span>(<span class="cm-keyword">false</span>)</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">pipe</span>:<span class="cm-variable">bind</span>(<span class="cm-string">'/tmp/sock.test'</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">pipe</span>:<span class="cm-variable">listen</span>(<span class="cm-number">128</span>, <span class="cm-keyword">function</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">local</span> <span class="cm-variable">client</span> = <span class="cm-variable">uv.new_pipe</span>(<span class="cm-keyword">false</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">pipe</span>:<span class="cm-variable">accept</span>(<span class="cm-variable">client</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">client</span>:<span class="cm-builtin">write</span>(<span class="cm-string">"hello!\n"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">client</span>:<span class="cm-builtin">close</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 230px;"></div><div class="CodeMirror-gutters" style="display: none; height: 230px;"></div></div></div></pre><h3 id='uvnewpipeipc'><code>uv.new_pipe([ipc])</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>ipc</code><span>: </span><code>boolean</code><span> or </span><code>nil</code><span> (default: </span><code>false</code><span>)</span></p></li></ul><p><span>Creates and initializes a new </span><code>uv_pipe_t</code><span>. Returns the Lua userdata wrapping</span>
<span>it. The </span><code>ipc</code><span> argument is a boolean to indicate if this pipe will be used for</span>
<span>handle passing between processes.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_pipe_t userdata</code><span> or </span><code>fail</code></p><h3 id='uvpipeopenpipe-fd'><code>uv.pipe_open(pipe, fd)</code></h3><blockquote><p><span>method form </span><code>pipe:open(fd)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li><li><p><code>fd</code><span>: </span><code>integer</code></p></li></ul><p><span>Open an existing file descriptor or </span><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> as a pipe.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: The file descriptor is set to non-blocking mode.</span></p><h3 id='uvpipebindpipe-name'><code>uv.pipe_bind(pipe, name)</code></h3><blockquote><p><span>method form </span><code>pipe:bind(name)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li><li><p><code>name</code><span>: </span><code>string</code></p></li></ul><p><span>Bind the pipe to a file path (Unix) or a name (Windows).</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) bytes,</span>
<span>typically between 92 and 108 bytes.</span></p><h3 id='uvpipeconnectpipe-name-callback'><code>uv.pipe_connect(pipe, name, [callback])</code></h3><blockquote><p><span>method form </span><code>pipe:connect(name, [callback])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li><li><p><code>name</code><span>: </span><code>string</code></p></li><li><p><code>callback</code><span>: </span><code>callable</code><span> or </span><code>nil</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li></ul></li></ul><p><span>Connect to the Unix domain socket or the named pipe.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_connect_t userdata</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) bytes,</span>
<span>typically between 92 and 108 bytes.</span></p><h3 id='uvpipegetsocknamepipe'><code>uv.pipe_getsockname(pipe)</code></h3><blockquote><p><span>method form </span><code>pipe:getsockname()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li></ul><p><span>Get the name of the Unix domain socket or the named pipe.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>string</code><span> or </span><code>fail</code></p><h3 id='uvpipegetpeernamepipe'><code>uv.pipe_getpeername(pipe)</code></h3><blockquote><p><span>method form </span><code>pipe:getpeername()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li></ul><p><span>Get the name of the Unix domain socket or the named pipe to which the handle is</span>
<span>connected.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>string</code><span> or </span><code>fail</code></p><h3 id='uvpipependinginstancespipe-count'><code>uv.pipe_pending_instances(pipe, count)</code></h3><blockquote><p><span>method form </span><code>pipe:pending_instances(count)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li><li><p><code>count</code><span>: </span><code>integer</code></p></li></ul><p><span>Set the number of pending pipe instance handles when the pipe server is waiting</span>
<span>for connections.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><p><strong><span>Note</span></strong><span>: This setting applies to Windows only.</span></p><h3 id='uvpipependingcountpipe'><code>uv.pipe_pending_count(pipe)</code></h3><blockquote><p><span>method form </span><code>pipe:pending_count()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li></ul><p><span>Returns the pending pipe count for the named pipe.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer</code></p><h3 id='uvpipependingtypepipe'><code>uv.pipe_pending_type(pipe)</code></h3><blockquote><p><span>method form </span><code>pipe:pending_type()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li></ul><p><span>Used to receive handles over IPC pipes.</span></p><p><span>First - call </span><code>uv.pipe_pending_count()</code><span>, if it's > 0 then initialize a handle of</span>
<span>the given type, returned by </span><code>uv.pipe_pending_type()</code><span> and call</span>
<code>uv.accept(pipe, handle)</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>string</code></p><h3 id='uvpipechmodpipe-flags'><code>uv.pipe_chmod(pipe, flags)</code></h3><blockquote><p><span>method form </span><code>pipe:chmod(flags)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li><li><p><code>flags</code><span>: </span><code>string</code></p></li></ul><p><span>Alters pipe permissions, allowing it to be accessed from processes run by different users.</span>
<span>Makes the pipe writable or readable by all users. </span><code>flags</code><span> are: </span><code>"r"</code><span>, </span><code>"w"</code><span>, </span><code>"rw"</code><span>, or </span><code>"wr"</code>
<span>where </span><code>r</code><span> is </span><code>READABLE</code><span> and </span><code>w</code><span> is </span><code>WRITABLE</code><span>. This function is blocking.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvpipereadflags-writeflags'><code>uv.pipe([read_flags], [write_flags])</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>read_flags</code><span>: </span><code>table</code><span> or </span><code>nil</code></p><ul><li><p><code>nonblock</code><span>: </span><code>boolean</code><span> (default: </span><code>false</code><span>)</span></p></li></ul></li><li><p><code>write_flags</code><span>: </span><code>table</code><span> or </span><code>nil</code></p><ul><li><p><code>nonblock</code><span>: </span><code>boolean</code><span> (default: </span><code>false</code><span>)</span></p></li></ul></li></ul><p><span>Create a pair of connected pipe handles. Data may be written to the </span><code>write</code><span> fd and read from the </span><code>read</code><span> fd. The resulting handles can be passed to </span><code>pipe_open</code><span>, used with </span><code>spawn</code><span>, or for any other purpose.</span></p><p><span>Flags:</span></p><ul><li><p><code>nonblock</code><span>: Opens the specified socket handle for </span><code>OVERLAPPED</code><span> or </span><code>FIONBIO</code><span>/</span><code>O_NONBLOCK</code><span> I/O usage. This is recommended for handles that will be used by libuv, and not usually recommended otherwise.</span></p></li></ul><p><span>Equivalent to </span><code>pipe(2)</code><span> with the </span><code>O_CLOEXEC</code><span> flag set.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>table</code><span> or </span><code>fail</code></p><ul><li><p><code>read</code><span>: </span><code>integer</code><span> (file descriptor)</span></p></li><li><p><code>write</code><span>: </span><code>integer</code><span> (file descriptor)</span></p></li></ul><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Simple read/write with pipe_open</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">fds</span> = <span class="cm-variable">uv.pipe</span>({<span class="cm-variable">nonblock</span>=<span class="cm-keyword">true</span>}, {<span class="cm-variable">nonblock</span>=<span class="cm-keyword">true</span>})</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">read_pipe</span> = <span class="cm-variable">uv.new_pipe</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">read_pipe</span>:<span class="cm-variable">open</span>(<span class="cm-variable">fds.read</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">write_pipe</span> = <span class="cm-variable">uv.new_pipe</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">write_pipe</span>:<span class="cm-variable">open</span>(<span class="cm-variable">fds.write</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">write_pipe</span>:<span class="cm-builtin">write</span>(<span class="cm-string">"hello"</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">read_pipe</span>:<span class="cm-variable">read_start</span>(<span class="cm-keyword">function</span>(<span class="cm-variable">err</span>, <span class="cm-variable">chunk</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">assert</span>(<span class="cm-keyword">not</span> <span class="cm-variable">err</span>, <span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">print</span>(<span class="cm-variable">chunk</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 323px;"></div><div class="CodeMirror-gutters" style="display: none; height: 323px;"></div></div></div></pre><h3 id='uvpipebind2pipe-name-flags'><code>uv.pipe_bind2(pipe, name, [flags])</code></h3><blockquote><p><span>method form </span><code>pipe:bind2(name, [flags])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li><li><p><code>name</code><span>: </span><code>string</code></p></li><li><p><code>flags</code><span>: </span><code>integer</code><span> or </span><code>table</code><span> or </span><code>nil</code><span> (default: </span><code>0</code><span>)</span></p></li></ul><p><span>Bind the pipe to a file path (Unix) or a name (Windows).</span></p><p><code>Flags</code><span>:</span></p><ul><li><p><span>If </span><code>type(flags)</code><span> is </span><code>number</code><span>, it must be </span><code>0</code><span> or </span><code>uv.constants.PIPE_NO_TRUNCATE</code><span>.</span></p></li><li><p><span>If </span><code>type(flags)</code><span> is </span><code>table</code><span>, it must be </span><code>{}</code><span> or </span><code>{ no_truncate = true|false }</code><span>.</span></p></li><li><p><span>If </span><code>type(flags)</code><span> is </span><code>nil</code><span>, it use default value </span><code>0</code><span>.</span></p></li><li><p><span>Returns </span><code>EINVAL</code><span> for unsupported flags without performing the bind operation.</span></p></li></ul><p><span>Supports Linux abstract namespace sockets. namelen must include the leading '\0' byte but not the trailing nul byte.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>:</span></p><ol start='' ><li><p><span>Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) bytes,</span>
<span>typically between 92 and 108 bytes.</span></p></li><li><p><span>New in version 1.46.0.</span></p></li></ol><h3 id='uvpipeconnect2pipe-name-flags-callback'><code>uv.pipe_connect2(pipe, name, [flags], [callback])</code></h3><blockquote><p><span>method form </span><code>pipe:connect2(name, [flags], [callback])</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>pipe</code><span>: </span><code>uv_pipe_t userdata</code></p></li><li><p><code>name</code><span>: </span><code>string</code></p></li><li><p><code>flags</code><span>: </span><code>integer</code><span> or </span><code>table</code><span> or </span><code>nil</code><span> (default: </span><code>0</code><span>)</span></p></li><li><p><code>callback</code><span>: </span><code>callable</code><span> or </span><code>nil</code></p><ul><li><p><code>err</code><span>: </span><code>nil</code><span> or </span><code>string</code></p></li></ul></li></ul><p><span>Connect to the Unix domain socket or the named pipe.</span></p><p><code>Flags</code><span>:</span></p><ul><li><p><span>If </span><code>type(flags)</code><span> is </span><code>number</code><span>, it must be </span><code>0</code><span> or </span><code>uv.constants.PIPE_NO_TRUNCATE</code><span>.</span></p></li><li><p><span>If </span><code>type(flags)</code><span> is </span><code>table</code><span>, it must be </span><code>{}</code><span> or </span><code>{ no_truncate = true|false }</code><span>.</span></p></li><li><p><span>If </span><code>type(flags)</code><span> is </span><code>nil</code><span>, it use default value </span><code>0</code><span>.</span></p></li><li><p><span>Returns </span><code>EINVAL</code><span> for unsupported flags without performing the bind operation.</span></p></li></ul><p><span>Supports Linux abstract namespace sockets. namelen must include the leading nul byte but not the trailing nul byte.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_connect_t userdata</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>:</span></p><ol start='' ><li><p><span>Paths on Unix get truncated to sizeof(sockaddr_un.sun_path) bytes,</span>
<span>typically between 92 and 108 bytes.</span></p></li><li><p><span>New in version 1.46.0.</span></p></li></ol><h2 id='uvttyt-----tty-handle'><code>uv_tty_t</code><span> — TTY handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> and </span><a href='#uv_stream_t--stream-handle' target='_blank'><code>uv_stream_t</code></a><span> functions also apply.</span></p></blockquote><p><span>TTY handles represent a stream for the console.</span></p><pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="lua"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="lua"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.52344px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- Simple echo program</span></span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">stdin</span> = <span class="cm-variable">uv.new_tty</span>(<span class="cm-number">0</span>, <span class="cm-keyword">true</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">local</span> <span class="cm-variable">stdout</span> = <span class="cm-variable">uv.new_tty</span>(<span class="cm-number">1</span>, <span class="cm-keyword">false</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp="">
</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">stdin</span>:<span class="cm-variable">read_start</span>(<span class="cm-keyword">function</span> (<span class="cm-variable">err</span>, <span class="cm-variable">data</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-builtin">assert</span>(<span class="cm-keyword">not</span> <span class="cm-variable">err</span>, <span class="cm-variable">err</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> <span class="cm-variable">data</span> <span class="cm-keyword">then</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">stdout</span>:<span class="cm-builtin">write</span>(<span class="cm-variable">data</span>)</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">else</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">stdin</span>:<span class="cm-builtin">close</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">stdout</span>:<span class="cm-builtin">close</span>()</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">end</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">end</span>)</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 300px;"></div><div class="CodeMirror-gutters" style="display: none; height: 300px;"></div></div></div></pre><h3 id='uvnewttyfd-readable'><code>uv.new_tty(fd, readable)</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>fd</code><span>: </span><code>integer</code></p></li><li><p><code>readable</code><span>: </span><code>boolean</code></p></li></ul><p><span>Initialize a new TTY stream with the given file descriptor. Usually the file</span>
<span>descriptor will be:</span></p><ul><li><p><span>0 - stdin</span></p></li><li><p><span>1 - stdout</span></p></li><li><p><span>2 - stderr</span></p></li></ul><p><span>On Unix this function will determine the path of the fd of the terminal using</span>
<span>ttyname_r(3), open it, and use it if the passed file descriptor refers to a TTY.</span>
<span>This lets libuv put the tty in non-blocking mode without affecting other</span>
<span>processes that share the tty.</span></p><p><span>This function is not thread safe on systems that don’t support ioctl TIOCGPTN or TIOCPTYGNAME, for instance OpenBSD and Solaris.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>uv_tty_t userdata</code><span> or </span><code>fail</code></p><p><strong><span>Note</span></strong><span>: If reopening the TTY fails, libuv falls back to blocking writes.</span></p><h3 id='uvttysetmodetty-mode'><code>uv.tty_set_mode(tty, mode)</code></h3><blockquote><p><span>method form </span><code>tty:set_mode(mode)</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tty</code><span>: </span><code>uv_tty_t userdata</code></p></li><li><p><code>mode</code><span>: </span><code>string</code><span> or </span><code>integer</code></p></li></ul><p><span>Set the TTY using the specified terminal mode.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported TTY mode input values.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvttyresetmode'><code>uv.tty_reset_mode()</code></h3><p><span>To be called when the program exits. Resets TTY settings to default values for</span>
<span>the next process to take over.</span></p><p><span>This function is async signal-safe on Unix platforms but can fail with error</span>
<span>code </span><code>EBUSY</code><span> if you call it when execution is inside </span><code>uv.tty_set_mode()</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>0</code><span> or </span><code>fail</code></p><h3 id='uvttygetwinsizetty'><code>uv.tty_get_winsize(tty)</code></h3><blockquote><p><span>method form </span><code>tty:get_winsize()</code></p></blockquote><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>tty</code><span>: </span><code>uv_tty_t userdata</code></p></li></ul><p><span>Gets the current Window width and height.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>integer, integer</code><span> or </span><code>fail</code></p><h3 id='uvttysetvtermstatestate'><code>uv.tty_set_vterm_state(state)</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>state</code><span>: </span><code>string</code></p></li></ul><p><span>Controls whether console virtual terminal sequences are processed by libuv or</span>
<span>console. Useful in particular for enabling ConEmu support of ANSI X3.64 and</span>
<span>Xterm 256 colors. Otherwise Windows10 consoles are usually detected</span>
<span>automatically. State should be one of: </span><code>"supported"</code><span> or </span><code>"unsupported"</code><span>.</span></p><p><span>This function is only meaningful on Windows systems. On Unix it is silently</span>
<span>ignored.</span></p><p><strong><span>Returns:</span></strong><span> Nothing.</span></p><h3 id='uvttygetvtermstate'><code>uv.tty_get_vterm_state()</code></h3><p><span>Get the current state of whether console virtual terminal sequences are handled</span>
<span>by libuv or the console. The return value is </span><code>"supported"</code><span> or </span><code>"unsupported"</code><span>.</span></p><p><span>This function is not implemented on Unix, where it returns </span><code>ENOTSUP</code><span>.</span></p><p><strong><span>Returns:</span></strong><span> </span><code>string</code><span> or </span><code>fail</code></p><h2 id='uvudpt-----udp-handle'><code>uv_udp_t</code><span> — UDP handle</span></h2><blockquote><p><a href='#uv_handle_t--base-handle' target='_blank'><code>uv_handle_t</code></a><span> functions also apply.</span></p></blockquote><p><span>UDP handles encapsulate UDP communication for both clients and servers.</span></p><h3 id='uvnewudpflags'><code>uv.new_udp([flags])</code></h3><p><strong><span>Parameters:</span></strong></p><ul><li><p><code>flags</code><span>: </span><code>table</code><span> or </span><code>nil</code></p><ul><li><p><code>family</code><span>: </span><code>string</code><span> or </span><code>nil</code></p></li><li><p><code>mmsgs</code><span>: </span><code>integer</code><span> or </span><code>nil</code><span> (default: </span><code>1</code><span>)</span></p></li></ul></li></ul><p><span>Creates and initializes a new </span><code>uv_udp_t</code><span>. Returns the Lua userdata wrapping</span>
<span>it. The actual socket is created lazily.</span></p><p><span>See </span><a href='#constants' target='_blank'><span>Constants</span></a><span> for supported address </span><code>family</code><span> input values.</span></p><p><span>When specified, </span><code>mmsgs</code><span> determines the number of messages able to be received</span>