[pypy-svn] r42140 - in pypy/dist/pypy: module/rsocket rlib

afa at codespeak.net afa at codespeak.net
Tue Apr 17 23:22:46 CEST 2007


Author: afa
Date: Tue Apr 17 23:22:45 2007
New Revision: 42140

Modified:
   pypy/dist/pypy/module/rsocket/__init__.py
   pypy/dist/pypy/rlib/rsocket.py
Log:
Call WSAStartup() on module import.
Also hide two functions invalid on win32


Modified: pypy/dist/pypy/module/rsocket/__init__.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/__init__.py	(original)
+++ pypy/dist/pypy/module/rsocket/__init__.py	Tue Apr 17 23:22:45 2007
@@ -17,6 +17,10 @@
         'socket'    :  'interp_socket.W_RSocket',
     }
 
+    def startup(self, space):
+        from pypy.rlib.rsocket import rsocket_startup
+        rsocket_startup()
+
     def buildloaders(cls):
         from pypy.rlib import rsocket
         for name in """
@@ -29,6 +33,7 @@
             """.split():
 
             if name in ('inet_pton', 'inet_ntop',
+                        'fromfd', 'socketpair',
                         ) and not hasattr(rsocket, name):
                 continue
             

Modified: pypy/dist/pypy/rlib/rsocket.py
==============================================================================
--- pypy/dist/pypy/rlib/rsocket.py	(original)
+++ pypy/dist/pypy/rlib/rsocket.py	Tue Apr 17 23:22:45 2007
@@ -862,28 +862,30 @@
 else:
     socketpair_default_family = AF_UNIX
 
-def socketpair(family=socketpair_default_family, type=SOCK_STREAM, proto=0,
-               SocketClass=RSocket):
-    """socketpair([family[, type[, proto]]]) -> (socket object, socket object)
-
-    Create a pair of socket objects from the sockets returned by the platform
-    socketpair() function.
-    The arguments are the same as for socket() except the default family is
-    AF_UNIX if defined on the platform; otherwise, the default is AF_INET.
-    """
-    result = _c.socketpair_t()
-    res = _c.socketpair(family, type, proto, byref(result))
-    if res < 0:
-        raise last_error()
-    return (make_socket(result[0], family, type, proto, SocketClass),
-            make_socket(result[1], family, type, proto, SocketClass))
+if hasattr(_c, 'socketpair'):
+    def socketpair(family=socketpair_default_family, type=SOCK_STREAM, proto=0,
+                   SocketClass=RSocket):
+        """socketpair([family[, type[, proto]]]) -> (socket object, socket object)
+
+        Create a pair of socket objects from the sockets returned by the platform
+        socketpair() function.
+        The arguments are the same as for socket() except the default family is
+        AF_UNIX if defined on the platform; otherwise, the default is AF_INET.
+        """
+        result = _c.socketpair_t()
+        res = _c.socketpair(family, type, proto, byref(result))
+        if res < 0:
+            raise last_error()
+        return (make_socket(result[0], family, type, proto, SocketClass),
+                make_socket(result[1], family, type, proto, SocketClass))
 
-def fromfd(fd, family, type, proto=0, SocketClass=RSocket):
-    # Dup the fd so it and the socket can be closed independently
-    fd = _c.dup(fd)
-    if fd < 0:
-        raise last_error()
-    return make_socket(fd, family, type, proto, SocketClass)
+if hasattr(_c, 'dup'):
+    def fromfd(fd, family, type, proto=0, SocketClass=RSocket):
+        # Dup the fd so it and the socket can be closed independently
+        fd = _c.dup(fd)
+        if fd < 0:
+            raise last_error()
+        return make_socket(fd, family, type, proto, SocketClass)
 
 def getdefaulttimeout():
     return defaults.timeout



More information about the Pypy-commit mailing list