Fixed SIGPIPE on MacOS
This commit is contained in:
parent
d5dc0e96d0
commit
c2a52a9849
3 changed files with 11 additions and 6 deletions
|
|
@ -1580,8 +1580,11 @@ else:
|
||||||
|
|
||||||
when defined(macosx):
|
when defined(macosx):
|
||||||
# We can't use the NOSIGNAL flag in the ``send`` function, it has no effect
|
# We can't use the NOSIGNAL flag in the ``send`` function, it has no effect
|
||||||
var
|
# Instead we should use SO_NOSIGPIPE in setsockopt
|
||||||
|
const
|
||||||
MSG_NOSIGNAL* = 0'i32
|
MSG_NOSIGNAL* = 0'i32
|
||||||
|
var
|
||||||
|
SO_NOSIGPIPE* {.importc, header: "<sys/socket.h>".}: cint
|
||||||
else:
|
else:
|
||||||
var
|
var
|
||||||
MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
|
MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
|
||||||
|
|
|
||||||
|
|
@ -841,6 +841,8 @@ else:
|
||||||
proc newAsyncRawSocket*(domain: cint, typ: cint, protocol: cint): TAsyncFD =
|
proc newAsyncRawSocket*(domain: cint, typ: cint, protocol: cint): TAsyncFD =
|
||||||
result = newRawSocket(domain, typ, protocol).TAsyncFD
|
result = newRawSocket(domain, typ, protocol).TAsyncFD
|
||||||
result.SocketHandle.setBlocking(false)
|
result.SocketHandle.setBlocking(false)
|
||||||
|
when defined(macosx):
|
||||||
|
result.SocketHandle.setSockOptInt(SOL_SOCKET, SO_NOSIGPIPE, 1)
|
||||||
register(result)
|
register(result)
|
||||||
|
|
||||||
proc newAsyncRawSocket*(domain: Domain = AF_INET,
|
proc newAsyncRawSocket*(domain: Domain = AF_INET,
|
||||||
|
|
@ -848,6 +850,8 @@ else:
|
||||||
protocol: Protocol = IPPROTO_TCP): TAsyncFD =
|
protocol: Protocol = IPPROTO_TCP): TAsyncFD =
|
||||||
result = newRawSocket(domain, typ, protocol).TAsyncFD
|
result = newRawSocket(domain, typ, protocol).TAsyncFD
|
||||||
result.SocketHandle.setBlocking(false)
|
result.SocketHandle.setBlocking(false)
|
||||||
|
when defined(macosx):
|
||||||
|
result.SocketHandle.setSockOptInt(SOL_SOCKET, SO_NOSIGPIPE, 1)
|
||||||
register(result)
|
register(result)
|
||||||
|
|
||||||
proc closeSocket*(sock: TAsyncFD) =
|
proc closeSocket*(sock: TAsyncFD) =
|
||||||
|
|
@ -959,7 +963,6 @@ else:
|
||||||
result = true
|
result = true
|
||||||
let res = recv(sock.SocketHandle, addr readBuffer[0], size.cint,
|
let res = recv(sock.SocketHandle, addr readBuffer[0], size.cint,
|
||||||
flags.toOSFlags())
|
flags.toOSFlags())
|
||||||
#echo("recv cb res: ", res)
|
|
||||||
if res < 0:
|
if res < 0:
|
||||||
let lastError = osLastError()
|
let lastError = osLastError()
|
||||||
if lastError.int32 notin {EINTR, EWOULDBLOCK, EAGAIN}:
|
if lastError.int32 notin {EINTR, EWOULDBLOCK, EAGAIN}:
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,9 @@ export
|
||||||
SO_KEEPALIVE, SO_OOBINLINE, SO_REUSEADDR,
|
SO_KEEPALIVE, SO_OOBINLINE, SO_REUSEADDR,
|
||||||
MSG_PEEK
|
MSG_PEEK
|
||||||
|
|
||||||
|
when defined(macosx):
|
||||||
|
export SO_NOSIGPIPE
|
||||||
|
|
||||||
type
|
type
|
||||||
Port* = distinct uint16 ## port type
|
Port* = distinct uint16 ## port type
|
||||||
|
|
||||||
|
|
@ -428,10 +431,6 @@ proc selectWrite*(writefds: var seq[SocketHandle],
|
||||||
|
|
||||||
pruneSocketSet(writefds, (wr))
|
pruneSocketSet(writefds, (wr))
|
||||||
|
|
||||||
# We ignore signal SIGPIPE on Darwin
|
|
||||||
when defined(macosx) and not defined(nimdoc):
|
|
||||||
signal(SIGPIPE, SIG_IGN)
|
|
||||||
|
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var wsa: WSAData
|
var wsa: WSAData
|
||||||
if wsaStartup(0x0101'i16, addr wsa) != 0: raiseOSError(osLastError())
|
if wsaStartup(0x0101'i16, addr wsa) != 0: raiseOSError(osLastError())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue