applied SO_NOSIGPIPE patch, with fix from Peter Bex and slight subsequent modification