mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-32454: socket closefd (#5048)
Add close(fd) function to the socket module Signed-off-by: Christian Heimes <christian@python.org>
This commit is contained in:
parent
2f050c7e1b
commit
d0e31b980f
4 changed files with 54 additions and 2 deletions
|
@ -1519,6 +1519,22 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
self.assertRaises(ValueError, fp.writable)
|
||||
self.assertRaises(ValueError, fp.seekable)
|
||||
|
||||
def test_socket_close(self):
|
||||
sock = socket.socket()
|
||||
try:
|
||||
sock.bind((HOST, 0))
|
||||
socket.close(sock.fileno())
|
||||
with self.assertRaises(OSError):
|
||||
sock.listen(1)
|
||||
finally:
|
||||
with self.assertRaises(OSError):
|
||||
# sock.close() fails with EBADF
|
||||
sock.close()
|
||||
with self.assertRaises(TypeError):
|
||||
socket.close(None)
|
||||
with self.assertRaises(OSError):
|
||||
socket.close(-1)
|
||||
|
||||
def test_makefile_mode(self):
|
||||
for mode in 'r', 'rb', 'rw', 'w', 'wb':
|
||||
with self.subTest(mode=mode):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue