backport the ssl handshake change from sublime master.  Also, cleanup some reconnecting logic.