From 9e51e737b6216fa373662442907874d7b61db1a6 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Sun, 1 Apr 2018 20:17:32 +0800 Subject: [PATCH] RLIMIT_NOFILE as posix const --- lib/posix/posix_linux_amd64_consts.nim | 3 +++ lib/posix/posix_other_consts.nim | 3 +++ lib/pure/ioselects/ioselectors_epoll.nim | 6 ++---- lib/pure/ioselects/ioselectors_poll.nim | 6 ++---- tools/detect/detect.nim | 3 +++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/posix/posix_linux_amd64_consts.nim b/lib/posix/posix_linux_amd64_consts.nim index 4b693960e6..ee4fac1e86 100644 --- a/lib/posix/posix_linux_amd64_consts.nim +++ b/lib/posix/posix_linux_amd64_consts.nim @@ -433,6 +433,9 @@ const POSIX_MADV_WILLNEED* = cint(3) const POSIX_MADV_DONTNEED* = cint(4) const MAP_POPULATE* = cint(32768) +# +const RLIMIT_NOFILE* = cint(7) + # const FD_SETSIZE* = cint(1024) diff --git a/lib/posix/posix_other_consts.nim b/lib/posix/posix_other_consts.nim index 003414a6a8..1b27fc5f64 100644 --- a/lib/posix/posix_other_consts.nim +++ b/lib/posix/posix_other_consts.nim @@ -451,6 +451,9 @@ var POSIX_TYPED_MEM_ALLOCATE* {.importc: "POSIX_TYPED_MEM_ALLOCATE", header: "".}: cint var POSIX_TYPED_MEM_MAP_ALLOCATABLE* {.importc: "POSIX_TYPED_MEM_MAP_ALLOCATABLE", header: "".}: cint +# +var RLIMIT_NOFILE* {.importc: "RLIMIT_NOFILE", header: "".}: cint + # var FD_SETSIZE* {.importc: "FD_SETSIZE", header: "".}: cint diff --git a/lib/pure/ioselects/ioselectors_epoll.nim b/lib/pure/ioselects/ioselectors_epoll.nim index 98b8a2b2bb..65efeabab3 100644 --- a/lib/pure/ioselects/ioselectors_epoll.nim +++ b/lib/pure/ioselects/ioselectors_epoll.nim @@ -48,8 +48,6 @@ when not defined(android): proc signalfd(fd: cint, mask: var Sigset, flags: cint): cint {.cdecl, importc: "signalfd", header: "".} -var RLIMIT_NOFILE {.importc: "RLIMIT_NOFILE", - header: "".}: cint type RLimit {.importc: "struct rlimit", header: "", pure, final.} = object @@ -82,7 +80,7 @@ type proc newSelector*[T](): Selector[T] = # Retrieve the maximum fd count (for current OS) via getrlimit() var a = RLimit() - if getrlimit(RLIMIT_NOFILE, a) != 0: + if getrlimit(posix.RLIMIT_NOFILE, a) != 0: raiseOsError(osLastError()) var maxFD = int(a.rlim_max) doAssert(maxFD > 0) @@ -528,4 +526,4 @@ template withData*[T](s: Selector[T], fd: SocketHandle|int, value, body1, body2 proc getFd*[T](s: Selector[T]): int = - return s.epollFd.int \ No newline at end of file + return s.epollFd.int diff --git a/lib/pure/ioselects/ioselectors_poll.nim b/lib/pure/ioselects/ioselectors_poll.nim index 66d52b3529..081c57fa68 100644 --- a/lib/pure/ioselects/ioselectors_poll.nim +++ b/lib/pure/ioselects/ioselectors_poll.nim @@ -40,8 +40,6 @@ type wfd: cint SelectEvent* = ptr SelectEventImpl -var RLIMIT_NOFILE {.importc: "RLIMIT_NOFILE", - header: "".}: cint type rlimit {.importc: "struct rlimit", header: "", pure, final.} = object @@ -64,7 +62,7 @@ else: proc newSelector*[T](): Selector[T] = var a = rlimit() - if getrlimit(RLIMIT_NOFILE, a) != 0: + if getrlimit(posix.RLIMIT_NOFILE, a) != 0: raiseIOSelectorsError(osLastError()) var maxFD = int(a.rlim_max) @@ -317,4 +315,4 @@ template withData*[T](s: Selector[T], fd: SocketHandle|int, value, body1, proc getFd*[T](s: Selector[T]): int = - return -1 \ No newline at end of file + return -1 diff --git a/tools/detect/detect.nim b/tools/detect/detect.nim index 1b016cef9c..5b4fdc99e6 100644 --- a/tools/detect/detect.nim +++ b/tools/detect/detect.nim @@ -586,6 +586,9 @@ v("POSIX_TYPED_MEM_ALLOCATE_CONTIG") v("POSIX_TYPED_MEM_MAP_ALLOCATABLE") v("MAP_POPULATE", no_other = true) +header("") +v("RLIMIT_NOFILE") + header("") v("FD_SETSIZE")