Add IO sleep to agent forward communications.

Without this, use of agent forwarding causes
high CPU usage on some clients.
This commit is contained in:
Jeff Forcier 2012-01-17 12:10:57 -08:00
parent 543651bfd2
commit 3030589aaa
3 changed files with 9 additions and 1 deletions

View File

@ -98,6 +98,8 @@ from common import AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED, \
from sftp import SFTP_OK, SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED, SFTP_FAILURE, \ from sftp import SFTP_OK, SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED, SFTP_FAILURE, \
SFTP_BAD_MESSAGE, SFTP_NO_CONNECTION, SFTP_CONNECTION_LOST, SFTP_OP_UNSUPPORTED SFTP_BAD_MESSAGE, SFTP_NO_CONNECTION, SFTP_CONNECTION_LOST, SFTP_OP_UNSUPPORTED
from common import io_sleep
__all__ = [ 'Transport', __all__ = [ 'Transport',
'SSHClient', 'SSHClient',
'MissingHostKeyPolicy', 'MissingHostKeyPolicy',
@ -131,4 +133,5 @@ __all__ = [ 'Transport',
'AgentKey', 'AgentKey',
'HostKeys', 'HostKeys',
'SSHConfig', 'SSHConfig',
'util' ] 'util',
'io_sleep' ]

View File

@ -34,6 +34,7 @@ from ssh.ssh_exception import SSHException
from ssh.message import Message from ssh.message import Message
from ssh.pkey import PKey from ssh.pkey import PKey
from ssh.channel import Channel from ssh.channel import Channel
from ssh.common import io_sleep
SSH2_AGENTC_REQUEST_IDENTITIES, SSH2_AGENT_IDENTITIES_ANSWER, \ SSH2_AGENTC_REQUEST_IDENTITIES, SSH2_AGENT_IDENTITIES_ANSWER, \
SSH2_AGENTC_SIGN_REQUEST, SSH2_AGENT_SIGN_RESPONSE = range(11, 15) SSH2_AGENTC_SIGN_REQUEST, SSH2_AGENT_SIGN_RESPONSE = range(11, 15)
@ -134,6 +135,7 @@ class AgentProxyThread(threading.Thread):
self._agent._conn.send(data) self._agent._conn.send(data)
else: else:
break break
time.sleep(io_sleep)
class AgentLocalProxy(AgentProxyThread): class AgentLocalProxy(AgentProxyThread):
""" """

View File

@ -124,3 +124,6 @@ INFO = logging.INFO
WARNING = logging.WARNING WARNING = logging.WARNING
ERROR = logging.ERROR ERROR = logging.ERROR
CRITICAL = logging.CRITICAL CRITICAL = logging.CRITICAL
# Common IO/select/etc sleep period, in seconds
io_sleep = 0.01