Boost logo

Boost Users :

Subject: [Boost-users] [asio::serial_port] I can read and write synchronously, but how do I unblock when I want to end?
From: Dario Ramos (dario_ramos_at_[hidden])
Date: 2012-02-09 09:59:10


I'm using boost::asio::serial_port to read and write to a serial port
device. I do the reading inside a boost::thread to take advantage of RS-232
being full-duplex. My read calls are like this one:

BYTE b;
read( m_SerialPort, boost::asio::buffer(&b,1) );

Everything works OK except for shutdown. When I want to end the thread,
it's almost always blocked in a read call. How do I unblock it? I tried:

   - Calling close on the port: This generates an exception, which I can
   catch, but I was told I can't distinguish shutdown from error if I do this.
   - Stopping the io_service I passed to the serial_port's constructor.
   This had no effect, the thread remained blocked on the read call.

-- 
*Darío Eduardo Ramos*
Meditech S.A. www.meditech.com.ar
(+54) 01147603300, Interno 31
Av. Julio A. Roca 3456
Florida Oeste, Bs.As. Argentina


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net