summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/qpid/selector.py25
-rw-r--r--python/tests/connection.py4
2 files changed, 18 insertions, 11 deletions
diff --git a/python/qpid/selector.py b/python/qpid/selector.py
index 46052e1108..a7993be0b1 100644
--- a/python/qpid/selector.py
+++ b/python/qpid/selector.py
@@ -16,7 +16,7 @@
# specific language governing permissions and limitations
# under the License.
#
-import atexit, os, time
+import atexit, time, socket
from compat import select, set
from threading import Thread, Lock
@@ -41,20 +41,20 @@ class Acceptor:
class Sink:
- def __init__(self, fd):
- self.fd = fd
+ def __init__(self, sock):
+ self.sock = sock
def fileno(self):
- return self.fd
+ return self.sock.fileno()
def reading(self):
return True
def readable(self):
- os.read(self.fd, 65536)
+ self.sock.recv(65536)
def __repr__(self):
- return "Sink(%r)" % self.fd
+ return "Sink(%r)" % self.sock.fileno()
class Selector:
@@ -78,13 +78,20 @@ class Selector:
self.selectables = set()
self.reading = set()
self.writing = set()
- self.wait_fd, self.wakeup_fd = os.pipe()
- self.reading.add(Sink(self.wait_fd))
+ listener = socket.socket()
+ listener.bind(('', 0))
+ listener.listen(1)
+ me_ip, me_port = listener.getsockname()
+ self.wakeup_sock = socket.socket()
+ self.wakeup_sock.connect(("127.0.0.1", me_port))
+ self.wait_sock, me = listener.accept()
+ listener.close()
+ self.reading.add(Sink(self.wait_sock))
self.stopped = False
self.thread = None
def wakeup(self):
- os.write(self.wakeup_fd, "\0")
+ self.wakeup_sock.send("\0")
def register(self, selectable):
self.selectables.add(selectable)
diff --git a/python/tests/connection.py b/python/tests/connection.py
index d340e4e9c1..8c00df56e1 100644
--- a/python/tests/connection.py
+++ b/python/tests/connection.py
@@ -91,11 +91,11 @@ class ConnectionTest(TestCase):
def tearDown(self):
self.running = False
- connect("0.0.0.0", PORT).close()
+ connect("127.0.0.1", PORT).close()
self.server.join(3)
def connect(self, **kwargs):
- return Connection(connect("0.0.0.0", PORT), **kwargs)
+ return Connection(connect("127.0.0.1", PORT), **kwargs)
def test(self):
c = self.connect()