Add shutdown() before close() for portability

"For portable behaviour with respect to graceful closure of a connected socket, call shutdown() before closing the socket."
Ignore connection_reset errors