TIL: writing to a socket and dying

kdevel kdevel at vogtner.de
Thu Apr 24 19:36:03 UTC 2025


On Thursday, 24 April 2025 at 14:04:03 UTC, Andy Valencia wrote:
> [...]
> Phobos appears to try and inhibit this on some BSD systems,

How does it do that?

> but on Linux if the recipient has closed the socket and [the 
> OPs process running his progam] write[s]--SIGPIPE.

"the whole point of the signal is to notify [the process writing 
to the closed socket] asynchronously that the write is no longer 
possible. This is part of what makes the whole elegant co-routine 
structure of pipes work in UNIX." [1]

The truth is probably that there are lots of programs which don't 
check write's (printf's etc.) return value so that they will 
continue running.

> [...] I added a SIG_IGN of SIGPIPE and that made the problem 
> stop.

You know that it will now throw? [0]


[0] [Issue 21649] Make D runtime ignore or handle SIGPIPE or 
document the behavior, 
https://forum.dlang.org/thread/bug-21649-3@https.issues.dlang.org%2F

[1] 
https://stackoverflow.com/questions/8369506/why-does-sigpipe-exist


More information about the Digitalmars-d-learn mailing list