Its actually a lot simpler than the answers here have implied, and you can do it synchronously:Suppose your blocking read was something like this: sizet len = socket. Receivefrom ( boost:: asio:: buffer ( recvbuf ), senderendpoint );Then you replace it with socket. Nonblocking ( true ); sizet len = 0;error = boost:: asio:: error:: wouldblock; while ( error boost:: asio:: error:: wouldblock ) //do other things here like go and make coffeelen = socket.
Receivefrom ( boost:: asio:: buffer ( recvbuf ), senderendpoint, 0, error );std:: cout. Write ( recvbuf. Data , len );You use the alternative overloaded form of receivefrom which almost all the send/receive methods have. They unfortunately take a flags argument but 0 seems to work fine.
Jason,If it is suitable for your application, I'd highly recommend implementing a callback-based asynchronous serial RX. How do I perform a nonblocking read using asio?
Has a great little example of how to implement asynch serial with a timeout. As you recognised, it will require a multi-threaded implementation to get the performance advantages, so you will need to put some thought where your recieved data will be buffered to make sure you aren't doing a lot of copying.As far as the boost::streambuff stuff goes, I personally prefer just to block out some memory as a char array - char mRXBuffermRXBuffSize and use boost::asio::buffer(mRXBuffer, mRXBuffSize) to pass the target buffer into asyncreadsome.
Serial Windows 8.1
In particular for RS232, I have always found the fact that the underlying data is a stream of bytes naturally maps a lot better onto a simple char array than any of the more complex data structures.Good Luck!