summaryrefslogtreecommitdiffstats
path: root/Lib/dos-8x3/test_soc.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-22 20:48:03 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-22 20:48:03 (GMT)
commitf1e63545483a3b4eb7d8357e8a1ed2cb048bbb00 (patch)
treebb0a99e2f85607bec83bca986256c54cd3f05505 /Lib/dos-8x3/test_soc.py
parentc2d14176153038d568770f5499c8aa6a8c6a93fc (diff)
downloadcpython-f1e63545483a3b4eb7d8357e8a1ed2cb048bbb00.zip
cpython-f1e63545483a3b4eb7d8357e8a1ed2cb048bbb00.tar.gz
cpython-f1e63545483a3b4eb7d8357e8a1ed2cb048bbb00.tar.bz2
The usual
Diffstat (limited to 'Lib/dos-8x3/test_soc.py')
-rw-r--r--Lib/dos-8x3/test_soc.py71
1 files changed, 37 insertions, 34 deletions
diff --git a/Lib/dos-8x3/test_soc.py b/Lib/dos-8x3/test_soc.py
index 1e157b9..1fe8c41 100644
--- a/Lib/dos-8x3/test_soc.py
+++ b/Lib/dos-8x3/test_soc.py
@@ -8,7 +8,7 @@
# sktobj.shutdown()
-from test_support import verbose
+from test_support import verbose, TestFailed
import socket
import os
import time
@@ -22,13 +22,13 @@ def missing_ok(str):
print socket.error
-print socket.AF_INET
+socket.AF_INET
-print socket.SOCK_STREAM
-print socket.SOCK_DGRAM
-print socket.SOCK_RAW
-print socket.SOCK_RDM
-print socket.SOCK_SEQPACKET
+socket.SOCK_STREAM
+socket.SOCK_DGRAM
+socket.SOCK_RAW
+socket.SOCK_RDM
+socket.SOCK_SEQPACKET
for optional in ("AF_UNIX",
@@ -65,6 +65,7 @@ for optional in ("AF_UNIX",
):
missing_ok(optional)
+socktype = socket.socket_type
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
hname, aliases, ipaddrs = socket.gethostbyaddr(ip)
@@ -89,43 +90,45 @@ except socket.error:
pass
+canfork = hasattr(os, 'fork')
try:
PORT = 50007
- if os.fork():
+ if not canfork or os.fork():
# parent is server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(hostname, PORT)
s.listen(1)
if verbose:
print 'parent accepting'
- conn, addr = s.accept()
- if verbose:
- print 'connected by', addr
- # couple of interesting tests while we've got a live socket
- f = conn.fileno()
- if verbose:
- print 'fileno:', f
- p = conn.getpeername()
- if verbose:
- print 'peer:', p
- n = conn.getsockname()
- if verbose:
- print 'sockname:', n
- f = conn.makefile()
- if verbose:
- print 'file obj:', f
- while 1:
- data = conn.recv(1024)
- if not data:
- break
+ if canfork:
+ conn, addr = s.accept()
+ if verbose:
+ print 'connected by', addr
+ # couple of interesting tests while we've got a live socket
+ f = conn.fileno()
if verbose:
- print 'received:', data
- conn.send(data)
- conn.close()
+ print 'fileno:', f
+ p = conn.getpeername()
+ if verbose:
+ print 'peer:', p
+ n = conn.getsockname()
+ if verbose:
+ print 'sockname:', n
+ f = conn.makefile()
+ if verbose:
+ print 'file obj:', f
+ while 1:
+ data = conn.recv(1024)
+ if not data:
+ break
+ if verbose:
+ print 'received:', data
+ conn.send(data)
+ conn.close()
else:
try:
# child is client
- time.sleep(1)
+ time.sleep(5)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if verbose:
print 'child connecting'
@@ -138,5 +141,5 @@ try:
s.close()
finally:
os._exit(1)
-except socket.error:
- pass
+except socket.error, msg:
+ raise TestFailed, msg