Port poll-using code to use select() instead.

Re #1
This commit is contained in:
Jeff Forcier 2011-11-17 15:18:35 -08:00
parent 35a173631f
commit eb49bf4870
1 changed files with 5 additions and 9 deletions

View File

@ -27,8 +27,8 @@ import sys
import threading import threading
import tempfile import tempfile
import stat import stat
import select
import fcntl import fcntl
from select import select
from ssh.ssh_exception import SSHException from ssh.ssh_exception import SSHException
from ssh.message import Message from ssh.message import Message
@ -117,22 +117,18 @@ class AgentProxyThread(threading.Thread):
raise raise
def _communicate(self): def _communicate(self):
p = select.poll()
oldflags = fcntl.fcntl(self.__inr, fcntl.F_GETFL) oldflags = fcntl.fcntl(self.__inr, fcntl.F_GETFL)
fcntl.fcntl(self.__inr, fcntl.F_SETFL, oldflags | os.O_NONBLOCK) 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: while not self._exit:
c = p.poll(500) events = select([self._agent._conn, self.__inr], [], [], 0.5)
for cc in c: for fd in events[0]:
fd, event = cc if self._agent._conn == fd:
if self._agent._conn.fileno() == fd:
data = self._agent._conn.recv(512) data = self._agent._conn.recv(512)
if len(data) != 0: if len(data) != 0:
self.__inr.send(data) self.__inr.send(data)
else: else:
break break
elif self.__inr.fileno() == fd: elif self.__inr == fd:
data = self.__inr.recv(512) data = self.__inr.recv(512)
if len(data) != 0: if len(data) != 0:
self._agent._conn.send(data) self._agent._conn.send(data)