* Note: This method is not libevent safe. */
| 355 | * Note: This method is not libevent safe. |
| 356 | */ |
| 357 | void TSSLSocket::close() { |
| 358 | if (ssl_ != nullptr) { |
| 359 | try { |
| 360 | int rc; |
| 361 | int errno_copy = 0; |
| 362 | int error = 0; |
| 363 | |
| 364 | do { |
| 365 | rc = SSL_shutdown(ssl_); |
| 366 | if (rc <= 0) { |
| 367 | errno_copy = THRIFT_GET_SOCKET_ERROR; |
| 368 | error = SSL_get_error(ssl_, rc); |
| 369 | switch (error) { |
| 370 | case SSL_ERROR_SYSCALL: |
| 371 | if ((errno_copy != THRIFT_EINTR) |
| 372 | && (errno_copy != THRIFT_EAGAIN)) { |
| 373 | break; |
| 374 | } |
| 375 | // fallthrough |
| 376 | case SSL_ERROR_WANT_READ: |
| 377 | case SSL_ERROR_WANT_WRITE: |
| 378 | // in the case of SSL_ERROR_SYSCALL we want to wait for an write/read event again |
| 379 | waitForEvent(error == SSL_ERROR_WANT_READ); |
| 380 | rc = 2; |
| 381 | default:;// do nothing |
| 382 | } |
| 383 | } |
| 384 | } while (rc == 2); |
| 385 | |
| 386 | if (rc < 0) { |
| 387 | string errors; |
| 388 | buildErrors(errors, errno_copy, error); |
| 389 | TOutput::instance()(("SSL_shutdown: " + errors).c_str()); |
| 390 | } |
| 391 | } catch (TTransportException& te) { |
| 392 | // Don't emit an exception because this method is called by the |
| 393 | // destructor. There's also not much that a user can do to recover, so |
| 394 | // just clean up as much as possible without throwing, similar to the rc |
| 395 | // < 0 case above. |
| 396 | TOutput::instance().printf("SSL_shutdown: %s", te.what()); |
| 397 | } |
| 398 | SSL_free(ssl_); |
| 399 | ssl_ = nullptr; |
| 400 | handshakeCompleted_ = false; |
| 401 | #if OPENSSL_VERSION_NUMBER >= 0x10100000 |
| 402 | // Do nothing unless an openssl derivative is detected |
| 403 | # if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_IS_AWSLC) |
| 404 | // https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_thread_stop.html |
| 405 | OPENSSL_thread_stop(); |
| 406 | # endif |
| 407 | #else |
| 408 | // ERR_remove_state() was deprecated in OpenSSL 1.0.0 and ERR_remove_thread_state() |
| 409 | // was deprecated in OpenSSL 1.1.0; these functions and should not be used. |
| 410 | // https://www.openssl.org/docs/manmaster/man3/ERR_remove_state.html |
| 411 | ERR_remove_state(0); |
| 412 | #endif |
| 413 | } |
| 414 | TSocket::close(); |
nothing calls this directly
no test coverage detected