设置读写回调函数:
mbedtls_ssl_set_bio(&session->ssl, &session->server_fd, mbedtls_net_send, mbedtls_net_recv, NULL);
void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
void *p_bio,
mbedtls_ssl_send_t *f_send,
mbedtls_ssl_recv_t *f_recv,
mbedtls_ssl_recv_timeout_t *f_recv_timeout )
{
ssl->p_bio = p_bio;
ssl->f_send = f_send;
ssl->f_recv = f_recv;
ssl->f_recv_timeout = f_recv_timeout;
}
f_recv()->mbedtls_ssl_fetch_input()->mbedtls_ssl_read_record_layer()->mbedtls_ssl_read_record()->mbedtls_ssl_read()->mbedtls_client_read()
mbedtls_ssl_read_record_layer()函数内:
1、调用mbedtls_ssl_fetch_input()接收数据
2、ssl_parse_record_header()函数判断一个 record 的数据是否超过缓存(MBEDTLS_SSL_MAX_CONTENT_LEN)大小
3、调用ssl_prepare_record_content()->ssl_decrypt_buf()对接收到的数据进行对称解密