简体   繁体   English

异步 http 客户端库和 glib 事件循环

[英]Asynchronous http client library and glib event loop

A am looking for an asynchronous http client library with some specific need:我正在寻找具有某些特定需求的异步 http 客户端库:

  • It must be possible it implement it as a glibmm source必须有可能将其实现为 glibmm 源
  • It must be single threated它必须是单一威胁的
  • It must have a lgpl, bsd, mit or similar license它必须具有 lgpl、bsd、mit 或类似许可证

In order to impement it as a glibmm source, one must have access to its file descriptor, create a Glib::PollFD object, and I should be good to go.为了将它作为一个 glibmm 源来实现,必须能够访问它的文件描述符,创建一个 Glib::PollFD object,我应该对 go 很好。

I have been looking at several libraries, which all have some problems:我一直在查看几个库,它们都有一些问题:

  • libcurl, can almost do what I want, in the multi source API it has a curl_multi_fdset function, which return fd_set's. libcurl,几乎可以做我想做的事,在多源 API 中它有一个 curl_multi_fdset function,它返回 fd_set。 The problem is that I can not figure out how I can convert a fd_set to one or more Glib::PollFD's问题是我不知道如何将 fd_set 转换为一个或多个 Glib::PollFD
  • Poco, has a HttpSessionClient which returns in istream, which I can not find a way to do unblocking read from. Poco,有一个在 istream 中返回的 HttpSessionClient,我找不到一种方法来解除阻塞读取。
  • Boost::Asio require to use the io_service as event loop. Boost::Asio 需要使用 io_service 作为事件循环。

Can anyone overcome the problems I see with these tree libraries, or suggest alternative libraries?任何人都可以克服我在这些树库中看到的问题,或者建议替代库吗?

Glib::PollFD::PollFD(int fd) is the constructor that you want. Glib::PollFD::PollFD(int fd) 是您想要的构造函数。 An fd_set is just a set of integer fds.一个 fd_set 只是一组 integer fds。 The word "set" is used in the mathematical sense, ie no fd can occur more than once in a set, therefore they do not refer to it as an array or a list. “集合”这个词是在数学意义上使用的,即 fd 在集合中不能出现多次,因此他们不将其称为数组或列表。 An fd_set is just a fixed size buffer. fd_set 只是一个固定大小的缓冲区。 Try it out by making an fd_set and adding some fds to it, then look at it in a debugger or just dump it out in hex.通过创建一个 fd_set 并向其中添加一些 fd 来尝试一下,然后在调试器中查看它,或者只是将其转储为十六进制。

This is a common patter in async programming where you need to join two async event loops.这是异步编程中的常见模式,您需要加入两个异步事件循环。 While you could poll two loops with a timeout, it is generally better to get the raw fds out of one event loop, and add them虽然您可以轮询两个带有超时的循环,但通常最好将原始 fds 从一个事件循环中取出,然后添加它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM