boost-asio

Why must io_service::reset() be called?

和自甴很熟 提交于 2019-12-01 06:45:28
io_service::reset documentation states that reset() must be called before subsequent calls to run() , run_one() , poll() or poll_one() . Questions: Why is this necessary? - What behaviour might I expect if this step is neglected? Why is this requirement not important enough to warrant an assert if it's neglected? Some context: I finished debugging some unit-tests that checked that called poll() repeatedly without reset() and was attempting to check the expected number of handlers was being executed each time. It appears that with enough calls to poll() , all handlers are eventually executed in

boost asio streambuf don't release memory after calling consume?

做~自己de王妃 提交于 2019-12-01 06:32:41
boost::asio::streambuf b; ... void handler(const boost::system::error_code& e, std::size_t size) { if (!e) { std::stringstream sstr(std::string((std::istreambuf_iterator<char>(&b)), std::istreambuf_iterator<char>())); b.consume(size); ... } } ... boost::asio::async_read_until(s, b, "END\r\n", handler); when the consume method is called, the memory occupied by streambuf b is not released. The memory will grow up as async_read_until is called multiple times. Is my usage correct? Is there any way to free the memory before the get pointer of streambuf? asio::streambuf is based on std::vector that

Why must io_service::reset() be called?

走远了吗. 提交于 2019-12-01 05:34:04
问题 io_service::reset documentation states that reset() must be called before subsequent calls to run() , run_one() , poll() or poll_one() . Questions: Why is this necessary? - What behaviour might I expect if this step is neglected? Why is this requirement not important enough to warrant an assert if it's neglected? Some context: I finished debugging some unit-tests that checked that called poll() repeatedly without reset() and was attempting to check the expected number of handlers was being

boost asio streambuf don't release memory after calling consume?

心不动则不痛 提交于 2019-12-01 05:04:36
问题 boost::asio::streambuf b; ... void handler(const boost::system::error_code& e, std::size_t size) { if (!e) { std::stringstream sstr(std::string((std::istreambuf_iterator<char>(&b)), std::istreambuf_iterator<char>())); b.consume(size); ... } } ... boost::asio::async_read_until(s, b, "END\r\n", handler); when the consume method is called, the memory occupied by streambuf b is not released. The memory will grow up as async_read_until is called multiple times. Is my usage correct? Is there any

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

耗尽温柔 提交于 2019-12-01 04:35:57
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 not be called, thus I never read anything from the serial port. What is the usual approach to this

boost asio asynchronously waiting on a condition variable

烂漫一生 提交于 2019-12-01 04:26:36
Is it possible to perform an asynchronous wait (read : non-blocking) on a conditional variable in boost::asio ? if it isn't directly supported any hints on implementing it would be appreciated. I could implement a timer and fire a wakeup even every few ms, but this is approach is vastly inferior, I find it hard to believe that condition variable synchronization is not implemented / documented. If I understand the intent correctly, you want to launch an event handler, when some condition variable is signaled, in context of asio thread pool? I think it would be sufficient to wait on the

connect on “connection less” boost::asio::ip::udp::socket

不想你离开。 提交于 2019-12-01 04:20:47
I've been learning about UDP socket lately by browsing the net and all the pages that were explaining it were mentioning that UDP sockets are "connection less". This, if I understand it correctly means that one does not have a "connection" between two sockets but instead shoots datagram packets to specified endpoints without knowing whether the other end is listening. Then I go and start reading the boost::asio::ip::udp::socket docs and find that it mentions API like: async_connect: Start an asynchronous connect . async_receive: Start an asynchronous receive on a connected socket . async_send:

How to check if a socket connection is live in Boost::asio?

百般思念 提交于 2019-12-01 03:41:28
I'm using the Boost::asio to implement a client/server applicaion. The client code below is used to connect to the remote server . try { boost::asio::io_service m_io_service; boost::asio::ip::tcp::socket m_socket(m_io_service); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 17); m_socket.connect(endpoint); } catch (std::exception& e) { std::cerr << e.what() << std::endl; } At the client side, I want to check if the connection is live. The function " m_socket.is_open(); " doesn't work. When the server socket is closed, the " m_socket.is_open(); "

boost asio asynchronously waiting on a condition variable

坚强是说给别人听的谎言 提交于 2019-12-01 02:03:13
问题 Is it possible to perform an asynchronous wait (read : non-blocking) on a conditional variable in boost::asio ? if it isn't directly supported any hints on implementing it would be appreciated. I could implement a timer and fire a wakeup even every few ms, but this is approach is vastly inferior, I find it hard to believe that condition variable synchronization is not implemented / documented. 回答1: If I understand the intent correctly, you want to launch an event handler, when some condition

How to check if a socket connection is live in Boost::asio?

情到浓时终转凉″ 提交于 2019-12-01 00:51:54
问题 I'm using the Boost::asio to implement a client/server applicaion. The client code below is used to connect to the remote server . try { boost::asio::io_service m_io_service; boost::asio::ip::tcp::socket m_socket(m_io_service); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 17); m_socket.connect(endpoint); } catch (std::exception& e) { std::cerr << e.what() << std::endl; } At the client side, I want to check if the connection is live. The function