Handle SSL_shutdown returning WANT_READ / WANT_WRITE

Previously, connection_terminate handled SSL_shutdown return codes
poorly and assumed that SSL_shutdown would work (it retried it
once). This could lead to a situation where SSL_shutdown returned
WANT_READ or WANT_WRITE which would be ignored and then the TCP
connection terminated.

Now each connection has a TERMINATING state added and it will
continue to process reads and call SSL_shutdown repeatedly on read
events until the connection has been terminated. Only then will
memory be cleaned up and the TCP connection killed.