diff --git a/src/core/lib/iomgr/cfstream_handle.cc b/src/core/lib/iomgr/cfstream_handle.cc index ea28e620695..c1e7d67e568 100644 --- a/src/core/lib/iomgr/cfstream_handle.cc +++ b/src/core/lib/iomgr/cfstream_handle.cc @@ -25,6 +25,7 @@ #import #import "src/core/lib/iomgr/cfstream_handle.h" +#include #include #include @@ -35,6 +36,10 @@ extern grpc_core::TraceFlag grpc_tcp_trace; +GrpcLibraryInitHolder::GrpcLibraryInitHolder() { grpc_init(); } + +GrpcLibraryInitHolder::~GrpcLibraryInitHolder() { grpc_shutdown(); } + void* CFStreamHandle::Retain(void* info) { CFStreamHandle* handle = static_cast(info); CFSTREAM_HANDLE_REF(handle, "retain"); diff --git a/src/core/lib/iomgr/cfstream_handle.h b/src/core/lib/iomgr/cfstream_handle.h index 05f45ed6251..5f3a525930c 100644 --- a/src/core/lib/iomgr/cfstream_handle.h +++ b/src/core/lib/iomgr/cfstream_handle.h @@ -33,11 +33,17 @@ #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/lockfree_event.h" -class CFStreamHandle final { +class GrpcLibraryInitHolder { + public: + GrpcLibraryInitHolder(); + virtual ~GrpcLibraryInitHolder(); +}; + +class CFStreamHandle : public GrpcLibraryInitHolder { public: static CFStreamHandle* CreateStreamHandle(CFReadStreamRef read_stream, CFWriteStreamRef write_stream); - ~CFStreamHandle(); + ~CFStreamHandle() override; CFStreamHandle(const CFStreamHandle& ref) = delete; CFStreamHandle(CFStreamHandle&& ref) = delete; CFStreamHandle& operator=(const CFStreamHandle& rhs) = delete;