1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 11:44:53 +08:00

Fixed nonblocking read problem.

This commit is contained in:
William Woodall 2011-03-27 15:35:05 -05:00
parent 3d69d04c86
commit 1b2d29f6a7

View File

@ -202,12 +202,9 @@ static const boost::posix_time::time_duration timeout_zero_comparison(boost::pos
const int Serial::read(char* buffer, int size) {
this->reading = true;
if(this->nonblocking) // Do not wait for data
boost::asio::async_read(*this->serial_port, boost::asio::buffer(buffer, size),
boost::bind(&Serial::read_complete, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
else // Wait for data until size is read or timeout occurs
if(this->nonblocking) {// Do not wait for data
return this->serial_port->read_some(boost::asio::buffer(buffer, size));
} else { // Wait for data until size is read or timeout occurs
boost::asio::async_read(*this->serial_port, boost::asio::buffer(buffer, size), transfer_at_least_ignore_invalid_argument(size),
boost::bind(&Serial::read_complete, this,
boost::asio::placeholders::error,
@ -224,6 +221,7 @@ const int Serial::read(char* buffer, int size) {
this->bytes_to_read = size;
return this->bytes_read;
}
}
const std::string Serial::read(int size) {