boost-asio

boost::asio internal threads

孤人 提交于 2019-12-03 16:37:41
When using boost::asio for some asynchronous TCP communication I noticed it starts a lot of (3-4) internal threads. Reading in the documentation , it says "The implementation of this library for a particular platform may make use of one or more internal threads to emulate asynchronicity" Now my lib has very strict requirements to not start any extra threads (except one that is supplied by the client and which now starts io_service::run() ). Is there any way to stop boost::asio from creating these extra threads? Alternatively, is there any other async library out there that can run in only one

How do it clear all posted tasks which already queued in a strand?

狂风中的少年 提交于 2019-12-03 16:27:13
How do it clear all posted tasks which already queued in a io_service::strand ? I see no similar method from boost document. I have yet to find a need for it, as it can be resolved correctly with properly designing the asynchronous call chains. Generally, the Boost.Asio API is carefully designed in such a way that it prevents complex applications from becoming complicated in the asynchronous flow. If you have examined the call chains, and are absolutely certain that the effort to redesign them is a greater current and future risk than introducing the complication of clearing a strand, then

How to correctly send binary data over HTTPS POST?

时间秒杀一切 提交于 2019-12-03 16:23: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

What's the best way of ensuring valid object lifespan when using Boost.Asio?

被刻印的时光 ゝ 提交于 2019-12-03 16:23:13
问题 Been playing a lot with Boost.Asio of late. I like the library a lot since it offers a fantastic way to squeeze performance out of today's multicore systems. A question I have asked myself a few times, and I thought worth throwing out there regards object lifespan / ownership when making async calls with Asio. The problem I've come accross repeatedly is that you quite often have to "expire" an object that still has async callbacks pending against it. If that object goes out of scope before

using boost:asio with select? blocking on TCP input OR file update

帅比萌擦擦* 提交于 2019-12-03 16:12:32
I had intended to have a thread in my program which would wait on two file descriptors, one for a socket and a second one for a FD describing the file system (specifically waiting to see if a new file is added to a directory). Since I expect to rarely see either the new file added or new TCP messages coming in I wanted to have one thread waiting for either input and handle whichever input is detected when it occures rather then bothering with seperate threads. I then (finally!) got permission from the 'boss' to use boost. So now I want to replace the basic sockets with boost:asio. Only I'm

How strands guarantee correct execution of pending events in boost.asio

雨燕双飞 提交于 2019-12-03 15:56:35
Consider an echo server implemented using Boost.asio. Read events from connected clients result in blocks of data being placed on to an arrival event queue. A pool of threads works through these events - for each event, a thread takes the data in the event and echos it back to the connected client. As shown in the diagram above, there could be multiple events in the event queue all from a single client. In order to ensure that these events for a given client are executed and delivered in order, strands are used. In this case, all events from a given connected client with be executed in a

How to trick boost::asio to allow move-only handlers

感情迁移 提交于 2019-12-03 15:24:42
问题 In a RPC communication protocol, after the invocation of a method I'm sending "done" messages back to the caller. Since the methods are invoked in a concurrent fashion, the buffer containing the response (a std::string ) needs to be protected by a mutex. What I'm trying to achieve is the following: void connection::send_response() { // block until previous response is sent std::unique_lock<std::mutex> locker(response_mutex_); // prepare response response_ = "foo"; // send response back to

Boost Asio how to read/write on a SSL socket that doesnt use SSL?

随声附和 提交于 2019-12-03 15:24:32
The title is my question. I already found a topic related to this here -> Using SSL sockets and non-SSL sockets simultaneously in Boost.Asio? and basically I'm in the same situation but for some reason I couldn't comment there and/or contact the questioner directly so I'm doing this as a new question. I have a set up ssl socket ssl::stream<ip::tcp::socket> socket_; where clients can connect just fine with socket_.async_handshake(ssl::stream_base::server, session::handle_handshake) and then read/write with async_write(socket_, buffer(send_data, send_length), session::handle_read) socket_.async

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

戏子无情 提交于 2019-12-03 15:13:55
问题 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

Create an iostream using boost asio specifying ip and port

白昼怎懂夜的黑 提交于 2019-12-03 13:31:25
问题 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