]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Trap KRPC errors in writing to the transport and wait for timeout instead.
authorCameron Dale <camrdale@gmail.com>
Wed, 23 Apr 2008 03:16:21 +0000 (20:16 -0700)
committerCameron Dale <camrdale@gmail.com>
Wed, 23 Apr 2008 03:16:21 +0000 (20:16 -0700)
apt_p2p_Khashmir/krpc.py

index 9ae5ac7e09f5b075f17c384ccef343bd355fa48a..3a2e5b310005c5ddd1b0d0d853afae3a43b59884 100644 (file)
@@ -240,13 +240,16 @@ class KrpcRequest(defer.Deferred):
         self.delay = self.config.get('KRPC_INITIAL_DELAY', 2)
         self.start = datetime.now()
         self.later = None
-        self.send()
+        reactor.callLater(0, self.send)
         
     def send(self):
         """Send the request to the remote node."""
         assert not self.later, 'There is already a pending request'
         self.later = reactor.callLater(self.delay, self.timeOut)
-        self.protocol.sendData(self.method, self.data)
+        try:
+            self.protocol.sendData(self.method, self.data)
+        except:
+            log.err()
 
     def timeOut(self):
         """Check for a unrecoverable timeout, otherwise resend."""
@@ -261,7 +264,7 @@ class KrpcRequest(defer.Deferred):
         else:
             self.delay *= 2
             log.msg('Trying to resend %r now with delay %d sec' % (self.tid, self.delay))
-            self.send()
+            reactor.callLater(0, self.send)
         
     def callback(self, resp):
         self.dropTimeOut()
@@ -535,11 +538,10 @@ class KRPC:
         @type data: C{string}
         @param data: the message to send to the remote node
         """
+        self.transport.write(data, self.addr)
         self.stats.sentAction(method)
         self.stats.sentBytes(len(data))
         
-        self.transport.write(data, self.addr)
-        
     def timeOut(self, badTID, method):
         """Call the deferred's errback if a timeout occurs.