← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2496: fix bug 604983 regarding /upload 0 and /download 0

 

------------------------------------------------------------
revno: 2496
committer: cologic <ne5@xxxxxxxxxxx>
branch nick: dcplusplus
timestamp: Sun 2011-04-17 16:29:37 -0400
message:
  fix bug 604983 regarding /upload 0 and /download 0
modified:
  changelog.txt
  dcpp/ThrottleManager.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2011-04-15 21:51:55 +0000
+++ changelog.txt	2011-04-17 20:29:37 +0000
@@ -20,6 +20,7 @@
 * Remember the last settings page (poy)
 * Fix focus problems in dialogs (poy)
 * Fix Ctrl+W / Ctrl+F4 sometimes closing the wrong tab (poy)
+* [L#604983] Fix transfers dying on setting upload/download throttle to 0 (cologic)
 
 -- 0.782 2011-03-05 --
 * Prevent a remote crash triggered via malformed user commands (poy)

=== modified file 'dcpp/ThrottleManager.cpp'
--- dcpp/ThrottleManager.cpp	2011-04-13 19:16:51 +0000
+++ dcpp/ThrottleManager.cpp	2011-04-17 20:29:37 +0000
@@ -40,7 +40,8 @@
 {
 	int64_t readSize = -1;
 	size_t downs = DownloadManager::getInstance()->getDownloadCount();
-	if(!getCurThrottling() || downTokens == -1 || downs == 0)
+	auto downLimit = getDownLimit(); // avoid even intra-function races
+	if(!getCurThrottling() || downLimit == 0 || downs == 0)
 		return sock->read(buffer, len);
 
 	{
@@ -48,7 +49,7 @@
 
 		if(downTokens > 0)
 		{
-			int64_t slice = (getDownLimit() * 1024) / downs;
+			int64_t slice = (downLimit * 1024) / downs;
 			readSize = min(slice, min(static_cast<int64_t>(len), downTokens));
 
 			// read from socket
@@ -77,7 +78,8 @@
 {
 	bool gotToken = false;
 	size_t ups = UploadManager::getInstance()->getUploadCount();
-	if(!getCurThrottling() || upTokens == -1 || ups == 0)
+	auto upLimit = getUpLimit(); // avoid even intra-function races
+	if(!getCurThrottling() || upLimit == 0 || ups == 0)
 		return sock->write(buffer, len);
 
 	{
@@ -85,7 +87,7 @@
 
 		if(upTokens > 0)
 		{
-			size_t slice = (getUpLimit() * 1024) / ups;
+			size_t slice = (upLimit * 1024) / ups;
 			len = min(slice, min(len, static_cast<size_t>(upTokens)));
 			upTokens -= len;
 
@@ -198,24 +200,15 @@
 			waitCS[activeWaiter = 0].lock();
 	}
 
-	int downLimit = getDownLimit();
-	int upLimit   = getUpLimit();
-
 	// readd tokens
 	{
 		Lock l(downCS);
-		if(downLimit > 0)
-			downTokens = downLimit * 1024;
-		else
-			downTokens = -1;
+		downTokens = getDownLimit() * 1024;
 	}
 
 	{
 		Lock l(upCS);
-		if(upLimit > 0)
-			upTokens = upLimit * 1024;
-		else
-			upTokens = -1;
+		upTokens = getUpLimit() * 1024;
 	}
 
 	// let existing events drain out (fairness).