BIND 10 master, updated. 60e8cc24f35b0a7821bfb368b89c6bff1440756d [1828] Remove another use of with statement on sockets
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jun 18 18:48:12 UTC 2012
The branch, master has been updated
via 60e8cc24f35b0a7821bfb368b89c6bff1440756d (commit)
via e8d6a1ad9b75f12c4d8647b4b90a51fc3cd2abe5 (commit)
via 1fafcf498b18734dd6529396eef317d985adde52 (commit)
via 498eb58a8836eceea9e8233688de9863ed6b89bc (commit)
via 7406cfc6f01f9388c5edf7793117687f340f8266 (commit)
via 7d35486ac5c76b6a28db0967881fbb18c8900e01 (commit)
via 92e3f4158853be65dcc1852fbd3d8443ef5d8613 (commit)
via dfe666442be832504586e4102da22c29d78aab60 (commit)
from 38cf088a4f48930a8b4c67c6c89e8166e4573bfc (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 60e8cc24f35b0a7821bfb368b89c6bff1440756d
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Jun 19 00:09:38 2012 +0530
[1828] Remove another use of with statement on sockets
This is because CPython < version 3.2 does not support it.
commit e8d6a1ad9b75f12c4d8647b4b90a51fc3cd2abe5
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Jun 19 00:07:18 2012 +0530
Revert "[1828] Cleanup code by using with"
This reverts commit 9040c49022e84e7b1398e84a14abd54f8d99ec8c.
commit 1fafcf498b18734dd6529396eef317d985adde52
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Jun 19 00:07:04 2012 +0530
Revert "[1828] Make code safer in case socket.socket() raises an exception"
This reverts commit e295b40a31dedb3671705ab44c2683624f3d541c.
commit 498eb58a8836eceea9e8233688de9863ed6b89bc
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Jun 19 00:05:03 2012 +0530
Revert most of "[1828] Make code safer by using with"
This reverts most of commit 57449046356fda9a21f3cf2dc1e5faadaaf42d7c.
commit 7406cfc6f01f9388c5edf7793117687f340f8266
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jun 18 23:26:14 2012 +0530
[1828] Add comments about the close() calls
commit 7d35486ac5c76b6a28db0967881fbb18c8900e01
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jun 18 23:24:04 2012 +0530
Revert "[1828] Cleanup code by using with"
This reverts commit 7d741f7ea2ddc3ab22e37b12132b7e029e6da573.
commit 92e3f4158853be65dcc1852fbd3d8443ef5d8613
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jun 18 23:20:07 2012 +0530
Revert "[1828] Cleanup code by using with (for accept_sock)"
This reverts commit 74b4b2f998f9512b2a326e81062da9099d1eeaf4.
commit dfe666442be832504586e4102da22c29d78aab60
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jun 18 23:18:39 2012 +0530
Revert "[1828] Make code safer by using with (for sock)"
This reverts commit ff9dd7da0902101332312526c4b52d11f18650ba.
-----------------------------------------------------------------------
Summary of changes:
src/bin/xfrout/tests/xfrout_test.py.in | 35 +++---
src/bin/xfrout/xfrout.py.in | 11 +-
.../python/isc/bind10/tests/sockcreator_test.py | 18 +--
.../isc/util/cio/tests/socketsession_test.py | 124 ++++++++++----------
4 files changed, 98 insertions(+), 90 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/xfrout/tests/xfrout_test.py.in b/src/bin/xfrout/tests/xfrout_test.py.in
index 6f38b75..bc409a8 100644
--- a/src/bin/xfrout/tests/xfrout_test.py.in
+++ b/src/bin/xfrout/tests/xfrout_test.py.in
@@ -1196,30 +1196,31 @@ class TestUnixSockServer(unittest.TestCase):
# We test with UDP, as it can be "connected" without other
# endpoint. Note that in the current implementation _guess_remote()
# unconditionally returns SOCK_STREAM.
- with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
- sock.connect(('127.0.0.1', 12345))
- self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
- ('127.0.0.1', 12345)),
- self.unix._guess_remote(sock.fileno()))
-
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ sock.connect(('127.0.0.1', 12345))
+ self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
+ ('127.0.0.1', 12345)),
+ self.unix._guess_remote(sock.fileno()))
+ sock.close()
if socket.has_ipv6:
# Don't check IPv6 address on hosts not supporting them
- with socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) as sock:
- sock.connect(('::1', 12345))
- self.assertEqual((socket.AF_INET6, socket.SOCK_STREAM,
- ('::1', 12345, 0, 0)),
- self.unix._guess_remote(sock.fileno()))
-
+ sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
+ sock.connect(('::1', 12345))
+ self.assertEqual((socket.AF_INET6, socket.SOCK_STREAM,
+ ('::1', 12345, 0, 0)),
+ self.unix._guess_remote(sock.fileno()))
+ sock.close()
# Try when pretending there's no IPv6 support
# (No need to pretend when there's really no IPv6)
xfrout.socket.has_ipv6 = False
- with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
- sock.connect(('127.0.0.1', 12345))
- self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
- ('127.0.0.1', 12345)),
- self.unix._guess_remote(sock.fileno()))
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ sock.connect(('127.0.0.1', 12345))
+ self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
+ ('127.0.0.1', 12345)),
+ self.unix._guess_remote(sock.fileno()))
# Return it back
xfrout.socket.has_ipv6 = True
+ sock.close()
def test_receive_query_message(self):
send_msg = b"\xd6=\x00\x00\x00\x01\x00"
diff --git a/src/bin/xfrout/xfrout.py.in b/src/bin/xfrout/xfrout.py.in
index 89bf701..73055fe 100755
--- a/src/bin/xfrout/xfrout.py.in
+++ b/src/bin/xfrout/xfrout.py.in
@@ -753,8 +753,9 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
# (Any idea how to simulate this in test?)
sock_domain = socket.AF_INET
- with socket.fromfd(sock_fd, sock_domain, socket.SOCK_STREAM) as sock:
- peer = sock.getpeername()
+ sock = socket.fromfd(sock_fd, sock_domain, socket.SOCK_STREAM)
+ peer = sock.getpeername()
+ sock.close()
# Identify the correct socket family. Due to the above "trick",
# we cannot simply use sock.family.
@@ -805,11 +806,13 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
is being used by one running xfrout process. If it is,
return True, or else return False. '''
try:
- with socket.socket(socket.AF_UNIX) as sock:
- sock.connect(sock_file)
+ sock = socket.socket(socket.AF_UNIX)
+ sock.connect(sock_file)
except socket.error as err:
+ sock.close()
return False
else:
+ sock.close()
return True
def shutdown(self):
diff --git a/src/lib/python/isc/bind10/tests/sockcreator_test.py b/src/lib/python/isc/bind10/tests/sockcreator_test.py
index 115064b..f67781c 100644
--- a/src/lib/python/isc/bind10/tests/sockcreator_test.py
+++ b/src/lib/python/isc/bind10/tests/sockcreator_test.py
@@ -304,15 +304,12 @@ class WrapTests(unittest.TestCase):
# Transfer the descriptor
send_fd(t1.fileno(), p1.fileno())
p1.close()
+ p1 = socket.fromfd(t2.read_fd(), socket.AF_UNIX, socket.SOCK_STREAM)
- with socket.fromfd(t2.read_fd(), socket.AF_UNIX,
- socket.SOCK_STREAM) as p1:
- # Now, pass some data trough the socket
- p1.send(b'A')
- data = p2.recv(1)
- self.assertEqual(b'A', data)
-
- p2.close()
+ # Now, pass some data trough the socket
+ p1.send(b'A')
+ data = p2.recv(1)
+ self.assertEqual(b'A', data)
# Test the wrapping didn't hurt the socket's usual methods
t1.send(b'B')
@@ -322,6 +319,11 @@ class WrapTests(unittest.TestCase):
data = t1.recv(1)
self.assertEqual(b'C', data)
+ # Explicitly close temporary socket pair as the Python
+ # interpreter expects it. It may not be 100% exception safe,
+ # but since this is only for tests we prefer brevity.
+ p1.close()
+ p2.close()
t1.close()
t2.close()
diff --git a/src/lib/python/isc/util/cio/tests/socketsession_test.py b/src/lib/python/isc/util/cio/tests/socketsession_test.py
index 6502aba..d492f6d 100644
--- a/src/lib/python/isc/util/cio/tests/socketsession_test.py
+++ b/src/lib/python/isc/util/cio/tests/socketsession_test.py
@@ -128,63 +128,64 @@ class TestForwarder(unittest.TestCase):
def check_push_and_pop(self, family, type, protocol, local, remote,
data, new_connection):
- with self.create_socket(family, type, protocol, local, True) as sock:
- fwd_fd = sock.fileno()
- if protocol == IPPROTO_TCP:
- client_addr = ('::1', 0, 0, 0) if family == AF_INET6 \
- else ('127.0.0.1', 0)
- client_sock = self.create_socket(family, type, protocol,
- client_addr, False)
- client_sock.setblocking(False)
- try:
- client_sock.connect(local)
- except socket.error:
- pass
- server_sock, _ = sock.accept()
- fwd_fd = server_sock.fileno()
-
- # If a new connection is required, start the "server", have the
- # internal forwarder connect to it, and then internally accept it.
- if new_connection:
- self.start_listen()
- self.forwarder.connect_to_receiver()
- self.accept_sock = self.accept_forwarder()
-
- # Then push one socket session via the forwarder.
- self.forwarder.push(fwd_fd, family, type, protocol, local, remote,
- data)
-
- # Pop the socket session we just pushed from a local receiver, and
- # check the content.
- receiver = SocketSessionReceiver(self.accept_sock)
- signal.alarm(1)
- sock_session = receiver.pop()
- signal.alarm(0)
- passed_sock = sock_session[0]
- self.assertNotEqual(fwd_fd, passed_sock.fileno())
- self.assertEqual(family, passed_sock.family)
- self.assertEqual(type, passed_sock.type)
- self.assertEqual(protocol, passed_sock.proto)
- self.assertEqual(local, sock_session[1])
- self.assertEqual(remote, sock_session[2])
- self.assertEqual(data, sock_session[3])
-
- # Check if the passed FD is usable by sending some data from it.
- passed_sock.setblocking(True)
- if protocol == IPPROTO_UDP:
- self.assertEqual(len(TEST_DATA), passed_sock.sendto(TEST_DATA,
- local))
- sock.settimeout(10)
- self.assertEqual(TEST_DATA, sock.recvfrom(len(TEST_DATA))[0])
- else:
- self.assertEqual(len(TEST_DATA), passed_sock.send(TEST_DATA))
- client_sock.setblocking(True)
- client_sock.settimeout(10)
- self.assertEqual(TEST_DATA, client_sock.recv(len(TEST_DATA)))
- server_sock.close()
- client_sock.close()
-
- passed_sock.close()
+ sock = self.create_socket(family, type, protocol, local, True)
+ fwd_fd = sock.fileno()
+ if protocol == IPPROTO_TCP:
+ client_addr = ('::1', 0, 0, 0) if family == AF_INET6 \
+ else ('127.0.0.1', 0)
+ client_sock = self.create_socket(family, type, protocol,
+ client_addr, False)
+ client_sock.setblocking(False)
+ try:
+ client_sock.connect(local)
+ except socket.error:
+ pass
+ server_sock, _ = sock.accept()
+ fwd_fd = server_sock.fileno()
+
+ # If a new connection is required, start the "server", have the
+ # internal forwarder connect to it, and then internally accept it.
+ if new_connection:
+ self.start_listen()
+ self.forwarder.connect_to_receiver()
+ self.accept_sock = self.accept_forwarder()
+
+ # Then push one socket session via the forwarder.
+ self.forwarder.push(fwd_fd, family, type, protocol, local, remote,
+ data)
+
+ # Pop the socket session we just pushed from a local receiver, and
+ # check the content.
+ receiver = SocketSessionReceiver(self.accept_sock)
+ signal.alarm(1)
+ sock_session = receiver.pop()
+ signal.alarm(0)
+ passed_sock = sock_session[0]
+ self.assertNotEqual(fwd_fd, passed_sock.fileno())
+ self.assertEqual(family, passed_sock.family)
+ self.assertEqual(type, passed_sock.type)
+ self.assertEqual(protocol, passed_sock.proto)
+ self.assertEqual(local, sock_session[1])
+ self.assertEqual(remote, sock_session[2])
+ self.assertEqual(data, sock_session[3])
+
+ # Check if the passed FD is usable by sending some data from it.
+ passed_sock.setblocking(True)
+ if protocol == IPPROTO_UDP:
+ self.assertEqual(len(TEST_DATA), passed_sock.sendto(TEST_DATA,
+ local))
+ sock.settimeout(10)
+ self.assertEqual(TEST_DATA, sock.recvfrom(len(TEST_DATA))[0])
+ else:
+ self.assertEqual(len(TEST_DATA), passed_sock.send(TEST_DATA))
+ client_sock.setblocking(True)
+ client_sock.settimeout(10)
+ self.assertEqual(TEST_DATA, client_sock.recv(len(TEST_DATA)))
+ server_sock.close()
+ client_sock.close()
+
+ passed_sock.close()
+ sock.close()
def test_push_and_pop(self):
# This is a straightforward port of C++ pushAndPop test. See the
@@ -243,10 +244,11 @@ class TestForwarder(unittest.TestCase):
s = socket.socket(socket.AF_UNIX, SOCK_STREAM, 0)
s.setblocking(False)
s.connect(TEST_UNIX_FILE)
- with self.accept_forwarder() as accept_sock:
- receiver = SocketSessionReceiver(accept_sock)
- s.close()
- self.assertRaises(SocketSessionError, receiver.pop)
+ accept_sock = self.accept_forwarder()
+ receiver = SocketSessionReceiver(accept_sock)
+ s.close()
+ self.assertRaises(SocketSessionError, receiver.pop)
+ accept_sock.close()
class TestReceiver(unittest.TestCase):
# We only check a couple of failure cases on construction. Valid cases
More information about the bind10-changes
mailing list