|
|
@ -63,6 +63,7 @@ typedef struct { |
|
|
|
grpc_alarm alarm; |
|
|
|
grpc_alarm alarm; |
|
|
|
int refs; |
|
|
|
int refs; |
|
|
|
grpc_iomgr_closure write_closure; |
|
|
|
grpc_iomgr_closure write_closure; |
|
|
|
|
|
|
|
grpc_pollset_set *interested_parties; |
|
|
|
} async_connect; |
|
|
|
} async_connect; |
|
|
|
|
|
|
|
|
|
|
|
static int prepare_socket(const struct sockaddr *addr, int fd) { |
|
|
|
static int prepare_socket(const struct sockaddr *addr, int fd) { |
|
|
@ -152,6 +153,7 @@ static void on_writable(void *acp, int success) { |
|
|
|
goto finish; |
|
|
|
goto finish; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
grpc_pollset_set_del_fd(ac->interested_parties, ac->fd); |
|
|
|
ep = grpc_tcp_create(ac->fd, GRPC_TCP_DEFAULT_READ_SLICE_SIZE); |
|
|
|
ep = grpc_tcp_create(ac->fd, GRPC_TCP_DEFAULT_READ_SLICE_SIZE); |
|
|
|
goto finish; |
|
|
|
goto finish; |
|
|
|
} |
|
|
|
} |
|
|
@ -164,10 +166,13 @@ static void on_writable(void *acp, int success) { |
|
|
|
|
|
|
|
|
|
|
|
finish: |
|
|
|
finish: |
|
|
|
gpr_mu_lock(&ac->mu); |
|
|
|
gpr_mu_lock(&ac->mu); |
|
|
|
|
|
|
|
gpr_log(GPR_DEBUG, "ep=%p", ep); |
|
|
|
if (!ep) { |
|
|
|
if (!ep) { |
|
|
|
|
|
|
|
grpc_pollset_set_del_fd(ac->interested_parties, ac->fd); |
|
|
|
grpc_fd_orphan(ac->fd, NULL, "tcp_client_orphan"); |
|
|
|
grpc_fd_orphan(ac->fd, NULL, "tcp_client_orphan"); |
|
|
|
} |
|
|
|
} |
|
|
|
done = (--ac->refs == 0); |
|
|
|
done = (--ac->refs == 0); |
|
|
|
|
|
|
|
gpr_log(GPR_DEBUG, "refs=%d", ac->refs); |
|
|
|
gpr_mu_unlock(&ac->mu); |
|
|
|
gpr_mu_unlock(&ac->mu); |
|
|
|
if (done) { |
|
|
|
if (done) { |
|
|
|
gpr_mu_destroy(&ac->mu); |
|
|
|
gpr_mu_destroy(&ac->mu); |
|
|
@ -240,6 +245,7 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), |
|
|
|
ac->cb = cb; |
|
|
|
ac->cb = cb; |
|
|
|
ac->cb_arg = arg; |
|
|
|
ac->cb_arg = arg; |
|
|
|
ac->fd = fdobj; |
|
|
|
ac->fd = fdobj; |
|
|
|
|
|
|
|
ac->interested_parties = interested_parties; |
|
|
|
gpr_mu_init(&ac->mu); |
|
|
|
gpr_mu_init(&ac->mu); |
|
|
|
ac->refs = 2; |
|
|
|
ac->refs = 2; |
|
|
|
ac->write_closure.cb = on_writable; |
|
|
|
ac->write_closure.cb = on_writable; |
|
|
|