boost-asio

boost::asio::ip::multicast::join_group does not work

倖福魔咒の 提交于 2019-11-30 19:06:31
I tried the example , but it does not work. Apparently it does not set IPPROTO_IP/IP_MULTICAST_IF option. I can only find boost::asio::ip::multicast::outbound_interface for IPPROTO_IP/IP_MULTICAST_IF, I tried but failed. Is there any way to make boost::asio::ip::multicast work without calling c-level setsockopt? boost::asio::ip::udp::endpoint listen_endpoint( listen_address, multicast_port); socket_.open(listen_endpoint.protocol()); socket_.set_option(boost::asio::ip::udp::socket::reuse_address(true)); socket_.bind(listen_endpoint); // Join the multicast group. socket_.set_option( boost::asio:

Calculating the sum of a large vector in parallel

99封情书 提交于 2019-11-30 18:47:25
问题 Problem background I have a program that currently takes way too long to sum up large std::vector s of ~100 million elements using std::accumulate , and this is a bottleneck. I want it to be faster and I want it to be an asynchronous calculation so the GUI/Server doesn't block. The calculation should also be using multithreading so I can reduce the time it takes to sum up a vector. I want to split up the summation so that each thread sums a part of the vector and then when all partial sums

boost asio deadline_timer

徘徊边缘 提交于 2019-11-30 18:43:41
I expected the code below to print Hello, world! every 5 seconds, but what happens is that the program pauses for 5 seconds and then prints the message over and over with no subsequent pauses. What am I missing? #include <iostream> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> using namespace boost::asio; using namespace std; io_service io; void print(const boost::system::error_code& /*e*/) { cout << "Hello, world!\n"; deadline_timer t(io, boost::posix_time::seconds(5)); t.async_wait(print); } int main() { deadline_timer t(io, boost::posix_time::seconds(5)); t

How do you post a boost packaged_task to an io_service in C++03?

筅森魡賤 提交于 2019-11-30 18:41:48
This is a follow-on from a previous question ( here ), but I'm working on a multithreaded application and I would like to post a Boost packaged_task to a threaded io_service. I'm stuck using a C++03 compiler (so std::move is out), and the packaged_task is not copyable. I've tried wrapping it in a shared_ptr and passing that, and a lot of other things. Here is my current attempt and the subsequent compiler errors. Any idea how to get this to work? boost::asio::io_service io_service; boost::thread_group threads; boost::asio::io_service::work work(io_service); for (int i = 0; i < maxNumThreads; +

boost::thread data structure sizes on the ridiculous side?

孤街浪徒 提交于 2019-11-30 18:11:14
问题 Compiler: clang++ x86-64 on linux. It has been a while since I have written any intricate low level system code, and I ussualy program against the system primitives (windows and pthreads/posix). So, the in#s and out's have slipped from my memory. I am working with boost::asio and boost::thread at the moment. In order to emulate synchronous RPC against an asynchronous function executor ( boost::io_service with multiple threads io::service::run 'ing where requests are io_serviced::post 'ed), I

EOF in async_read() in boost::asio

一世执手 提交于 2019-11-30 18:06:16
When the async_read_some() returns an exception of EOF does it mean the server stopped sending data or does it mean the connection is closed. I'm having this confusion as I cant find a method to know if the client has received all data from server. It indicates the connection has closed. Although documented elswhere it is still applicable: An error code of boost::asio::error::eof indicates that the connection was closed by the peer. If a client needs to know that all data has been received from the server, then consider supporting framing in the communication protocol. Boost.Asio provides

How to discard data as it is sent with boost::asio?

匆匆过客 提交于 2019-11-30 18:04:00
问题 I'm writing some code that reads and writes to serial device using boost::asio class. However, when sending several strings between programs, I've noticed that on the receiving program the data is read in the order as it was written to the serial port, and not as the data is sent from the other program - If I start reading data some seconds later, I don't get the values that I am sending at the moment but those that were sent previously. I'm assuming this is caused by how I am setting up my

Remove all handlers from a boost::asio::io_service without calling them

孤人 提交于 2019-11-30 17:52:16
I want to remove all handlers from an IO_service right before I reuse it. Is this possible? I'm writing unit tests that involve an asio::io_service . In between each test case I want to clear the handlers from the global io_service . I thought that io_service::reset would to that but it doesn't. reset() only allows the io_service to be resumed. All of the handlers from the last test case are still queued up. I only need to do this for unit testing so any crazy hack would work. More info: The io_service is from a deadline_timer member variable. The deadline_timer is part of the code I'm testing

How to use std::string with asio::buffer()

十年热恋 提交于 2019-11-30 17:41:45
I get the following error message when I'm trying to use std::string with boost::asio::buffer: boost/asio/detail/consuming_buffers.hpp: In constructor 'boost::asio::detail::consuming_buffers< boost::asio::mutable_buffer, boost::asio::const_buffers_1 ::consuming_buffers(const boost::asio::const_buffers_1 &)': boost/asio/impl/read.hpp:140:25: instantiated from 'boost::asio::detail::read_op< boost::asio::basic_stream_socket, boost::asio::const_buffers_1 , boost::asio::detail::transfer_all_t , boost::_bi::bind_t< void, boost::_mfi::mf1 , boost::_bi::list2, boost::arg<1> (*)()> ::read_op( boost:

boost asio io_service.run()

橙三吉。 提交于 2019-11-30 17:33:40
I was just going over the asio chat server example . My question is about their usage of the io_service.run() function. The documentation for the io_service.run() function says: The run() function blocks until all work has finished and there are no more handlers to be dispatched, or until the io_service has been stopped. Multiple threads may call the run() function to set up a pool of threads from which the io_service may execute handlers. All threads that are waiting in the pool are equivalent and the io_service may choose any one of them to invoke a handler. The run() function may be safely