c++ - boost asio - 来自一个线程的 SSL async_read 和 async_write

标签 c++ boost ssl openssl boost-asio

我知道 OpenSSL,boost asio SSL 实现基于,不允许并发 SSL_read() 和 SSL_write()(即由不同线程执行的 SSL_read() 和 SSL_write())。

从同一线程在 SSL 套接字上调用 boost asio async_read() 和 async_write() 是否安全?

谢谢

最佳答案

boost::asio::ssl:::stream 的要求是为了线程安全;它不要求哪个线程可以启动操作:

Distinct objects: Safe.

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() 是从该线程内启动的,那么它是安全的,因为操作和完成处理程序在隐式链中运行。

另一方面,如果多个线程正在处理 io_service,则需要显式的 strandasync_read()async_write() 操作需要从 strand 中启动,并且完成处理程序需要由相同的包装

有关 Boost.Asio 的线程安全要求、strands 和组合操作的更多详细信息,请考虑阅读 this回答。

关于c++ - boost asio - 来自一个线程的 SSL async_read 和 async_write,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18409517/

相关文章:

ssl - Erlang:使用 SSL 的 inets httpd

c++ - CMake 添加带有子目录的库

c++ - 在模板类中定义迭代器时出现 STL 编译错误

c++ - 通过 Visual Studio 使用 Boost 构建未选择正确的 VS 版本或静态链接库

ssl - 如何在docker中的应用程序上设置远程访问SSL JMX接口(interface)

ssl - Jenkins 2 和 Atlassian Crowd(crowd2 插件)与双向 SSL 集成

c++ - 如何使用 boost spirit 将字符串解析为元组 vector ?

c++ - 为什么在此 CRTP 基函数调用中添加引用会消除错误?

c++ - 为 std::vector<double> boost 自定义验证器

c++ - 如何正确退出可能正在等待 std::condition_variable 的 std::thread?