[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/network/ktorrent/libbtcore
From:       Joris Guisson <joris.guisson () gmail ! com>
Date:       2010-02-21 15:52:57
Message-ID: 1266767577.582619.24502.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1093859 by guisson:

Fix some bugs introduced in big UTP commit


 M  +3 -1      net/socket.cpp  
 M  +36 -0     net/tests/polltest.cpp  
 M  +6 -0      peer/authenticate.cpp  
 M  +11 -10    peer/authenticationmonitor.cpp  


--- trunk/extragear/network/ktorrent/libbtcore/net/socket.cpp #1093858:1093859
@@ -270,8 +270,10 @@
 			{
 			//	Out(SYS_CON|LOG_DEBUG) << "Receive error : " << QString(strerror(errno)) << endl;
 				close();
+				return 0;
 			}
-			return 0;
+			
+			return ret;
 		}
 		else if (ret == 0)
 		{
--- trunk/extragear/network/ktorrent/libbtcore/net/tests/polltest.cpp #1093858:1093859
@@ -23,6 +23,7 @@
 #include <util/log.h>
 #include <util/pipe.h>
 #include <net/poll.h>
+#include <net/socket.h>
 
 using namespace net;
 using namespace bt;
@@ -113,6 +114,41 @@
 		QVERIFY(p.poll(100) == 0);
 	}
 	
+	void testSocket()
+	{
+		net::Socket sock(true,4);
+		QVERIFY(sock.bind("127.0.0.1",0,true));
+		
+		net::Address local_addr = sock.getSockName();
+		net::Socket writer(true,4);
+		writer.setBlocking(false);
+		writer.connectTo(local_addr);
+		
+		net::Address dummy;
+		net::Poll poll;
+		sock.prepare(&poll,net::Poll::INPUT);
+		
+		QVERIFY(poll.poll(1000) > 0);
+		int fd = sock.accept(dummy);
+		QVERIFY(fd >= 0);
+		
+		poll.reset();
+		QVERIFY(writer.connectSuccesFull());
+		
+		net::Socket reader(fd,6);
+		
+		bt::Uint8 data[20];
+		memset(data,0xFF,20);
+		QVERIFY(writer.send(data,20) == 20);
+		reader.prepare(&poll,net::Poll::INPUT);
+		
+		QVERIFY(poll.poll(1000) > 0);
+		
+		bt::Uint8 tmp[20];
+		QVERIFY(reader.recv(tmp,20) == 20);
+		QVERIFY(memcmp(tmp,data,20) == 0);
+	}
+	
 private:
 };
 
--- trunk/extragear/network/ktorrent/libbtcore/peer/authenticate.cpp #1093858:1093859
@@ -85,6 +85,9 @@
 	
 	void Authenticate::onReadyWrite()
 	{
+		if (!sock)
+			return;
+		
 		if (socks)
 		{
 			switch (socks->onReadyToWrite())
@@ -114,6 +117,9 @@
 	
 	void Authenticate::onReadyRead()
 	{
+		if (!sock)
+			return;
+		
 		if (!socks)
 		{
 			AuthenticateBase::onReadyRead();
--- trunk/extragear/network/ktorrent/libbtcore/peer/authenticationmonitor.cpp #1093858:1093859
@@ -106,23 +106,24 @@
 		while (itr != auths.end())
 		{
 			AuthenticateBase* ab = *itr;
-			mse::StreamSocket* socket = ab->getSocket();
-			if (socket)
-			{
-				net::SocketDevice* dev = socket->socketDevice();
-				if (dev->ready(this,Poll::INPUT))
-					ab->onReadyRead();
-				if (dev->ready(this,Poll::OUTPUT))
-					ab->onReadyWrite();
-			}
-			
 			if (ab->isFinished())
 			{
 				ab->deleteLater();
 				itr = auths.erase(itr);
 			}
 			else
+			{
+				mse::StreamSocket* socket = ab->getSocket();
+				if (socket)
+				{
+					net::SocketDevice* dev = socket->socketDevice();
+					if (dev->ready(this,Poll::INPUT))
+						ab->onReadyRead();
+					if (dev->ready(this,Poll::OUTPUT))
+						ab->onReadyWrite();
+				}
 				itr++;
+			}
 		}
 	}
 	
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic