summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2006-04-19 11:50:27 (GMT)
committerArmin Rigo <arigo@tunes.org>2006-04-19 11:50:27 (GMT)
commita9017c39ce5db85602235dfd03da30f4de8bd823 (patch)
tree670aacf6665b4558844aebede696e979727f9d96 /Lib/test/test_socket.py
parentab012af6ed8fb9a57f4d558532f4201de6534672 (diff)
downloadcpython-a9017c39ce5db85602235dfd03da30f4de8bd823.zip
cpython-a9017c39ce5db85602235dfd03da30f4de8bd823.tar.gz
cpython-a9017c39ce5db85602235dfd03da30f4de8bd823.tar.bz2
SF Patch #1062014: AF_UNIX sockets under Linux have a special
abstract namespace that is now fully supported.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 46468a6..6943080 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -825,6 +825,32 @@ class TestExceptions(unittest.TestCase):
self.assert_(issubclass(socket.gaierror, socket.error))
self.assert_(issubclass(socket.timeout, socket.error))
+class TestLinuxAbstractNamespace(unittest.TestCase):
+
+ UNIX_PATH_MAX = 108
+
+ def testLinuxAbstractNamespace(self):
+ address = "\x00python-test-hello\x00\xff"
+ s1 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ s1.bind(address)
+ s1.listen(1)
+ s2 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ s2.connect(s1.getsockname())
+ s1.accept()
+ self.assertEqual(s1.getsockname(), address)
+ self.assertEqual(s2.getpeername(), address)
+
+ def testMaxName(self):
+ address = "\x00" + "h" * (self.UNIX_PATH_MAX - 1)
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ s.bind(address)
+ self.assertEqual(s.getsockname(), address)
+
+ def testNameOverflow(self):
+ address = "\x00" + "h" * self.UNIX_PATH_MAX
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ self.assertRaises(socket.error, s.bind, address)
+
def test_main():
tests = [GeneralModuleTests, BasicTCPTest, TCPTimeoutTest, TestExceptions]
@@ -840,6 +866,8 @@ def test_main():
])
if hasattr(socket, "socketpair"):
tests.append(BasicSocketPairTest)
+ if sys.platform == 'linux2':
+ tests.append(TestLinuxAbstractNamespace)
test_support.run_unittest(*tests)
if __name__ == "__main__":