socket: more pythonic language
connection: fix exceptions thrown trying to close unconnected sockets