Move RLimit and getrlimit to posix.nim and add setrlimit to easily limit FD allocation (#7564)
This commit is contained in:
parent
85e21158db
commit
63160855aa
4 changed files with 18 additions and 18 deletions
|
|
@ -48,14 +48,6 @@ when not defined(android):
|
|||
proc signalfd(fd: cint, mask: var Sigset, flags: cint): cint
|
||||
{.cdecl, importc: "signalfd", header: "<sys/signalfd.h>".}
|
||||
|
||||
type
|
||||
RLimit {.importc: "struct rlimit",
|
||||
header: "<sys/resource.h>", pure, final.} = object
|
||||
rlim_cur: int
|
||||
rlim_max: int
|
||||
proc getrlimit(resource: cint, rlp: var RLimit): cint
|
||||
{.importc: "getrlimit",header: "<sys/resource.h>".}
|
||||
|
||||
when hasThreadSupport:
|
||||
type
|
||||
SelectorImpl[T] = object
|
||||
|
|
|
|||
|
|
@ -40,14 +40,6 @@ type
|
|||
wfd: cint
|
||||
SelectEvent* = ptr SelectEventImpl
|
||||
|
||||
type
|
||||
rlimit {.importc: "struct rlimit",
|
||||
header: "<sys/resource.h>", pure, final.} = object
|
||||
rlim_cur: int
|
||||
rlim_max: int
|
||||
proc getrlimit(resource: cint, rlp: var rlimit): cint
|
||||
{.importc: "getrlimit",header: "<sys/resource.h>".}
|
||||
|
||||
when hasThreadSupport:
|
||||
template withPollLock[T](s: Selector[T], body: untyped) =
|
||||
acquire(s.lock)
|
||||
|
|
@ -61,7 +53,7 @@ else:
|
|||
body
|
||||
|
||||
proc newSelector*[T](): Selector[T] =
|
||||
var a = rlimit()
|
||||
var a = RLimit()
|
||||
if getrlimit(posix.RLIMIT_NOFILE, a) != 0:
|
||||
raiseIOSelectorsError(osLastError())
|
||||
var maxFD = int(a.rlim_max)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue