diff options
Diffstat (limited to 'lib/posix')
-rw-r--r-- | lib/posix/kqueue.nim | 71 | ||||
-rw-r--r-- | lib/posix/posix.nim | 6 |
2 files changed, 74 insertions, 3 deletions
diff --git a/lib/posix/kqueue.nim b/lib/posix/kqueue.nim new file mode 100644 index 000000000..511ada9ac --- /dev/null +++ b/lib/posix/kqueue.nim @@ -0,0 +1,71 @@ +# +# +# Nim's Runtime Library +# (c) Copyright 2015 Adam Strzelecki +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +{.deadCodeElim:on.} + +from posix import Timespec + +# Filters: +const + EVFILT_READ* = -1 + EVFILT_WRITE* = -2 + EVFILT_AIO* = -3 + EVFILT_VNODE* = -4 + EVFILT_PROC* = -5 + EVFILT_SIGNAL* = -6 + EVFILT_TIMER* = -7 + EVFILT_MACHPORT* = -8 + EVFILT_FS* = -9 + EVFILT_USER* = -10 + # -11 is unused + EVFILT_VM* = -12 + +# Actions: +const + EV_ADD* = 0x0001 ## Add event to queue (implies enable). + ## Re-adding an existing element modifies it. + EV_DELETE* = 0x0002 ## Delete event from queue. + EV_ENABLE* = 0x0004 ## Enable event. + EV_DISABLE* = 0x0008 ## Disable event (not reported). + +# Flags: +const + EV_ONESHOT* = 0x0010 ## Only report one occurrence. + EV_CLEAR* = 0x0020 ## Clear event state after reporting. + EV_RECEIPT* = 0x0040 ## Force EV_ERROR on success, data == 0 + EV_DISPATCH* = 0x0080 ## Disable event after reporting. + +# Return values: +const + EV_EOF* = 0x8000 ## EOF detected + EV_ERROR* = 0x4000 ## Error, data contains errno + +type + KEvent* {.importc: "struct kevent", + header: "<sys/event.h>", pure, final.} = object + ident*: cuint ## identifier for this event (uintptr_t) + filter*: cshort ## filter for event + flags*: cushort ## general flags + fflags*: cuint ## filter-specific flags + data*: cuint ## filter-specific data (intptr_t) + #udata*: ptr void ## opaque user data identifier + +proc kqueue*(): cint {.importc: "kqueue", header: "<sys/event.h>".} + ## Creates new queue and returns its descriptor. + +proc kevent*(kqFD: cint, + changelist: ptr KEvent, nchanges: cint, + eventlist: ptr KEvent, nevents: cint, timeout: ptr Timespec): cint + {.importc: "kevent", header: "<sys/event.h>".} + ## Manipulates queue for given ``kqFD`` descriptor. + +proc EV_SET*(event: ptr KEvent, ident: cuint, filter: cshort, flags: cushort, + fflags: cuint, data: cuint, udata: ptr void) + {.importc: "EV_SET", header: "<sys/event.h>".} + ## Fills event with given data. diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index 8486fa04f..5f1dfcfcd 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -1810,7 +1810,7 @@ proc ntohs*(a1: int16): int16 {.importc, header: "<arpa/inet.h>".} proc inet_addr*(a1: cstring): InAddrT {.importc, header: "<arpa/inet.h>".} proc inet_ntoa*(a1: InAddr): cstring {.importc, header: "<arpa/inet.h>".} proc inet_ntop*(a1: cint, a2: pointer, a3: cstring, a4: int32): cstring {. - importc, header: "<arpa/inet.h>".} + importc:"(char *)$1", header: "<arpa/inet.h>".} proc inet_pton*(a1: cint, a2: cstring, a3: pointer): cint {. importc, header: "<arpa/inet.h>".} @@ -2381,7 +2381,7 @@ proc sched_setscheduler*(a1: Pid, a2: cint, a3: var Sched_param): cint {. proc sched_yield*(): cint {.importc, header: "<sched.h>".} proc strerror*(errnum: cint): cstring {.importc, header: "<string.h>".} -proc hstrerror*(herrnum: cint): cstring {.importc, header: "<netdb.h>".} +proc hstrerror*(herrnum: cint): cstring {.importc:"(char *)$1", header: "<netdb.h>".} proc FD_CLR*(a1: cint, a2: var TFdSet) {.importc, header: "<sys/select.h>".} proc FD_ISSET*(a1: cint | SocketHandle, a2: var TFdSet): cint {. @@ -2565,7 +2565,7 @@ proc endprotoent*() {.importc, header: "<netdb.h>".} proc endservent*() {.importc, header: "<netdb.h>".} proc freeaddrinfo*(a1: ptr AddrInfo) {.importc, header: "<netdb.h>".} -proc gai_strerror*(a1: cint): cstring {.importc, header: "<netdb.h>".} +proc gai_strerror*(a1: cint): cstring {.importc:"(char *)$1", header: "<netdb.h>".} proc getaddrinfo*(a1, a2: cstring, a3: ptr AddrInfo, a4: var ptr AddrInfo): cint {.importc, header: "<netdb.h>".} |