下面的伪代码解释了我面临的情况
服务器端
while (<some condition>)
{
// wait for SSL connection
acceptor.async_accept();
// wait until connection
io_service.run();
// perform handshake
ssl_socket.handhake();
// handshake successfully complete, start command manager thread
pthread_create();
io_service.reset();
// Go for the new connection waiting
}
这里的问题是我能够连接两个客户端但不能同时连接。 1个连接到达之后,握手和证书验证需要40-50毫秒,因此,任何连接请求都会失败。
更新:
在握手过程中有没有办法停止听客户问候?
我必须为每个循环创建新的io_service
实例,因为我可能想要使用io_service.stop()
调用取消特定的线程。 boost还有其他选择吗?
答案 0 :(得分:0)
同步ssl_socket.handshake()
将阻止接受其他连接。如果您需要异步行为,请使用ssl_socket.async_handshake()
。
另外值得注意的是:您不需要每个线程的连接,因为该设计不会超出简单的范例。