| 560 | } |
| 561 | |
| 562 | int polarssl_io::sock_read(void *ctx, unsigned char *buf, size_t len) |
| 563 | { |
| 564 | #ifdef HAS_POLARSSL |
| 565 | polarssl_io* io = (polarssl_io*) ctx; |
| 566 | ACL_VSTREAM* vs = io->stream_; |
| 567 | ACL_SOCKET fd = ACL_VSTREAM_SOCK(vs); |
| 568 | |
| 569 | //logger(">>>non_block: %s, sys_ready: %s", |
| 570 | // io->nblock_ ? "yes" : "no", |
| 571 | // vs->read_ready ? "yes":"no"); |
| 572 | |
| 573 | // ������ģʽ�£���� read_ready ��־λΪ 0����˵���п��� |
| 574 | // ���� IO �����������ݣ�Ϊ�˷�ֹ�ö����̱����������Դ˴�ֱ�� |
| 575 | // ���ظ� polarssl ����֮�ȴ��´ζ����´ζ����������¼����津���� |
| 576 | // ���������ŵ����ڷ�����ģʽ�¼�ʹ����û������Ϊ������״̬ |
| 577 | // Ҳ���������̣߳���ȱ�����������¼�ѭ�������Ĵ��� |
| 578 | if (io->nblock_ && vs->read_ready == 0) { |
| 579 | int ret = acl_readable(fd); |
| 580 | if (ret == -1) { |
| 581 | return POLARSSL_ERR_NET_RECV_FAILED; |
| 582 | } else if (ret == 0) { |
| 583 | // �����ڴ˴�����ϵͳ�� errno �ţ��˴���ģ���� |
| 584 | // ������������ |
| 585 | acl_set_error(ACL_EWOULDBLOCK); |
| 586 | return POLARSSL_ERR_NET_WANT_READ; |
| 587 | } |
| 588 | // else: ret == 1 |
| 589 | } |
| 590 | |
| 591 | // acl_socket_read �ڲ������ vs->read_ready ��־λ�����Ƿ���Ҫ |
| 592 | // �Գ�ʱ��ʽ�����ݣ�ͬʱ���Զ���� vs->read_ready ��־λ |
| 593 | int ret = acl_socket_read(fd, buf, len, vs->rw_timeout, vs, NULL); |
| 594 | |
| 595 | if (ret < 0) { |
| 596 | int errnum = acl_last_error(); |
| 597 | |
| 598 | if (errnum == ACL_EINTR) { |
| 599 | return POLARSSL_ERR_NET_WANT_READ; |
| 600 | } else if (errnum == ACL_EWOULDBLOCK) { |
| 601 | return POLARSSL_ERR_NET_WANT_READ; |
| 602 | #if ACL_EWOULDBLOCK != ACL_EAGAIN |
| 603 | } else if (errnum == ACL_EAGAIN) { |
| 604 | return POLARSSL_ERR_NET_WANT_READ; |
| 605 | #endif |
| 606 | } else if (errnum == ACL_ECONNRESET || errno == EPIPE) { |
| 607 | return POLARSSL_ERR_NET_CONN_RESET; |
| 608 | } else { |
| 609 | return POLARSSL_ERR_NET_RECV_FAILED; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | return ret; |
| 614 | #else |
| 615 | (void) ctx; |
| 616 | (void) buf; |
| 617 | (void) len; |
| 618 | logger_error("HAS_POLARSSL not defined!"); |
| 619 | return -1; |
nothing calls this directly
no test coverage detected