将安全套接字作为普通套接字传递到升压中
pass secure socket as normal socket in boost
我有这些类型定义,问题是我需要传递一个安全套接字,因为 TSocket 会从 TSecureSocket 直接投射到 TSocket 工作吗? 还是有其他解决方案? 根据端口的不同,我将使套接字安全,而在其他情况下则不会。我只需要返回类型是 TSocket。
typedef boost::asio::ip::tcp::socket TBoostSocket;
typedef boost::asio::ssl::stream<TBoostSocket> TSLLSocket;
typedef boost::shared_ptr<TBoostSocket> TSocket;
typedef boost::shared_ptr<TSLLSocket> TSecureSocket;
我看过这个 提升::ASIO 将套接字转换为安全套接字
我有这些类型定义
typedef boost::asio::ip::tcp::socket TBoostSocket;
typedef boost::asio::ssl::stream<TBoostSocket> TSLLSocket;
typedef boost::shared_ptr<TBoostSocket> TSocket;
typedef boost::shared_ptr<TSLLSocket> TSecureSocket;
问题是我需要传递一个安全套接字作为 TSocket。将直接 从插座到工作
?
简答题 否。因为boost::asio::ssl::stream<TBoostSocket>
包裹了插座。
还是有其他解决方案? 根据端口,我将使 套接字安全,在其他情况下,我不会,我只需要返回类型 是索克特。
但是,TSLLSocket
(或 boost::asio::ssl::stream )提供了一种从实例中检索套接字的方法:
const next_layer_type & next_layer() const;
http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/reference/ssl__stream/next_layer/overload1.html
其中next_layer_type
由以下 typedef 定义:
typedef boost::remove_reference< Stream >::type next_layer_type;
http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/reference/ssl__stream/next_layer_type.html
由于您使用TBoostSocket
定义模板,因此当您调用next_layer()
或lowest_layer()
时,您应该得到
当然,这将返回一个引用而不是一个指针,并且该引用是指向不属于您的实例。因此,您现在需要以某种方式将其包装在shared_ptr中,这可能并不容易,因为您不允许将其删除。
- 当套接字连接断开时检测C/C++Unix
- 通过套接字[TCP]传输数据 如何在C / C ++中打包多个整数并使用send() recv()传输数据
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 如何在C/C++中用FD_set Unix设置套接字文件描述符
- 套接字读取后,我在缓冲区中看到意外输入
- 如何在CPP中创建应该在Windows和Linux上运行的套接字?
- 我可以与 python 服务器而不是 c++ 客户端建立 tcp/ip 套接字吗?
- 套接字连接"Operation not permitted"错误,甚至使用升压/平发器根.cpp
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- (Winsock) UDP 接收工作正常,但同一套接字的发送失败
- MSG_WAITALL的套接字发送得到了 22 EINVAL
- C++套接字客户端到 Python 服务器未创建连接
- 在不知道套接字的情况下关闭网络连接
- C++套接字对不读/写父/子
- 非更新套接字消息
- SIGSEGV on Boost UDP 套接字关闭 - tcache_get at malloc.c.
- 将"uint8_t"(从套接字读取)隐式转换为"char"安全吗
- 当对套接字 send() 的同步调用由于连接另一端丢失而被阻止时,如何恢复?
- 从安卓客户端发送数据时,C++ 套接字接收函数中第一个字符中的 NUL 值
- 安卓 NDK 套接字 网络无法访问