OSDN Git Service

* fhandler_serial.cc (fhandler_serial::ioctl): Don't try to figure out if OS
authorcgf <cgf>
Wed, 6 Nov 2002 01:50:31 +0000 (01:50 +0000)
committercgf <cgf>
Wed, 6 Nov 2002 01:50:31 +0000 (01:50 +0000)
has the capability to retrieve RTS/CTS.  Just set default values if
DeviceIoControl fails.  (suggested by Sergey Okhapkin)

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler_serial.cc

index 1ebd0a4..e27ca80 100644 (file)
@@ -1,3 +1,9 @@
+2002-11-05  Christopher Faylor  <cgf@redhat.com>
+
+       * fhandler_serial.cc (fhandler_serial::ioctl): Don't try to figure out
+       if OS has the capability to retrieve RTS/CTS.  Just set default values
+       if DeviceIoControl fails.  (suggested by Sergey Okhapkin)
+
 2002-11-05  Sergey Okhapkin  <sos@prospect.com.ru>
 
        * fhandler_serial.cc (fhandler_serial::raw_read): Use correct type for minchars.
index c12d23d..2c8c27f 100644 (file)
@@ -18,6 +18,7 @@ details. */
 #include "sigproc.h"
 #include "pinfo.h"
 #include <sys/termios.h>
+#include <ddk/ntddser.h>
 
 /**********************************************************************/
 /* fhandler_serial */
@@ -56,7 +57,7 @@ fhandler_serial::raw_read (void *ptr, size_t ulen)
       ResetEvent (io_status.hEvent);
     }
 
-  for (n = 0, tot = 0; ulen; ulen -= n, ptr = (char *)ptr + n)
+  for (n = 0, tot = 0; ulen; ulen -= n, ptr = (char *) ptr + n)
     {
       COMSTAT st;
       DWORD inq = 1;
@@ -407,41 +408,28 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
          }
        else
          {
-           unsigned modem_status = 0;
+           ipbuffer = 0;
            if (modem_lines & MS_CTS_ON)
-             modem_status |= TIOCM_CTS;
+             ipbuffer |= TIOCM_CTS;
            if (modem_lines & MS_DSR_ON)
-             modem_status |= TIOCM_DSR;
+             ipbuffer |= TIOCM_DSR;
            if (modem_lines & MS_RING_ON)
-             modem_status |= TIOCM_RI;
+             ipbuffer |= TIOCM_RI;
            if (modem_lines & MS_RLSD_ON)
-             modem_status |= TIOCM_CD;
-           if (!wincap.supports_reading_modem_output_lines ())
-             modem_status |= rts | dtr;
+             ipbuffer |= TIOCM_CD;
+
+           DWORD cb;
+           DWORD mcr;
+           if (!DeviceIoControl (get_handle (), IOCTL_SERIAL_GET_DTRRTS,
+                                 NULL, 0, &mcr, 4, &cb, 0) || cb != 4)
+             ipbuffer |= rts | dtr;
            else
              {
-               DWORD cb;
-               DWORD mcr;
-               BOOL result = DeviceIoControl (get_handle (), 0x001B0078, NULL,
-                                              0, &mcr, 4, &cb, 0);
-               if (!result)
-                 {
-                   __seterrno ();
-                   res = -1;
-                   goto out;
-                 }
-               if (cb != 4)
-                 {
-                   set_errno (EINVAL); /* FIXME: right errno? */
-                   res = -1;
-                   goto out;
-                 }
                if (mcr & 2)
-                 modem_status |= TIOCM_RTS;
+                 ipbuffer |= TIOCM_RTS;
                if (mcr & 1)
-                 modem_status |= TIOCM_DTR;
+                 ipbuffer |= TIOCM_DTR;
              }
-           ipbuffer = modem_status;
          }
        break;
       case TIOCMSET:
@@ -475,15 +463,12 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
                res = -1;
              }
          }
+       else if (EscapeCommFunction (get_handle (), CLRDTR))
+         dtr = 0;
        else
          {
-           if (EscapeCommFunction (get_handle (), CLRDTR))
-             dtr = 0;
-           else
-             {
-               __seterrno ();
-               res = -1;
-             }
+           __seterrno ();
+           res = -1;
          }
        break;
      case TIOCINQ:
@@ -502,7 +487,6 @@ fhandler_serial::ioctl (unsigned int cmd, void *buffer)
        break;
      }
 
-out:
   termios_printf ("%d = ioctl (%p, %p)", res, cmd, buffer);
 # undef ibuffer
 # undef ipbuffer