Merge pull request #7459 from arnetheduck/posix-rlimit-nofile

RLIMIT_NOFILE as posix const
This commit is contained in:
Dominik Picheta
2018-04-02 14:35:04 +01:00
committed by GitHub
5 changed files with 13 additions and 8 deletions

View File

@@ -433,6 +433,9 @@ const POSIX_MADV_WILLNEED* = cint(3)
const POSIX_MADV_DONTNEED* = cint(4)
const MAP_POPULATE* = cint(32768)
# <sys/resource.h>
const RLIMIT_NOFILE* = cint(7)
# <sys/select.h>
const FD_SETSIZE* = cint(1024)

View File

@@ -451,6 +451,9 @@ var POSIX_TYPED_MEM_ALLOCATE* {.importc: "POSIX_TYPED_MEM_ALLOCATE", header: "<s
var POSIX_TYPED_MEM_ALLOCATE_CONTIG* {.importc: "POSIX_TYPED_MEM_ALLOCATE_CONTIG", header: "<sys/mman.h>".}: cint
var POSIX_TYPED_MEM_MAP_ALLOCATABLE* {.importc: "POSIX_TYPED_MEM_MAP_ALLOCATABLE", header: "<sys/mman.h>".}: cint
# <sys/resource.h>
var RLIMIT_NOFILE* {.importc: "RLIMIT_NOFILE", header: "<sys/resource.h>".}: cint
# <sys/select.h>
var FD_SETSIZE* {.importc: "FD_SETSIZE", header: "<sys/select.h>".}: cint

View File

@@ -48,8 +48,6 @@ when not defined(android):
proc signalfd(fd: cint, mask: var Sigset, flags: cint): cint
{.cdecl, importc: "signalfd", header: "<sys/signalfd.h>".}
var RLIMIT_NOFILE {.importc: "RLIMIT_NOFILE",
header: "<sys/resource.h>".}: cint
type
RLimit {.importc: "struct rlimit",
header: "<sys/resource.h>", 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
return s.epollFd.int

View File

@@ -40,8 +40,6 @@ type
wfd: cint
SelectEvent* = ptr SelectEventImpl
var RLIMIT_NOFILE {.importc: "RLIMIT_NOFILE",
header: "<sys/resource.h>".}: cint
type
rlimit {.importc: "struct rlimit",
header: "<sys/resource.h>", 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
return -1

View File

@@ -586,6 +586,9 @@ v("POSIX_TYPED_MEM_ALLOCATE_CONTIG")
v("POSIX_TYPED_MEM_MAP_ALLOCATABLE")
v("MAP_POPULATE", no_other = true)
header("<sys/resource.h>")
v("RLIMIT_NOFILE")
header("<sys/select.h>")
v("FD_SETSIZE")