ported to FreeRTOS
This commit is contained in:
parent
fa7b12bcf9
commit
9f566881f1
2 changed files with 22 additions and 11 deletions
|
|
@ -1946,13 +1946,15 @@ proc activeDescriptors*(): int {.inline.} =
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
import posix
|
import posix
|
||||||
|
|
||||||
proc maxDescriptors*(): int {.raises: OSError.} =
|
when defined(linux) or defined(windows) or defined(macosx) or defined(bsd):
|
||||||
## Returns the maximum number of active file descriptors for the current
|
proc maxDescriptors*(): int {.raises: OSError.} =
|
||||||
## process. This involves a system call.
|
## Returns the maximum number of active file descriptors for the current
|
||||||
when defined(windows):
|
## process. This involves a system call. For now `maxDescriptors` is
|
||||||
result = 16_700_000
|
## supported on the following OSes: Windows, Linux, OSX, BSD.
|
||||||
else:
|
when defined(windows):
|
||||||
var fdLim: RLimit
|
result = 16_700_000
|
||||||
if getrlimit(RLIMIT_NOFILE, fdLim) < 0:
|
else:
|
||||||
raiseOSError(osLastError())
|
var fdLim: RLimit
|
||||||
result = int(fdLim.rlim_cur) - 1
|
if getrlimit(RLIMIT_NOFILE, fdLim) < 0:
|
||||||
|
raiseOSError(osLastError())
|
||||||
|
result = int(fdLim.rlim_cur) - 1
|
||||||
|
|
|
||||||
|
|
@ -308,9 +308,18 @@ proc processClient(server: AsyncHttpServer, client: AsyncSocket, address: string
|
||||||
)
|
)
|
||||||
if not retry: break
|
if not retry: break
|
||||||
|
|
||||||
|
const
|
||||||
|
nimMaxDescriptorsFallback* {.intdefine.} = 16_000 ## fallback value for \
|
||||||
|
## when `maxDescriptors` is not available.
|
||||||
|
## This can be set on the command line during compilation
|
||||||
|
## via `-d:nimMaxDescriptorsFallback=N`
|
||||||
|
|
||||||
proc listen*(server: AsyncHttpServer; port: Port; address = "") =
|
proc listen*(server: AsyncHttpServer; port: Port; address = "") =
|
||||||
## Listen to the given port and address.
|
## Listen to the given port and address.
|
||||||
server.maxFDs = maxDescriptors()
|
when declared(maxDescriptors):
|
||||||
|
server.maxFDs = try: maxDescriptors() except: nimMaxDescriptorsFallback
|
||||||
|
else:
|
||||||
|
server.maxFDs = nimMaxDescriptorsFallback
|
||||||
server.socket = newAsyncSocket()
|
server.socket = newAsyncSocket()
|
||||||
if server.reuseAddr:
|
if server.reuseAddr:
|
||||||
server.socket.setSockOpt(OptReuseAddr, true)
|
server.socket.setSockOpt(OptReuseAddr, true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue