diff --git a/src/test/msgr/test_async_driver.cc b/src/test/msgr/test_async_driver.cc index d666ac69985f4..e77d23a1513da 100644 --- a/src/test/msgr/test_async_driver.cc +++ b/src/test/msgr/test_async_driver.cc @@ -138,26 +138,29 @@ TEST_P(EventDriverTest, PipeTest) { void* echoclient(void *arg) { intptr_t port = (intptr_t)arg; - int connect_sd = ::socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in sa; sa.sin_family = AF_INET; sa.sin_port = htons(port); char addr[] = "127.0.0.1"; int r = inet_aton(addr, &sa.sin_addr); - r = connect(connect_sd, (struct sockaddr*)&sa, sizeof(sa)); - int t = 0; - do { - char c[] = "banner"; - r = write(connect_sd, c, sizeof(c)); - char d[100]; - r = read(connect_sd, d, sizeof(d)); - if (r == 0) - break; - if (t++ == 30) - break; - } while (1); - ::close(connect_sd); + int connect_sd = ::socket(AF_INET, SOCK_STREAM, 0); + if (connect_sd >= 0) { + r = connect(connect_sd, (struct sockaddr*)&sa, sizeof(sa)); + int t = 0; + + do { + char c[] = "banner"; + r = write(connect_sd, c, sizeof(c)); + char d[100]; + r = read(connect_sd, d, sizeof(d)); + if (r == 0) + break; + if (t++ == 30) + break; + } while (1); + ::close(connect_sd); + } return 0; }