boost-asio

Boost::asio server/client socket, access permissions and ports issue

狂风中的少年 提交于 2019-12-30 11:24:06
问题 A new error arose with my server (boost::asio based) once I implemented reconnection on my client but I am not even sure if this is the cause. The scenario is like this: I run Client.exe which can reconnect in case a server is not running. Client.exe creates several objects which connect independently to my server. So several connections to my servers are created from the same process. Because I haven't run the server yet, every object try to reconnect every 3 seconds (some of them

Can I share boost::asio::tcp::socket object between 2 threads that perform read and write

微笑、不失礼 提交于 2019-12-30 10:06:43
问题 I have two threads, one sending and another receiving data via TCP socket. I use boost::asio::read() and boost::asio::write() for reading and writing. My question is do I have to guard the access to socket object during read and write operation? The other case would be what if I have two threads both writing using the same socket object? 回答1: The socket is not thread safe when shared between two or more threads. For more information look at the Boost.Asio documentation. 来源: https:/

How to implement a QThread that runs forever{} with a QWaitCondition but still needs to catch another Slot while doing that

微笑、不失礼 提交于 2019-12-30 08:36:14
问题 I implemented a class that can write data to a serial port via a QQueue and read from it by a slot. I use QAsyncSerial for this which in turn uses boost::asio with a callback. The class is moved to a thread and its start() method is executed when the QThread emits "started()" The problem is that I dequeue the QQueue in the start()-method using forever {} and a QWaitCondition. While this is running (which obviously runs forever) the slot connected to the dataReceived signal of QAsyncSerial can

Force boost::asio::buffer to copy by value

丶灬走出姿态 提交于 2019-12-30 08:26:46
问题 I use boost::asio::buffer to send a message using void Send(const std::string& messageData) { socket.async_write(boost::asio::buffer(messageData), ...); } And encounter "string iterator not dereferencable" runtime error somewhere within io_service' thread. When I create objects' variable to store message data for the buffer: void Send(const std::string& messageData) { this->tempStorage = messageData; socket.async_write(boost::asio::buffer(this->tempStorage), ...); } the error is never occured

cancel a deadline_timer, callback triggered anyway

浪子不回头ぞ 提交于 2019-12-30 07:00:14
问题 I was suprised not to find a clock component in boost::asio (our any widely used library) so it tried making a simple, minimalistic, implementation for testing some of my code. Using boost::asio::deadline_timer I made the following class class Clock { public: using callback_t = std::function<void(int, Clock&)>; using duration_t = boost::posix_time::time_duration; public: Clock(boost::asio::io_service& io, callback_t callback = nullptr, duration_t duration = boost::posix_time::seconds(1), bool

Scalability of Boost.Asio

人盡茶涼 提交于 2019-12-30 06:38:06
问题 I'm curious how far others have pushed Boost.Asio in terms of scalability. I am writing an application that may use close to 1000 socket objects, a handful of acceptor objects, and many thousand timer objects. I've configured it such that there's a thread pool invoking io_service::run and use strand s in the appropriate places to ensure my handlers do not stomp on each other. My platform is Red Hat Enterprise Linux with Boost 1.39, though I'm not opposed to upgrading to a more recent version

how to use asio with device files

送分小仙女□ 提交于 2019-12-30 06:18:06
问题 I'm using boost asio throughout my project. I now want to read a device file ( /dev/input/eventX ). In the boost asio documentation it states that normal file IO is not possible but device files or pipes are supported by using asio::posix::stream_descriptor. I opened the file descriptor via open and assigned it to the stream_descriptor. I now issue a async_read() call which never returns. Is it possible to use boost asio with input events? Do I need to configure the file handle before using

boost asio deadline_timer

痴心易碎 提交于 2019-12-30 06:03:47
问题 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:

EOF in async_read() in boost::asio

一曲冷凌霜 提交于 2019-12-30 05:59:08
问题 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. 回答1: 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

How to asynchronously read input from command line using boost asio in Windows?

久未见 提交于 2019-12-30 02:25:27
问题 I found this question which asks how to read input asynchronously, but will only work with POSIX stream descriptors, which won't work on Windows. So, I found this tutorial which shows that instead of using a POSIX stream descriptor I can use a boost::asio::windows::stream_handle . Following both examples I came up with the code below. When I run it, I cannot type anything into the command prompt, as the program immediately terminates. I'd like it to capture any input from the user, possibly