提高ASIO - SSL async_read和async_write从一个线程 [英] boost asio - SSL async_read and async_write from one thread
问题描述
我知道的OpenSSL,提高ASIO SSL实现是基于,不允许并发SSL_read()和SSL_write()(即SSL_read()和SSL_write()被不同的线程执行)。
I know that OpenSSL, boost asio SSL implementation is based on, doesn't allow concurrent SSL_read() and SSL_write() (i.e. SSL_read() and SSL_write() executed by different threads).
它是安全的SSL套接字在同一个线程调用提升ASIO async_read()和async_write()?
Is it safe to call boost asio async_read() and async_write() on SSL socket from the same thread?
感谢
推荐答案
有关的 提高:: ASIO :: SSL :::流
是线程安全;它不到位的要求是哪个线程可以启动操作:
The requirement for boost::asio::ssl:::stream
is for thread safety; it does not place a requirement as to which thread may initiate operations:
不同的对象:安全
共享对象:不安全。该应用程序还必须确保所有异步操作都是一样的隐性或显性链内进行。
Shared objects: Unsafe. The application must also ensure that all asynchronous operations are performed within the same implicit or explicit strand.
如果该应用程序只有一个线程处理 io_service对象
和 async_read()
和 async_write()
从线程中被初始化,那么它是安全的,因为操作和完成处理(S)是一个隐含链中运行。
If the application only has one thread processing the io_service
, and async_read()
and async_write()
are initiated from within that thread, then it is safe, as the operation and completion handler(s) are running within an implicit strand.
在另一方面,如果将多个线程处理 io_service对象
,然后一个明确的链
是必要的。在 async_read()
和 async_write()
操作需要从内发起链
,并完成处理需要由同一个包裹链
。
On the other hand, if multiple threads are processing the io_service
, then an explicit strand
is necessary. The async_read()
and async_write()
operations need to be initiated from within a strand
, and the completion handlers need to be wrapped by the same strand
.
有关Boost.Asio的的线程安全要求的更多详细信息,股
,并组成操作,请考虑阅读的这个答案。
For more details on Boost.Asio's thread safety requirements, strands
, and composed operations, consider reading this answer.
这篇关于提高ASIO - SSL async_read和async_write从一个线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!