small cleanup - use of CloseSocket()

- call CloseSocket() before printing any text (ensure consistent
  usage in the code), exception is when using NetworkErrorString()
- also use same form and comment for disabling sigpipe

Includes also a minor compat.h cleanup (leftover from the old pull #4348).