Joel Sherrill (joel@OARcorp.com)
[deliverable/binutils-gdb.git] / gdb / ser-unix.c
index b1ffca0fea87a826853434b90bd63d229c2e0449..dc5236fbe662330acde9f9b80359176fc06bdf11 100644 (file)
@@ -1,5 +1,5 @@
 /* Serial interface for local (hardwired) serial ports on Un*x like systems
-   Copyright 1992, 1993, 1994 Free Software Foundation, Inc.
+   Copyright 1992, 1993, 1994, 1998 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -83,6 +83,10 @@ static int hardwire_flush_input PARAMS ((serial_t));
 static int hardwire_send_break PARAMS ((serial_t));
 static int hardwire_setstopbits PARAMS ((serial_t, int));
 
+void _initialize_ser_hardwire PARAMS ((void));
+
+extern int (*ui_loop_hook) PARAMS ((int));
+
 /* Open up a real live device for serial I/O */
 
 static int
@@ -98,13 +102,11 @@ hardwire_open(scb, name)
 }
 
 static int
-get_tty_state(scb, state)
+get_tty_state (scb, state)
      serial_t scb;
      struct hardwire_ttystate *state;
 {
 #ifdef HAVE_TERMIOS
-  extern int errno;
-
   if (tcgetattr(scb->fd, &state->termios) < 0)
     return -1;
 
@@ -430,8 +432,6 @@ wait_for(scb, timeout)
      serial_t scb;
      int timeout;
 {
-  scb->timeout_remaining = 0;
-
 #ifdef HAVE_SGTTY
   {
     struct timeval tv;
@@ -539,20 +539,44 @@ wait_for(scb, timeout)
    to wait, or -1 to wait forever.  Use timeout of 0 to effect a poll.  Returns
    char if successful.  Returns SERIAL_TIMEOUT if timeout expired, EOF if line
    dropped dead, or SERIAL_ERROR for any other error (see errno in that case).  */
-
 static int
-hardwire_readchar(scb, timeout)
+hardwire_readchar (scb, timeout)
      serial_t scb;
      int timeout;
 {
-  int status;
+  int status, delta;
+  int detach = 0;
 
   if (scb->bufcnt-- > 0)
     return *scb->bufp++;
 
+  if (timeout > 0)
+    timeout++;
+
+  /* We have to be able to keep the GUI alive here, so we break the original
+     timeout into steps of 1 second, running the "keep the GUI alive" hook 
+     each time through the loop.
+     Also, timeout = 0 means to poll, so we just set the delta to 0, so we
+     will only go through the loop once. */
+   
+  delta = (timeout == 0 ? 0 : 1);
   while (1)
     {
-      status = wait_for (scb, timeout);
+
+      /* N.B. The UI may destroy our world (for instance by calling
+         remote_stop,) in which case we want to get out of here as
+         quickly as possible.  It is not safe to touch scb, since
+         someone else might have freed it.  The ui_loop_hook signals that 
+         we should exit by returning 1. */
+
+      if (ui_loop_hook)
+        detach = ui_loop_hook (0);
+
+      if (detach)
+       return SERIAL_TIMEOUT;
+
+      scb->timeout_remaining = (timeout < 0 ? timeout : timeout - delta);
+      status = wait_for (scb, delta);
 
       if (status < 0)
        return status;
@@ -570,6 +594,8 @@ hardwire_readchar(scb, timeout)
                  timeout = scb->timeout_remaining;
                  continue;
                }
+          else if (scb->timeout_remaining < 0)
+            continue;
              else
                return SERIAL_TIMEOUT;
            }
@@ -618,6 +644,18 @@ baudtab[] =
   {9600, B9600},
   {19200, B19200},
   {38400, B38400},
+#ifdef B57600
+  {57600, B57600},
+#endif
+#ifdef B115200
+  {115200, B115200},
+#endif
+#ifdef B230400
+  {230400, B230400},
+#endif
+#ifdef B460800
+  {460800, B460800},
+#endif
   {-1, -1},
 };
 
This page took 0.024453 seconds and 4 git commands to generate.