c++ - boost::asio::async_write issue over serial channel -


i have client server application, flow explained below:

client @ windows side , not use boost server @ linux side , uses boost client-server communicates on serial channel rs485. , server uses boost::asio::async_write.

client --> calls command specific command_id --> server client <-- sends acknowledgement                  <-- server {server process command, meanwhile client blocked response} client <-- sends response                         <-- server 

sometimes happens client receives acknowledgement not receive response if response sent server. pending response later received client when client sends command.

if use boost::asio::write serial communication there no problem @ all.

below code snippet async_write

boost::asio::async_write(serial_port, boost::asio::buffer(&v_chunk[0], v_chunk.size()),         boost::bind(&serial_channel::async_write_callback, this, boost::asio::placeholders::error,                 boost::asio::placeholders::bytes_transferred));  io_serv->run(); io_serv->reset(); 

the way use io_service not work. first of run function doesn't return until service event loop stopped. secondly, if want use "poller" should use poll or optionally poll_one (or perhaps run_one).

but if that, it's same doing non-async write call, , loos benefits of async functions.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -