Nmap Development mailing list archives
[PATCH] Flush console input queue differently in nmap_tty.cc
From: Kris Katterjohn <kjak () ispwest com>
Date: Tue, 22 Aug 2006 18:36:15 -0500
This uses tcflush() in tty_getchar() under the !WIN32 section and does the "flush loop" inside tty_getchar() in the WIN32 section. It's definitely better for the UNIX part, and is probably better for WIN32 because only _getch() is looped instead of the whole tty_getchar(). I tried to find something like tcflush() for Windows, but I didn't see anything. Maybe kx knows of something. It's a diff against 4.20ALPHA4. Thanks, Kris Katterjohn
--- x/nmap_tty.cc 2006-03-08 15:45:01.000000000 -0600
+++ y/nmap_tty.cc 2006-08-22 18:26:07.000000000 -0500
@@ -126,7 +126,21 @@ extern NmapOps o;
// Microsoft's runtime makes this fairly simple. :)
void tty_init() { return; }
-static int tty_getchar() { return _kbhit() ? _getch() : -1; }
+
+static int tty_getchar()
+{
+ if (_kbhit()) {
+ int c = _getch();
+
+ /* flush input queue */
+ while (_getch() >= 0);
+
+ return c;
+ }
+
+ return -1;
+}
+
static void tty_done() { return; }
#else
@@ -167,6 +181,10 @@ static int tty_getchar()
#endif
c = 0;
numChars = read(tty_fd, &c, 1);
+
+ /* flush input queue */
+ tcflush(tty_fd, TCIFLUSH);
+
if (numChars > 0) return c;
}
@@ -232,9 +250,6 @@ bool keyWasPressed()
return false;
if ((c = tty_getchar()) >= 0) {
- // Eat any extra keys (so they can't queue up and print forever)
- while (tty_getchar() >= 0);
-
// printf("You pressed key '%c'!\n", c);
if (c == 'v') {
o.verbose++;
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- [PATCH] Flush console input queue differently in nmap_tty.cc Kris Katterjohn (Aug 22)
- Re: [PATCH] Flush console input queue differently in nmap_tty.cc kx (Aug 22)
- Re: [PATCH] Flush console input queue differently in nmap_tty.cc Kris Katterjohn (Aug 22)
- Re: [PATCH] Flush console input queue differently in nmap_tty.cc kx (Aug 22)
