From 9bcc751e13e9c5fe65baebb8af52c01ff1a7b65f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 11 May 2015 14:59:48 -0700 Subject: [PATCH] Minor cleanup --- src/core/iomgr/tcp_client_posix.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c index 44e9c718ac3..2a81cf56a41 100644 --- a/src/core/iomgr/tcp_client_posix.c +++ b/src/core/iomgr/tcp_client_posix.c @@ -152,6 +152,7 @@ static void on_writable(void *acp, int success) { goto finish; } } else { + gpr_log(GPR_DEBUG, "connected"); ep = grpc_tcp_create(ac->fd, GRPC_TCP_DEFAULT_READ_SLICE_SIZE); goto finish; } @@ -186,6 +187,7 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), async_connect *ac; struct sockaddr_in6 addr6_v4mapped; struct sockaddr_in addr4_copy; + grpc_fd *fdobj; /* Use dualstack sockets where available. */ if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) { @@ -208,20 +210,25 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), return; } + gpr_log(GPR_DEBUG, "connecting fd %d", fd); + do { err = connect(fd, addr, addr_len); } while (err < 0 && errno == EINTR); + fdobj = grpc_fd_create(fd); + grpc_pollset_set_add_fd(interested_parties, fdobj); + if (err >= 0) { gpr_log(GPR_DEBUG, "instant connect"); cb(arg, - grpc_tcp_create(grpc_fd_create(fd), GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); + grpc_tcp_create(fdobj, GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); return; } if (errno != EWOULDBLOCK && errno != EINPROGRESS) { gpr_log(GPR_ERROR, "connect error: %s", strerror(errno)); - close(fd); + grpc_fd_orphan(fdobj, NULL, NULL); cb(arg, NULL); return; } @@ -229,14 +236,12 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), ac = gpr_malloc(sizeof(async_connect)); ac->cb = cb; ac->cb_arg = arg; - ac->fd = grpc_fd_create(fd); + ac->fd = fdobj; gpr_mu_init(&ac->mu); ac->refs = 2; ac->write_closure.cb = on_writable; ac->write_closure.cb_arg = ac; - grpc_pollset_set_add_fd(interested_parties, ac->fd); - grpc_alarm_init(&ac->alarm, deadline, on_alarm, ac, gpr_now()); grpc_fd_notify_on_write(ac->fd, &ac->write_closure); }