[pypy-svn] r20967 - in pypy/dist/pypy: module/_socket translator/c/src translator/c/test

nik at codespeak.net nik at codespeak.net
Fri Dec 9 20:02:02 CET 2005


Author: nik
Date: Fri Dec  9 20:02:00 2005
New Revision: 20967

Modified:
   pypy/dist/pypy/module/_socket/interp_socket.py
   pypy/dist/pypy/translator/c/src/ll__socket.h
   pypy/dist/pypy/translator/c/test/test_ext__socket.py
Log:
(ale, nik)
raising errors out of C socket helpers. they are OSErrors at the moment, because
socket.errors can't be raised from C. must investigated at some later point ...


Modified: pypy/dist/pypy/module/_socket/interp_socket.py
==============================================================================
--- pypy/dist/pypy/module/_socket/interp_socket.py	(original)
+++ pypy/dist/pypy/module/_socket/interp_socket.py	Fri Dec  9 20:02:00 2005
@@ -709,6 +709,9 @@
             port = space.int_w(addr_w[1])
             try:
                 rsocket.connect(self.fd, host, port)
+            except OSError, ex:
+                raise w_get_socketerror(space, e.strerror, e.errno)
+            # XXX timeout doesn't really work at the moment
             except socket.timeout:
                 raise wrap_timeouterror(space)
             except socket.error, e:

Modified: pypy/dist/pypy/translator/c/src/ll__socket.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll__socket.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll__socket.h	Fri Dec  9 20:02:00 2005
@@ -108,12 +108,16 @@
     
     if (setipaddr(RPyString_AsString(host), (struct sockaddr *) &addr,
 		      sizeof(addr), AF_INET) < 0) {
-        // XXX raise some error here
+        // XXX we actually want to raise socket.error
+        RPYTHON_RAISE_OSERROR(errno);
+        return NULL;
     }
     addr.sin_family = AF_INET;
     addr.sin_port = htons(port);
     if (connect(fd, &addr, sizeof(addr)) < 0) {
-        // XXX raise some error here
+        // XXX we actually want to raise socket.error
+        RPYTHON_RAISE_OSERROR(errno);
+        return NULL;
     }
 }
 

Modified: pypy/dist/pypy/translator/c/test/test_ext__socket.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_ext__socket.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_ext__socket.py	Fri Dec  9 20:02:00 2005
@@ -103,3 +103,19 @@
     f1 = compile(does_stuff, [])
     res = f1()
     assert res == 80
+
+def test_connect_error():
+    from pypy.module._socket.rpython import rsocket
+    import os
+    tests = [
+        ("blablablablabla", 80),
+        ("127.0.0.1", 909090),
+        ("127.0.0.1", -2),
+    ]
+    def does_stuff(host, port):
+        fd = rsocket.newsocket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
+        rsocket.connect(fd, host, port)
+        os.close(fd)
+    f1 = compile(does_stuff, [str, int])
+    for args in tests:
+        py.test.raises(OSError, f1, *args)



More information about the Pypy-commit mailing list