boost-asio

boost::asio::io_service occupied queue lengths for timers and posts

六眼飞鱼酱① 提交于 2019-12-03 05:58:51
I'm fairly new to boost::asio, but I'm working on a project that has already existed for a few years and uses asio extensively. My current assignment is to add periodic metrics about various things the system is doing. One of the metrics is to observe how deep the boost::asio::io_service work queues and timer queues become at an arbitrary period of runtime. So I need to be able to ask a boost:asio::io_service object how many things it has in its queues. To illustrate what I'm asking, consider the following: boost::asio::io_service asio_service; asio_service.post( boost::bind( do_work, "eat" )

Does boost::asio::io_service preserve the order of handlers?

北城以北 提交于 2019-12-03 05:54:26
Does boost::asio::io_service guarantee that handlers are called in the same order that they are given via post() ? I can't find anything saying this in the documentation. Assume that calls to io_service::post are serialized. The current implementation does execute things in the sequence you post them, but ordering is only guaranteed for handlers that are explicitly post()ed through a strand . afaik if you want guaranteed ordering of post handler execution you have to use strand as described in the docs . 来源: https://stackoverflow.com/questions/6442812/does-boostasioio-service-preserve-the

How to correctly send binary data over HTTPS POST?

↘锁芯ラ 提交于 2019-12-03 05:44:27
I send binary data from client (Debian 6.0.3) to server (Windows Server 2003). To bypass most firewalls I use HTTPS POST . Client and server are implemented using Boost.Asio and OpenSSL . First I implemented the simplest possible version and it worked fine. HTTP Header: POST / HTTP/1.1 User-Agent: my custom client v.1 [binary data] ( [binary data] is not base64 encoded if this matters) Then, on another client machine it failed (connected to the same server machine). The behavior is not stable. Connection always is established fine (port 443). Most time I pass SSL handshake fine but server

How to turn URL into IP address using boost::asio?

笑着哭i 提交于 2019-12-03 04:54:54
So I need some way of turning given Protocol://URLorIP:Port string into string ip int port How to do such thing with boost ASIO and Boost Regex? Or is it possible - to get IP using C++ Net Lib (boost candidate) - notice - we do not need long connection - only IP. So I currently use such code for parsing #include <boost/regex.hpp> #include <vector> #include <string> int main(int argc, char** argv) { if (argc < 2) return 0; std::vector<std::string> values; boost::regex expression( // proto host port "^(\?:([^:/\?#]+)://)\?(\\w+[^/\?#:]*)(\?::(\\d+))\?" // path file parameters "(/\?(\?:[^\?#/]*/)

What does boost::asio::spawn do?

删除回忆录丶 提交于 2019-12-03 04:38:45
问题 I am unable to form a mental picture of how the control flow happens with spawn. When I call spawn(io_service, my_coroutine) , does it add a new handler to the io_service queue that wraps a call to the my_coroutine ? When inside the coroutine I call an async function passing it my yield_context , does it suspend the coroutine until the async operation completes? void my_coroutine(yield_context yield) { ... async_foo(params ..., yield); ... // control comes here only once the async_foo

boost::asio read n bytes from socket to streambuf

自闭症网瘾萝莉.ら 提交于 2019-12-03 03:58:36
问题 I have a serialized structure, which is being sent via socket. I need to read it in chunks, since one of its fields contains the size of the data remaining: I need to read first few bytes, find out the length and read the rest. This is what I have got: boost::asio::streambuf buffer; boost::system::error_code err_code; // here I need to read only first 16 bytes boost::asio::read(socket, buffer, err_code); std::istream is(&buffer); boost::archive::binary_iarchive ia(is); ia >> my_struct; I have

Use same udp socket for async receive/send

主宰稳场 提交于 2019-12-03 03:38:43
I use the same socket in my udp server in order to receive data from clients on some port, and later after processing of requests respond to to clients using ip::ud::socket ::async_send_to Receive is done async with async_receive_from also. The socket uses same ioService (it's the same socket after all) The documentation does not state clearly if one can have at a moment the same udp socket receive datagrams from client A (in async way) and possibly send another datagram to client B (async sent) at the same time I suspect this could lead to problems. I ended up using same socket for reply

boost::asio, threads and synchronization

一曲冷凌霜 提交于 2019-12-03 03:31:13
This is somewhat related to this question , but I think I need to know a little bit more. I've been trying to get my head around how to do this for a few days (whilst working on other parts), but the time has come for me to bite the bullet and get multi-threaded. Also, I'm after a bit more information than the question linked. Firstly, about multi-threading. As I have been testing my code, I've not bothered with any multi-threading. It's just a console application that starts a connection to a test server and everything else is then handled. The main loop is this: while(true) { Root::instance(

Create an iostream using boost asio specifying ip and port

限于喜欢 提交于 2019-12-03 03:26:48
I have a problem concerning boost asio libraries. I successfully tried to create a socket between a client and a server, this involves creation of resolvers in order to specify ip and port to the server (the server only requires port) and other objects, but, most importantly, it is necessary to use write and read_some as functions to read and write from/in the socket. I would really appreciate to use a stream, and this is possible in boost asio, but that's strange... In almost all examples using streams, to create a server it is necessary to provide port, ok, let's talk about the client...

boost shared_from_this<>()

99封情书 提交于 2019-12-03 03:07:59
could someone summarize in a few succinct words how the boost shared_from_this<>() smart pointer should be used, particularly from the perspective of registering handlers in the io_service using the bind function. EDIT: Some of the responses have asked for more context. Basically, I'm looking for "gotchas", counter-intuitive behaviour people have observed using this mechanism. The biggest "gotcha" I've run into is that it's illegal to call shared_from_this from the constructor. This follows directly from the rule that a shared_ptr to the object must exist before you can call shared_from_this.