summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2006-07-26 12:15:15 -0700
committerRobey Pointer <robey@lag.net>2006-07-26 12:15:15 -0700
commit17a93bce4c0b91a933f6c5e873fb41d238209ee1 (patch)
tree993de5c9dcc9d48dd931992318d4d61ce32c15d1
parentc731a077fb44144f0c6e40281e4ffce0cd7e3e1e (diff)
[project @ robey@lag.net-20060726191515-6ff627b4d7216073]
if a chunk has been requested in prefetch, don't bother doing an overlapping prefetch during readv
-rw-r--r--paramiko/sftp_file.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py
index 52948996..9dafbaf6 100644
--- a/paramiko/sftp_file.py
+++ b/paramiko/sftp_file.py
@@ -83,6 +83,20 @@ class SFTPFile (BufferedFile):
# may have outlived the Transport connection
pass
+ def _data_in_prefetch_requests(self, offset, size):
+ k = [i for i in self._prefetch_reads if i[0] <= offset]
+ if len(k) == 0:
+ return False
+ k.sort(cmp=lambda x, y: cmp(x[0], y[0]))
+ buf_offset, buf_size = k[-1]
+ if buf_offset + buf_size <= offset:
+ return True
+ if buf_offset + buf_size >= offset + size:
+ # inclusive
+ return True
+ # well, we have part of the request. see if another chunk has the rest.
+ return self._data_in_prefetch_requests(buf_offset + buf_size, offset + size - buf_offset - buf_size)
+
def _data_in_prefetch_buffers(self, offset):
"""
if a block of data is present in the prefetch buffers, at the given
@@ -393,7 +407,7 @@ class SFTPFile (BufferedFile):
read_chunks = []
for offset, size in chunks:
# don't fetch data that's already in the prefetch buffer
- if self._data_in_prefetch_buffers(offset):
+ if self._data_in_prefetch_buffers(offset) or self._data_in_prefetch_requests(offset, size):
continue
# break up anything larger than the max read size