[英]POCO: How to properly attach StreamSocket to SecureStreamSocket?
I try to attach connected StreamSocket to SecureStreamSocket: 我尝试将连接的StreamSocket附加到SecureStreamSocket:
class MyConnection : public TCPServerConnection {
private:
Context::Ptr m_pContext;
public:
MyConnection(const StreamSocket& socket, Context::Ptr pContext)
: TCPServerConnection(socket),
m_pContext(pContext)
{
}
virtual void run() {
SecureStreamSocket secureSock(SecureStreamSocket::attach(socket(), m_pContext));
socket() = secureSock;
}
}
But I have SSLException: 但我有SSLException:
SSL Exception [N4Poco3Net12SSLExceptionE]: error:140C5042:SSL routines:SSL_UNDEFINED_FUNCTION:called a function you should not call
Initialization of SSL library was performed: SSL库的初始化已执行:
Poco::Net::initializeSSL(); // inside Application::initialize
The context init after SSL initialization: SSL初始化后的上下文初始化:
Poco::Net::Context::Ptr pContext =
new Poco::Net::Context(
Poco::Net::Context::SERVER_USE,
"server.key",
"server.crt",
"/path/to/certs/"
);
We can rewrite SecureStreamSocket::attach(...) this way: 我们可以这样重写SecureStreamSocket :: attach(...):
SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket, Context::Ptr pContext)
{
SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>streamSocket.impl()), pContext);
SecureStreamSocket result(pImpl);
if (pImpl->context()->isForServerUse())
pImpl->acceptSSL();
else
pImpl->connectSSL();
return result;
}
Thanks for this post . 谢谢你的这篇文章 。 Now it works well for servers and clients. 现在,它适用于服务器和客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.