[pypy-svn] r20917 - in pypy/dist/pypy/module/_socket: rpython test
nik at codespeak.net
nik at codespeak.net
Fri Dec 9 11:00:43 CET 2005
Author: nik
Date: Fri Dec 9 11:00:42 2005
New Revision: 20917
Modified:
pypy/dist/pypy/module/_socket/rpython/rsocket.py
pypy/dist/pypy/module/_socket/test/test_socket2.py
Log:
(ale, nik)
fixed mystery test failures related to the way we hack around the association of
file descriptors and socket objects on untranslated pypy.
Modified: pypy/dist/pypy/module/_socket/rpython/rsocket.py
==============================================================================
--- pypy/dist/pypy/module/_socket/rpython/rsocket.py (original)
+++ pypy/dist/pypy/module/_socket/rpython/rsocket.py Fri Dec 9 11:00:42 2005
@@ -4,7 +4,11 @@
import socket
-keep_sockets_alive = {}
+# HACK: We have to prevent GC to collect the socket object we create within this
+#Êmodule. Because socket.close() is called on GC this can lead to strange
+# effects in corner cases where file descriptors are reused.
+socket_cache = {}
+keep_sockets_alive = []
class ADDRINFO(object):
# a simulated addrinfo structure from C, i.e. a chained list
@@ -30,21 +34,21 @@
def newsocket(family, type, protocol):
s = socket.socket(family, type, protocol)
- # HACK: We have to prevent GC to collect the socket object because we don't
- # want it to be closed.
fileno = s.fileno()
- keep_sockets_alive[fileno] = s
+ if socket_cache.has_key(fileno):
+ keep_sockets_alive.append(socket_cache[fileno])
+ socket_cache[fileno] = s
return fileno
def connect(fd, host, port):
# XXX IPv4 only
- s = keep_sockets_alive[fd]
+ s = socket_cache[fd]
try:
s.connect((host, port))
except Exception, ex:
print ex
def getpeername(fd):
- s = keep_sockets_alive[fd]
+ s = socket_cache[fd]
return s.getpeername()
Modified: pypy/dist/pypy/module/_socket/test/test_socket2.py
==============================================================================
--- pypy/dist/pypy/module/_socket/test/test_socket2.py (original)
+++ pypy/dist/pypy/module/_socket/test/test_socket2.py Fri Dec 9 11:00:42 2005
@@ -294,12 +294,15 @@
def app_test_socket_connect():
import _socket, os
s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
+ # XXX temporarily we use codespeak to test, will have more robust tests in
+ # the absence of a network connection later when mroe parts of the socket
+ # API are implemented.
s.connect(("codespeak.net", 80))
name = s.getpeername() # Will raise socket.error if not connected
assert name[1] == 80
s.close()
-def DONOT_app_test_socket_connect_typeerrors():
+def app_test_socket_connect_typeerrors():
tests = [
"",
("80"),
More information about the Pypy-commit
mailing list