Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] PR remote/21188: Fix remote serial timeout
@ 2017-02-20 22:52 Gareth McMullin
  2017-03-01 21:52 ` Gareth McMullin
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Gareth McMullin @ 2017-02-20 22:52 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

The timeout mechanism in ser-unix.c was changed in commit 048094acc.

In do_hardwire_readchar(), the required timeout is broken into 1
second intervals and wait_for() is called.  Before, wait_for() set
VTIME and VMIN so the read would block, but now it uses select() to
block for the specified timeout.  If wait_for() returns
SERIAL_TIMEOUT, do_hardwire_readchar() returns immediately, so the
timeout is always only 1s.

The attached patch will repeatedly call wait_for() until the full
timeout has elapsed.

Gareth

[-- Attachment #2: serial_timeout.patch --]
[-- Type: text/x-patch, Size: 1341 bytes --]

2017-02-21 Gareth McMullin  <gareth@blacksphere.co.nz>

	PR remote/21188
	* ser-unix.c (do_hardwire_readchar): Wait for full timeout to elapse.

diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index b9e55f0..0a74672 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -549,6 +549,18 @@ do_hardwire_readchar (struct serial *scb, int timeout)
       scb->timeout_remaining = (timeout < 0 ? timeout : timeout - delta);
       status = wait_for (scb, delta);

+      if (status == SERIAL_TIMEOUT) {
+	if (scb->timeout_remaining > 0)
+	  {
+	    timeout = scb->timeout_remaining;
+	    continue;
+	  }
+	  else if (scb->timeout_remaining < 0)
+	    continue;
+	  else
+	    return SERIAL_TIMEOUT;
+      }
+
       if (status < 0)
 	return status;

@@ -556,21 +568,7 @@ do_hardwire_readchar (struct serial *scb, int timeout)

       if (status <= 0)
 	{
-	  if (status == 0)
-	    {
-	      /* Zero characters means timeout (it could also be EOF, but
-	         we don't (yet at least) distinguish).  */
-	      if (scb->timeout_remaining > 0)
-		{
-		  timeout = scb->timeout_remaining;
-		  continue;
-		}
-	      else if (scb->timeout_remaining < 0)
-		continue;
-	      else
-		return SERIAL_TIMEOUT;
-	    }
-	  else if (errno == EINTR)
+	  if (errno == EINTR)
 	    continue;
 	  else
 	    return SERIAL_ERROR;	/* Got an error from read.  */

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-03-17 16:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-20 22:52 [PATCH] PR remote/21188: Fix remote serial timeout Gareth McMullin
2017-03-01 21:52 ` Gareth McMullin
2017-03-02 16:15 ` Simon Marchi
2017-03-14  1:02   ` Gareth McMullin
2017-03-14  1:40     ` Simon Marchi
2017-03-14  2:13       ` Gareth McMullin
2017-03-14 14:29 ` Pedro Alves
2017-03-17 16:26   ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox