qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kgiu...@apache.org
Subject svn commit: r1485331 - /qpid/trunk/qpid/python/qpid/messaging/transports.py
Date Wed, 22 May 2013 18:46:56 GMT
Author: kgiusti
Date: Wed May 22 18:46:56 2013
New Revision: 1485331

URL: http://svn.apache.org/r1485331
Log:
QPID-4872: when retrying ssl reads or writes, use previous arguments

Modified:
    qpid/trunk/qpid/python/qpid/messaging/transports.py

Modified: qpid/trunk/qpid/python/qpid/messaging/transports.py
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/python/qpid/messaging/transports.py?rev=1485331&r1=1485330&r2=1485331&view=diff
==============================================================================
--- qpid/trunk/qpid/python/qpid/messaging/transports.py (original)
+++ qpid/trunk/qpid/python/qpid/messaging/transports.py Wed May 22 18:46:56 2013
@@ -139,6 +139,11 @@ else:
 
       self.socket.setblocking(0)
       self.state = None
+      # See qpid-4872: need to store the parameters last passed to
+      # tls.recv_into() and tls.write() in case the calls fail with an
+      # SSL_ERROR_WANT_* error and we have to retry the call.
+      self.write_retry = None   # buffer passed to last call of tls.write()
+      self.read_retry = None    # buffer passed to last call of tls.recv_into()
 
     def reading(self, reading):
       if self.state is None:
@@ -153,24 +158,41 @@ else:
         return self.state == SSL_ERROR_WANT_WRITE
 
     def send(self, bytes):
+      if self.write_retry is None:
+        self.write_retry = bytes
       self._clear_state()
       try:
-        return self.tls.write(bytes)
+        n = self.tls.write( self.write_retry )
+        self.write_retry = None
+        return n
       except SSLError, e:
         if self._update_state(e.args[0]):
+          # will retry on next invokation
           return 0
-        else:
-          raise
+        self.write_retry = None
+        raise
+      except:
+        self.write_retry = None
+        raise
 
     def recv(self, n):
+      if self.read_retry == None:
+        self.read_retry = bytearray( n )
       self._clear_state()
       try:
-        return self.tls.read(n)
+        n = self.tls.recv_into( self.read_retry )
+        r = str(self.read_retry[:n])
+        self.read_retry = None
+        return r
       except SSLError, e:
         if self._update_state(e.args[0]):
+          # will retry on next invokation
           return None
-        else:
-          raise
+        self.read_retry = None
+        raise
+      except:
+        self.read_retry = None
+        raise
 
     def _clear_state(self):
       self.state = None



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message