boost-asio

why must a Boost.Asio handler be copy constructible?

夙愿已清 提交于 2021-02-18 20:51:52
问题 According to http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/reference/Handler.html, a handler provided to io_service::post must be copy constructible. However, this excludes a scenario where a socket is accepted, and the response handler is moved, guaranteeing me that there is only one handler for the job: auto socket = std::make_unique<socket>(); accepter.accept(*socket); service.post([s{std::move(socket)}] { asio::write(*s, buffer("response"), ignored_err); }); So why is this copy

Using futures with boost::asio

空扰寡人 提交于 2021-02-17 21:52:10
问题 Does anyone have a good pointer to examples which use futures from the Boost thread library with Boost ASIO? I have an existing asynchronous library which uses callback function that I would like to provide a friendlier synchronous interface for. 回答1: It is difficult to provide a concise solution without understanding the interactions with the existing asynchronous library. Nevertheless, this answer uses Boost.Future and Boost.Asio to implement an Active Object pattern. When creating a future

Boost receive data from the tcp socket

折月煮酒 提交于 2021-02-11 01:16:36
问题 I am trying to read specific number of bytes from the socket. My server is sending: 1) byte[0] - length of the message 2) byte[1:N] - the actual message How do I read the first byte and then read the remaining bytes using boost::asio::ip::tcp::socket::read ? Here is the code snippet: // receive data through the socket void TCPTestClient::ReceiveData( ) { try { boost::system::error_code error; boost::asio::streambuf receivedStreamBuffer; // reserve 512 bytes in output sequence boost::asio:

Boost receive data from the tcp socket

我是研究僧i 提交于 2021-02-11 01:13:11
问题 I am trying to read specific number of bytes from the socket. My server is sending: 1) byte[0] - length of the message 2) byte[1:N] - the actual message How do I read the first byte and then read the remaining bytes using boost::asio::ip::tcp::socket::read ? Here is the code snippet: // receive data through the socket void TCPTestClient::ReceiveData( ) { try { boost::system::error_code error; boost::asio::streambuf receivedStreamBuffer; // reserve 512 bytes in output sequence boost::asio:

How to eliminate crashes when destroying boost::asio entities on fly?

主宰稳场 提交于 2021-02-10 09:22:33
问题 Note!!! The question is for people who are experts in boost::asio library . Unfortunately, I cannot do the code more compact, It contains a minimum amount to describe the problem. The code is example, artificially created. Places where it crashes known and described in comments, it is designed to illustrate the crashes!!! NO need any help with debugging of the code... The question is about how to design the asio server, not about - where it crashes!!! This example is close to "chat server"

asio::io_service is ending immediately with work

亡梦爱人 提交于 2021-02-10 05:12:38
问题 I'm trying to learn io_service and work with shared pointers. I want the code to work infinitely until I call stop method or sth like this. Unfortunately after seeing workHandler's output on the screen the program shutdowns. Can anybody explain why this happen? #include <boost/asio.hpp> #include <iostream> #include <atomic> #include <memory> #include <thread> #include <vector> class Service : public std::enable_shared_from_this<Service> { std::shared_ptr<boost::asio::io_service> _service; std

SSL tunnel with Boost::Beast

ぃ、小莉子 提交于 2021-02-09 09:57:01
问题 I want to connect to a proxy server that only allows HTTP connections, to speak with the target server by HTTPS. The proxy server documentation states that the only way to do that is by means of the HTTP Connect verb (they are planning to add direct HTTPS connections to the proxy server itself, but for the moment only HTTP connections are allowed). In my C++ program, I successfully connected and worked with the target server using ssl_stream 's during a couple of months, using boost::asio

SSL tunnel with Boost::Beast

﹥>﹥吖頭↗ 提交于 2021-02-09 09:56:18
问题 I want to connect to a proxy server that only allows HTTP connections, to speak with the target server by HTTPS. The proxy server documentation states that the only way to do that is by means of the HTTP Connect verb (they are planning to add direct HTTPS connections to the proxy server itself, but for the moment only HTTP connections are allowed). In my C++ program, I successfully connected and worked with the target server using ssl_stream 's during a couple of months, using boost::asio

Using boost::asio::deadline_timer inside a thread

这一生的挚爱 提交于 2021-02-08 10:42:28
问题 I used boost::asio::deadline_timer to run a function. I have MosquitoInterface class as follow class MosquitoInterface{ MosquitoInterface(deadline_timer &timer) : t(timer){} } Inside my main.c int main(int argc, char** argv ) { io_service io; deadline_timer t(io); MosquitoInterface *m = new MosquitoInterface(t); io.run(); d = new Detectdirection(); while(run) { int ret = d->Tracking(); if(ret < 0) cout << "Pattern is not found" << endl ; } if(d!=NULL) delete d; if(m!=NULL) delete m; cout <<

Loading CA certificate from memory

ぃ、小莉子 提交于 2021-02-08 02:00:46
问题 I am trying to load CA certificate from memory instead of file. But I keep getting handshake error while connecting. The file loading works perfectly, memory loading fails. What am I missing? std::ifstream file("message_server_ca.crt"); std::vector<char> fileContents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); boost::asio::const_buffer buffer(&fileContents.at(0),fileContents.size()); bool useFile = false; // switch between file and memory loading. boost::asio: