Port poll-using code to use select() instead.
(cherry picked from commit eb49bf4870
)
This commit is contained in:
parent
c46fddeb16
commit
212276af13
|
@ -27,8 +27,8 @@ import sys
|
|||
import threading
|
||||
import tempfile
|
||||
import stat
|
||||
import select
|
||||
import fcntl
|
||||
from select import select
|
||||
|
||||
from paramiko.ssh_exception import SSHException
|
||||
from paramiko.message import Message
|
||||
|
@ -117,22 +117,18 @@ class AgentProxyThread(threading.Thread):
|
|||
raise
|
||||
|
||||
def _communicate(self):
|
||||
p = select.poll()
|
||||
oldflags = fcntl.fcntl(self.__inr, fcntl.F_GETFL)
|
||||
fcntl.fcntl(self.__inr, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
|
||||
p.register(self._agent._conn, select.POLLIN)
|
||||
p.register(self.__inr, select.POLLIN)
|
||||
while not self._exit:
|
||||
c = p.poll(500)
|
||||
for cc in c:
|
||||
fd, event = cc
|
||||
if self._agent._conn.fileno() == fd:
|
||||
events = select([self._agent._conn, self.__inr], [], [], 0.5)
|
||||
for fd in events[0]:
|
||||
if self._agent._conn == fd:
|
||||
data = self._agent._conn.recv(512)
|
||||
if len(data) != 0:
|
||||
self.__inr.send(data)
|
||||
else:
|
||||
break
|
||||
elif self.__inr.fileno() == fd:
|
||||
elif self.__inr == fd:
|
||||
data = self.__inr.recv(512)
|
||||
if len(data) != 0:
|
||||
self._agent._conn.send(data)
|
||||
|
|
Loading…
Reference in New Issue