boost-asio

Payload split over two TCP packets when using Boost ASIO, when it fits within the MTU

淺唱寂寞╮ 提交于 2019-12-06 22:52:44
问题 I have a problem with a boost::asio::ip::tcp::iostream. I am trying to send about 20 raw bytes. The problem is that this 20 byte payload is split into two TCP packets with 1 byte, then 19 bytes. Simple problem, why it is happening I have no idea. I am writing this for a legacy binary protocol that very much requires the payload to fit in a single TCP packet (groan). Pasting the whole source from my program would be long and overly complex, I've posted the functional issue just within 2

boost::asio over SocketCAN

时光怂恿深爱的人放手 提交于 2019-12-06 22:03:54
问题 I was thinking of making use of Boost Asio to read data from a Socket CAN. There's nothing fancy going on in linux/can.h , and the device should behave like the loopback interface, and be used with a raw socket. Looking at the basic_raw_socket interface it seems that I can make use of basic_raw_socket::assign to assign the native socket created with socket( PF_CAN, SOCK_RAW, CAN_RAW ); This is what I have so far namespace can { class CanSocket { public: typedef boost::asio::ip::basic_endpoint

boost::asio::deadline_timer with std::chrono time values

老子叫甜甜 提交于 2019-12-06 17:30:32
问题 I have an application that uses asio deadline timers. The rest of the application uses std::chrono constructs for its time values, and it feels awkward to use boost::posix_time for only the stuff that touches asio. I'd like to use std::chrono throughout the application if I can, for consistency, readability, etc. It seems to me that the answer would involve using the timer's template: typedef boost::asio::basic_deadline_timer<std::chrono::system_clock::time_point> my_deadline_timer_type; my

boost async_wait and adding “this” in a bind [duplicate]

孤街浪徒 提交于 2019-12-06 16:48:29
This question already has an answer here : How to use boost bind with a member function (1 answer) Closed 4 years ago . In this example of using a boost asynchronous timer inside a class, the author added "this" pointer to the bind function inside m_timer.async_wait method. That's strange because the handler is a public method (message(void)) that takes no argument, so why the hell using boost::bind and especially the pointer "this" ? class handler { public: handler(boost::asio::io_service& io) : m_timer(io, boost::posix_time::seconds(1)), m_count(0) { m_timer.async_wait(boost::bind(&handler:

boost::asio::async_read bind compilation error

Deadly 提交于 2019-12-06 15:08:06
I can't figure out why I get this error : /usr/local/include/boost/asio/impl/read.hpp: In member function ‘void boost::asio::detail::read_op<AsyncReadStream, boost::asio::mutable_buffers_1, CompletionCondition, ReadHandler>::operator()(const boost::system::error_code&, size_t, int) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, CompletionCondition = boost::asio::detail::transfer_at_least_t, ReadHandler = boost::function<void ()(long unsigned int)>]’: /usr/local/include/boost/asio/impl/read.hpp:263:

Simple proxy using C++/boost::asio/libcurl - can't download images

╄→гoц情女王★ 提交于 2019-12-06 15:04:34
问题 I'm trying to implement a very simple proxy server with the following code. You set your browser's proxy to 192.168.1.x:8080 and web pages are accessible through the proxy. #include <ctime> #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <boost/asio.hpp> #include <boost/algorithm/string.hpp> #include <curl/curl.h> #include <cstdlib> using boost::asio::ip::tcp; int port=8080; //CURL *curl; /

async_resolve and async_connect params lifetime

旧时模样 提交于 2019-12-06 14:50:25
I would like to know what is lifetime of objects passed to mentioned methods. async_resolve ip::basic_resolver::async_resolve(const query & q, ResolveHandler handler); (1) Do I need to keep resolver alive until handler is called? (yes) (2) Does async_resolve copy query object? (I am passing one created on the stack - yes) { boost::asio::ip::tcp::resolver::query query(host_, port_); resolver_.async_resolve(query, ); } (3) Is boost::asio::ip::tcp::resolver::iterator returned in handler by value? (yes) async_connect template<..> void async_connect(basic_socket<Protocol, SocketService> & s,

How to retrieve program output as soon as it printed?

孤街浪徒 提交于 2019-12-06 12:01:11
I have a boost::process::child. There are many examples on how to get all its stdout or stderr in a single vector, but in this method you capture all data at once. But how to retrieve lines/characters as soon as they are printed in child process? The docs are here: Synchronous IO Asynchronous IO Using ipstream The simplest way: Live On Coliru #include <boost/process.hpp> #include <iostream> namespace bp = boost::process; int main() { std::vector<std::string> args { "-c", R"--(for a in one two three four; do sleep "$(($RANDOM%2)).$(($RANDOM%10))"; echo "line $a"; done)--" }; bp::ipstream output

What is the performance difference between strand.post and strand.wrap?

喜你入骨 提交于 2019-12-06 11:52:31
What is the performance difference between strand::post() and strand::wrap() ? And what's the story about race condition when use strand::wrap( )? Just for clarification, strand::wrap only creates a handler, neither the provided handler nor returned handler are dispatched or posted to the io_service . If the result from strand::wrap is executed, then performance differences from overhead is negligible. However, a perceived performance difference could occur as the result of the wrapped handler using dispatch() , where under certain conditions the user's handler will be executed immediately,

Using Boost.Asio to get “the whole packet”

本小妞迷上赌 提交于 2019-12-06 11:45:56
问题 I have a TCP client connecting to my server which is sending raw data packets. How, using Boost.Asio, can I get the "whole" packet every time (asynchronously, of course)? Assume these packets can be any size up to the full size of my memory. Basically, I want to avoid creating a statically sized buffer. 回答1: typically, when you do async IO, your protocol should support it. one easy way is to prefix a byte array with it's length at the logical level, and have the reading code buffer up until