From patchwork Fri Nov 18 21:36:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Daniels X-Patchwork-Id: 17574 Received: (qmail 88004 invoked by alias); 18 Nov 2016 21:36:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 87975 invoked by uid 89); 18 Nov 2016 21:36:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=scb, Hx-languages-length:1637 X-HELO: smtp-p01.blackberry.com Received: from smtp-p01.blackberry.com (HELO smtp-p01.blackberry.com) (208.65.78.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Nov 2016 21:36:57 +0000 Received: from xct103cnc.rim.net ([10.65.161.203]) by mhs212cnc.rim.net with ESMTP/TLS/DHE-RSA-AES256-SHA; 18 Nov 2016 16:36:56 -0500 Received: from XCT196YKF.rim.net (10.2.25.4) by XCT103CNC.rim.net (10.65.161.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 18 Nov 2016 16:36:54 -0500 Received: from XMB126CNC.rim.net ([fe80::8025:a9ca:ffe7:8a3c]) by XCT196YKF.rim.net ([fe80::a15e:e4be:7302:3372%12]) with mapi id 14.03.0319.002; Fri, 18 Nov 2016 16:36:54 -0500 From: Michael Daniels To: "gdb-patches@sourceware.org" Subject: [PATCH] Avoid premature serial timeouts Date: Fri, 18 Nov 2016 21:36:53 +0000 Message-ID: <303AEF3B642EDD4B994EA21E8DEFDC5E6F94D5@XMB126CNC.rim.net> MIME-Version: 1.0 I noticed that when calling serial_readchar() with a large timeout (or -1), and there is no data to read for > 1s then it will prematurely return SERIAL_TIMEOUT. I narrowed it down to do_hardwire_readchar() calling wait_for() with a timeout of 1, and returning immediately if there was an error/timeout. I have moved some lines around to capture what I believe was the original intent. Thoughts? diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c index 2e7b1b4..9bd45f6 100644 --- a/gdb/ser-unix.c +++ b/gdb/ser-unix.c @@ -549,32 +549,23 @@ do_hardwire_readchar (struct serial *scb, int timeout) scb->timeout_remaining = (timeout < 0 ? timeout : timeout - delta); status = wait_for (scb, delta); - if (status < 0) + 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; + } else if (status < 0) return status; status = read (scb->fd, scb->buf, BUFSIZ); - 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) - continue; - else - return SERIAL_ERROR; /* Got an error from read. */ - } + if (status < 0 && errno == EINTR) + continue; + else if (status <= 0) + return SERIAL_ERROR; /* Got an error from read. */ scb->bufcnt = status; scb->bufcnt--;