summary refs log tree commit diff stats
path: root/lib/wrappers/libuv.nim
blob: 0cb14fb2bbbf3be8a934e5ba6207dbb429a65dba (plain) (blame)
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
## libuv is still fast moving target
## This file was last updated against a development HEAD revision of https://github.com/joyent/libuv/

## Use the following link to see changes (in uv.h) since then and don't forget to update the information here.
## https://github.com/joyent/libuv/compare/9f6024a6fa9d254527b4b59af724257df870288b...master

when defined(Windows):
  import winlean
else:
  import posix

type
  Port* = distinct int16  ## port type

  cssize = int
  coff = int
  csize = int

  AllocProc* = proc (handle: PHandle, suggested_size: csize): Buf {.cdecl.}
  ReadProc* = proc (stream: PStream, nread: cssize, buf: Buf) {.cdecl.}
  ReadProc2* = proc (stream: PPipe, nread: cssize, buf: Buf, pending: HandleType) {.cdecl.}
  WriteProc* = proc (req: PWrite, status: cint) {.cdecl.}
  ConnectProc* = proc (req: PConnect, status: cint) {.cdecl.}
  ShutdownProc* = proc (req: PShutdown, status: cint) {.cdecl.}
  ConnectionProc* = proc (server: PStream, status: cint) {.cdecl.}
  CloseProc* = proc (handle: PHandle) {.cdecl.}
  TimerProc* = proc (handle: PTimer, status: cint) {.cdecl.}
  AsyncProc* = proc (handle: PAsync, status: cint) {.cdecl.}
  PrepareProc* = proc (handle: PPrepare, status: cint) {.cdecl.}
  CheckProc* = proc (handle: PCheck, status: cint) {.cdecl.}
  IdleProc* = proc (handle: PIdle, status: cint) {.cdecl.}

  PSockAddr* = ptr SockAddr

  GetAddrInfoProc* = proc (handle: PGetAddrInfo, status: cint, res: ptr AddrInfo)

  ExitProc* = proc (a2: PProcess, exit_status: cint, term_signal: cint)
  FsProc* = proc (req: PFS)
  WorkProc* = proc (req: PWork)
  AfterWorkProc* = proc (req: PWork)

  FsEventProc* = proc (handle: PFsEvent, filename: cstring, events: cint, status: cint)

  ErrorCode* {.size: sizeof(cint).} = enum
    UNKNOWN = - 1, OK = 0, EOF, EACCESS, EAGAIN, EADDRINUSE, EADDRNOTAVAIL,
    EAFNOSUPPORT, EALREADY, EBADF, EBUSY, ECONNABORTED, ECONNREFUSED,
    ECONNRESET, EDESTADDRREQ, EFAULT, EHOSTUNREACH, EINTR, EINVAL, EISCONN,
    EMFILE, EMSGSIZE, ENETDOWN, ENETUNREACH, ENFILE, ENOBUFS, ENOMEM, ENONET,
    ENOPROTOOPT, ENOTCONN, ENOTSOCK, ENOTSUP, ENOENT, EPIPE, EPROTO,
    EPROTONOSUPPORT, EPROTOTYPE, ETIMEDOUT, ECHARSET, EAIFAMNOSUPPORT,
    EAINONAME, EAISERVICE, EAISOCKTYPE, ESHUTDOWN, EEXIST

  HandleType* {.size: sizeof(cint).} = enum
    UNKNOWN_HANDLE = 0, TCP, UDP, NAMED_PIPE, TTY, FILE, TIMER, PREPARE, CHECK,
    IDLE, ASYNC, ARES_TASK, ARES_EVENT, PROCESS, FS_EVENT

  ReqType* {.size: sizeof(cint).} = enum
    rUNKNOWN_REQ = 0,
    rCONNECT,
    rACCEPT,
    rREAD,
    rWRITE,
    rSHUTDOWN,
    rWAKEUP,
    rUDP_SEND,
    rFS,
    rWORK,
    rGETADDRINFO,
    rREQ_TYPE_PRIVATE

  Err* {.pure, final, importc: "uv_err_t", header: "uv.h".} = object
    code* {.importc: "code".}: ErrorCode
    sys_errno* {.importc: "sys_errno_".}: cint

  FsEventType* = enum
    evRENAME = 1,
    evCHANGE = 2

  TFsEvent* {.pure, final, importc: "uv_fs_event_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer
    filename {.importc: "filename".}: cstring

  PFsEvent* = ptr TFsEvent

  FsEvents* {.pure, final, importc: "uv_fs_event_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer
    filename* {.importc: "filename".}: cstring

  Buf* {.pure, final, importc: "uv_buf_t", header: "uv.h"} = object
    base* {.importc: "base".}: cstring
    len* {.importc: "len".}: csize

  AnyHandle* {.pure, final, importc: "uv_any_handle", header: "uv.h".} = object
    tcp* {.importc: "tcp".}: TTcp
    pipe* {.importc: "pipe".}: Pipe
    prepare* {.importc: "prepare".}: TPrepare
    check* {.importc: "check".}: TCheck
    idle* {.importc: "idle".}: TIdle
    async* {.importc: "async".}: TAsync
    timer* {.importc: "timer".}: TTimer
    getaddrinfo* {.importc: "getaddrinfo".}: Getaddrinfo
    fs_event* {.importc: "fs_event".}: FsEvents

  AnyReq* {.pure, final, importc: "uv_any_req", header: "uv.h".} = object
    req* {.importc: "req".}: Req
    write* {.importc: "write".}: Write
    connect* {.importc: "connect".}: Connect
    shutdown* {.importc: "shutdown".}: Shutdown
    fs_req* {.importc: "fs_req".}: Fs
    work_req* {.importc: "work_req".}: Work

  ## better import this
  uint64 = int64

  Counters* {.pure, final, importc: "uv_counters_t", header: "uv.h".} = object
    eio_init* {.importc: "eio_init".}: uint64
    req_init* {.importc: "req_init".}: uint64
    handle_init* {.importc: "handle_init".}: uint64
    stream_init* {.importc: "stream_init".}: uint64
    tcp_init* {.importc: "tcp_init".}: uint64
    udp_init* {.importc: "udp_init".}: uint64
    pipe_init* {.importc: "pipe_init".}: uint64
    tty_init* {.importc: "tty_init".}: uint64
    prepare_init* {.importc: "prepare_init".}: uint64
    check_init* {.importc: "check_init".}: uint64
    idle_init* {.importc: "idle_init".}: uint64
    async_init* {.importc: "async_init".}: uint64
    timer_init* {.importc: "timer_init".}: uint64
    process_init* {.importc: "process_init".}: uint64
    fs_event_init* {.importc: "fs_event_init".}: uint64

  Loop* {.pure, final, importc: "uv_loop_t", header: "uv.h".} = object
    # ares_handles_* {.importc: "uv_ares_handles_".}: pointer # XXX: This seems to be a private field? 
    eio_want_poll_notifier* {.importc: "uv_eio_want_poll_notifier".}: TAsync
    eio_done_poll_notifier* {.importc: "uv_eio_done_poll_notifier".}: TAsync
    eio_poller* {.importc: "uv_eio_poller".}: TIdle
    counters* {.importc: "counters".}: Counters
    last_err* {.importc: "last_err".}: Err
    data* {.importc: "data".}: pointer

  PLoop* = ptr Loop

  Shutdown* {.pure, final, importc: "uv_shutdown_t", header: "uv.h".} = object
    typ* {.importc: "type".}: ReqType
    data* {.importc: "data".}: pointer
    handle* {.importc: "handle".}: PStream
    cb* {.importc: "cb".}: ShutdownProc

  PShutdown* = ptr Shutdown

  Handle* {.pure, final, importc: "uv_handle_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer

  PHandle* = ptr Handle

  Stream* {.pure, final, importc: "uv_stream_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    alloc_cb* {.importc: "alloc_cb".}: AllocProc
    read_cb* {.importc: "read_cb".}: ReadProc
    read2_cb* {.importc: "read2_cb".}: ReadProc2
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer
    write_queue_size* {.importc: "write_queue_size".}: csize

  PStream* = ptr Stream

  Write* {.pure, final, importc: "uv_write_t", header: "uv.h".} = object
    typ* {.importc: "type".}: ReqType
    data* {.importc: "data".}: pointer
    cb* {.importc: "cb".}: WriteProc
    send_handle* {.importc: "send_handle".}: PStream
    handle* {.importc: "handle".}: PStream

  PWrite* = ptr Write

  TTcp* {.pure, final, importc: "uv_tcp_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    alloc_cb* {.importc: "alloc_cb".}: AllocProc
    read_cb* {.importc: "read_cb".}: ReadProc
    read2_cb* {.importc: "read2_cb".}: ReadProc2
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer
    write_queue_size* {.importc: "write_queue_size".}: csize

  PTcp* = ptr TTcp

  Connect* {.pure, final, importc: "uv_connect_t", header: "uv.h".} = object
    typ* {.importc: "type".}: ReqType
    data* {.importc: "data".}: pointer
    cb* {.importc: "cb".}: ConnectProc
    handle* {.importc: "handle".}: PStream

  PConnect* = ptr Connect

  UdpFlags* = enum
    UDP_IPV6ONLY = 1, UDP_PARTIAL = 2

  ## XXX: better import this
  cunsigned = int

  UdpSendProc* = proc (req: PUdpSend, status: cint)
  UdpRecvProc* = proc (handle: PUdp, nread: cssize, buf: Buf, adr: ptr SockAddr, flags: cunsigned)

  TUdp* {.pure, final, importc: "uv_udp_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer

  PUdp* = ptr TUdp

  UdpSend* {.pure, final, importc: "uv_udp_send_t", header: "uv.h".} = object
    typ* {.importc: "type".}: ReqType
    data* {.importc: "data".}: pointer
    handle* {.importc: "handle".}: PUdp
    cb* {.importc: "cb".}: UdpSendProc

  PUdpSend* = ptr UdpSend

  tTTy* {.pure, final, importc: "uv_tty_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    alloc_cb* {.importc: "alloc_cb".}: AllocProc
    read_cb* {.importc: "read_cb".}: ReadProc
    read2_cb* {.importc: "read2_cb".}: ReadProc2
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer
    write_queue_size* {.importc: "write_queue_size".}: csize

  pTTy* = ptr tTTy

  Pipe* {.pure, final, importc: "uv_pipe_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    alloc_cb* {.importc: "alloc_cb".}: AllocProc
    read_cb* {.importc: "read_cb".}: ReadProc
    read2_cb* {.importc: "read2_cb".}: ReadProc2
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer
    write_queue_size* {.importc: "write_queue_size".}: csize
    ipc {.importc: "ipc".}: int

  PPipe* = ptr Pipe

  TPrepare* {.pure, final, importc: "uv_prepare_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer

  PPrepare* = ptr TPrepare

  TCheck* {.pure, final, importc: "uv_check_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer

  PCheck* = ptr TCheck

  TIdle* {.pure, final, importc: "uv_idle_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer

  PIdle* = ptr TIdle

  TAsync* {.pure, final, importc: "uv_async_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer

  PAsync* = ptr TAsync

  TTimer* {.pure, final, importc: "uv_timer_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer

  PTimer* = ptr TTimer

  GetAddrInfo* {.pure, final, importc: "uv_getaddrinfo_t", header: "uv.h".} = object
    typ* {.importc: "type".}: ReqType
    data* {.importc: "data".}: pointer
    loop* {.importc: "loop".}: PLoop

  PGetAddrInfo* = ptr GetAddrInfo

  ProcessOptions* {.pure, final, importc: "uv_process_options_t", header: "uv.h".} = object
    exit_cb* {.importc: "exit_cb".}: ExitProc
    file* {.importc: "file".}: cstring
    args* {.importc: "args".}: cstringArray
    env* {.importc: "env".}: cstringArray
    cwd* {.importc: "cwd".}: cstring
    windows_verbatim_arguments* {.importc: "windows_verbatim_arguments".}: cint
    stdin_stream* {.importc: "stdin_stream".}: PPipe
    stdout_stream* {.importc: "stdout_stream".}: PPipe
    stderr_stream* {.importc: "stderr_stream".}: PPipe

  PProcessOptions* = ptr ProcessOptions

  TProcess* {.pure, final, importc: "uv_process_t", header: "uv.h".} = object
    loop* {.importc: "loop".}: PLoop
    typ* {.importc: "type".}: HandleType
    close_cb* {.importc: "close_cb".}: CloseProc
    data* {.importc: "data".}: pointer
    exit_cb* {.importc: "exit_cb".}: ExitProc
    pid* {.importc: "pid".}: cint

  PProcess* = ptr TProcess

  Work* {.pure, final, importc: "uv_work_t", header: "uv.h".} = object
    typ* {.importc: "type".}: ReqType
    data* {.importc: "data".}: pointer
    loop* {.importc: "loop".}: PLoop
    work_cb* {.importc: "work_cb".}: WorkProc
    after_work_cb* {.importc: "after_work_cb".}: AfterWorkProc

  PWork* = ptr Work

  FsType* {.size: sizeof(cint).} = enum
    FS_UNKNOWN = - 1, FS_CUSTOM, FS_OPEN, FS_CLOSE, FS_READ, FS_WRITE,
    FS_SENDFILE, FS_STAT, FS_LSTAT, FS_FSTAT, FS_FTRUNCATE, FS_UTIME, FS_FUTIME,
    FS_CHMOD, FS_FCHMOD, FS_FSYNC, FS_FDATASYNC, FS_UNLINK, FS_RMDIR, FS_MKDIR,
    FS_RENAME, FS_READDIR, FS_LINK, FS_SYMLINK, FS_READLINK, FS_CHOWN, FS_FCHOWN

  FS* {.pure, final, importc: "uv_fs_t", header: "uv.h".} = object
    typ* {.importc: "type".}: ReqType
    data* {.importc: "data".}: pointer
    loop* {.importc: "loop".}: PLoop
    fs_type* {.importc: "fs_type".}: FsType
    cb* {.importc: "cb".}: FsProc
    result* {.importc: "result".}: cssize
    fsPtr* {.importc: "ptr".}: pointer
    path* {.importc: "path".}: cstring
    errorno* {.importc: "errorno".}: cint

  PFS* = ptr FS

  Req* {.pure, final, importc: "uv_req_t", header: "uv.h".} = object
    typ* {.importc: "type".}: ReqType
    data* {.importc: "data".}: pointer

  PReq* = ptr Req

  AresOptions* {.pure, final, importc: "ares_options", header: "uv.h".} = object
    flags* {.importc: "flags".}: int
    timeout* {.importc: "timeout".}: int
    tries* {.importc: "tries".}: int
    ndots* {.importc: "ndots".}: int
    udp_port* {.importc: "udp_port".}: Port
    tcp_port* {.importc: "tcp_port".}: Port
    socket_send_buffer_size* {.importc: "socket_send_buffer_size".}: int
    socket_recv_buffer_size* {.importc: "socket_receive_buffer_size".}: int
    servers* {.importc: "servers".}: ptr InAddr
    nservers* {.importc: "nservers".}: int
    domains* {.importc: "domains".}: ptr cstring
    ndomains* {.importc: "ndomains".}: int
    lookups* {.importc: "lookups".}: cstring

  #XXX: not yet exported
  #ares_sock_state_cb sock_state_cb;
  #void *sock_state_cb_data;
  #struct apattern *sortlist;
  #int nsort;

  PAresOptions* = ptr AresOptions
  PAresChannel* = pointer
{.deprecated: [THandle: Handle, THandleType: HandleType, TAnyHandle: AnyHandle,
              TAnyReq: AnyReq, TPort: Port, TErrorCode: ErrorCode, TReqType: ReqType,
              TErr: Err, TFsEventType: FsEventType,
              # TFsEvent: FsEvent, # Name conflict if we drop `T`
              TFsEvents: FsEvents, TBuf: Buf, TCounters: Counters, TLoop: Loop,
              TShutdown: Shutdown, TStream: Stream, TWrite: Write,
              # TTcp: Tcp, # Name conflict if we drop `T`
              TConnect: Connect,
              TUdpFlags: UdpFlags,
              # TUdp: Udp, # Name conflict if we drop `T`
              TUdpSend: UdpSend,
              # tTTy: TTy, # Name conflict if we drop `T`
              TPipe: Pipe,
              # TPrepare: Prepare, # Name conflict if we drop `T`
              # TCheck: Check, # Name conflict if we drop `T`
              # TIdle: Idle, # Name conflict if we drop `T`
              # TAsync: Async, # Name conflict if we drop `T`
              # TTimer: Timer, # Name conflict if we drop `T`
              TGetAddrInfo: GetAddrInfo, TProcessOptions: ProcessOptions,
              # TProcess: Process, # Name conflict if we drop `T`
              TWork: Work,
              TFsType: FsType, TFS: FS, TReq: Req, TAresOptions: AresOptions].}

proc loop_new*(): PLoop{.
    importc: "uv_loop_new", header: "uv.h".}

proc loop_delete*(a2: PLoop){.
    importc: "uv_loop_delete", header: "uv.h".}

proc default_loop*(): PLoop{.
    importc: "uv_default_loop", header: "uv.h".}

proc run*(a2: PLoop): cint{.
    importc: "uv_run", header: "uv.h".}

proc addref*(a2: PLoop){.
    importc: "uv_ref", header: "uv.h".}

proc unref*(a2: PLoop){.
    importc: "uv_unref", header: "uv.h".}

proc update_time*(a2: PLoop){.
    importc: "uv_update_time", header: "uv.h".}

proc now*(a2: PLoop): int64{.
    importc: "uv_now", header: "uv.h".}

proc last_error*(a2: PLoop): Err{.
    importc: "uv_last_error", header: "uv.h".}

proc strerror*(err: Err): cstring{.
    importc: "uv_strerror", header: "uv.h".}

proc err_name*(err: Err): cstring{.
    importc: "uv_err_name", header: "uv.h".}

proc shutdown*(req: PShutdown, handle: PStream, cb: ShutdownProc): cint{.
    importc: "uv_shutdown", header: "uv.h".}

proc is_active*(handle: PHandle): cint{.
    importc: "uv_is_active", header: "uv.h".}

proc close*(handle: PHandle, close_cb: CloseProc){.
    importc: "uv_close", header: "uv.h".}

proc buf_init*(base: cstring, len: csize): Buf{.
    importc: "uv_buf_init", header: "uv.h".}

proc listen*(stream: PStream, backlog: cint, cb: ConnectionProc): cint{.
    importc: "uv_listen", header: "uv.h".}

proc accept*(server: PStream, client: PStream): cint{.
    importc: "uv_accept", header: "uv.h".}

proc read_start*(a2: PStream, alloc_cb: AllocProc, read_cb: ReadProc): cint{.
    importc: "uv_read_start", header: "uv.h".}

proc read_start*(a2: PStream, alloc_cb: AllocProc, read_cb: ReadProc2): cint{.
    importc: "uv_read2_start", header: "uv.h".}

proc read_stop*(a2: PStream): cint{.
    importc: "uv_read_stop", header: "uv.h".}

proc write*(req: PWrite, handle: PStream, bufs: ptr Buf, bufcnt: cint, cb: WriteProc): cint{.
    importc: "uv_write", header: "uv.h".}

proc write*(req: PWrite, handle: PStream, bufs: ptr Buf, bufcnt: cint, send_handle: PStream, cb: WriteProc): cint{.
    importc: "uv_write2", header: "uv.h".}

proc tcp_init*(a2: PLoop, handle: PTcp): cint{.
    importc: "uv_tcp_init", header: "uv.h".}

proc tcp_bind*(handle: PTcp, a3: SockAddrIn): cint{.
    importc: "uv_tcp_bind", header: "uv.h".}

proc tcp_bind6*(handle: PTcp, a3: TSockAddrIn6): cint{.
    importc: "uv_tcp_bind6", header: "uv.h".}

proc tcp_getsockname*(handle: PTcp, name: ptr SockAddr, namelen: var cint): cint{.
    importc: "uv_tcp_getsockname", header: "uv.h".}

proc tcp_getpeername*(handle: PTcp, name: ptr SockAddr, namelen: var cint): cint{.
    importc: "uv_tcp_getpeername", header: "uv.h".}

proc tcp_connect*(req: PConnect, handle: PTcp, address: SockAddrIn, cb: ConnectProc): cint{.
    importc: "uv_tcp_connect", header: "uv.h".}

proc tcp_connect6*(req: PConnect, handle: PTcp, address: TSockAddrIn6, cb: ConnectProc): cint{.
    importc: "uv_tcp_connect6", header: "uv.h".}

proc udp_init*(a2: PLoop, handle: PUdp): cint{.
    importc: "uv_udp_init", header: "uv.h".}

proc udp_bind*(handle: PUdp, adr: SockAddrIn, flags: cunsigned): cint{.
    importc: "uv_udp_bind", header: "uv.h".}

proc udp_bind6*(handle: PUdp, adr: TSockAddrIn6, flags: cunsigned): cint{.
    importc: "uv_udp_bind6", header: "uv.h".}

proc udp_getsockname*(handle: PUdp, name: ptr SockAddr, namelen: var cint): cint{.
    importc: "uv_udp_getsockname", header: "uv.h".}

proc udp_send*(req: PUdpSend, handle: PUdp, bufs: ptr Buf, bufcnt: cint, adr: SockAddrIn, send_cb: UdpSendProc): cint{.
    importc: "uv_udp_send", header: "uv.h".}

proc udp_send6*(req: PUdpSend, handle: PUdp, bufs: ptr Buf, bufcnt: cint, adr: TSockAddrIn6, send_cb: UdpSendProc): cint{.
    importc: "uv_udp_send6", header: "uv.h".}

proc udp_recv_start*(handle: PUdp, alloc_cb: AllocProc, recv_cb: UdpRecvProc): cint{.
    importc: "uv_udp_recv_start", header: "uv.h".}

proc udp_recv_stop*(handle: PUdp): cint{.
    importc: "uv_udp_recv_stop", header: "uv.h".}

proc tty_init*(a2: PLoop, a3: pTTy, fd: File): cint{.
    importc: "uv_tty_init", header: "uv.h".}

proc tty_set_mode*(a2: pTTy, mode: cint): cint{.
    importc: "uv_tty_set_mode", header: "uv.h".}

proc tty_get_winsize*(a2: pTTy, width: var cint, height: var cint): cint{.
    importc: "uv_tty_get_winsize", header: "uv.h".}

proc tty_reset_mode*() {.
    importc: "uv_tty_reset_mode", header: "uv.h".}

proc guess_handle*(file: File): HandleType{.
    importc: "uv_guess_handle", header: "uv.h".}

proc pipe_init*(a2: PLoop, handle: PPipe, ipc: int): cint{.
    importc: "uv_pipe_init", header: "uv.h".}

proc pipe_open*(a2: PPipe, file: File){.
    importc: "uv_pipe_open", header: "uv.h".}

proc pipe_bind*(handle: PPipe, name: cstring): cint{.
    importc: "uv_pipe_bind", header: "uv.h".}

proc pipe_connect*(req: PConnect, handle: PPipe, name: cstring, cb: ConnectProc): cint{.
    importc: "uv_pipe_connect", header: "uv.h".}

proc prepare_init*(a2: PLoop, prepare: PPrepare): cint{.
    importc: "uv_prepare_init", header: "uv.h".}

proc prepare_start*(prepare: PPrepare, cb: PrepareProc): cint{.
    importc: "uv_prepare_start", header: "uv.h".}

proc prepare_stop*(prepare: PPrepare): cint{.
    importc: "uv_prepare_stop", header: "uv.h".}

proc check_init*(a2: PLoop, check: PCheck): cint{.
    importc: "uv_check_init", header: "uv.h".}

proc check_start*(check: PCheck, cb: CheckProc): cint{.
    importc: "uv_check_start", header: "uv.h".}

proc check_stop*(check: PCheck): cint{.
    importc: "uv_check_stop", header: "uv.h".}

proc idle_init*(a2: PLoop, idle: PIdle): cint{.
    importc: "uv_idle_init", header: "uv.h".}

proc idle_start*(idle: PIdle, cb: IdleProc): cint{.
    importc: "uv_idle_start", header: "uv.h".}

proc idle_stop*(idle: PIdle): cint{.
    importc: "uv_idle_stop", header: "uv.h".}

proc async_init*(a2: PLoop, async: PAsync, async_cb: AsyncProc): cint{.
    importc: "uv_async_init", header: "uv.h".}

proc async_send*(async: PAsync): cint{.
    importc: "uv_async_send", header: "uv.h".}

proc timer_init*(a2: PLoop, timer: PTimer): cint{.
    importc: "uv_timer_init", header: "uv.h".}

proc timer_start*(timer: PTimer, cb: TimerProc, timeout: int64, repeat: int64): cint{.
    importc: "uv_timer_start", header: "uv.h".}

proc timer_stop*(timer: PTimer): cint{.
    importc: "uv_timer_stop", header: "uv.h".}

proc timer_again*(timer: PTimer): cint{.
    importc: "uv_timer_again", header: "uv.h".}

proc timer_set_repeat*(timer: PTimer, repeat: int64){.
    importc: "uv_timer_set_repeat", header: "uv.h".}

proc timer_get_repeat*(timer: PTimer): int64{.
    importc: "uv_timer_get_repeat", header: "uv.h".}

proc ares_init_options*(a2: PLoop, channel: PAresChannel, options: PAresOptions, optmask: cint): cint{.
    importc: "uv_ares_init_options", header: "uv.h".}

proc ares_destroy*(a2: PLoop, channel: PAresChannel){.
    importc: "uv_ares_destroy", header: "uv.h".}

proc getaddrinfo*(a2: PLoop, handle: PGetAddrInfo,getaddrinfo_cb: GetAddrInfoProc, node: cstring, service: cstring, hints: ptr AddrInfo): cint{.
    importc: "uv_getaddrinfo", header: "uv.h".}

proc freeaddrinfo*(ai: ptr AddrInfo){.
    importc: "uv_freeaddrinfo", header: "uv.h".}

proc spawn*(a2: PLoop, a3: PProcess, options: ProcessOptions): cint{.
    importc: "uv_spawn", header: "uv.h".}

proc process_kill*(a2: PProcess, signum: cint): cint{.
    importc: "uv_process_kill", header: "uv.h".}

proc queue_work*(loop: PLoop, req: PWork, work_cb: WorkProc, after_work_cb: AfterWorkProc): cint{.
    importc: "uv_queue_work", header: "uv.h".}

proc req_cleanup*(req: PFS){.
    importc: "uv_fs_req_cleanup", header: "uv.h".}

proc close*(loop: PLoop, req: PFS, file: File, cb: FsProc): cint{.
    importc: "uv_fs_close", header: "uv.h".}

proc open*(loop: PLoop, req: PFS, path: cstring, flags: cint, mode: cint, cb: FsProc): cint{.
    importc: "uv_fs_open", header: "uv.h".}

proc read*(loop: PLoop, req: PFS, file: File, buf: pointer, length: csize, offset: coff, cb: FsProc): cint{.
    importc: "uv_fs_read", header: "uv.h".}

proc unlink*(loop: PLoop, req: PFS, path: cstring, cb: FsProc): cint{.
    importc: "uv_fs_unlink", header: "uv.h".}

proc write*(loop: PLoop, req: PFS, file: File, buf: pointer, length: csize, offset: coff, cb: FsProc): cint{.
    importc: "uv_fs_write", header: "uv.h".}

proc mkdir*(loop: PLoop, req: PFS, path: cstring, mode: cint, cb: FsProc): cint{.
    importc: "uv_fs_mkdir", header: "uv.h".}

proc rmdir*(loop: PLoop, req: PFS, path: cstring, cb: FsProc): cint{.
    importc: "uv_fs_rmdir", header: "uv.h".}

proc readdir*(loop: PLoop, req: PFS, path: cstring, flags: cint, cb: FsProc): cint{.
    importc: "uv_fs_readdir", header: "uv.h".}

proc stat*(loop: PLoop, req: PFS, path: cstring, cb: FsProc): cint{.
    importc: "uv_fs_stat", header: "uv.h".}

proc fstat*(loop: PLoop, req: PFS, file: File, cb: FsProc): cint{.
    importc: "uv_fs_fstat", header: "uv.h".}

proc rename*(loop: PLoop, req: PFS, path: cstring, new_path: cstring, cb: FsProc): cint{.
    importc: "uv_fs_rename", header: "uv.h".}

proc fsync*(loop: PLoop, req: PFS, file: File, cb: FsProc): cint{.
    importc: "uv_fs_fsync", header: "uv.h".}

proc fdatasync*(loop: PLoop, req: PFS, file: File, cb: FsProc): cint{.
    importc: "uv_fs_fdatasync", header: "uv.h".}

proc ftruncate*(loop: PLoop, req: PFS, file: File, offset: coff, cb: FsProc): cint{.
    importc: "uv_fs_ftruncate", header: "uv.h".}

proc sendfile*(loop: PLoop, req: PFS, out_fd: File, in_fd: File, in_offset: coff, length: csize, cb: FsProc): cint{.
    importc: "uv_fs_sendfile", header: "uv.h".}

proc chmod*(loop: PLoop, req: PFS, path: cstring, mode: cint, cb: FsProc): cint{.
    importc: "uv_fs_chmod", header: "uv.h".}

proc utime*(loop: PLoop, req: PFS, path: cstring, atime: cdouble, mtime: cdouble, cb: FsProc): cint{.
    importc: "uv_fs_utime", header: "uv.h".}

proc futime*(loop: PLoop, req: PFS, file: File, atime: cdouble, mtime: cdouble, cb: FsProc): cint{.
    importc: "uv_fs_futime", header: "uv.h".}

proc lstat*(loop: PLoop, req: PFS, path: cstring, cb: FsProc): cint{.
    importc: "uv_fs_lstat", header: "uv.h".}

proc link*(loop: PLoop, req: PFS, path: cstring, new_path: cstring, cb: FsProc): cint{.
    importc: "uv_fs_link", header: "uv.h".}

proc symlink*(loop: PLoop, req: PFS, path: cstring, new_path: cstring, flags: cint, cb: FsProc): cint{.
    importc: "uv_fs_symlink", header: "uv.h".}

proc readlink*(loop: PLoop, req: PFS, path: cstring, cb: FsProc): cint{.
    importc: "uv_fs_readlink", header: "uv.h".}

proc fchmod*(loop: PLoop, req: PFS, file: File, mode: cint, cb: FsProc): cint{.
    importc: "uv_fs_fchmod", header: "uv.h".}

proc chown*(loop: PLoop, req: PFS, path: cstring, uid: cint, gid: cint, cb: FsProc): cint{.
    importc: "uv_fs_chown", header: "uv.h".}

proc fchown*(loop: PLoop, req: PFS, file: File, uid: cint, gid: cint, cb: FsProc): cint{.
    importc: "uv_fs_fchown", header: "uv.h".}

proc event_init*(loop: PLoop, handle: PFSEvent, filename: cstring, cb: FsEventProc): cint{.
    importc: "uv_fs_event_init", header: "uv.h".}

proc ip4_addr*(ip: cstring, port: cint): SockAddrIn{.
    importc: "uv_ip4_addr", header: "uv.h".}

proc ip6_addr*(ip: cstring, port: cint): TSockAddrIn6{.
    importc: "uv_ip6_addr", header: "uv.h".}

proc ip4_name*(src: ptr SockAddrIn, dst: cstring, size: csize): cint{.
    importc: "uv_ip4_name", header: "uv.h".}

proc ip6_name*(src: ptr TSockAddrIn6, dst: cstring, size: csize): cint{.
    importc: "uv_ip6_name", header: "uv.h".}

proc exepath*(buffer: cstring, size: var csize): cint{.
    importc: "uv_exepath", header: "uv.h".}

proc hrtime*(): uint64{.
    importc: "uv_hrtime", header: "uv.h".}

proc loadavg*(load: var array[0..2, cdouble]) {.
    importc: "uv_loadavg", header: "uv.h"}

proc get_free_memory*(): cdouble {.
    importc: "uv_get_free_memory", header: "uv.h".}

proc get_total_memory*(): cdouble {.
    importc: "uv_get_total_memory", header: "uv.h".}