Improve error handling during ssl handshake.

Previously if do_handshake raised an error not in CONNRESET,
the socket would not be closed properly and the server would start
using 100% of the cpu.

Also handle EBADF errors from do_handshake without logging since
they can be generated by some modes of nmap scans.