- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我目前正在探索 Asio 库,并拥有用于常规 TCP 连接的工作代码。我使用了 asio::ip::tcp::iostream
对象,因为我想要传输的东西已经可以序列化到 iostreams 或从 iostreams 反序列化,所以这真的很方便,对我来说效果很好。
然后我尝试切换到 SSL 连接,那时一切都变得疯狂了。显然没有内置支持来获得所有其他协议(protocol)支持安全连接的相同 iostream 接口(interface)。从设计的角度来看,这真的让我感到困惑。为什么会这样?
我知道 How to create a boost ssl iostream? 中的讨论它以包装器类结束,以使用 boost 提供 iostream 功能。除此之外,根据评论,该实现存在缺陷,这也没有提供与其他协议(protocol)相同的接口(interface)(basic_socket_iostream
),它还允许例如设置过期时间并关闭联系。 (我还在非提升版本中使用 asio,并且希望尽可能避免将提升作为附加依赖项添加)。
所以,我想我的问题是:
asio::basic_streambuf
或 asio::basic_socket_streambuf
的派生,但我不知何故无法弄清楚它们是如何工作的,需要进行调整..有只是一堆奇怪的指针移动和缓冲区分配和文档对我来说很不清楚什么时候会发生什么来实现什么...tcp::iostream
的项目以支持安全连接最佳答案
> Well, the problem I have is that the ssl::stream really does neither: I doesn't give a socket but it also doesn't give me a stream interface that would be compatible to those available from the other protocols and, yes, in that sense it behaves very differently from the others (for no apparent reason)
我不认为流的行为与其他协议(protocol)有任何不同(参见 https://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio/overview/core/streams.html ):
Streams, Short Reads and Short Writes
Many I/O objects in Boost.Asio are stream-oriented. This means that:
There are no message boundaries. The data being transferred is a continuous sequence of bytes.
Read or write operations may transfer fewer bytes than requested. This is referred to as a short read or short write.
Objects that provide stream-oriented I/O model one or more of the following type requirements:
- SyncReadStream, where synchronous read operations are performed using a member function called read_some().
- AsyncReadStream, where asynchronous read operations are performed using a member function called async_read_some().
- SyncWriteStream, where synchronous write operations are performed using a member function called write_some().
- AsyncWriteStream, where synchronous write operations are performed using a member function called async_write_some().
Examples of stream-oriented I/O objects include
ip::tcp::socket
,ssl::stream<>
,posix::stream_descriptor
,windows::stream_handle
, etc.
也许混淆是因为您正在与 iostream
进行比较接口(interface),这根本不是同一个概念(它来自标准库)。
关于如何制作 iostream
的问题ssl 流的兼容流包装器,如果不更多地查阅文档并使用我目前手头没有的编译器,我无法设计出答案。
关于c++ - 为什么没有 asio::ssl::iostream? (以及如何实现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54311116/
在 C++ 中包含头文件时,和...有什么区别 在 <> 标志中包含 .h 部分与不包括 .h 部分? #include 与 #include 将标题名称用双引号括起来还是用 符号括起来? #inc
最近我在阅读 Accelerated C++ 并从练习答案中发现了这个有趣的代码。这是完整的代码, #include "stdafx.h" #include "4_4.h" #include usi
我正在开发一个需要能够在标准 C++ 编译器和准标准编译器上编译的实用程序。代码可以而且将会被扔到几乎任何现有的 C++ 编译器上。 我正在寻找一种可靠且可移植地确定目标编译器是否支持带或不带 .h
如果有一个文件 foo.cpp,那么它通常有一个关联的头文件 foo.h,其中包含 foo.cpp 中定义的函数的所有声明。这样,所有其他使用 foo.cpp 中的函数的文件都可以只包含 foo.h
iostream 和 iostream.h 有什么区别? 最佳答案 iostream.h 已被提供它的编译器弃用,iostream 是 C++ 标准的一部分。 为了明确说明,当前 C++ 标准 (IN
我知道关于 之间的区别的问题和 之前有人问过。阅读这些答案后,我发现了以下差异 当然iostream.h已弃用,新的符合标准的编译器不支持它 iostream.h不包含 std 中的所有内容命名
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Difference between iostream and iostream.h 我的教授说了以下内容:
我需要构建一些我在办公室电脑上得到的旧代码,它有 gcc 4.4.5安装。我编辑了代码(删除 .h 或添加类似 的内容)以使它们保持最新,以便它们可以由 gcc 4.4.5 编译.但是,在看似成功编
我在学习C++的时候遇到了一个问题,在编译的时候遇到了错误。 详情如下: 最佳答案 您似乎没有在 MinGW 中安装 C++ 支持。如果您使用手动安装路径,请下载 gcc-c++ dev、dll 和
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: What is the difference between #include and #include
对于我当前的任务,我需要能够读/写(主要是基于文件的)比特流。虽然如果用标准 C/C++ 编码,这或多或少是一项微不足道的任务,但我喜欢通过重载和使用更通用的方法重写代码标准的 STL iostrea
这个问题在这里已经有了答案: Difference between iostream and iostream.h (3 个答案) 关闭 9 年前。 有什么区别 #include 和 #inclu
我正在尝试为 linux/MacOS 转换一个用 C++14 编写的应用程序。它使用 boost::filesystem,但不用于某些 iostream 操作。例如: boost::filesyste
示例: namespace boostio = boost::iostreams; boostio::stream memStream(arr); while (!memStream.eof())
我编写了以下简单的 C++ 程序: #include using namespace std; int main() { cout ^~~~~~~~~~ 1 error
我想在我的代码中将流公开为它们的标准等价物,以消除用户对 boost::iostreams 的依赖性.如果有必要,当然想有效地执行此操作而无需创建拷贝。我考虑过只设置 std::istream的缓冲区
#include in header files and #include only in cpp files 被认为是最佳实践。我正在尝试将大量 #include 从 header 移动到现有
#include #include #include #include using namespace std; int main() { int ival; while(ci
假设我得到一个 stringbuf,其中包含一些必须删除的特定字符序列的内容: std::stringbuf string_buff; std::iostream io_stream (&string
我有一个包含如下记录的文件 123 Tag 现在是所有好人都来帮忙的时候了 总是有一个数字和一些标签,后面跟着一系列单词。我想将数字提取为整数,将标记提取为字符串,将句子提取为字符串。我已经使用 ge
我是一名优秀的程序员,十分优秀!