mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #18904: test_socket: add inheritance tests using fcntl and FD_CLOEXEC
This commit is contained in:
parent
7ba6b0f943
commit
a3c18d0f14
1 changed files with 30 additions and 0 deletions
|
@ -26,6 +26,10 @@ try:
|
|||
import multiprocessing
|
||||
except ImportError:
|
||||
multiprocessing = False
|
||||
try:
|
||||
import fcntl
|
||||
except ImportError:
|
||||
fcntl = None
|
||||
|
||||
HOST = support.HOST
|
||||
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8') ## test unicode string and carriage return
|
||||
|
@ -4804,6 +4808,32 @@ class InheritanceTest(unittest.TestCase):
|
|||
sock.set_inheritable(False)
|
||||
self.assertEqual(sock.get_inheritable(), False)
|
||||
|
||||
if fcntl:
|
||||
def test_get_inheritable_cloexec(self):
|
||||
sock = socket.socket()
|
||||
with sock:
|
||||
fd = sock.fileno()
|
||||
self.assertEqual(sock.get_inheritable(), False)
|
||||
|
||||
# clear FD_CLOEXEC flag
|
||||
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
||||
flags &= ~fcntl.FD_CLOEXEC
|
||||
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
|
||||
|
||||
self.assertEqual(sock.get_inheritable(), True)
|
||||
|
||||
def test_set_inheritable_cloexec(self):
|
||||
sock = socket.socket()
|
||||
with sock:
|
||||
fd = sock.fileno()
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
fcntl.FD_CLOEXEC)
|
||||
|
||||
sock.set_inheritable(True)
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
0)
|
||||
|
||||
|
||||
@unittest.skipUnless(hasattr(socket, "socketpair"),
|
||||
"need socket.socketpair()")
|
||||
def test_socketpair(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue