
I'm writing code to implement an existing communication protocol that uses a packet with a fixed header and variable payload (depending on a header field). I started using a previously recorded file and fstream::read() calls; i.e. read(buf,1) looking for the start-of-packet, read(buf, HEADER_LEN), extract the payload size and read the remainder. I am now looking to hook up the receiver logic to the actual gear and need to handle timeouts and such. I'm new to asio but it looks like what I may need given that I have to support device connections via serial ports and sockets but I also need to retain the ability to read from files. I'm wondering if anyone could suggest an approach to support all three comm schemes with the same packet reception logic. The idea would be for the receive routine to return message pointers or throw on timeouts or partial packets Paul

I'm new to asio but it looks like what I may need given that I have to support device connections via serial ports and sockets but I also need to retain the ability to read from files. I'm wondering if anyone could suggest an approach to support all three comm schemes with the same packet reception logic.
You can take a look at windows::random_access_handle reference and example: http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/windows__... http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/example/windows/tra...

On Sun, Feb 28, 2010 at 9:44 AM, Igor R
I'm new to asio but it looks like what I may need given that I have to support device connections via serial ports and sockets but I also need to retain the ability to read from files. I'm wondering if anyone could suggest an approach to support all three comm schemes with the same packet reception logic.
You can take a look at windows::random_access_handle reference and example: http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/windows__... http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/example/windows/tra...
Sorry, should have mentioned I'm not on Windows; Linux is the target. The posix::stream_descriptor looked promising until I read the "but not regular files" bit. P

On Sun, Feb 28, 2010 at 11:48 AM, Paul Dugas
On Sun, Feb 28, 2010 at 9:44 AM, Igor R
wrote: I'm new to asio but it looks like what I may need given that I have to support device connections via serial ports and sockets but I also need to retain the ability to read from files. I'm wondering if anyone could suggest an approach to support all three comm schemes with the same packet reception logic.
You can take a look at windows::random_access_handle reference and example:
http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/windows__...
http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/example/windows/tra...
Sorry, should have mentioned I'm not on Windows; Linux is the target. The posix::stream_descriptor looked promising until I read the "but not regular files" bit.
This is a serious limitation of asio, and has been for a long time. It's possible there will be an equivalent of windows::random_access_handle for posix sometime in the near future, but that's about all I can say right now. You can "fake it" without too much complicated work by copying the interface of windows_random_access_handle and filling out the routines with logic to send requests to a thread pool (also managed in asio) and executing synchronous i/o operations inside the thread pool and then invoking the callbacks on the main thread.
participants (3)
-
Igor R
-
Paul Dugas
-
Zachary Turner