[pypy-svn] r33655 - in pypy/dist/pypy/module/rsocket: . test
ac at codespeak.net
ac at codespeak.net
Tue Oct 24 15:36:41 CEST 2006
Author: ac
Date: Tue Oct 24 15:36:34 2006
New Revision: 33655
Modified:
pypy/dist/pypy/module/rsocket/interp_socket.py
pypy/dist/pypy/module/rsocket/rsocket.py
pypy/dist/pypy/module/rsocket/test/test_rsocket.py
pypy/dist/pypy/module/rsocket/test/test_sock_app.py
Log:
Implement dup().
Modified: pypy/dist/pypy/module/rsocket/interp_socket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/interp_socket.py (original)
+++ pypy/dist/pypy/module/rsocket/interp_socket.py Tue Oct 24 15:36:34 2006
@@ -71,6 +71,13 @@
return space.wrap(error)
connect_ex_w.unwrap_spec = ['self', ObjSpace, W_Root]
+ def dup_w(self, space):
+ try:
+ return self.dup(W_RSocket)
+ except SocketError, e:
+ raise converted_error(space, e)
+ dup_w.unwrap_spec = ['self', ObjSpace]
+
def fileno_w(self, space):
"""fileno() -> integer
@@ -320,7 +327,7 @@
# ____________________________________________________________
socketmethodnames = """
-accept bind close connect connect_ex fileno
+accept bind close connect connect_ex dup fileno
getpeername getsockname getsockopt gettimeout listen recv
recvfrom send sendall sendto setblocking
setsockopt settimeout shutdown
Modified: pypy/dist/pypy/module/rsocket/rsocket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/rsocket.py (original)
+++ pypy/dist/pypy/module/rsocket/rsocket.py Tue Oct 24 15:36:34 2006
@@ -8,7 +8,7 @@
#
# - support for non-Linux platforms
# - address families other than AF_INET, AF_INET6, AF_UNIX
-# - methods dup(), makefile(),
+# - methods makefile(),
# - functions getnameinfo()
# - SSL
@@ -538,26 +538,35 @@
return _c.geterrno()
return res
+ def dup(self, SocketClass=None):
+ if SocketClass is None:
+ SocketClass = RSocket
+ fd = _c.dup(self.fd)
+ if fd < 0:
+ raise self.error_handler()
+ return make_socket(fd, self.family, self.type, self.proto,
+ SocketClass=SocketClass)
+
def fileno(self):
fd = self.fd
if _c.invalid_socket(fd):
raise RSocketError("socket already closed")
return fd
- def getsockname(self):
- """Return the address of the local endpoint."""
+ def getpeername(self):
+ """Return the address of the remote endpoint."""
address, addrlen = self._addrbuf()
- res = _c.socketgetsockname(self.fd, byref(address.addr),
+ res = _c.socketgetpeername(self.fd, byref(address.addr),
byref(addrlen))
if res < 0:
raise self.error_handler()
address.addrlen = addrlen.value
return address
- def getpeername(self):
- """Return the address of the remote endpoint."""
+ def getsockname(self):
+ """Return the address of the local endpoint."""
address, addrlen = self._addrbuf()
- res = _c.socketgetpeername(self.fd, byref(address.addr),
+ res = _c.socketgetsockname(self.fd, byref(address.addr),
byref(addrlen))
if res < 0:
raise self.error_handler()
Modified: pypy/dist/pypy/module/rsocket/test/test_rsocket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/test/test_rsocket.py (original)
+++ pypy/dist/pypy/module/rsocket/test/test_rsocket.py Tue Oct 24 15:36:34 2006
@@ -205,6 +205,14 @@
reuseptr = _c.cast(_c.c_char_p(reusestr), _c.POINTER(_c.c_int))
assert reuseptr[0] != 0
+def test_dup():
+ s = RSocket(_c.AF_INET, _c.SOCK_STREAM)
+ s.setsockopt_int(_c.SOL_SOCKET, _c.SO_REUSEADDR, 1)
+ s.bind(INETAddress('localhost', 50007))
+ s2 = s.dup()
+ assert s.fileno() != s2.fileno()
+ assert s.getsockname().eq(s2.getsockname())
+
class TestTCP:
PORT = 50007
HOST = 'localhost'
Modified: pypy/dist/pypy/module/rsocket/test/test_sock_app.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/test/test_sock_app.py (original)
+++ pypy/dist/pypy/module/rsocket/test/test_sock_app.py Tue Oct 24 15:36:34 2006
@@ -376,6 +376,15 @@
(reuse,) = struct.unpack('i', reusestr)
assert reuse != 0
+ def test_dup(self):
+ import _socket as socket
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ s.bind(('localhost', 50007))
+ s2 = s.dup()
+ assert s.fileno() != s2.fileno()
+ assert s.getsockname() == s2.getsockname()
+
class AppTestSocketTCP:
def setup_class(cls):
More information about the Pypy-commit
mailing list