* Returns number of bytes read in SSL Socket. * If eventSafe is set, and it may returns 0 bytes then read method * needs to be called again until it is successfull or it throws * exception incase of failure. */
| 421 | * exception incase of failure. |
| 422 | */ |
| 423 | uint32_t TSSLSocket::read(uint8_t* buf, uint32_t len) { |
| 424 | checkReadBytesAvailable(len); |
| 425 | initializeHandshake(); |
| 426 | if (!checkHandshake()) |
| 427 | throw TTransportException(TTransportException::UNKNOWN, "retry again"); |
| 428 | int32_t bytes = 0; |
| 429 | while (readRetryCount_ < maxRecvRetries_) { |
| 430 | bytes = SSL_read(ssl_, buf, len); |
| 431 | int32_t errno_copy = THRIFT_GET_SOCKET_ERROR; |
| 432 | int32_t error = SSL_get_error(ssl_, bytes); |
| 433 | readRetryCount_++; |
| 434 | if (error == SSL_ERROR_NONE) { |
| 435 | readRetryCount_ = 0; |
| 436 | break; |
| 437 | } |
| 438 | unsigned int waitEventReturn; |
| 439 | bool breakout = false; |
| 440 | switch (error) { |
| 441 | case SSL_ERROR_ZERO_RETURN: |
| 442 | throw TTransportException(TTransportException::END_OF_FILE, "client disconnected"); |
| 443 | |
| 444 | case SSL_ERROR_SYSCALL: |
| 445 | if (errno_copy == 0 && ERR_peek_error() == 0) { |
| 446 | breakout = true; |
| 447 | break; |
| 448 | } |
| 449 | if ((errno_copy != THRIFT_EINTR) |
| 450 | && (errno_copy != THRIFT_EAGAIN)) { |
| 451 | break; |
| 452 | } |
| 453 | if (readRetryCount_ >= maxRecvRetries_) { |
| 454 | // THRIFT_EINTR needs to be handled manually and we can tolerate |
| 455 | // a certain number |
| 456 | break; |
| 457 | } |
| 458 | // fallthrough |
| 459 | |
| 460 | case SSL_ERROR_WANT_READ: |
| 461 | case SSL_ERROR_WANT_WRITE: |
| 462 | if (isLibeventSafe()) { |
| 463 | if (readRetryCount_ < maxRecvRetries_) { |
| 464 | // THRIFT_EINTR needs to be handled manually and we can tolerate |
| 465 | // a certain number |
| 466 | throw TTransportException(TTransportException::UNKNOWN, "retry again"); |
| 467 | } |
| 468 | throw TTransportException(TTransportException::INTERNAL_ERROR, "too much recv retries"); |
| 469 | } |
| 470 | // in the case of SSL_ERROR_SYSCALL we want to wait for an read event again |
| 471 | else if ((waitEventReturn = waitForEvent(error != SSL_ERROR_WANT_WRITE)) == TSSL_EINTR ) { |
| 472 | // repeat operation |
| 473 | if (readRetryCount_ < maxRecvRetries_) { |
| 474 | // THRIFT_EINTR needs to be handled manually and we can tolerate |
| 475 | // a certain number |
| 476 | continue; |
| 477 | } |
| 478 | throw TTransportException(TTransportException::INTERNAL_ERROR, "too much recv retries"); |
| 479 | } |
| 480 | else if (waitEventReturn == TSSL_DATA) { |
nothing calls this directly
no test coverage detected