From d6be87b0c1a95064784852bc9803b4f064a3da92 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Fri, 8 Jun 2018 14:17:21 -0700 Subject: [PATCH] Fix previously-encountered issue: set so_reuseaddr on dummy sockets --- test/cpp/naming/resolver_component_test.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 649441d4fa7..07ddfd30eee 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -269,8 +269,14 @@ void OpenAndCloseSocketsStressLoop(int dummy_port, gpr_event* done_ev) { for (size_t i = 0; i < 50; i++) { int s = socket(AF_INET6, SOCK_STREAM, 0); int val = 1; - setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); - fcntl(s, F_SETFL, O_NONBLOCK); + ASSERT_TRUE(setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)) == + 0) + << "Failed to set socketopt reuseport"; + ASSERT_TRUE(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) == + 0) + << "Failed to set socket reuseaddr"; + ASSERT_TRUE(fcntl(s, F_SETFL, O_NONBLOCK) == 0) + << "Failed to set socket non-blocking"; ASSERT_TRUE(s != BAD_SOCKET_RETURN_VAL) << "Failed to create TCP ipv6 socket"; gpr_log(GPR_DEBUG, "Opened fd: %d", s);