|
20 | 20 | from collections import deque |
21 | 21 | from warnings import warn |
22 | 22 |
|
23 | | -from gevent import sleep, spawn, get_hub, Timeout as GTimeout |
| 23 | +from gevent import sleep, spawn, get_hub |
24 | 24 | from gevent.select import POLLIN, POLLOUT |
25 | 25 | from ssh2.error_codes import LIBSSH2_ERROR_EAGAIN |
26 | 26 | from ssh2.exceptions import SFTPHandleError, SFTPProtocolError, \ |
@@ -314,13 +314,7 @@ def close_channel(self, channel): |
314 | 314 | self._eagain(channel.close) |
315 | 315 |
|
316 | 316 | def _eagain(self, func, *args, **kwargs): |
317 | | - timeout = kwargs.pop('timeout', self.timeout) |
318 | | - with GTimeout(seconds=timeout, exception=Timeout): |
319 | | - ret = func(*args, **kwargs) |
320 | | - while ret == LIBSSH2_ERROR_EAGAIN: |
321 | | - self.poll() |
322 | | - ret = func(*args, **kwargs) |
323 | | - return ret |
| 317 | + return self._eagain_errcode(func, LIBSSH2_ERROR_EAGAIN, *args, **kwargs) |
324 | 318 |
|
325 | 319 | def _make_sftp(self): |
326 | 320 | """Make SFTP client from open transport""" |
@@ -707,18 +701,12 @@ def poll(self, timeout=None): |
707 | 701 | events |= POLLOUT |
708 | 702 | self._poll_socket(events, timeout=timeout) |
709 | 703 |
|
710 | | - def eagain_write(self, write_func, data, timeout=None): |
| 704 | + def _eagain_write(self, write_func, data, timeout=None): |
711 | 705 | """Write data with given write_func for an ssh2-python session while |
712 | 706 | handling EAGAIN and resuming writes from last written byte on each call to |
713 | 707 | write_func. |
714 | 708 | """ |
715 | | - data_len = len(data) |
716 | | - total_written = 0 |
717 | | - while total_written < data_len: |
718 | | - rc, bytes_written = write_func(data[total_written:]) |
719 | | - total_written += bytes_written |
720 | | - if rc == LIBSSH2_ERROR_EAGAIN: |
721 | | - self.poll(timeout=timeout) |
| 709 | + return self._eagain_write_errcode(write_func, data, LIBSSH2_ERROR_EAGAIN, timeout=timeout) |
722 | 710 |
|
723 | | - def _eagain_write(self, write_func, data, timeout=None): |
724 | | - return self.eagain_write(write_func, data, timeout=timeout) |
| 711 | + def eagain_write(self, write_func, data, timeout=None): |
| 712 | + return self._eagain_write(write_func, data, timeout=timeout) |
0 commit comments