boost-asio

Setting limit on post queue size with Boost Asio?

穿精又带淫゛_ 提交于 2020-06-24 22:12:05
问题 I'm using boost::asio::io_service as a basic thread pool. Some threads get added to io_service, the main thread starts posting handlers, the worker threads start running the handlers, and everything finishes. So far, so good; I get a nice speedup over single-threaded code. However, the main thread has millions of things to post. And it just keeps on posting them, much faster than the worker threads can handle them. I don't hit RAM limits, but it's still kind of silly to be enqueuing so many

How to pass a boost asio tcp socket to a thread for sending heartbeat to client or server

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-16 23:43:34
问题 I am writing a client/server program in boost TCP in which I want to send a HEARTBEAT message to the client every 2 seconds for which I am trying to create a new thread by which I can send it easily but unable to solve it. I am creating thread using boost::thread t(hearbeatSender,sock); this. but giving lots of errors. I also use bind to bind function name with the socket but not resolved the error. void process(boost::asio::ip::tcp::socket & sock); std::string read_data(boost::asio::ip::tcp:

boost::asio::streambuf - how to reuse buffer?

↘锁芯ラ 提交于 2020-05-26 04:02:07
问题 I'm implementing TCP server that uses both asio socket.async_read() and boost::asio::async_read_until() methods for asynchronous reading data from socket. Both use the same handler for reading data from boost::asio::streambuf. The handler that perfectly works invoked via async_read() : void handle_read(const boost::system::error_code& ec, std::size_t ytes_transferred) ) { m_request_buffer.commit(bytes_transferred); boost::asio::streambuf::const_buffers_type rq_buf_data = m_request_buffer.data

pthread is not starting for class instance

白昼怎懂夜的黑 提交于 2020-05-24 04:04:56
问题 NOTE: C++98 Hi, I'm a little new to c++ and I am writing a databaes program and am attempting to start a timer using the boost::asio package using pthread. The aim of the timer is to start after sql queries have been placed inside a buffer, of which will run an execute function if nothing has been received for a period of time. I have managed to get it to compile, but it doesn't look like the pthread instance is starting. I have called the pthread inside my getInstance method, and the boost:

How do I avoid body_limit error in boost's beast and correctly handle large messages

不羁岁月 提交于 2020-05-15 07:58:04
问题 I have cases when there is a chunked response which is too big for beast, and I want to stop before I get to beast's body_limit , and continue handling the message from that point using plain boost::asio. Mind that this (obviously) means I already received the header and a large part of the body. I'm using it for a reverse proxy, so basically what I want to do is somehow send the incomplete response to the http client, while continuing relaying the remaining response data using boost::asio. I

how spawn and post works with asio?

陌路散爱 提交于 2020-05-13 17:52:35
问题 // I asked this question // https://stackoverflow.com/questions/61026135/asio-use-future-instead-of-yieldec // and comments lead to need to modify code of answer and put in in this new // question. // I tried to ask questions in form of code trials and causes of writing them // or how i under stand them // asio_packaged_task.cpp : Defines the entry point for the console application. //#include "stdafx.h" #define BOOST_COROUTINES_NO_DEPRECATION_WARNING #include <boost/asio.hpp> #include <boost

asio use_future instead of yield[ec]

随声附和 提交于 2020-05-13 14:35:19
问题 i want to make container of futures ,each future is void result of a task so that i could use wait_for_any on the container ,each task is coroutine which i currently implement using yield_context,and inside this coroutine there initiating function which returns ec and result where i use ec to analyze result.and then another coroutine is called passes same yield_context . i want to know how to make this design. and if i ll use use_future ,how can i pass error code to ec not throwing it unless

TIME_WAIT with boost asio

怎甘沉沦 提交于 2020-04-18 04:08:37
问题 I tried the official tcp echo server example server and client. With netstat -ano | findstr TIME_WAIT I can see the client causes a TIME_WAIT every time, while the server disconnects cleanly. Is there anyway to prevent the TIME_WAIT or CLOSE_WAIT, that disconnect cleanly for both sides? Here's the captured packets, seems the last ACK is sent correctly, but still there is TIME_WAIT on client side. 回答1: CLOSE_WAIT is a programming error. The local application has received an incoming close but

io_context.run() in a separate thread blocks

折月煮酒 提交于 2020-04-07 08:49:33
问题 I have a RESTServer.hpp implemented using boost.beast as shown below. #pragma once #include <boost/property_tree/json_parser.hpp> #include <boost/beast/core.hpp> #include <boost/beast/http.hpp> #include <boost/beast/version.hpp> #include <boost/asio.hpp> #include <chrono> #include <cstdlib> #include <ctime> #include <iostream> #include <memory> #include <string> namespace beast = boost::beast; namespace http = beast::http; namespace net = boost::asio; using tcp = boost::asio::ip::tcp; class

boost::asio acceptor reopen and async read after EOF

吃可爱长大的小学妹 提交于 2020-03-06 03:55:27
问题 sadly I've come to a hold in my development since I can not understand how exactly the boost::asio::ip::tcp::acceptor is supposed to be used. The TCPReader class is designed to be a singleton and the header declares the following as private. void runInThread(); void read_handler(const boost::system::error_code &ec, std::size_t bytes_transferred); void accept_handler(const boost::system::error_code &ec); boost::asio::io_service io_service; boost::asio::io_service::work runningService; boost: