* Returns number of bytes written in SSL Socket. * If eventSafe is set, and it may returns 0 bytes then write method * needs to be called again until it is successfull or it throws * exception incase of failure. */
| 544 | * exception incase of failure. |
| 545 | */ |
| 546 | uint32_t TSSLSocket::write_partial(const uint8_t* buf, uint32_t len) { |
| 547 | initializeHandshake(); |
| 548 | if (!checkHandshake()) |
| 549 | return 0; |
| 550 | // loop in case SSL_MODE_ENABLE_PARTIAL_WRITE is set in SSL_CTX. |
| 551 | uint32_t written = 0; |
| 552 | while (written < len) { |
| 553 | ERR_clear_error(); |
| 554 | int32_t bytes = SSL_write(ssl_, &buf[written], len - written); |
| 555 | if (bytes <= 0) { |
| 556 | int errno_copy = THRIFT_GET_SOCKET_ERROR; |
| 557 | int error = SSL_get_error(ssl_, bytes); |
| 558 | switch (error) { |
| 559 | case SSL_ERROR_SYSCALL: |
| 560 | if ((errno_copy != THRIFT_EINTR) |
| 561 | && (errno_copy != THRIFT_EAGAIN)) { |
| 562 | break; |
| 563 | } |
| 564 | // fallthrough |
| 565 | case SSL_ERROR_WANT_READ: |
| 566 | case SSL_ERROR_WANT_WRITE: |
| 567 | if (isLibeventSafe()) { |
| 568 | return 0; |
| 569 | } |
| 570 | else { |
| 571 | // in the case of SSL_ERROR_SYSCALL we want to wait for an write event again |
| 572 | waitForEvent(error == SSL_ERROR_WANT_READ); |
| 573 | continue; |
| 574 | } |
| 575 | default:;// do nothing |
| 576 | } |
| 577 | string errors; |
| 578 | buildErrors(errors, errno_copy, error); |
| 579 | throw TSSLException("SSL_write: " + errors); |
| 580 | } |
| 581 | written += bytes; |
| 582 | } |
| 583 | return written; |
| 584 | } |
| 585 | |
| 586 | void TSSLSocket::flush() { |
| 587 | resetConsumedMessageSize(); |
nothing calls this directly
no test coverage detected