| 541 | } |
| 542 | |
| 543 | int mbedtls_io::sock_send(void *ctx, const unsigned char *buf, size_t len) |
| 544 | { |
| 545 | #ifdef HAS_MBEDTLS |
| 546 | mbedtls_io* io = (mbedtls_io*) ctx; |
| 547 | ACL_VSTREAM* vs = io->stream_; |
| 548 | ACL_SOCKET fd = ACL_VSTREAM_SOCK(vs); |
| 549 | int timeout = io->nblock_ ? 0 : vs->rw_timeout; |
| 550 | |
| 551 | time_t begin = time(NULL); |
| 552 | if (acl_write_wait(fd, timeout) < 0) { |
| 553 | time_t end = time(NULL); |
| 554 | logger_error("acl_write_wait error=%s, fd=%d, cost=%ld", |
| 555 | last_serror(), (int) fd, (long) (end - begin)); |
| 556 | return MBEDTLS_ERR_NET_SEND_FAILED; |
| 557 | } |
| 558 | |
| 559 | // ��Ϊ������ģʽʱ����ʱ�ȴ�Ϊ 0 �� |
| 560 | int ret = acl_socket_write(fd, buf, len, io->nblock_ |
| 561 | ? 0 : vs->rw_timeout, vs, NULL); |
| 562 | if (ret < 0) { |
| 563 | int errnum = acl_last_error(); |
| 564 | |
| 565 | if (errnum == ACL_EINTR) { |
| 566 | return MBEDTLS_ERR_SSL_WANT_WRITE; |
| 567 | } else if (errnum == ACL_EWOULDBLOCK) { |
| 568 | return MBEDTLS_ERR_SSL_WANT_WRITE; |
| 569 | #if ACL_EWOULDBLOCK != ACL_EAGAIN |
| 570 | } else if (errnum == ACL_EAGAIN) { |
| 571 | return MBEDTLS_ERR_SSL_WANT_WRITE; |
| 572 | #endif |
| 573 | } else if (errnum == ACL_ECONNRESET || errno == EPIPE) { |
| 574 | return MBEDTLS_ERR_NET_CONN_RESET; |
| 575 | } else { |
| 576 | return MBEDTLS_ERR_NET_SEND_FAILED; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | return ret; |
| 581 | #else |
| 582 | (void) ctx; |
| 583 | (void) buf; |
| 584 | (void) len; |
| 585 | logger_error("HAS_MBEDTLS not defined!"); |
| 586 | return -1; |
| 587 | #endif |
| 588 | } |
| 589 | |
| 590 | } // namespace acl |
nothing calls this directly
no test coverage detected