boost-asio

Unblock synchronous read on boost::asio::serial_port

自闭症网瘾萝莉.ら 提交于 2019-12-23 08:47:08
问题 I have a boost::thread which performs synchronous reads on a boost::asio::serial_port . When I destroy an instance of the class which contains both, I want the thread to end gracefully even if its blocked in a read call. How can I do this? Looking at the docs, I tried cancel , but it works only for asynchronous reads/writes. Then I tried close , but I got an exception and it wasn't the kind you can recover from. Perhaps using send_break or native_handle ? (this is Windows and portability's

Unable to detect C++ synchronous boost::asio::ip::tcp::socket connection being closed

孤街醉人 提交于 2019-12-23 06:07:10
问题 I am using boost::asio to make a synchronous TCP socket connection to a node.js TCP server application that runs on the same computer. I am using Embarcadero RAD studio XE4 on Windows building 64 bit application that uses the Embarcadero integrated boost version 1.50. Things work fine except when the node.js TCP server shuts down. When this occurs my C++ client application does not detect the disconnection when I read from the socket. However, it does detect the disconnection when I write to

Unable to detect C++ synchronous boost::asio::ip::tcp::socket connection being closed

流过昼夜 提交于 2019-12-23 06:07:03
问题 I am using boost::asio to make a synchronous TCP socket connection to a node.js TCP server application that runs on the same computer. I am using Embarcadero RAD studio XE4 on Windows building 64 bit application that uses the Embarcadero integrated boost version 1.50. Things work fine except when the node.js TCP server shuts down. When this occurs my C++ client application does not detect the disconnection when I read from the socket. However, it does detect the disconnection when I write to

Boost Asio serial port issue

China☆狼群 提交于 2019-12-23 05:01:59
问题 I'm using CodeBlocks on a windows systems and have downloaded Boost, complied and setup my IDE variables and build options. I have been successfully using other boost libraries and now I need to work on a program that reads and writes to a serial port. I can not get any example that I try to compile for asio serial port. The following, for example will generate a compile error which follows the code: #include <iostream> #include <boost/asio.hpp> #include <boost/asio/serial_port.hpp> #include

Boost Asio async_read doesn't stop reading?

我的未来我决定 提交于 2019-12-23 04:17:08
问题 So, I've been playing around with the Boost asio functions and sockets (specifically the async read/write). Now, I thought that boost::asio::async_read only called the handler when a new buffer came in from the network connection... however it doesn't stop reading the same buffer and thus keeps calling the handler. I've been able to mitigate it by checking the number of bytes transferred, however it is basically in a busy-waiting loop wasting CPU cycles. Here is what I have: class tcp

ASIO UDP: class std::allocator<void> has no member named ‘construct’

三世轮回 提交于 2019-12-23 02:13:32
问题 I have followed this example to set up an asynchronous UDP receive. But it fails on compilation: g++ -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 test1.cpp Error message: In file included from /usr/include/c++/5/ext/alloc_traits.h:36:0, from /usr/include/c++/5/bits/basic_string.h:40, from /usr/include/c++/5/string:52, from /usr/include/c++/5/stdexcept:39, from /usr/include/c++/5/array:38, from /usr/include/c++/5/tuple:39, from /usr/include/c++/5/functional:55, from /usr/include/c++/5

BOOST ASIO: Why don't I get “bind: Address already in use” in Windows (but do get it in Linux)?

最后都变了- 提交于 2019-12-23 01:12:10
问题 Trying to bind an already bound TCP port should raise exception ("bind: Address already in use" exception). It does happen under Linux. But under Windows , no exception is raised.. Could it be because under windows it tries to bind to ANY interface? but in Linux it tries to bind to ALL of them and raise an exception if not all of them are bound ? Here is the code snippet: try { tcp::endpoint endpoint(tcp::v4(), 8081); tcp::acceptor acceptor(io_service); acceptor.open(endpoint.protocol());

Compiling issues with boost

泄露秘密 提交于 2019-12-22 20:05:12
问题 I'm having problems with compiling a program which includes "boost/asio.hpp". Compiling this program(taken from boost site): example.cpp: #include <boost/lambda/lambda.hpp> #include <iostream> #include <iterator> #include <algorithm> int main() { using namespace boost::lambda; typedef std::istream_iterator<int> in; std::for_each( in(std::cin), in(), std::cout << (_1 * 3) << " " ); } with c++ -I path/to/boost_1_55_0 example.cpp -o example works fine. But when the program includes: boost/asio

Compiling issues with boost

落花浮王杯 提交于 2019-12-22 20:01:34
问题 I'm having problems with compiling a program which includes "boost/asio.hpp". Compiling this program(taken from boost site): example.cpp: #include <boost/lambda/lambda.hpp> #include <iostream> #include <iterator> #include <algorithm> int main() { using namespace boost::lambda; typedef std::istream_iterator<int> in; std::for_each( in(std::cin), in(), std::cout << (_1 * 3) << " " ); } with c++ -I path/to/boost_1_55_0 example.cpp -o example works fine. But when the program includes: boost/asio

How to retrieve program output as soon as it printed?

柔情痞子 提交于 2019-12-22 17:58:08
问题 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? 回答1: 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