sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: "Måns Rullgård" <mans@mansr.com>
Cc: Eric Wong <e@80x24.org>, sox-devel@lists.sourceforge.net
Subject: [PATCH RESEND 1/9] use non-blocking stdin for interactive mode
Date: Fri, 31 Jul 2020 09:37:53 +0000	[thread overview]
Message-ID: <20200731093801.23548-2-normalperson@yhbt.net> (raw)
In-Reply-To: <20200731093801.23548-1-normalperson@yhbt.net>

From: Eric Wong <e@80x24.org>

When accepting keyboard input, it is possible for select() to
return a false-positive with spurious wakeups from inside the
update_status callback.

Using the FIONREAD ioctl in place of select is also a possibility,
but may be less portable.
---
 src/sox.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/sox.c b/src/sox.c
index 9412614e..6b35041b 100644
--- a/src/sox.c
+++ b/src/sox.c
@@ -1804,6 +1804,18 @@ static int process(void)
     tcsetattr(fileno(stdin), TCSANOW, &modified_termios);
   }
 #endif
+#if defined(F_GETFL) && defined(F_SETFL) && defined(O_NONBLOCK)
+  if (interactive) {
+    int fd = fileno(stdin);
+    int flags = fcntl(fd, F_GETFL);
+    if (flags == -1) {
+      lsx_warn("error getting flags on stdin descriptor: %s", strerror(errno));
+    } else if (!(flags & O_NONBLOCK)) {
+      if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
+        lsx_warn("error setting non-blocking on stdin: %s", strerror(errno));
+    }
+  }
+#endif
 
   setsig(SIGTERM, sigint); /* Stop gracefully, as soon as we possibly can. */
   setsig(SIGINT , sigint); /* Either skip current input or behave as SIGTERM. */


_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

  reply	other threads:[~2020-07-31  9:38 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31  9:37 [PATCH RESEND 0/9] some old accumulated patches Eric Wong
2020-07-31  9:37 ` Eric Wong [this message]
2020-07-31  9:37 ` [PATCH RESEND 2/9] speed up "|program" inputs on Linux 2.6.35+ Eric Wong
2020-07-31 10:53   ` Måns Rullgård
2020-07-31  9:37 ` [PATCH RESEND 3/9] sox.1: fix section name Eric Wong
2020-07-31  9:37 ` [PATCH RESEND 4/9] sndio: handle 24-bit samples properly on OpenBSD Eric Wong
2020-07-31 10:59   ` Måns Rullgård
2020-07-31  9:37 ` [PATCH RESEND 5/9] Handle vorbis_analysis_headerout errors Eric Wong
2020-07-31  9:37 ` [PATCH RESEND 6/9] fix manpage warning: "table wider than line width" Eric Wong
2020-07-31  9:37 ` [PATCH RESEND 7/9] spectrogram: remove arbitrary limit on height of spectrogram Eric Wong
2020-07-31 14:34   ` Måns Rullgård
     [not found]     ` <CAL4-wQpF-qOD=BRVPhgZFC7fjvFDV-rQx1stvwY_xCTyj5uooA@mail.gmail.com>
2020-08-13 16:20       ` Måns Rullgård
2020-08-13 16:30         ` Pander via SoX-devel
2020-08-13 16:38           ` Måns Rullgård
2020-07-31  9:38 ` [PATCH RESEND 8/9] Add spectrogram -n flag to normalise the output to maximum brightness Eric Wong
2020-07-31  9:38 ` [PATCH RESEND 9/9] Added average power spectrum for stat -freq -a Eric Wong
2020-08-01 11:52   ` Måns Rullgård
2020-08-02  1:03     ` Eric Wong
2020-08-02 10:43       ` Måns Rullgård
2020-08-02 10:52     ` Måns Rullgård
2020-08-03 12:44       ` Pander via SoX-devel
2020-08-03 13:41         ` Måns Rullgård
2020-07-31 10:13 ` [PATCH RESEND 0/9] some old accumulated patches Måns Rullgård
2020-07-31 21:16   ` Eric Wong
2020-07-31 21:44     ` Måns Rullgård
2020-08-01 16:57 ` Måns Rullgård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.sourceforge.net/lists/listinfo/sox-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200731093801.23548-2-normalperson@yhbt.net \
    --to=sox-devel@lists.sourceforge.net \
    --cc=e@80x24.org \
    --cc=mans@mansr.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).