← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2287: prevent a race condition when trying to access the properties of a socket that is still being cre...

 

------------------------------------------------------------
revno: 2287
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2010-11-10 16:11:27 +0100
message:
  prevent a race condition when trying to access the properties of a socket that is still being created
modified:
  changelog.txt
  dcpp/Client.cpp
  dcpp/Client.h


--
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	2010-11-08 16:39:26 +0000
+++ changelog.txt	2010-11-10 15:11:27 +0000
@@ -28,6 +28,7 @@
 * Help updates (poy, emtee)
 * [L#571914] Fix crash when a zero sized bloom filter is requested (emtee)
 * Don't close the net stats window when double-clicking on the status bar (poy)
+* Fix a random crash when reconnecting hubs and being unlucky (poy)
 
 -- 0.770 2010-07-05 --
 * [L#550300] Catch more potential file corruptions (thanks bigmuscle)

=== modified file 'dcpp/Client.cpp'
--- dcpp/Client.cpp	2010-08-30 14:04:10 +0000
+++ dcpp/Client.cpp	2010-11-10 15:11:27 +0000
@@ -106,19 +106,18 @@
 		sock->addListener(this);
 		sock->connect(address, port, secure, BOOLSETTING(ALLOW_UNTRUSTED_HUBS), true);
 	} catch(const Exception& e) {
-		if(sock) {
-			BufferedSocket::putSocket(sock);
-			sock = 0;
-		}
+		shutdown();
+		/// @todo at this point, this hub instance is completely useless
 		fire(ClientListener::Failed(), this, e.getError());
 	}
 	updateActivity();
 }
 
 void Client::send(const char* aMessage, size_t aLen) {
-	dcassert(sock);
-	if(!sock)
+	if(!isReady()) {
+		dcassert(0);
 		return;
+	}
 	updateActivity();
 	sock->write(aMessage, aLen);
 }
@@ -144,15 +143,15 @@
 }
 
 bool Client::isSecure() const {
-	return sock && sock->isSecure();
+	return isReady() && sock->isSecure();
 }
 
 bool Client::isTrusted() const {
-	return sock && sock->isTrusted();
+	return isReady() && sock->isTrusted();
 }
 
 std::string Client::getCipherName() const {
-	return sock ? sock->getCipherName() : Util::emptyString;
+	return isReady() ? sock->getCipherName() : Util::emptyString;
 }
 
 void Client::updateCounts(bool aRemove) {

=== modified file 'dcpp/Client.h'
--- dcpp/Client.h	2010-08-30 14:04:10 +0000
+++ dcpp/Client.h	2010-11-10 15:11:27 +0000
@@ -57,6 +57,7 @@
 	virtual string escape(string const& str) const { return str; }
 
 	bool isConnected() const { return state != STATE_DISCONNECTED; }
+	bool isReady() const { return state != STATE_CONNECTING && state != STATE_DISCONNECTED; }
 	bool isSecure() const;
 	bool isTrusted() const;
 	std::string getCipherName() const;