boost-asio

Clear boost::asio::io_service after stop()

[亡魂溺海] 提交于 2019-12-18 02:54:11
问题 I am using (single threaded) a boost::asio:io_service to handle a lot of tcp connections. For each connection I use a deadline_timer to catch timeouts. If any of the connections times out, I can use none of the results of the other connections. Therefore I want to completely restart my io_service. I thought that calling io_service.stop() would allow "finished" handlers in the queue to be called and would call handlers in the queue with an error. However it looks like the handlers remain in

How resume the execution of a stackful coroutine in the context of its strand?

自古美人都是妖i 提交于 2019-12-18 01:32:13
问题 using Yield = asio::yield_context; using boost::system::error_code; int Func(Yield yield) { error_code ec; asio::detail::async_result_init<Yield, void(error_code, int)> init(yield[ec]); std::thread th(std::bind(Process, init.handler)); int result = init.result.get(); // <--- yield at here return result; } How to implement Process so that Func will resumed in the context of the strand that Func was originally spawned on? 回答1: Boost.Asio uses a helper function, asio_handler_invoke, to provide a

Linker error when compiling boost.asio example

天涯浪子 提交于 2019-12-17 18:54:41
问题 I'm trying to learn a little bit C++ and Boost.Asio. I'm trying to compile the following code example: #include <iostream> #include <boost/array.hpp> #include <boost/asio.hpp> using boost::asio::ip::tcp; int main(int argc, char* argv[]) { try { if (argc != 2) { std::cerr << "Usage: client <host>" << std::endl; return 1; } boost::asio::io_service io_service; tcp::resolver resolver(io_service); tcp::resolver::query query(argv[1], "daytime"); tcp::resolver::iterator endpoint_iterator = resolver

boost asio write/read vector

杀马特。学长 韩版系。学妹 提交于 2019-12-17 17:11:18
问题 I have trouble reading a vector from boost asio buffer. I have this vector: std::vector<float> points; And I send it with boost asio write boost::asio::write (socket, boost::asio::buffer(&new_buffers->points.front(), nr_points * 3 * sizeof (float))); On the other end I have: std::vector<float> recv_vector; tcp_socket.async_read_some(boost::asio::buffer(recv_vector), read_handler); When I do recv_vector.size() , its always empty. Can somebody tell me what I am doing wrong? Marek 回答1: Asio is

Get Local IP-Address using Boost.Asio

╄→гoц情女王★ 提交于 2019-12-17 15:36:17
问题 I'm currently searching for a portable way of getting the local IP-addresses. Because I'm using Boost anyway I thought it would be a good idea to use Boost.Asio for this task. There are several examples on the net which should do the trick. Examples: Official Boost.Asio Documentation Some Asian Page I tried both codes with just slight modifications. The Code on Boost.Doc was changed to not resolve "www.boost.org" but "localhost" or my hostname instead. For getting the hostname I used boost:

Strange exception throw - assign: Operation not permitted

回眸只為那壹抹淺笑 提交于 2019-12-17 14:17:14
问题 I want to do asynchronous read from cin therefore I have a piece of code client.h ... boost::asio::posix::stream_descriptor input; boost::asio::streambuf input_buffer client.cpp Client::Client(int argc, char **argv, boost::asio::io_service &io_service) : tcp_socket(io_service) , udp_socket(io_service) , input(io_service, ::dup(STDIN_FILENO)) { ... read_std_input(); } void Client::read_std_input() { async_read_until(input, input_buffer, '\n', boost::bind(&Client::handle_std_read, this, boost:

Strange exception throw - assign: Operation not permitted

元气小坏坏 提交于 2019-12-17 14:15:27
问题 I want to do asynchronous read from cin therefore I have a piece of code client.h ... boost::asio::posix::stream_descriptor input; boost::asio::streambuf input_buffer client.cpp Client::Client(int argc, char **argv, boost::asio::io_service &io_service) : tcp_socket(io_service) , udp_socket(io_service) , input(io_service, ::dup(STDIN_FILENO)) { ... read_std_input(); } void Client::read_std_input() { async_read_until(input, input_buffer, '\n', boost::bind(&Client::handle_std_read, this, boost:

boost::asio + std::future - Access violation after closing socket

坚强是说给别人听的谎言 提交于 2019-12-17 09:59:16
问题 I am writing a simple tcp client to send and receive single lines of text. The asynchronous operations are handled by std::future in order to faciliate blocking queries with timeouts. Unfortunately, my test application crashes with an access violation when destructing the server object. Here is my code: TCPClient.hpp #ifndef __TCPCLIENT_H__ #define __TCPCLIENT_H__ #include <boost/asio.hpp> #include <boost/asio/use_future.hpp> #include <memory> #include <vector> #include <future> #include

BOOST ASIO - How to write console server

瘦欲@ 提交于 2019-12-17 09:53:44
问题 I have to write asynchronous TCP Sever. TCP Server have to be managed by console (for eg: remove client, show list of all connected client, etcc..) The problem is: How can I attach (or write) console, which can calls above functionalities. This console have to be a client? Should I run this console client as a sepearate thread? I have read a lot of tutorials and I couldn`t find a solution to my problem. ServerTCP code class ServerTCP { public: ServerTCP(boost::asio::io_service& A_ioService,

BOOST ASIO - How to write console server

穿精又带淫゛_ 提交于 2019-12-17 09:53:12
问题 I have to write asynchronous TCP Sever. TCP Server have to be managed by console (for eg: remove client, show list of all connected client, etcc..) The problem is: How can I attach (or write) console, which can calls above functionalities. This console have to be a client? Should I run this console client as a sepearate thread? I have read a lot of tutorials and I couldn`t find a solution to my problem. ServerTCP code class ServerTCP { public: ServerTCP(boost::asio::io_service& A_ioService,