从 http 流(在 boost::beast 中)读取和写入的要求是什么?
What are the requirements to read and write from an http stream (in boost::beast)?
我想用boost::beast读写etcd。首先,我希望能够做到 these examples with boost beast. They're easily doable with curl. Etcd can be seen as a key/value store. The functions to set/get (put/range in the examples page) are easy to do with the boost::beast client example。没问题。
但是"watch",我不明白。根据 docs,watch 是一个连续的流,不像其他会话在检索结果后立即死亡。 curl 示例显示在手表仍处于活动状态时更改值和响应 on-spot。我应该使用相同的流来执行与该手表相关的所有操作,包括停止它。
我的问题大致是:如何在 boost::beast 中实现它?
假设从 client example I submit ioc.run
through a thread 到
std::thread t(&std::iocontext::run, &ioc);
t.detach();
现在我在主线程中完全控制了客户端。我是否应该创建新的 http 请求并通过套接字 object 在 async_write
中提交它们?但是如果我这样做了,我就失去了 boost::beast 将 http header 包装成很好的 http::request<http::string_body>
的特性。我应该手动创建 header 吗?还是我应该只发送带有某种行终止符的 json
以指示消息结束?通信协议是什么样的?
有 boost::beast 的例子会很棒。
etcd好像用了"long running requests."这个,你想用http::read_header
[1]或者http::async_read_header
[2]来获取响应头,然后用http::read_some
[3] 或 http::async_read_some
[4] 在循环中读取部分响应主体。为了让它干净地工作,你想使用专为这类事情设计的 http::buffer_body
[5] 。文档中的 HTTP 中继示例[6] 演示了 buffer_body
的使用,并且可以适应处理长 运行 请求。
[6]https://www.boost.org/doc/libs/1_69_0/libs/beast/doc/html/beast/more_examples/http_relay.html
我想用boost::beast读写etcd。首先,我希望能够做到 these examples with boost beast. They're easily doable with curl. Etcd can be seen as a key/value store. The functions to set/get (put/range in the examples page) are easy to do with the boost::beast client example。没问题。
但是"watch",我不明白。根据 docs,watch 是一个连续的流,不像其他会话在检索结果后立即死亡。 curl 示例显示在手表仍处于活动状态时更改值和响应 on-spot。我应该使用相同的流来执行与该手表相关的所有操作,包括停止它。
我的问题大致是:如何在 boost::beast 中实现它?
假设从 client example I submit ioc.run
through a thread 到
std::thread t(&std::iocontext::run, &ioc);
t.detach();
现在我在主线程中完全控制了客户端。我是否应该创建新的 http 请求并通过套接字 object 在 async_write
中提交它们?但是如果我这样做了,我就失去了 boost::beast 将 http header 包装成很好的 http::request<http::string_body>
的特性。我应该手动创建 header 吗?还是我应该只发送带有某种行终止符的 json
以指示消息结束?通信协议是什么样的?
有 boost::beast 的例子会很棒。
etcd好像用了"long running requests."这个,你想用http::read_header
[1]或者http::async_read_header
[2]来获取响应头,然后用http::read_some
[3] 或 http::async_read_some
[4] 在循环中读取部分响应主体。为了让它干净地工作,你想使用专为这类事情设计的 http::buffer_body
[5] 。文档中的 HTTP 中继示例[6] 演示了 buffer_body
的使用,并且可以适应处理长 运行 请求。
[6]https://www.boost.org/doc/libs/1_69_0/libs/beast/doc/html/beast/more_examples/http_relay.html