I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 61d5f462 authored by zzz's avatar zzz
Browse files

* Streaming: Fix active stream counting so it doesn't count streams

   that are closed and in TIME-WAIT state. Also, break out of the
   counting loop as soon as we know the answer. (Ticket #1039)
parent bd0c18b2
No related branches found
No related tags found
No related merge requests found
...@@ -361,18 +361,29 @@ class ConnectionManager { ...@@ -361,18 +361,29 @@ class ConnectionManager {
private boolean locked_tooManyStreams() { private boolean locked_tooManyStreams() {
int max = _defaultOptions.getMaxConns(); int max = _defaultOptions.getMaxConns();
if (max <= 0) return false; if (max <= 0) return false;
if (_connectionByInboundId.size() < max) return false; int size = _connectionByInboundId.size();
if (size < max) return false;
// count both so we can break out of the for loop asap
int active = 0; int active = 0;
int inactive = 0;
int maxInactive = size - max;
for (Connection con : _connectionByInboundId.values()) { for (Connection con : _connectionByInboundId.values()) {
if (con.getIsConnected()) // ticket #1039
active++; if (con.getIsConnected() &&
!(con.getCloseSentOn() > 0 && con.getCloseReceivedOn() > 0)) {
if (++active >= max)
return true;
} else {
if (++inactive > maxInactive)
return false;
}
} }
if ( (_connectionByInboundId.size() > 100) && (_log.shouldLog(Log.INFO)) ) //if ( (_connectionByInboundId.size() > 100) && (_log.shouldLog(Log.INFO)) )
_log.info("More than 100 connections! " + active // _log.info("More than 100 connections! " + active
+ " total: " + _connectionByInboundId.size()); // + " total: " + _connectionByInboundId.size());
return (active >= max); return false;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment