| 391 | } |
| 392 | |
| 393 | int openssl_io::read(void* buf, size_t len) |
| 394 | { |
| 395 | #ifdef HAS_OPENSSL |
| 396 | size_t nbytes = 0; |
| 397 | char* ptr = (char*) buf; |
| 398 | int timeo = nblock_ ? 0 : this->stream_->rw_timeout; |
| 399 | ACL_SOCKET fd = ACL_VSTREAM_SOCK(this->stream_); |
| 400 | bool opt = conf_.is_sockopt_timeout(); |
| 401 | |
| 402 | //#define DEBUG_READ_TIMEOUT |
| 403 | |
| 404 | while (len > 0) { |
| 405 | #ifdef DEBUG_READ_TIMEOUT |
| 406 | time_t begin = time(NULL); |
| 407 | #endif |
| 408 | if (timeo > 0 && !opt && acl_read_wait(fd, timeo) < 0) { |
| 409 | #ifdef DEBUG_READ_TIMEOUT |
| 410 | time_t end = time(NULL); |
| 411 | logger_error("read_wait error=%s, fd=%d, cost=%ld, ttl=%d", |
| 412 | last_serror(), (int) fd, (long) (end - begin), timeo); |
| 413 | #endif |
| 414 | return -1; |
| 415 | } |
| 416 | |
| 417 | int ret = __ssl_read(ssl_, ptr, (int) len); |
| 418 | |
| 419 | this->stream_->read_ready = 0; |
| 420 | |
| 421 | if (ret > 0) { |
| 422 | nbytes += ret; |
| 423 | ptr += ret; |
| 424 | len -= ret; |
| 425 | |
| 426 | break; |
| 427 | } |
| 428 | |
| 429 | |
| 430 | if (nbytes > 0) { |
| 431 | break; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | int err = __ssl_get_error(ssl_, ret); |
| 436 | |
| 437 | if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) { |
| 438 | if (nblock_ || opt) { |
| 439 | break; |
| 440 | } |
| 441 | } else { |
| 442 | // SSL_ERROR_ZERO_RETURN, SSL_ERROR_SYSCALL, others. |
| 443 | |
| 444 | /* |
| 445 | if (ERR_peek_error() == 0) { |
| 446 | } |
| 447 | */ |
| 448 | return -1; |
| 449 | } |
| 450 | } |
nothing calls this directly
no test coverage detected