From 17a93bce4c0b91a933f6c5e873fb41d238209ee1 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Wed, 26 Jul 2006 12:15:15 -0700 Subject: [PATCH] [project @ robey@lag.net-20060726191515-6ff627b4d7216073] if a chunk has been requested in prefetch, don't bother doing an overlapping prefetch during readv --- paramiko/sftp_file.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index 5294899..9dafbaf 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