boost-asio

Multiple async_wait from a boost Asio deadline_timer

走远了吗. 提交于 2020-01-04 02:46:08
问题 Is it possible to call async_wait several times on the same boost::asio::deadline_timer? What I mean to do is something like the following: t->expires_from_now(delay); t->async_wait(f1); t->async_wait(f2); Does this ensures that the two functions will be called? Does this ensures that the two functions will be called in this order? If not, any idea how to have f1 and f2 successively called when the timer times out? (I don't care if another handler is executed between the calls to f1 and f2).

boost::asio::async_resolve Problem

孤者浪人 提交于 2020-01-03 17:04:13
问题 I'm in the process of constructing a Socket class that uses boost::asio . To start with, I made a connect method that took a host and a port and resolved it to an IP address. This worked well, so I decided to look in to async_resolve . However, my callback always gets an error code of 995 (using the same destination host/port as when it worked synchronously). code : Function that starts the resolution: // resolve a host asynchronously template<typename ResolveHandler> void resolveHost(const

boost::asio::async_resolve Problem

让人想犯罪 __ 提交于 2020-01-03 17:02:16
问题 I'm in the process of constructing a Socket class that uses boost::asio . To start with, I made a connect method that took a host and a port and resolved it to an IP address. This worked well, so I decided to look in to async_resolve . However, my callback always gets an error code of 995 (using the same destination host/port as when it worked synchronously). code : Function that starts the resolution: // resolve a host asynchronously template<typename ResolveHandler> void resolveHost(const

Dynamically sized boost::asio::buffer

五迷三道 提交于 2020-01-03 08:45:12
问题 I'm reading from a boost::asio::ip::udp::socket like this: using boost::asio::ip::udp; // ... char recv_buf[128]; udp::endpoint sender_endpoint; size_t len = socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint); Now, this works perfectly fine, but the maximum amount of characters that I am able to recieve is now 127. However I am facing a problem because I need to accept some data input of which the length can greatly vary (and is not of well-defined length with prefixed

How to find the destination address of a UDP packet using boost::asio?

蹲街弑〆低调 提交于 2020-01-03 05:36:29
问题 I'm developing a peer-to-peer communications network for use over a LAN in an industrial environment. Some messages are are just asynchronous, and don't require a response. Others are request-response. The request messages (and the async messages) are sent to a multicast group, and the replies to requests are sent unicast. Each endpoint, therefore, receives UDP packets that are sent to the multicast group, and also receives messages that are just sent to it using plain unicast. So far it's

boost asio,how to cancel an asynchronous operation

两盒软妹~` 提交于 2020-01-03 05:33:11
问题 I wrote a proxy service program that used boost asio, the proxy server has two socket(client_socket_,server_socket_),If one of the socket is disconnected another one to remain active。For example, if read from client_socket_ results in error, i will close client_socket_ and then wait for client to reconnect and after client reconnects, I read from one socket and write to another. The problem is that, when i close the client_socket_ how to cancel the asynchronous operation in server_socket_? if

boost::asio::async_read() of stream_descriptor now returning EOF

主宰稳场 提交于 2020-01-03 05:12:32
问题 Upgraded Ubuntu today from 14.10 to 15.04. Now seeing different behaviour either in boost::asio::async_read() , boost::asio::posix::stream_descriptor , or tap/tun interfaces. Calling async_read() immediately returns boost::asio::error::eof . If I ignore the error and loop back up to start a new async_read() it does eventually read when bytes are available, and the application continues to work. The problem with doing this workaround loop is the application now consumes 100% of a core as it

Boost asio read an unknown number of bytes

北城以北 提交于 2020-01-02 21:24:16
问题 I have 2 cases: Client connects, send no bytes and wait for server response. Client connects, send more than 1 bytes and wait for server response. Problem is next: in 1st case I should read no bytes and get some server response. in 2nd case I should read at least 1 byte and only then I'll get a server response. If i try to read at least 0 bytes, like this: async_read(sock, boost::asio::buffer(data), boost::asio::transfer_at_least(0), boost::bind(&server::read, this, boost::asio::placeholders:

Boost asio read an unknown number of bytes

别说谁变了你拦得住时间么 提交于 2020-01-02 21:23:37
问题 I have 2 cases: Client connects, send no bytes and wait for server response. Client connects, send more than 1 bytes and wait for server response. Problem is next: in 1st case I should read no bytes and get some server response. in 2nd case I should read at least 1 byte and only then I'll get a server response. If i try to read at least 0 bytes, like this: async_read(sock, boost::asio::buffer(data), boost::asio::transfer_at_least(0), boost::bind(&server::read, this, boost::asio::placeholders:

Is it thread safe to call async_send and async_receive at the same time?

£可爱£侵袭症+ 提交于 2020-01-02 19:13:40
问题 I understood that calling boost::asio::ip::tcp::socket::async_receive (or boost::asio::ip::tcp::socket::async_send ) two times may result in a bad behavior.. Is it OK if i call boost::asio::ip::tcp::socket::async_recive and boost::asio::ip::tcp::socket::async_send at the same time? I am going to have 2 or more threads running the boost::asio::run so you need to take that into account.. Thanks 回答1: This has to be OK. How else would you perform full duplex async communications on a single