Author: Matti Picus <matti.pi...@gmail.com>
Branch: 
Changeset: r70334:7fbef7602628
Date: 2014-03-30 06:15 +0300
http://bitbucket.org/pypy/pypy/changeset/7fbef7602628/

Log:    remerge branch, use select() rather than poll() for ssl on win32

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -64,6 +64,7 @@
 ^pypy/goal/pypy-jvm.jar
 ^pypy/goal/.+\.exe$
 ^pypy/goal/.+\.dll$
+^pypy/goal/.+\.lib$
 ^pypy/_cache$
 ^pypy/doc/statistic/.+\.html$
 ^pypy/doc/statistic/.+\.eps$
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -35,7 +35,7 @@
 SOCKET_HAS_TIMED_OUT, SOCKET_HAS_BEEN_CLOSED = 2, 3
 SOCKET_TOO_LARGE_FOR_SELECT, SOCKET_OPERATION_OK = 4, 5
 
-HAVE_RPOLL = True  # Even win32 has rpoll.poll
+HAVE_RPOLL = 'poll' in dir(rpoll)
 
 constants = {}
 constants["SSL_ERROR_ZERO_RETURN"] = PY_SSL_ERROR_ZERO_RETURN
diff --git a/rpython/rlib/rpoll.py b/rpython/rlib/rpoll.py
--- a/rpython/rlib/rpoll.py
+++ b/rpython/rlib/rpoll.py
@@ -141,8 +141,9 @@
 # poll() for Win32
 #
 if hasattr(_c, 'WSAEventSelect'):
-
-    def poll(fddict, timeout=-1):
+    # WSAWaitForMultipleEvents is broken. If you wish to try it,
+    # rename the function to poll() and run test_exchange in test_rpoll
+    def _poll(fddict, timeout=-1):
         """'fddict' maps file descriptors to interesting events.
         'timeout' is an integer in milliseconds, and NOT a float
         number of seconds, but it's the same in CPython.  Use -1 for infinite.
@@ -188,6 +189,7 @@
             if timeout < 0:
                 timeout = _c.INFINITE
 
+            # XXX does not correctly report write status of a port
             ret = _c.WSAWaitForMultipleEvents(numevents, socketevents,
                                               False, timeout, False)
 
diff --git a/rpython/rlib/test/test_rpoll.py b/rpython/rlib/test/test_rpoll.py
--- a/rpython/rlib/test/test_rpoll.py
+++ b/rpython/rlib/test/test_rpoll.py
@@ -3,12 +3,25 @@
 import py
 
 from rpython.rlib.rsocket import *
-from rpython.rlib.rpoll import *
+try:
+    from rpython.rlib.rpoll import poll
+except ImportError:
+    py.test.skip('no poll available on this platform')
 from rpython.rtyper.test.test_llinterp import interpret
 
 def setup_module(mod):
     rsocket_startup()
 
+def one_in_event(events, fd):
+    assert len(events) == 1
+    assert events[0][0] == fd
+    assert events[0][1] & POLLIN
+
+def one_out_event(events, fd):
+    assert len(events) == 1
+    assert events[0][0] == fd
+    assert events[0][1] & POLLOUT
+
 def test_simple():
     serv = RSocket(AF_INET, SOCK_STREAM)
     serv.bind(INETAddress('127.0.0.1', INADDR_ANY))
@@ -24,18 +37,14 @@
     assert err != 0
 
     events = poll({serv.fd: POLLIN}, timeout=500)
-    assert len(events) == 1
-    assert events[0][0] == serv.fd
-    assert events[0][1] & POLLIN
+    one_in_event(events, serv.fd)
 
     servconn_fd, cliaddr = serv.accept()
     servconn = RSocket(AF_INET, fd=servconn_fd)
 
     events = poll({serv.fd: POLLIN,
                    cli.fd: POLLOUT}, timeout=500)
-    assert len(events) == 1
-    assert events[0][0] == cli.fd
-    assert events[0][1] & POLLOUT
+    one_out_event(events, cli.fd)
 
     err = cli.connect_ex(servaddr)
     # win32: returns WSAEISCONN when the connection finally succeed.
@@ -55,6 +64,72 @@
     servconn.close()
     serv.close()
 
+def test_exchange():
+    if not poll:
+        py.test.skip('poll not available for this platform')
+    serv = RSocket(AF_INET, SOCK_STREAM)
+    serv.bind(INETAddress('127.0.0.1', INADDR_ANY))
+    serv.listen(1)
+    servaddr = serv.getsockname()
+
+    events = poll({serv.fd: POLLIN}, timeout=100)
+    assert len(events) == 0
+
+    cli = RSocket(AF_INET, SOCK_STREAM)
+    cli.setblocking(True)
+    err = cli.connect_ex(servaddr)
+    assert err == 0
+
+    events = poll({serv.fd: POLLIN}, timeout=500)
+    one_in_event(events, serv.fd)
+
+    servconn_fd, cliaddr = serv.accept()
+    servconn = RSocket(AF_INET, fd=servconn_fd)
+
+    events = poll({serv.fd: POLLIN,
+                   cli.fd: POLLOUT}, timeout=500)
+    one_out_event(events, cli.fd)
+
+    #send some data
+    events = poll({cli.fd: POLLOUT}, timeout=500)
+    one_out_event(events, cli.fd)
+    cli.send("g'day, mate")
+    events = poll({servconn.fd: POLLIN}, timeout=500)
+    one_in_event(events, servconn.fd)
+    answer = servconn.recv(1024)
+    assert answer == "g'day, mate"
+
+    #send a reply
+    events = poll({servconn.fd: POLLOUT}, timeout=500)
+    one_out_event(events, servconn.fd)
+    servconn.send("you mean hello?")
+    events = poll({cli.fd: POLLIN}, timeout=500)
+    one_in_event(events, cli.fd)
+    answer = cli.recv(1024)
+    assert answer == "you mean hello?"
+
+    #send more data
+    events = poll({cli.fd: POLLOUT}, timeout=500)
+    one_out_event(events, cli.fd)
+    cli.send("sorry, wrong channel")
+    events = poll({servconn.fd: POLLIN}, timeout=500)
+    one_in_event(events, servconn.fd)
+    answer = servconn.recv(1024)
+    assert answer == "sorry, wrong channel"
+
+    events = poll({servconn.fd: POLLOUT}, timeout=500)
+    one_out_event(events, servconn.fd)
+    servconn.send("np bye")
+    events = poll({cli.fd: POLLIN}, timeout=500)
+    one_in_event(events, cli.fd)
+    answer = cli.recv(1024)
+    assert answer == "np bye"
+
+    cli.close()
+    servconn.close()
+    serv.close()
+
+
 def test_select():
     if os.name == 'nt':
         py.test.skip('cannot select on file handles on windows')
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to