Boost logo

Boost-Commit :

From: chris_at_[hidden]
Date: 2008-06-19 08:50:03


Author: chris_kohlhoff
Date: 2008-06-19 08:50:02 EDT (Thu, 19 Jun 2008)
New Revision: 46507
URL: http://svn.boost.org/trac/boost/changeset/46507

Log:
Fix serial port support on POSIX platforms that don't provide the BSD
extensions cfmakeraw, cfsetspeed and CRTSCTS.

Text files modified:
   trunk/boost/asio/detail/reactive_serial_port_service.hpp | 9 +++++++++
   trunk/boost/asio/impl/serial_port_base.ipp | 14 ++++++++++++++
   2 files changed, 23 insertions(+), 0 deletions(-)

Modified: trunk/boost/asio/detail/reactive_serial_port_service.hpp
==============================================================================
--- trunk/boost/asio/detail/reactive_serial_port_service.hpp (original)
+++ trunk/boost/asio/detail/reactive_serial_port_service.hpp 2008-06-19 08:50:02 EDT (Thu, 19 Jun 2008)
@@ -109,7 +109,16 @@
     s = descriptor_ops::error_wrapper(::tcgetattr(fd, &ios), ec);
     if (s >= 0)
     {
+#if defined(_BSD_SOURCE)
       ::cfmakeraw(&ios);
+#else
+ ios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK
+ | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
+ ios.c_oflag &= ~OPOST;
+ ios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
+ ios.c_cflag &= ~(CSIZE | PARENB);
+ ios.c_cflag |= CS8;
+#endif
       ios.c_iflag |= IGNPAR;
       descriptor_ops::clear_error(ec);
       s = descriptor_ops::error_wrapper(::tcsetattr(fd, TCSANOW, &ios), ec);

Modified: trunk/boost/asio/impl/serial_port_base.ipp
==============================================================================
--- trunk/boost/asio/impl/serial_port_base.ipp (original)
+++ trunk/boost/asio/impl/serial_port_base.ipp 2008-06-19 08:50:02 EDT (Thu, 19 Jun 2008)
@@ -108,7 +108,12 @@
     ec = boost::asio::error::invalid_argument;
     return ec;
   }
+# if defined(_BSD_SOURCE)
   ::cfsetspeed(&storage, baud);
+# else
+ ::cfsetispeed(&storage, baud);
+ ::cfsetospeed(&storage, baud);
+# endif
 #endif
   ec = boost::system::error_code();
   return ec;
@@ -242,16 +247,25 @@
   {
   case none:
     storage.c_iflag &= ~(IXOFF | IXON);
+# if defined(_BSD_SOURCE)
     storage.c_cflag &= ~CRTSCTS;
+# endif
     break;
   case software:
     storage.c_iflag |= IXOFF | IXON;
+# if defined(_BSD_SOURCE)
     storage.c_cflag &= ~CRTSCTS;
+# endif
     break;
   case hardware:
+# if defined(_BSD_SOURCE)
     storage.c_iflag &= ~(IXOFF | IXON);
     storage.c_cflag |= CRTSCTS;
     break;
+# else
+ ec = boost::asio::error::operation_not_supported;
+ return ec;
+# endif
   default:
     break;
   }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk