diff options
author | 2015-01-21 22:10:26 -0800 | |
---|---|---|
committer | 2015-01-21 22:10:26 -0800 | |
commit | 9497b3c1c467ae8d13258e835e71119e77884999 (patch) | |
tree | 99ed9d0ffa784987511ee22f1eecb6c2258139b8 /test/core/iomgr/fd_posix_test.c | |
parent | a83567d72907d3b8abe3ca006363db8afedd1698 (diff) |
Bugfix connection code in test
Diffstat (limited to 'test/core/iomgr/fd_posix_test.c')
-rw-r--r-- | test/core/iomgr/fd_posix_test.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 136f34a8b0..05c91ffdd4 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -37,6 +37,7 @@ #include <errno.h> #include <fcntl.h> #include <netinet/in.h> +#include <poll.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -79,7 +80,7 @@ static void create_test_socket(int port, int *socket_fd, /* Use local address for test */ sin->sin_family = AF_INET; - sin->sin_addr.s_addr = 0; + sin->sin_addr.s_addr = htonl(0x7f000001); sin->sin_port = htons(port); } @@ -164,7 +165,7 @@ static void session_read_cb(void *arg, /*session*/ grpc_fd_notify_on_read(se->em_fd, session_read_cb, se); } else { gpr_log(GPR_ERROR, "Unhandled read error %s", strerror(errno)); - GPR_ASSERT(0); + abort(); } } } @@ -316,7 +317,7 @@ static void client_session_write(void *arg, /*client*/ gpr_mu_unlock(&cl->mu); } else { gpr_log(GPR_ERROR, "unknown errno %s", strerror(errno)); - GPR_ASSERT(0); + abort(); } } @@ -325,10 +326,20 @@ static void client_start(client *cl, int port) { int fd; struct sockaddr_in sin; create_test_socket(port, &fd, &sin); - if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == -1 && - errno != EINPROGRESS) { - gpr_log(GPR_ERROR, "Failed to connect to the server"); - GPR_ASSERT(0); + if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { + if (errno == EINPROGRESS) { + struct pollfd pfd; + pfd.fd = fd; + pfd.events = POLLOUT; + pfd.revents = 0; + if (poll(&pfd, 1, -1) == -1) { + gpr_log(GPR_ERROR, "poll() failed during connect; errno=%d", errno); + abort(); + } + } else { + gpr_log(GPR_ERROR, "Failed to connect to the server (errno=%d)", errno); + abort(); + } } cl->em_fd = grpc_fd_create(fd); |