Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can writes to a datagram socket ever raise SIGPIPE?

I'm working with some code that needs to be safe against killing the caller due to SIGPIPE, but the only socket writes it's performing are going to datagram sockets (both UDP and Unix domain datagram sockets). Do I need to worry about SIGPIPE? I'm using connect on the socket, but preliminary testing (on Linux) showed that I just get ECONNREFUSED on send if there's nobody listening on the Unix domain socket. Not sure what happens with UDP.

I can wrap the whole thing in hacks to get rid of SIGPIPE, but if it's a non-issue I'd rather save the overhead and keep the code complexity down.

like image 845
R.. GitHub STOP HELPING ICE Avatar asked Apr 13 '11 21:04

R.. GitHub STOP HELPING ICE


1 Answers

The answer is in the specification for send:

[EPIPE] The socket is shut down for writing, or the socket is connection-mode and is no longer connected. In the latter case, and if the socket is of type SOCK_STREAM or SOCK_SEQPACKET and the MSG_NOSIGNAL flag is not set, the SIGPIPE signal is generated to the calling thread.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html

Thus, no, writes to datagram sockets do not generate SIGPIPE or an EPIPE error.

like image 173
R.. GitHub STOP HELPING ICE Avatar answered Sep 30 '22 03:09

R.. GitHub STOP HELPING ICE