Skip to content

Commit

Permalink
Avoid SIGPIPE signal when writing to a broken TCP socket in Linux
Browse files Browse the repository at this point in the history
Errors are handled anyway checking send() return value
  • Loading branch information
davidepianca98 committed May 15, 2021
1 parent 4b6bb40 commit 7a4e315
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/linuxArm32HfpMain/kotlin/Posix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import kotlinx.cinterop.*
import platform.posix.*

actual fun send(socket: Int, buf: CValuesRef<ByteVar>?, len: Int, flags: Int): Int {
return platform.posix.send(socket.convert(), buf, len.convert(), flags)
return platform.posix.send(socket.convert(), buf, len.convert(), flags or MSG_NOSIGNAL)
}

actual fun recv(socket: Int, buf: CValuesRef<ByteVar>?, len: Int, flags: Int): Int {
Expand Down
2 changes: 1 addition & 1 deletion src/linuxX64Main/kotlin/Posix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import kotlinx.cinterop.*
import platform.posix.*

actual fun send(socket: Int, buf: CValuesRef<ByteVar>?, len: Int, flags: Int): Int {
return platform.posix.send(socket.convert(), buf, len.convert(), flags).convert()
return platform.posix.send(socket.convert(), buf, len.convert(), flags or MSG_NOSIGNAL).convert()
}

actual fun recv(socket: Int, buf: CValuesRef<ByteVar>?, len: Int, flags: Int): Int {
Expand Down

0 comments on commit 7a4e315

Please sign in to comment.