From d72758143044c73744aa93c7a1767ac3f2f1cd79 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 29 May 2016 22:31:31 +0200 Subject: make SO_REUSEPORT independent of Linux header --- lib/posix/posix.nim | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index b63a41460..e7d5ac8a6 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -1575,8 +1575,6 @@ var ## Receive timeout. SO_REUSEADDR* {.importc, header: "".}: cint ## Reuse of local addresses is supported. - SO_REUSEPORT* {.importc, header: "".}: cint - ## Multiple binding: load balancing on incoming TCP connections or UDP packets. (Requires Linux kernel > 3.9) SO_SNDBUF* {.importc, header: "".}: cint ## Send buffer size. SO_SNDLOWAT* {.importc, header: "".}: cint @@ -1615,6 +1613,16 @@ else: var MAP_POPULATE*: cint = 0 +when defined(linux) or defined(nimdoc): + when defined(alpha) or defined(mips) or defined(parisc) or + defined(sparc) or defined(nimdoc): + const SO_REUSEPORT* = cint(0x0200) + ## Multiple binding: load balancing on incoming TCP connections + ## or UDP packets. (Requires Linux kernel > 3.9) + else: + const SO_REUSEPORT* = cint(15) +else: + var SO_REUSEPORT* {.importc, header: "".}: cint when defined(macosx): # We can't use the NOSIGNAL flag in the ``send`` function, it has no effect @@ -2634,16 +2642,16 @@ proc utimes*(path: cstring, times: ptr array [2, Timeval]): int {. ## ## For more information read http://www.unix.com/man-page/posix/3/utimes/. -proc handle_signal(sig: cint, handler: proc (a: cint) {.noconv.}) {.importc: "signal", header: "".} - -template onSignal*(signals: varargs[cint], body: untyped): stmt = - ## Setup code to be executed when Unix signals are received. Example: - ## from posix import SIGINT, SIGTERM - ## onSignal(SIGINT, SIGTERM): - ## echo "bye" - - for s in signals: - handle_signal(s, - proc (sig: cint) {.noconv.} = - body +proc handle_signal(sig: cint, handler: proc (a: cint) {.noconv.}) {.importc: "signal", header: "".} + +template onSignal*(signals: varargs[cint], body: untyped): stmt = + ## Setup code to be executed when Unix signals are received. Example: + ## from posix import SIGINT, SIGTERM + ## onSignal(SIGINT, SIGTERM): + ## echo "bye" + + for s in signals: + handle_signal(s, + proc (sig: cint) {.noconv.} = + body ) -- cgit 1.4.1-2-gfad0