我在专用于视频的嵌入式系统中添加openSSL。
在代码中有C函数sendfile。套接字为ouf_fd,文件描述符为in_fd。
如何使用openSSL重写此功能?我尝试使用BIO或SSL_set_wfd / rfd,但我对openSSL缺乏经验。
如果可能的话,我想像sendfile那样保持内核优化。
当前代码:
SSL* ssl = SSL_new(ctx);
SSL_set_wfd(ssl, hc->sd); // socket OUT
SSL_set_rfd(ssl, fd); // file descriptor IN
char buf[1000];
int error = 0, written = 0;
struct timeval timeout;
fd_set fds;
while(1) {
written = SSL_write(ssl, buf, 1000);
if(written > 0) {
break;
}
else {
error = SSL_get_error(hc->ssl, written);
switch(error) {
case SSL_ERROR_NONE:
break;
case SSL_ERROR_WANT_READ:
{
int sock = SSL_get_rfd(hc->ssl);
FD_ZERO(&fds);
FD_SET(sock, &fds);
timeout.tv_sec = 5;
timeout.tv_usec = 0;
error = select(sock+1, NULL, &fds, NULL, &timeout);
if (error > 0)
continue; // can write more data now...
}
}
}
}
SSL_set_rfd(ssl, hc->sd);
while((written = SSL_read(ssl, buf, 1000)) <0) {
}
由于