jscanner

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit dcc9918ee18a3fe4a232004672f1caa52ea8008c
parent 521f1c25785e1edc29bcac21d740f6f60c47687b
Author: Matthias Jaros <jaros@mailbox.org>
Date:   Wed,  8 Jul 2026 00:13:37 +0200

Early exit through canceled check. Now shutdown is dramatically faster

Diffstat:
Msrc/main/java/com/it_jaros/jscanner/Scanner.java | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/it_jaros/jscanner/Scanner.java b/src/main/java/com/it_jaros/jscanner/Scanner.java @@ -71,6 +71,7 @@ public class Scanner implements AutoCloseable { try { scan.getHostCounter().inc(); scan.getHostTotalCounter().inc(); + if (cancelled) return null; return scanHostPorts(host, scan); } finally { scan.getHostCounter().dec(); @@ -149,7 +150,7 @@ public class Scanner implements AutoCloseable { // consumer is the main thread // we run as long as the producer is running or as long as things are in pipeline to be processed // only exception is when cancelled is set - while ((state.running().get() || state.inPipeline().get() > 0) && !cancelled) { + while (!cancelled && (state.running().get() || state.inPipeline().get() > 0)) { try { Future<PortResult> portResultFuture = state.completionService().poll(10, TimeUnit.MILLISECONDS); if (portResultFuture == null) { @@ -213,7 +214,7 @@ public class Scanner implements AutoCloseable { executor.submit(() -> { try { threadCounter.inc(); - while (queue.hasNext() && !cancelled) { + while (!cancelled && queue.hasNext()) { activeWorkers.acquire(); // remember if we submitted anything