【发布时间】:2021-01-05 21:52:02
【问题描述】:
我使用 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
【问题讨论】:
-
什么版本的 OpenSSL?
-
@AsteroidsWithWings,openssl 1.1.1
-
“问题是 send() 总是返回 errno 38,这意味着“功能未实现” 这是否表明问题出在
send(),而不是您使用的其他功能? -
你真的是说它“返回”errno 38?
send()不返回错误号。 It returns the number of bytes sent, or -1 for error。如果出现错误,请检查errno全局变量以找出原因。不幸的是,你没有在你的问题中展示你的工作,所以我只能猜测...... -
@AsteroidsWithWings,send() 与套接字完美配合。只有当我将其更改为管道时,我才有错误。你是对的 - send() return -1, errno = 38.