summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-06-06 21:08:16 (GMT)
committerGuido van Rossum <guido@python.org>2002-06-06 21:08:16 (GMT)
commit67f7a388496aec53896a0a5109edf9026bbe5d5b (patch)
treeafa4d86d404b77167e7da09152db2a3562b729a2 /Lib/test/test_socket.py
parentc9a55776c88619d1b79d47d4734af0f2c423c045 (diff)
downloadcpython-67f7a388496aec53896a0a5109edf9026bbe5d5b.zip
cpython-67f7a388496aec53896a0a5109edf9026bbe5d5b.tar.gz
cpython-67f7a388496aec53896a0a5109edf9026bbe5d5b.tar.bz2
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
I've made considerable changes to Michael's code, specifically to use the select() system call directly and to store the timeout as a C double instead of a Python object; internally, -1.0 (or anything negative) represents the None from the API. I'm not 100% sure that all corner cases are covered correctly, so please keep an eye on this. Next I'm going to try it Windows before Tim complains. No way is this a bugfix candidate. :-)
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py67
1 files changed, 57 insertions, 10 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 9cef316..56c7fb1 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -109,6 +109,7 @@ except socket.error:
canfork = hasattr(os, 'fork')
try:
PORT = 50007
+ msg = 'socket test\n'
if not canfork or os.fork():
# parent is server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -133,13 +134,52 @@ try:
f = conn.makefile()
if verbose:
print 'file obj:', f
+ data = conn.recv(1024)
+ if verbose:
+ print 'received:', data
+ conn.sendall(data)
+
+ # Perform a few tests on the windows file object
+ if verbose:
+ print "Staring _fileobject tests..."
+ f = socket._fileobject (conn, 'rb', 8192)
+ first_seg = f.read(7)
+ second_seg = f.read(5)
+ if not first_seg == 'socket ' or not second_seg == 'test\n':
+ print "Error performing read with the python _fileobject class"
+ os._exit (1)
+ elif verbose:
+ print "_fileobject buffered read works"
+ f.write (data)
+ f.flush ()
+
+ buf = ''
while 1:
- data = conn.recv(1024)
- if not data:
+ char = f.read(1)
+ if not char:
+ print "Error performing unbuffered read with the python ", \
+ "_fileobject class"
+ os._exit (1)
+ buf += char
+ if buf == msg:
+ if verbose:
+ print "__fileobject unbuffered read works"
break
- if verbose:
- print 'received:', data
- conn.sendall(data)
+ if verbose:
+ # If we got this far, write() must work as well
+ print "__fileobject write works"
+ f.write(buf)
+ f.flush()
+
+ line = f.readline()
+ if not line == msg:
+ print "Error perferming readline with the python _fileobject class"
+ os._exit (1)
+ f.write(line)
+ f.flush()
+ if verbose:
+ print "__fileobject readline works"
+
conn.close()
else:
try:
@@ -149,11 +189,18 @@ try:
if verbose:
print 'child connecting'
s.connect(("127.0.0.1", PORT))
- msg = 'socket test'
- s.send(msg)
- data = s.recv(1024)
- if msg != data:
- print 'parent/client mismatch'
+
+ iteration = 0
+ while 1:
+ s.send(msg)
+ data = s.recv(12)
+ if not data:
+ break
+ if msg != data:
+ print "parent/client mismatch. Failed in %s iteration. Received: [%s]" \
+ %(iteration, data)
+ time.sleep (1)
+ iteration += 1
s.close()
finally:
os._exit(1)