boost-asio

What socket send/recv operations can run concurrently using Boost.Asio

假如想象 提交于 2019-12-10 23:28:43
问题 I am aware that one can run async_send and async_receive operations concurrently on TCP and UDP sockets. But what is the expected behavior in these situations: calling two async_send operations concurrently on an UDP socket. calling two async_receive operations concurrently on an UDP socket. calling two async_send operations concurrently on a TCP socket. calling two async_receive operations concurrently on a TCP socket. I'm mainly interested in the first case; since UDP doesn't necessarily

How to determine if there are bytes available to be read from boost:asio:serial_port

孤者浪人 提交于 2019-12-10 21:56:07
问题 I am trying to use boost to communicate serially between my desktop and an arduino. In arduino space, I can ask the serial port whether or not there are bytes available before trying to perform a read. I am having trouble finding the equivalent for boost::asio::serial_port. 回答1: While Boost.Asio does not provide direct support for this, one can still accomplish this by using serial port's native_handle() with system specific calls. Consult the system's documentation to determine how to query

Boost::Asio. In which thread is the message sent?

梦想的初衷 提交于 2019-12-10 21:15:07
问题 I'm trying to understand the internal work of boost::asio library, which is really great. I've written a simple client that sends one message to a server. The question is - in which thread does it really send the message? Since I use async_write() method, it returns immediately after calling and doesn't send anything. I've commented the io_service.run() method, and after that the handler was not called (that's okay), but the message was sent! (I've checked it in server logs) By the way, I don

IP address v4/v6 equivalence testing

不羁岁月 提交于 2019-12-10 21:12:38
问题 Is it possible to test IP addresses for equivalence in a dual stack environment using both IPv4 and IPv6? If so, how? My application uses websocket++ on top of Boost ASIO. As an example, on my LAN, one application connects to another listening on 192.168.1.2 , but using this answer's IP address getter std::string s = socket.remote_endpoint().address().to_string(); gives ::ffff:192.168.1.3 as the client's address. The problem is that .2 will have its own node list with the original v4 address

Implements timeout using boost::asio::async_read without call run on io_service

时光毁灭记忆、已成空白 提交于 2019-12-10 20:41:05
问题 I'm trying to read from a input source (in this case stdin) with a timeout. Due to the design of the existing application where this have to fit is it not possible to call run on my io_service. Here is my try so far: #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/optional.hpp> void set_result( boost::optional<boost::system::error_code> * a, boost::system::error_code b ) { if( b == 0) a->reset( b ); } void receive(boost::asio::io_service & io, boost::asio::posix::stream

boost::asio::async_read ends without fulfilling the completion condition

风流意气都作罢 提交于 2019-12-10 20:19:39
问题 On Windows, I am observing that if an async_read operation successfully completes on a serial port, and I immediately initiate another async_read operation to read n bytes, the second async_read operation immediately completes unexpectedly with success and 0 bytes transferred. after the second async_read operation, if a third async_read operation is initiated to read n bytes, then it will complete with success and n bytes transferred // where buffer_size(buffer) and n are both greater than 1

C++ Non-Blocking ASIO Run

流过昼夜 提交于 2019-12-10 20:13:51
问题 I have created a series of functions that talk to Libcurl Multi and download files asynchronously via ASIO and Boost. Obviously though when I call io_service.run it blocks my main thread when it is run. I have tried to make it non blocking but my app crashes. I was wondering what is the simplest and best approach to running this in the background, in a non-blocking manner and have it call a call-back function when it is done (Like how you can do it in javascript). So I could just go:

Proactor and async write

Deadly 提交于 2019-12-10 18:59:06
问题 Boost asio implements proactor design pattern baded on ACE proactor. I understand why we need async read. Hovewer, I'm a confused with async write. Why we need is async write? Is it useful for TCP/UDP connection too (can write to TCP/UDP socket take time)? Can I mix async read with sync write? 回答1: 1) Why we need is async write? Is it useful for TCP/UDP connection too (can write to TCP/UDP socket take time)? Asynchronous write is needed for the very same reasons as asynchronous read. When

Boost asio socket: how to get your own IP, port adress?

五迷三道 提交于 2019-12-10 18:48:38
问题 I have a TCP server using boost asio. I have accepted a socket connection. How to get IP, Port of my server machine as it is seen by my user server is currently communicating with? 回答1: I believe it's basic_stream_socket::local_endpoint(), but that's not necessarily what the other end sees if you are behind a NAT gateway. 来源: https://stackoverflow.com/questions/6846050/boost-asio-socket-how-to-get-your-own-ip-port-adress

Boost ASIO Serial Write Hex values

断了今生、忘了曾经 提交于 2019-12-10 18:25:20
问题 I am communicating with a device via a serial port using ubuntu. All the messages need to be hex values. I have tested the communication setup using termite in a Windows environment and I get the responses I am expecting. I cannot get any responses when using Boost:asio though. Here is how I am setting up my serial port: boost::asio::serial_port serialPort; serialPort.open(portNumber); serialPort.set_option(boost::asio::serial_port_base::baud_rate(baudRate)); serialPort.set_option(boost::asio