Browse Source

Traffic.py: make want_to_write() correct

The first two parts were correct before: CONNECTING sockets should
check for write, and any socket with a nonempty outbuf should try to
write it.  But the third was wrong: only CONNECTED sockets should
try to write because their repetitions and data fields are set --
because on_writable does not actually do anything with those fields
unless the state happens to be CONNECTED.
Nick Mathewson 7 years ago
parent
commit
4f1d926c2b
1 changed files with 9 additions and 2 deletions
  1. 9 2
      lib/chutney/Traffic.py

+ 9 - 2
lib/chutney/Traffic.py

@@ -258,8 +258,15 @@ class Source(Peer):
         return self.want_to_write()  # Keep us around for writing if needed
 
     def want_to_write(self):
-        return (self.state == self.CONNECTING or len(self.outbuf) > 0 or
-                (self.repetitions > 0 and len(self.data) > 0))
+        if self.state == self.CONNECTING:
+            return True
+        if len(self.outbuf) > 0:
+            return True
+        if (self.state == self.CONNECTED and
+            self.repetitions > 0 and
+            len(self.data) > 0):
+            return True
+        return False
 
     def on_writable(self):
         """Invoked when the socket becomes writable.