www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Using the SO_NOSIGPIPE socket option on macOS

I've run into an issue using DCD [1] on macOS where it crashes with the 
exception "Unable to set socket option: Invalid argument". This occurs 
when DCD calls "accept" on the Socket it's using. Accept will, through 
some calls, eventually call "setSock", which will on macOS set the 
socket option SO_NOSIGPIPE.

It turns out that this call can fail if the remote end has closed/reset 
the socket [2]. I believe the solution is to try to reconnect. Since the 
Socket class automatically sets the SO_NOSIGPIPE option on macOS, should 
the Socket class also try to automatically reconnect or is that 
something up to the user of the Socket class to do?

[1] https://github.com/dlang-community/DCD/issues/345
[2] https://lists.apple.com/archives/macnetworkprog/2008/Jan/msg00084.html

/Jacob Carlborg
May 17 2017