From 8dbefeba864d70348d37d5137ae03744835d7bca Mon Sep 17 00:00:00 2001 From: dmiller Date: Fri, 23 Sep 2022 21:41:59 +0000 Subject: [PATCH] Don't wait around if STDIN has data. Closes #2426 --- CHANGELOG | 3 +++ nbase/nbase_misc.c | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 937725c12..b996a88c7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ #Nmap Changelog ($Id$); -*-text-*- +o [Ncat][GH#1026][GH#2426] Speed up transfers on Windows by avoiding a 125ms + wait for every read from STDIN. [scriptjunkie] + o [GH#1192][Windows] Periodically reset the system idle timer to keep the system from going to sleep while scans are in process. This only affects port scans and OS detection scans, since NSE and version scan do not rely on diff --git a/nbase/nbase_misc.c b/nbase/nbase_misc.c index 8fb39280b..1fbe584f3 100644 --- a/nbase/nbase_misc.c +++ b/nbase/nbase_misc.c @@ -363,6 +363,7 @@ int fselect(int s, fd_set *rmaster, fd_set *wmaster, fd_set *emaster, struct tim fd_set rset, wset, eset; int r_stdin = rmaster != NULL && checked_fd_isset(STDIN_FILENO, rmaster); int e_stdin = emaster != NULL && checked_fd_isset(STDIN_FILENO, emaster); + int stdin_ready = 0; /* Figure out whether there are any FDs in the sets, as @$@!$# Windows returns WSAINVAL (10022) if you call a select() with no FDs, even though @@ -440,6 +441,12 @@ int fselect(int s, fd_set *rmaster, fd_set *wmaster, fd_set *emaster, struct tim if (emaster) eset = *emaster; + if(r_stdin) { + stdin_ready = win_stdin_ready(); + if(stdin_ready) + stv.tv_usec = 0; /* get status but don't wait since stdin is ready */ + } + fds_ready = 0; /* selecting on anything other than stdin? */ if (s > 1) @@ -447,7 +454,7 @@ int fselect(int s, fd_set *rmaster, fd_set *wmaster, fd_set *emaster, struct tim else usleep(stv.tv_sec * 1000000UL + stv.tv_usec); - if (fds_ready > -1 && r_stdin && win_stdin_ready()) { + if (fds_ready > -1 && stdin_ready) { checked_fd_set(STDIN_FILENO, &rset); fds_ready++; }