-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuv.c3i
1932 lines (1723 loc) · 65.8 KB
/
uv.c3i
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
module libuv;
import std::io;
import std::os::win32;
def UV__Work_work = fn void* (UV__Work *w);
def UV__Work_done = fn void* (UV__Work *w, CInt status);
def UVUdpSendCb = fn void* (UVUdpSend* req, CLong status);
def UVUdpRecvCb = fn void* (UVUdp* handle,
CLong nread,
UVBuf* buf,
Platform_sockaddr* addr,
CLong flags);
struct UV__Work {
UV__Work_work work;
UV__Work_done done;
UVLoop* loop;
UV__Queue wq;
}
enum UVClockId {
UV_CLOCK_MONOTONIC,
UV_CLOCK_REALTIME
}
/* XXX(bnoordhuis) not 2038-proof, https://github.com/libuv/libuv/issues/3864 */
struct UVTimespec {
CLong tv_sec;
CLong tv_nsec;
}
struct UVTimespec64 {
CLongLong tv_sec;
CLong tv_nsec;
}
/* XXX(bnoordhuis) not 2038-proof, https://github.com/libuv/libuv/issues/3864 */
struct UVTimeval {
CLong tv_sec;
CLong tv_usec;
}
struct UVTimeval64 {
CLongLong tv_sec;
CLong tv_usec;
}
struct UVStat {
CULongLong st_dev;
CULongLong st_mode;
CULongLong st_nlink;
CULongLong st_uid;
CULongLong st_gid;
CULongLong st_rdev;
CULongLong st_ino;
CULongLong st_size;
CULongLong st_blksize;
CULongLong st_blocks;
CULongLong st_flags;
CULongLong st_gen;
UVTimespec st_atim;
UVTimespec st_mtim;
UVTimespec st_ctim;
UVTimespec st_birthtim;
}
enum UVHandleType {
UV_UNKNOWN_HANDLE,
UV_ASYNC,
UV_CHECK,
UV_FS_EVENT,
UV_FS_POLL,
UV_HANDLE,
UV_IDLE,
UV_NAMED_PIPE,
UV_POLL,
UV_PREPARE,
UV_PROCESS,
UV_STREAM,
UV_TCP,
UV_TIMER,
UV_TTY,
UV_UDP,
UV_SIGNAL,
UV_FILE,
UV_HANDLE_TYPE_MAX
}
/*
Internal type, do not use.
https://github.com/libuv/libuv/blob/0f31978c303b76798ff2b72e9498e5520722ef8a/include/uv.h#L63
*/
struct UV__Queue {
UV__Queue* next;
UV__Queue* prev;
}
// typedef struct uv_loop_s uv_loop_t;
struct UVLoop {
// inline UV_LOOP_PRIVATE_FIELDS_t uv_loop_private_fields;
/* User data - use this for whatever. */
void* data;
/* Loop reference counting. */
CUInt active_handles;
UV__Queue handle_queue;
union active_reqs {
void* unused;
CUInt count;
}
/* Internal storage for future extensions. */
void* internal_fields;
/* Internal flag to signal loop stop. */
CUInt stop_flag;
// unix
CULong flags @if(!env::WIN32);
CInt backend_fd @if(!env::WIN32);
UV__Queue pending_queue @if(!env::WIN32);
UV__Queue watcher_queue @if(!env::WIN32);
UV__Io** watchers @if(!env::WIN32);
CUInt nwatchers @if(!env::WIN32);
CUInt nfds @if(!env::WIN32);
UV__Queue wq @if(!env::WIN32);
UVMutex wq_mutex @if(!env::WIN32);
UVAsync wq_async @if(!env::WIN32);
UVRWLock cloexec_lock @if(!env::WIN32);
UVHandle* closing_handles @if(!env::WIN32);
UV__Queue process_handles @if(!env::WIN32);
UV__Queue prepare_handles @if(!env::WIN32);
UV__Queue check_handles @if(!env::WIN32);
UV__Queue idle_handles @if(!env::WIN32);
UV__Queue async_handles @if(!env::WIN32);
Async_unused async_unused @if(!env::WIN32); /* TODO(bnoordhuis) Remove in libuv v2. */
UV__Io async_io_watcher @if(!env::WIN32);
CInt async_wfd @if(!env::WIN32);
struct timer_heap @if(!env::WIN32) {
void* min;
CUInt nelts;
}
CULongLong timer_counter @if(!env::WIN32);
CULongLong time @if(!env::WIN32);
CInt[2]* signal_pipefd @if(!env::WIN32);
UV__Io signal_io_watcher @if(!env::WIN32);
UVSignal child_watcher @if(!env::WIN32);
CInt emfile_fd @if(!env::WIN32);
// inline UV_PLATFORM_LOOP_FIELDS_t uv_platform_loop_fields;
CInt fs_fd @if(env::OS_TYPE == OsType.AIX);
UVThread cf_thread @if(env::DARWIN);
void* _cf_reserved @if(env::DARWIN);
void* cf_state @if(env::DARWIN);
UVMutex cf_mutex @if(env::DARWIN);
UVSem cf_sem @if(env::DARWIN);
UV__Queue cf_signals @if(env::DARWIN);
UV__Io inotify_read_watcher @if(env::OS_TYPE == OsType.LINUX);
void* inotify_watchers @if(env::OS_TYPE == OsType.LINUX);
CInt inotify_fd @if(env::OS_TYPE == OsType.LINUX);
/* For the sake of convenience and reduced #ifdef-ery in src/unix/sunos.c,
* add the fs_event fields even when this version of SunOS doesn't support
* file watching.
*/
UV__Io fs_event_watcher @if(env::OS_TYPE == OsType.SOLARIS);
CInt fs_fd @if(env::OS_TYPE == OsType.SOLARIS);
// win
Win32_HANDLE iocp @if(env::WIN32);
/* The current time according to the event loop. in msecs. */
CULongLong time @if(env::WIN32);
/* Tail of a single-linked circular queue of pending reqs. If the queue */
/* is empty, tail_ is NULL. If there is only one item, */
/* tail_->next_req == tail_ */
UVReq* pending_reqs_tail @if(env::WIN32);
/* Head of a single-linked list of closed handles */
UVHandle* endgame_handles @if(env::WIN32);
/* TODO(bnoordhuis) Stop heap-allocating |timer_heap| in libuv v2.x. */
void* timer_heap @if(env::WIN32);
/* Lists of active loop (prepare / check / idle) watchers */
UVPrepare* prepare_handles @if(env::WIN32);
UVCheck* check_handles @if(env::WIN32);
UVIdle* idle_handles @if(env::WIN32);
/* This pointer will refer to the prepare/check/idle handle whose */
/* callback is scheduled to be called next. This is needed to allow */
/* safe removal from one of the lists above while that list being */
/* iterated over. */
UVPrepare* next_prepare_handle @if(env::WIN32);
UVCheck* next_check_handle @if(env::WIN32);
UVIdle* next_idle_handle @if(env::WIN32);
/* This handle holds the peer sockets for the fast variant of uv_poll_t */
Win32_SOCKET[UV_MSAFD_PROVIDER_COUNT] poll_peer_sockets @if(env::WIN32);
/* No longer used. */
CUInt active_tcp_streams @if(env::WIN32);
/* No longer used. */
CUInt active_udp_streams @if(env::WIN32);
/* Counter to started timer */
CULongLong timer_counter @if(env::WIN32);
/* Threadpool */
UV__Queue wq @if(env::WIN32);
UVMutex wq_mutex @if(env::WIN32);
UVAsync wq_async @if(env::WIN32);
}
extern fn void* uv_loop_get_data(UVLoop*);
extern fn void uv_loop_set_data(UVLoop*, void* data);
/* Unicode utilities needed for dealing with Windows. */
extern fn CLongLong uv_utf16_length_as_wtf8(CULong* utf16,
CULongLong utf16_len);
extern fn CInt uv_utf16_to_wtf8(CULong* utf16,
CULongLong utf16_len,
CChar** wtf8_ptr,
CLongLong* wtf8_len_ptr);
extern fn CULongLong uv_wtf8_length_as_utf16(CChar* wtf8);
extern fn void uv_wtf8_to_utf16(CChar* wtf8,
CULong* utf16,
CLongLong utf16_len);
// typedef struct uv_handle_s uv_handle_t;
struct UVHandle {
/* public */
void* data;
/* read-only */
UVLoop* loop;
UVHandleType type;
/* private */
UVCloseCb close_cb;
UV__Queue handle_queue;
union u {
CInt fd;
void*[4] reserved;
}
UVHandle* next_closing @if(!env::WIN32);
UVHandle* endgame_next @if(env::WIN32);
CUInt flags;
}
extern fn CLongLong uv_handle_size(UVHandleType type);
extern fn UVHandleType uv_handle_get_type(UVHandle* handle);
extern fn CChar* uv_handle_type_name(UVHandleType type);
extern fn void* uv_handle_get_data(UVHandle* handle);
extern fn UVLoop* uv_handle_get_loop(UVHandle* handle);
extern fn void uv_handle_set_data(UVHandle* handle, void* data);
extern fn CLongLong uv_req_size(UVReqType type);
extern fn void* uv_req_get_data(UVReq* req);
extern fn void uv_req_set_data(UVReq* req, void* data);
extern fn UVReqType uv_req_get_type(UVReq* req);
extern fn CChar* uv_req_type_name(UVReqType type);
extern fn CInt uv_is_active(UVHandle* handle);
extern fn void uv_walk(UVLoop* loop, UVWalkCb walk_cb, void* arg);
/* Helpers for ad hoc debugging, no API/ABI stability guaranteed. */
extern fn void uv_print_all_handles(UVLoop* loop, void* stream); // FILE* ?
extern fn void uv_print_active_handles(UVLoop* loop, void* stream); // FILE* ?
extern fn void uv_close(UVHandle* handle, UVCloseCb close_cb);
extern fn CInt uv_send_buffer_size(UVHandle* handle, CInt* value);
extern fn CInt uv_recv_buffer_size(UVHandle* handle, CInt* value);
extern fn CInt uv_fileno(UVHandle* handle, UVOsFd* fd);
extern fn UVBuf uv_buf_init(CChar* base, CUInt len);
extern fn CInt uv_pipe(UVFile[2]* fds, CInt read_flags, CInt write_flags);
extern fn CInt uv_socketpair(CInt type,
CInt protocol,
UVOsSock[2]* socket_vector,
CInt flags0,
CInt flags1);
// typedef struct uv_dir_s uv_dir_t;
import std::os::posix;
struct UVDir {
UVDirent* dirents;
CLongLong nentries;
void*[4]* reserved;
// UV_DIR_PRIVATE_FIELDS
DIRPtr dir @if(!env::WIN32);
Win32_HANDLE dir_handle @if(env::WIN32);
Win32_WIN32_FIND_DATAW find_data @if(env::WIN32);
bool need_find_call @if(env::WIN32);
}
extern fn UVFsType uv_fs_get_type(UVFs*);
extern fn CULongLong uv_fs_get_result(UVFs*);
extern fn CInt uv_fs_get_system_error(UVFs*);
extern fn void* uv_fs_get_ptr(UVFs*);
extern fn CChar* uv_fs_get_path(UVFs*);
extern fn UVStat* uv_fs_get_statbuf(UVFs*);
extern fn void uv_fs_req_cleanup(UVFs* req);
extern fn CInt uv_fs_close(UVLoop* loop,
UVFs* req,
UVFile file,
UVFsCb cb);
extern fn CInt uv_fs_open(UVLoop* loop,
UVFs* req,
CChar* path,
CInt flags,
CInt mode,
UVFsCb cb);
extern fn CInt uv_fs_read(UVLoop* loop,
UVFs* req,
UVFile file,
UVBuf* bufs,
CUInt nbufs,
CLongLong offset,
UVFsCb cb);
extern fn CInt uv_fs_unlink(UVLoop* loop,
UVFs* req,
CChar* path,
UVFsCb cb);
extern fn CInt uv_fs_write(UVLoop* loop,
UVFs* req,
UVFile file,
UVBuf* bufs,
CUInt nbufs,
CLongLong offset,
UVFsCb cb);
// typedef struct uv_stream_s uv_stream_t;
struct UVStream {
inline UVHandle h;
CLongLong write_queue_size;
UVAllocCb alloc_cb;
UVReadCb read_cb;
// UV_STREAM_PRIVATE_FIELDS
// win32
CUInt reqs_pending @if(env::WIN32);
CInt activecnt @if(env::WIN32);
UVRead read_req @if(env::WIN32);
union stream @if(env::WIN32) {
struct conn {
CUInt write_reqs_pending;
UVShutdown* shutdown_req;
}
struct serv {
UVConnectionCb connection_cb;
}
}
// unix
UVConnect *connect_req @if(!env::WIN32);
UVShutdown *shutdown_req @if(!env::WIN32);
UV__Io io_watcher @if(!env::WIN32);
UV__Queue write_queue @if(!env::WIN32);
UV__Queue write_completed_queue @if(!env::WIN32);
UVConnectionCb connection_cb @if(!env::WIN32);
CInt delayed_error @if(!env::WIN32);
CInt accepted_fd @if(!env::WIN32);
void* queued_fds @if(!env::WIN32);
// UV_STREAM_PRIVATE_FIELDS
void* select @if(env::DARWIN);
}
// typedef struct uv_tcp_s uv_tcp_t;
struct UVTcp {
inline UVStream s;
// UV_TCP_PRIVATE_FIELDS
Win32_SOCKET socket @if(env::WIN32);
CInt delayed_error @if(env::WIN32);
union tcp @if(env::WIN32) {
struct serv {
UVTcpAccept* accept_reqs;
CUInt processed_accepts;
UVTcpAccept* pending_accepts;
Win32_LPFn_ACCEPTEX func_acceptex;
}
struct conn {
UVBuf read_buffer;
Win32_LPFn_CONNECTEX func_connectex;
}
}
}
extern fn CLongLong uv_stream_get_write_queue_size(UVStream* stream);
extern fn CInt uv_listen(UVStream* stream, CInt backlog, UVConnectionCb cb);
extern fn CInt uv_accept(UVStream* server, UVStream* client);
extern fn CInt uv_read_start(UVStream*,
UVAllocCb alloc_cb,
UVReadCb read_cb);
extern fn CInt uv_read_stop(UVStream*);
extern fn CInt uv_write(UVWrite* req,
UVStream* handle,
UVBuf* bufs,
CUInt nbufs,
UVWriteCb cb);
extern fn CInt uv_write2(UVWrite* req,
UVStream* handle,
UVBuf* bufs,
CUInt nbufs,
UVStream* send_handle,
UVWriteCb cb);
extern fn CInt uv_try_write(UVStream* handle,
UVBuf* bufs,
CUInt nbufs);
extern fn CInt uv_try_write2(UVStream* handle,
UVBuf* bufs,
CUInt nbufs,
UVStream* send_handle);
extern fn CInt uv_tcp_init(UVLoop*, UVTcp* handle);
extern fn CInt uv_tcp_init_ex(UVLoop*, UVTcp* handle, CUInt flags);
extern fn CInt uv_tcp_open(UVTcp* handle, UVOsSock sock);
extern fn CInt uv_tcp_nodelay(UVTcp* handle, CInt enable);
extern fn CInt uv_tcp_keepalive(UVTcp* handle,
CInt enable,
CUInt delay);
extern fn CInt uv_tcp_simultaneous_accepts(UVTcp* handle, CInt enable);
enum UVTcpFlags : CInt (CInt code) {
/* Used with uv_tcp_bind, when an IPv6 address is used. */
UV_TCP_IPV6ONLY = 1,
/* Enable SO_REUSEPORT socket option when binding the handle.
* This allows completely duplicate bindings by multiple processes
* or threads if they all set SO_REUSEPORT before binding the port.
* Incoming connections are distributed across the participating
* listener sockets.
*
* This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+,
* FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+ for now.
*/
UV_TCP_REUSEPORT = 2,
}
extern fn CInt uv_tcp_bind(UVTcp* handle,
Platform_sockaddr* addr,
CUInt flags);
extern fn CInt uv_tcp_getsockname(UVTcp* handle,
Platform_sockaddr* name,
CInt* namelen);
extern fn CInt uv_tcp_getpeername(UVTcp* handle,
Platform_sockaddr* name,
CInt* namelen);
extern fn CInt uv_tcp_close_reset(UVTcp* handle, UVCloseCb close_cb);
extern fn CInt uv_tcp_connect(UVConnect* req,
UVTcp* handle,
Platform_sockaddr* addr,
UVConnectCb cb);
// typedef struct uv_udp_s uv_udp_t;
/* uv_udp_t is a subclass of uv_handle_t. */
struct UVUdp {
inline UVHandle h;
/* read-only */
/*
* Number of bytes queued for sending. This field strictly shows how much
* information is currently queued.
*/
CLongLong send_queue_size;
/*
* Number of send requests currently in the queue awaiting to be processed.
*/
CLongLong send_queue_count;
// UV_UDP_PRIVATE_FIELDS
// win
Win32_SOCKET socket @if(env::WIN32);
CUInt reqs_pending @if(env::WIN32);
CInt activecnt @if(env::WIN32);
UVReq recv_req @if(env::WIN32);
UVBuf recv_buffer @if(env::WIN32);
Win32_Sockaddr_storage recv_from @if(env::WIN32);
CInt recv_from_len @if(env::WIN32);
UVUdpRecvCb recv_cb @if(env::WIN32);
UVAllocCb alloc_cb @if(env::WIN32);
Win32_LPFN_WSARECV func_wsarecv @if(env::WIN32);
Win32_LPFN_WSARECVFROM func_wsarecvfrom @if(env::WIN32);
// unix
UVAllocCb alloc_cb @if(!env::WIN32);
UVUdpRecvCb recv_cb @if(!env::WIN32);
UV__Io io_watcher @if(!env::WIN32);
UV__Queue write_queue @if(!env::WIN32);
UV__Queue write_completed_queue @if(!env::WIN32);
}
// typedef struct uv_pipe_s uv_pipe_t;
/*
* uv_pipe_t is a subclass of uv_stream_t.
*
* Representing a pipe stream or pipe server. On Windows this is a Named
* Pipe. On Unix this is a Unix domain socket.
*/
struct UVPipe {
inline UVStream s;
CInt ipc; /* non-zero if this pipe is used for passing handles */
// UV_PIPE_PRIVATE_FIELDS
// win
Win32_HANDLE handle @if(env::WIN32);
Win32_WCHAR* name @if(env::WIN32);
union pipe @if(env::WIN32) {
struct serv {
// uv_pipe_server_fields
CInt pending_instances;
UVPipeAccept* accept_reqs;
UVPipeAccept* pending_accepts;
}
struct conn {
// uv_pipe_connection_fields
UVTimer* eof_timer;
UVWrite dummy; /* TODO: retained for ABI compat; remove this in v2.x. */
Win32_DWORD ipc_remote_pid;
union ipc_data_frame {
CULong payload_remaining;
CULongLong dummy; /* TODO: retained for ABI compat; remove this in v2.x. */
}
UV__Queue ipc_xfer_queue;
CInt ipc_xfer_queue_length;
UVWrite* non_overlapped_writes_tail;
Win32_CRITICAL_SECTION readfile_thread_lock;
Win32_HANDLE readfile_thread_handle;
}
}
// unix
CChar* pipe_fname @if(!env::WIN32);
}
extern fn CInt uv_pipe_init(UVLoop*, UVPipe* handle, CInt ipc);
extern fn CInt uv_pipe_open(UVPipe*, UVFile file);
extern fn CInt uv_pipe_bind(UVPipe* handle, CChar* name);
extern fn CInt uv_pipe_bind2(UVPipe* handle,
CChar* name,
CLongLong namelen,
CUInt flags);
extern fn void uv_pipe_connect(UVConnect* req,
UVPipe* handle,
CChar* name,
UVConnectCb cb);
extern fn CInt uv_pipe_connect2(UVConnect* req,
UVPipe* handle,
CChar* name,
CLongLong namelen,
CUInt flags,
UVConnectCb cb);
extern fn CInt uv_pipe_getsockname(UVPipe* handle,
CChar* buffer,
CLongLong* size);
extern fn CInt uv_pipe_getpeername(UVPipe* handle,
CChar* buffer,
CLongLong* size);
extern fn void uv_pipe_pending_instances(UVPipe* handle, CInt count);
extern fn CInt uv_pipe_pending_count(UVPipe* handle);
extern fn UVHandleType uv_pipe_pending_type(UVPipe* handle);
extern fn CInt uv_pipe_chmod(UVPipe* handle, CInt flags);
// typedef struct uv_tty_s uv_tty_t;
/*
* uv_tty_t is a subclass of uv_stream_t.
*
* Representing a stream for the console.
*/
def Termios = void*; // todo need termios bindings for c3
enum UVTtyMode {
/* Initial/normal terminal mode */
UV_TTY_MODE_NORMAL,
/* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
UV_TTY_MODE_RAW,
/* Binary-safe I/O mode for IPC (Unix-only) */
UV_TTY_MODE_IO
}
struct UVTty {
inline UVStream s;
// UV_TTY_PRIVATE_FIELDS
// win32
Win32_HANDLE handle @if(env::WIN32);
union tty @if(env::WIN32) {
struct rd {
/* Used for readable TTY handles */
/* TODO: remove me in v2.x. */
Win32_HANDLE unused_;
UVBuf read_line_buffer;
Win32_HANDLE read_raw_wait;
/* Fields used for translating win keystrokes CInto vt100 characters */
CChar[8]* last_key;
CUChar last_key_offset;
CUChar last_key_len;
Win32_WCHAR last_utf16_high_surrogate;
Win32_INPUT_RECORD last_input_record;
}
struct wr {
/* Used for writable TTY handles */
/* utf8-to-utf16 conversion state */
CUInt utf8_codepoCInt;
CUChar utf8_bytes_left;
/* eol conversion state */
CUChar previous_eol;
/* ansi parser state */
CUShort ansi_parser_state;
CUChar ansi_csi_argc;
CUShort[4]* ansi_csi_argv;
Win32_COORD saved_position;
Win32_WORD saved_attributes;
}
}
// unix
Termios orig_termios @if(!env::WIN32);
CInt mode @if(!env::WIN32);
}
enum UVTtyVtermstate {
/*
* The console supports handling of virtual terminal sequences
* (Windows10 new console, ConEmu)
*/
UV_TTY_SUPPORTED,
/* The console cannot process the virtual terminal sequence. (Legacy
* console)
*/
UV_TTY_UNSUPPORTED
}
extern fn CInt uv_tty_init(UVLoop*, UVTty*, UVFile fd, CInt readable);
extern fn CInt uv_tty_set_mode(UVTty*, UVTtyMode mode);
extern fn CInt uv_tty_reset_mode();
extern fn CInt uv_tty_get_winsize(UVTty*, CInt* width, CInt* height);
extern fn void uv_tty_set_vterm_state(UVTtyVtermstate state);
extern fn CInt uv_tty_get_vterm_state(UVTtyVtermstate* state);
// typedef struct uv_poll_s uv_poll_t;
struct UVPoll {
inline UVHandle h;
UVPollCb poll_cb;
// UV_POLL_PRIVATE_FIELDS
// win
Win32_SOCKET socket @if(env::WIN32);
/* Used in fast mode */
Win32_SOCKET peer_socket @if(env::WIN32);
Win32_AFD_POLL_INFO afd_poll_info_1 @if(env::WIN32);
Win32_AFD_POLL_INFO afd_poll_info_2 @if(env::WIN32);
/* Used in fast and slow mode. */
UVReq poll_req_1 @if(env::WIN32);
UVReq poll_req_2 @if(env::WIN32);
CUChar submitted_events_1 @if(env::WIN32);
CUChar submitted_events_2 @if(env::WIN32);
CUChar mask_events_1 @if(env::WIN32);
CUChar mask_events_2 @if(env::WIN32);
CUChar events @if(env::WIN32);
// unix
UV__Io io_watcher @if(!env::WIN32);
}
enum UVPollEvent : CInt (CInt code) {
UV_READABLE = 1,
UV_WRITABLE = 2,
UV_DISCONNECT = 4,
UV_PRIORITIZED = 8
}
extern fn CInt uv_poll_init(UVLoop* loop, UVPoll* handle, CInt fd);
extern fn CInt uv_poll_init_socket(UVLoop* loop,
UVPoll* handle,
UVOsSock socket);
extern fn CInt uv_poll_start(UVPoll* handle, CInt events, UVPollCb cb);
extern fn CInt uv_poll_stop(UVPoll* handle);
// typedef struct uv_timer_s uv_timer_t;
/*
* uv_timer_t is a subclass of uv_handle_t.
*
* Used to get woken up at a specified time in the future.
*/
struct UVTimer {
inline UVHandle h;
// UV_TIMER_PRIVATE_FIELDS
// win
union node @if(env::WIN32) {
void*[3]* heap;
UV__Queue queue;
}
CInt unused @if(env::WIN32);
CULongLong timeout @if(env::WIN32);
CULongLong repeat @if(env::WIN32);
CULongLong start_id @if(env::WIN32);
UVTimerCb timer_cb @if(env::WIN32);
// unix
UVTimerCb timer_cb @if(!env::WIN32);
union node @if(!env::WIN32) {
void*[3]* heap;
UV__Queue queue;
}
CULongLong timeout @if(!env::WIN32);
CULongLong repeat @if(!env::WIN32);
CULongLong start_id @if(!env::WIN32);
/*
> @velikoss
its practically identical in win and unix
but for fields ordering purposes i wrote them separately
*/
}
extern fn CInt uv_timer_init(UVLoop*, UVTimer* handle);
extern fn CInt uv_timer_start(UVTimer* handle,
UVTimerCb cb,
CULongLong timeout,
CULongLong repeat);
extern fn CInt uv_timer_stop(UVTimer* handle);
extern fn CInt uv_timer_again(UVTimer* handle);
extern fn void uv_timer_set_repeat(UVTimer* handle, CULongLong repeat);
extern fn CULongLong uv_timer_get_repeat(UVTimer* handle);
extern fn CULongLong uv_timer_get_due_in(UVTimer* handle);
// typedef struct uv_prepare_s uv_prepare_t;
struct UVPrepare {
inline UVHandle h;
// UV_PREPARE_PRIVATE_FIELDS
// win
UVPrepare* prepare_prev @if(env::WIN32);
UVPrepare* prepare_next @if(env::WIN32);
UVPrepareCb prepare_cb @if(env::WIN32);
// unix
UVPrepareCb prepare_cb @if(!env::WIN32);
UV__Queue queue @if(!env::WIN32);
}
extern fn CInt uv_prepare_init(UVLoop*, UVPrepare* prepare);
extern fn CInt uv_prepare_start(UVPrepare* prepare, UVPrepareCb cb);
extern fn CInt uv_prepare_stop(UVPrepare* prepare);
// typedef struct uv_check_s uv_check_t;
struct UVCheck {
inline UVHandle h;
// UV_CHECK_PRIVATE_FIELDS
// win
UVCheck* check_prev @if(env::WIN32);
UVCheck* check_next @if(env::WIN32);
UVCheckCb check_cb @if(env::WIN32);
// unix
UVCheckCb check_cb @if(!env::WIN32);
UV__Queue queue @if(!env::WIN32);
}
extern fn CInt uv_check_init(UVLoop*, UVCheck* check);
extern fn CInt uv_check_start(UVCheck* check, UVCheckCb cb);
extern fn CInt uv_check_stop(UVCheck* check);
// typedef struct uv_idle_s uv_idle_t;
struct UVIdle {
inline UVHandle uv_handle_fields;
// UV_IDLE_PRIVATE_FIELDS
// win
UVIdle* idle_prev @if(env::WIN32);
UVIdle* idle_next @if(env::WIN32);
UVIdleCb idle_cb @if(env::WIN32);
// unix
UVIdleCb idle_cb @if(!env::WIN32);
UV__Queue queue @if(!env::WIN32);
}
extern fn CInt uv_idle_init(UVLoop*, UVIdle* idle);
extern fn CInt uv_idle_start(UVIdle* idle, UVIdleCb cb);
extern fn CInt uv_idle_stop(UVIdle* idle);
// typedef struct uv_async_s uv_async_t;
struct UVAsync {
inline UVHandle h;
// UV_ASYNC_PRIVATE_FIELDS
// win
UVReq async_req @if(env::WIN32);
UVAsyncCb async_cb @if(env::WIN32);
/* include/uv/win.h > char to avoid alignment issues */
CChar async_sent @if(env::WIN32);
// unix
UVAsyncCb async_cb @if(!env::WIN32);
UV__Queue queue @if(!env::WIN32);
CInt pending @if(!env::WIN32);
}
extern fn CInt uv_async_init(UVLoop*,
UVAsync* async,
UVAsyncCb async_cb);
extern fn CInt uv_async_send(UVAsync* async);
// typedef struct uv_process_s uv_process_t;
struct UVProcessExit {
inline UVReq r;
}
enum UVStdioFlags : int (int code) {
UV_IGNORE = 0x00,
UV_CREATE_PIPE = 0x01,
UV_INHERIT_FD = 0x02,
UV_INHERIT_STREAM = 0x04,
/*
* When UV_CREATE_PIPE is specified, UV_READABLE_PIPE and UV_WRITABLE_PIPE
* determine the direction of flow, from the child process' perspective. Both
* flags may be specified to create a duplex data stream.
*/
UV_READABLE_PIPE = 0x10,
UV_WRITABLE_PIPE = 0x20,
/*
* When UV_CREATE_PIPE is specified, specifying UV_NONBLOCK_PIPE opens the
* handle in non-blocking mode in the child. This may cause loss of data,
* if the child is not designed to handle to encounter this mode,
* but can also be significantly more efficient.
*/
UV_NONBLOCK_PIPE = 0x40,
UV_OVERLAPPED_PIPE = 0x40 /* old name, for compatibility */
}
struct UVStdioContainer {
UVStdioFlags flags;
union data {
UVStream* stream;
CInt fd;
}
}
struct UVProcessOptions {
UVExitCb exit_cb; /* Called after the process exits. */
CChar* file; /* Path to program to execute. */
/*
* Command line arguments. args[0] should be the path to the program. On
* Windows this uses CreateProcess which concatenates the arguments into a
* string this can cause some strange errors. See the note at
* windows_verbatim_arguments.
*/
CChar** args;
/*
* This will be set as the environ variable in the subprocess. If this is
* NULL then the parents environ will be used.
*/
CChar** env;
/*
* If non-null this represents a directory the subprocess should execute
* in. Stands for current working directory.
*/
CChar* cwd;
/*
* Various flags that control how uv_spawn() behaves. See the definition of
* `enum uv_process_flags` below.
*/
CUInt flags;
/*
* The `stdio` field points to an array of uv_stdio_container_t structs that
* describe the file descriptors that will be made available to the child
* process. The convention is that stdio[0] points to stdin, fd 1 is used for
* stdout, and fd 2 is stderr.
*
* Note that on windows file descriptors greater than 2 are available to the
* child process only if the child processes uses the MSVCRT runtime.
*/
CInt stdio_count;
UVStdioContainer* stdio;
/*
* Libuv can change the child process' user/group id. This happens only when
* the appropriate bits are set in the flags fields. This is not supported on
* windows; uv_spawn() will fail and set the error to UV_ENOTSUP.
*/
UVUid uid;
UVGid gid;
}
/*
* uv_process_t is a subclass of uv_handle_t.
*/
struct UVProcess {
inline UVHandle h;
UVExitCb exit_cb;
CInt pid;
// UV_PROCESS_PRIVATE_FIELDS
// win
UVProcessExit exit_req @if(env::WIN32);
void* unused @if(env::WIN32); /* TODO: retained for ABI compat; remove this in v2.x. */
CInt exit_signal @if(env::WIN32);
Win32_HANDLE wait_handle @if(env::WIN32);
Win32_HANDLE process_handle @if(env::WIN32);
CChar exit_cb_pending @if(env::WIN32);
// unix
UV__Queue queue @if(!env::WIN32);
CInt status @if(!env::WIN32);
}
extern fn CInt uv_spawn(UVLoop* loop,
UVProcess* handle,
UVProcessOptions* options);
extern fn CInt uv_process_kill(UVProcess*, CInt signum);
extern fn CInt uv_kill(CInt pid, CInt signum);
extern fn UVPid uv_process_get_pid(UVProcess*);
// typedef struct uv_fs_event_s uv_fs_event_t;
enum UVFsEventE : CInt (CInt code) {
UV_RENAME = 1,
UV_CHANGE = 2
}
struct UVFsEvent {
inline UVHandle h;
/* private */
CChar* path;
// UV_FS_EVENT_PRIVATE_FIELDS
// win
UVProcessExit exit_req @if(env::WIN32);
void* unused; /* TODO: retained for ABI compat; remove this in v2.x. */
CInt exit_signal @if(env::WIN32);
Win32_HANDLE wait_handle @if(env::WIN32);
Win32_HANDLE process_handle @if(env::WIN32);
CChar exit_cb_pending @if(env::WIN32);
// unix
UVFsEventCb cb @if(!env::WIN32);
// UV_PLATFORM_FS_EVENT_FIELDS
// aix
UV__Io event_watcher @if(env::OS_TYPE == OsType.AIX);
CChar *dir_filename @if(env::OS_TYPE == OsType.AIX);
// linux
UV__Queue watchers @if(env::OS_TYPE == OsType.LINUX);
CInt wd @if(env::OS_TYPE == OsType.LINUX);
// bsd
UV__Io event_watcher @if(env::BSD_FAMILY);
// darwin
UV__Io event_watcher @if(env::DARWIN);
CChar* realpath @if(env::DARWIN);
CInt realpath_len @if(env::DARWIN);
CInt cf_flags @if(env::DARWIN);
UVAsync* cf_cb @if(env::DARWIN);
UV__Queue cf_events @if(env::DARWIN);
UV__Queue cf_member @if(env::DARWIN);
CInt cf_error @if(env::DARWIN);
UVMutex cf_mutex @if(env::DARWIN);
// sunos
void* fo @if(env::OS_TYPE == OsType.SOLARIS); // file_obj_t ?
CInt fd @if(env::OS_TYPE == OsType.SOLARIS);
}
// typedef struct uv_fs_poll_s uv_fs_poll_t;
/*
* uv_fs_stat() based polling file watcher.
*/
struct UVFsPoll {
inline UVHandle h;
/* Private, don't touch. */
void* poll_ctx;
}
extern fn CInt uv_fs_poll_init(UVLoop* loop, UVFsPoll* handle);
extern fn CInt uv_fs_poll_start(UVFsPoll* handle,
UVFsPollCb poll_cb,
CChar* path,
CUInt interval);
extern fn CInt uv_fs_poll_stop(UVFsPoll* handle);
extern fn CInt uv_fs_poll_getpath(UVFsPoll* handle,
CChar* buffer,
CLongLong* size);
/*
* Flags to be passed to uv_fs_event_start().
*/
enum UVFsEventFlags : CInt (CInt code) {
/*
* By default, if the fs event watcher is given a directory name, we will
* watch for all events in that directory. This flags overrides this behavior
* and makes fs_event report only changes to the directory entry itself. This
* flag does not affect individual files watched.
* This flag is currently not implemented yet on any backend.
*/
UV_FS_EVENT_WATCH_ENTRY = 1,