From b5f6c1bc46137cdc65b333ba9b32889634e39d55 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Tue, 22 May 2018 18:57:00 -0700 Subject: Bug fix and better log --- src/core/lib/iomgr/tcp_cfstream.cc | 26 ++++++++++++++++++-------- src/core/lib/iomgr/tcp_cfstream_sync.cc | 8 ++++---- 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src/core') diff --git a/src/core/lib/iomgr/tcp_cfstream.cc b/src/core/lib/iomgr/tcp_cfstream.cc index f7ef03d228..28957bd67f 100644 --- a/src/core/lib/iomgr/tcp_cfstream.cc +++ b/src/core/lib/iomgr/tcp_cfstream.cc @@ -166,10 +166,15 @@ static void ReadAction(void* arg, grpc_error* error) { if (read_size == -1) { grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); CFErrorRef stream_error = CFReadStreamCopyError(tcp->read_stream); - CallReadCB(tcp, TCPAnnotateError(GRPC_ERROR_CREATE_FROM_CFERROR( - stream_error, "Read error"), - tcp)); - CFRelease(stream_error); + if (stream_error != nullptr) { + error = TCPAnnotateError(GRPC_ERROR_CREATE_FROM_CFERROR( + stream_error, "Read error"), + tcp); + CFRelease(stream_error); + } else { + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Read error"); + } + CallReadCB(tcp, error); TCP_UNREF(tcp, "read"); } else if (read_size == 0) { grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); @@ -203,10 +208,15 @@ static void WriteAction(void* arg, grpc_error* error) { if (write_size == -1) { grpc_slice_buffer_reset_and_unref_internal(tcp->write_slices); CFErrorRef stream_error = CFWriteStreamCopyError(tcp->write_stream); - CallWriteCB(tcp, TCPAnnotateError(GRPC_ERROR_CREATE_FROM_CFERROR( - stream_error, "write failed."), - tcp)); - CFRelease(stream_error); + if (stream_error != nullptr) { + error = TCPAnnotateError(GRPC_ERROR_CREATE_FROM_CFERROR( + stream_error, "write failed."), + tcp); + CFRelease(stream_error); + } else { + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("write failed."); + } + CallWriteCB(tcp, error); TCP_UNREF(tcp, "write"); } else { if (write_size < GRPC_SLICE_LENGTH(slice)) { diff --git a/src/core/lib/iomgr/tcp_cfstream_sync.cc b/src/core/lib/iomgr/tcp_cfstream_sync.cc index 5571db7491..07ee53311c 100644 --- a/src/core/lib/iomgr/tcp_cfstream_sync.cc +++ b/src/core/lib/iomgr/tcp_cfstream_sync.cc @@ -57,8 +57,8 @@ void CFStreamSync::ReadCallback(CFReadStreamRef stream, CFStreamEventType type, ^{ grpc_core::ExecCtx exec_ctx; if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "TCP ReadCallback (%p, %lu, %p)", - stream, type, client_callback_info); + gpr_log(GPR_DEBUG, "TCP ReadCallback (%p, %p, %lu, %p)", + sync, stream, type, client_callback_info); } switch (type) { case kCFStreamEventOpenCompleted: @@ -88,8 +88,8 @@ void CFStreamSync::WriteCallback(CFWriteStreamRef stream, ^{ grpc_core::ExecCtx exec_ctx; if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "TCP WriteCallback (%p, %lu, %p)", - stream, type, clientCallBackInfo); + gpr_log(GPR_DEBUG, "TCP WriteCallback (%p, %p, %lu, %p)", + sync, stream, type, clientCallBackInfo); } switch (type) { case kCFStreamEventOpenCompleted: -- cgit v1.2.3