void AsyncSSLSocket::closeNow() {
  // Close the SSL connection.
  if (ssl_ != nullptr && fd_ != NetworkSocket() && !waitingOnAccept_) {
    int rc = SSL_shutdown(ssl_.get());
    if (rc == 0) {
      rc = SSL_shutdown(ssl_.get());
    }
    if (rc < 0) {
      ERR_clear_error();
    }
  }

  if (sslSession_ != nullptr) {
    SSL_SESSION_free(sslSession_);
    sslSession_ = nullptr;
  }

  sslState_ = STATE_CLOSED;

  if (handshakeTimeout_.isScheduled()) {
    handshakeTimeout_.cancelTimeout();
  }

  DestructorGuard dg(this);

  static const Indestructible<AsyncSocketException> ex(
      AsyncSocketException::END_OF_FILE, "SSL connection closed locally");
  invokeHandshakeErr(*ex);

  // Close the socket.
  AsyncSocket::closeNow();
}
void AsyncSSLSocket::closeNow() {
   
  if (ssl_ != nullptr && fd_ != NetworkSocket() && !waitingOnAccept_) {
    int rc = SSL_shutdown(ssl_.get());
    if (rc == 0) {
      rc = SSL_shutdown(ssl_.get());
    }
    if (rc < 0) {
      ERR_clear_error();
    }
  }

  if (sslSession_ != nullptr) {
    SSL_SESSION_free(sslSession_);
    sslSession_ = nullptr;
  }

  sslState_ = STATE_CLOSED;

  if (handshakeTimeout_.isScheduled()) {
    handshakeTimeout_.cancelTimeout();
  }

  DestructorGuard dg(this);

  static const Indestructible<AsyncSocketException> ex(
      AsyncSocketException::END_OF_FILE, "SSL connection closed locally");
  invokeHandshakeErr(*ex);

   
  AsyncSocket::closeNow();
}