From 7174ed5ded78b61307785d4f3e4ecbdcea6a3f83 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Mon, 11 Jun 2018 14:24:25 -0700 Subject: [PATCH] Backport #15714 to v1.13.x --- src/core/lib/iomgr/cfstream_handle.cc | 4 +++- src/core/lib/iomgr/tcp_client_cfstream.cc | 14 +++++++------- src/objective-c/tests/GRPCClientTests.m | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/lib/iomgr/cfstream_handle.cc b/src/core/lib/iomgr/cfstream_handle.cc index 30f4e656324..827fd24831e 100644 --- a/src/core/lib/iomgr/cfstream_handle.cc +++ b/src/core/lib/iomgr/cfstream_handle.cc @@ -116,7 +116,9 @@ CFStreamHandle::CFStreamHandle(CFReadStreamRef read_stream, open_event_.InitEvent(); read_event_.InitEvent(); write_event_.InitEvent(); - CFStreamClientContext ctx = {0, static_cast(this), nil, nil, nil}; + CFStreamClientContext ctx = {0, static_cast(this), + CFStreamHandle::Retain, CFStreamHandle::Release, + nil}; CFReadStreamSetClient( read_stream, kCFStreamEventOpenCompleted | kCFStreamEventHasBytesAvailable | diff --git a/src/core/lib/iomgr/tcp_client_cfstream.cc b/src/core/lib/iomgr/tcp_client_cfstream.cc index ffed3bbef67..5acea91792f 100644 --- a/src/core/lib/iomgr/tcp_client_cfstream.cc +++ b/src/core/lib/iomgr/tcp_client_cfstream.cc @@ -52,7 +52,7 @@ typedef struct CFStreamConnect { CFReadStreamRef read_stream; CFWriteStreamRef write_stream; - CFStreamHandle* stream_sync; + CFStreamHandle* stream_handle; grpc_timer alarm; grpc_closure on_alarm; @@ -71,7 +71,7 @@ typedef struct CFStreamConnect { static void CFStreamConnectCleanup(CFStreamConnect* connect) { grpc_resource_quota_unref_internal(connect->resource_quota); - CFSTREAM_HANDLE_UNREF(connect->stream_sync, "async connect clean up"); + CFSTREAM_HANDLE_UNREF(connect->stream_handle, "async connect clean up"); CFRelease(connect->read_stream); CFRelease(connect->write_stream); gpr_mu_destroy(&connect->mu); @@ -131,7 +131,7 @@ static void OnOpen(void* arg, grpc_error* error) { if (error == GRPC_ERROR_NONE) { *endpoint = grpc_cfstream_endpoint_create( connect->read_stream, connect->write_stream, connect->addr_name, - connect->resource_quota, connect->stream_sync); + connect->resource_quota, connect->stream_handle); } } else { GRPC_ERROR_REF(error); @@ -170,8 +170,8 @@ static void CFStreamClientConnect(grpc_closure* closure, grpc_endpoint** ep, gpr_mu_init(&connect->mu); if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: asynchronously connecting", - connect->addr_name); + gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %p, %s: asynchronously connecting", + connect, connect->addr_name); } grpc_resource_quota* resource_quota = grpc_resource_quota_create(NULL); @@ -197,11 +197,11 @@ static void CFStreamClientConnect(grpc_closure* closure, grpc_endpoint** ep, CFRelease(host); connect->read_stream = read_stream; connect->write_stream = write_stream; - connect->stream_sync = + connect->stream_handle = CFStreamHandle::CreateStreamHandle(read_stream, write_stream); GRPC_CLOSURE_INIT(&connect->on_open, OnOpen, static_cast(connect), grpc_schedule_on_exec_ctx); - connect->stream_sync->NotifyOnOpen(&connect->on_open); + connect->stream_handle->NotifyOnOpen(&connect->on_open); GRPC_CLOSURE_INIT(&connect->on_alarm, OnAlarm, connect, grpc_schedule_on_exec_ctx); gpr_mu_lock(&connect->mu); diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index 5cd0231db7f..d9186561c35 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -525,7 +525,8 @@ static GRPCProtoMethod *kFullDuplexCallMethod; - (void)testErrorCode { int port = [self findFreePort]; NSString *const kDummyAddress = [NSString stringWithFormat:@"localhost:%d", port]; - __weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."]; + __weak XCTestExpectation *completion = + [self expectationWithDescription:@"Received correct error code."]; GRPCCall *call = [[GRPCCall alloc] initWithHost:kDummyAddress path:kEmptyCallMethod.HTTPPath