From patchwork Mon Feb 20 22:52:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gareth McMullin X-Patchwork-Id: 19317 Received: (qmail 126253 invoked by alias); 20 Feb 2017 22:52:37 -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 126238 invoked by uid 89); 20 Feb 2017 22:52:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-22.3 required=5.0 tests=AWL, BAYES_20, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy=H*F:D*nz, H*F:D*co.nz, gareth, Gareth X-HELO: mail-ua0-f176.google.com Received: from mail-ua0-f176.google.com (HELO mail-ua0-f176.google.com) (209.85.217.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Feb 2017 22:52:34 +0000 Received: by mail-ua0-f176.google.com with SMTP id 35so73679782uak.1 for ; Mon, 20 Feb 2017 14:52:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=qmj9GLhvaiB1mHO4OmZpBSkl1QrFXD5ryyeoWjmsZ2A=; b=DGAFGoyJzT0KFUTdIzliyw9ByT8UJovT3lKK475v0160zwnz1g9O1deeKfuehq6Xaf D8hvIKDp+ipKCQ8vudpyZGhYcZ6I+dQgxwgX8xLeD+4tR0ozq/lVobNPG9hh6zlgejZ9 YhMwfQseoRww1IpXlc02PhoLJ8z7HNWk0qfcmTUyQdIpNm/f/1uGFUA9zdhPm+RsoF6u Abe6B3NU0OwvmgesQ3U3VVFPPQ7VN72eCcHXwjYM71rsKidfn0jpJLxYH6B0eqZv9K1a oW0xmqYet5YSoba82BrLln7SmT+0zdYW1ArBzCQqOKXFB/4pqe/5Gp1bjyA+0YqM8Z9S RqcA== X-Gm-Message-State: AMke39megXOzc7gJGfMHBf7eFdZk4tq9orIOeOqtWvH3OZtOw8jyD+cmCXvw7hn2/PYqf/VB3sfZnTE60yxFig== X-Received: by 10.159.49.66 with SMTP id n2mr12674051uab.72.1487631152234; Mon, 20 Feb 2017 14:52:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.94.212 with HTTP; Mon, 20 Feb 2017 14:52:11 -0800 (PST) From: Gareth McMullin Date: Tue, 21 Feb 2017 11:52:11 +1300 Message-ID: Subject: [PATCH] PR remote/21188: Fix remote serial timeout To: gdb-patches@sourceware.org X-IsSubscribed: yes 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 2017-02-21 Gareth McMullin 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. */