c++ - 是否可以将 SSL_set_fd() 与管道一起使用?
问题描述
我使用 ssl 服务器。我想在 SSL_set_fd 中使用管道作为文件描述符。
我的目标是通过管道将 ssl 数据包写入 ssl 服务器。代码:
// First thread
SSL * ssl = SSL_new(ctx);
int descriptors[2];
int res = pipe( descriptors );
if ( res == -1 ){
throw std::runtime_error( "pipe error" );
}
res = SSL_set_rfd(ssl, descriptors[0]);
if ( res != 1 ){
throw std::runtime_error("SSL_set_rfd");
}
// Here the thread will stop for waiting ssl-hello
res = SSL_accept( ssl );
// In the second thread I am going to write ssl-packets to server:
struct pollfd fds[1];
fds[0].fd = descriptors[1];
fds[0].events = POLLOUT;
std::vector <unsigned char> sslPacket = waitAndPop();
int rc = poll( fds, 1, 10000 );
if ( rc < 0 ){
throw std::runtime_error("poll error");
}
if ( rc == 0 ){
throw std::runtime_error("timeout");
}
if ( fds[0].revents & POLLOUT ){
fds[0].revents = 0;
rc = send( descriptors[1], sslPacket.data(), sslPacket.size(), 0 );
}
问题是 send() 总是返回 errno 38 ,这意味着“功能未实现”。难道我做错了什么?是否可以将管道设置为 ssl 的文件描述符?
macOS 10.15.4、Xcode 11.5、OpenSSL 1.1.1
我读了这个文档: 1.https://man7.org/linux/man-pages/man2/pipe.2.html 2.https://www.openssl.org/docs/manmaster/man3/SSL_set_fd.html 3 .https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/pipe.2.html
解决方案
您不能send
与管道一起使用。您可以使用write
管道。send
仅适用于套接字。
推荐阅读
- javascript - 如何定位本地文件夹的端点
- windows - 想知道我是否在批处理文件中成功设置变量
- ios - 如何删除ios第三方sdk中不必要的权限?
- java - 如何在没有错误 ArrayIndexOutOfBoundsException 的情况下实现具有 4 路分区的合并排序算法?
- python - QueryParser.parse,限制单词之间的距离
- javascript - 如何为我的聊天机器人制作自定义回复卡
- printing - 如何打印包含完整详细信息的 PNG 或 SVG 文件?
- c# - 如何从方法参数的列表中进行选择?
- javascript - IOS 设备中的浏览器不会在后台自动播放声音
- python - Python中如何判断一个多边形是否在另一个多边形内?