We created a server that receives commands through TCP or local UNIX sockets and sends the results.
Occasionally, the client leaves before receiving the result and SIGPIPE
occurs, each time the server dies.
How can I keep the server alive?
Do I have to check if I can write it on the socket? Or should I register SIGPIPE
with catch
and a handler that doesn't do anything?
Usually, in this case, we ignore (not even catch) SIGPIPE
and handle the error immediately within the code.
signal(SIGPIPE, SIG_IGN);
If you add this code, SIGPIPE
will not occur even if something is written to a socket/pipe that cannot be written.
If you are using the send()
function, you can also give the MSG_NOSIGNAL
option. However, not all operating systems support MSG_NOSIGNAL
, so please check and write it in advance,
Finally, there is a way to set SO_SIGNOPIPE flag
in setsockopt()
. Use this method when you want to ignore SIGPIPE
only in a specific socket.
This is also not supported by all operating systems, so please check it in advance and write it
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
581 PHP ssh2_scp_send fails to send files as intended
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.