Implementation of GreenSSL.read that I'm much happier about, as it only does trampolines when the underlying Connection wants some data read, since theoretically it may require multiple reads on the underlying socket to get enough data to present to the SSL client. This refactoring makes checking pending() unnecessary.

This commit is contained in:
Ryan Williams
2009-07-17 11:47:06 -07:00
parent 7a4f5e8a7b
commit e73849a867

View File

@@ -562,16 +562,14 @@ class GreenSSL(GreenSocket):
""" Read up to *size* bytes from the socket. This may return fewer than
*size* bytes in some circumstances, but everything appears to work as
long as you don't treat this precisely like standard socket read()."""
pending = self.fd.pending()
if pending:
return self.fd.recv(min(pending, size))
# no pending() == we must wait for IO on the underlying socket
trampoline(self.fd.fileno(), read=True,
timeout=self.timeout,
timeout_exc=socket.timeout)
return self.fd.recv(size)
while True:
try:
return self.fd.read(size)
except util.SSL.WantReadError:
trampoline(self.fd.fileno(),
read=True,
timeout=self.timeout,
timeout_exc=socket.timeout)
recv = read