aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr/cfstream_handle.h
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-05-30 15:42:31 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-05-30 16:00:06 -0700
commit142cbb59480794980e53062c846bcc2d7512548a (patch)
treeb393255c68f2f1141e703d2cb1bc70312bd1eb97 /src/core/lib/iomgr/cfstream_handle.h
parenta6e8d0ba24a684713b879eb18e7ce5313f8030cf (diff)
Address comments on names and comments
Diffstat (limited to 'src/core/lib/iomgr/cfstream_handle.h')
-rw-r--r--src/core/lib/iomgr/cfstream_handle.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/core/lib/iomgr/cfstream_handle.h b/src/core/lib/iomgr/cfstream_handle.h
new file mode 100644
index 0000000000..f6f7ae54ed
--- /dev/null
+++ b/src/core/lib/iomgr/cfstream_handle.h
@@ -0,0 +1,82 @@
+/*
+ *
+ * Copyright 2018 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* The CFStream handle acts as an event synchronization entity for
+ * read/write/open/error/eos events happening on CFStream streams. */
+
+#ifndef GRPC_CORE_LIB_IOMGR_CFSTREAM_HANDLE_H
+#define GRPC_CORE_LIB_IOMGR_CFSTREAM_HANDLE_H
+
+#include <grpc/support/port_platform.h>
+
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_CFSTREAM
+#import <CoreFoundation/CoreFoundation.h>
+
+#include "src/core/lib/iomgr/closure.h"
+#include "src/core/lib/iomgr/lockfree_event.h"
+
+class CFStreamHandle final {
+ public:
+ static CFStreamHandle* CreateStreamSync(CFReadStreamRef read_stream,
+ CFWriteStreamRef write_stream);
+ ~CFStreamHandle();
+ CFStreamHandle(const CFReadStreamRef& ref) = delete;
+ CFStreamHandle(CFReadStreamRef&& ref) = delete;
+ CFStreamHandle& operator=(const CFStreamHandle& rhs) = delete;
+
+ void NotifyOnOpen(grpc_closure* closure);
+ void NotifyOnRead(grpc_closure* closure);
+ void NotifyOnWrite(grpc_closure* closure);
+ void Shutdown(grpc_error* error);
+
+ void Ref(const char* file = nullptr, int line = 0,
+ const char* reason = nullptr);
+ void Unref(const char* file = nullptr, int line = 0,
+ const char* reason = nullptr);
+
+ private:
+ CFStreamHandle(CFReadStreamRef read_stream, CFWriteStreamRef write_stream);
+ static void ReadCallback(CFReadStreamRef stream, CFStreamEventType type,
+ void* client_callback_info);
+ static void WriteCallback(CFWriteStreamRef stream, CFStreamEventType type,
+ void* client_callback_info);
+ static void* Retain(void* info);
+ static void Release(void* info);
+
+ grpc_core::LockfreeEvent open_event_;
+ grpc_core::LockfreeEvent read_event_;
+ grpc_core::LockfreeEvent write_event_;
+
+ gpr_refcount refcount_;
+};
+
+#ifndef NDEBUG
+#define CFSTREAM_SYNC_REF(sync, reason) \
+ (sync)->Ref(__FILE__, __LINE__, (reason))
+#define CFSTREAM_SYNC_UNREF(sync, reason) \
+ (sync)->Unref(__FILE__, __LINE__, (reason))
+#else
+#define CFSTREAM_SYNC_REF(sync, reason) (sync)->Ref()
+#define CFSTREAM_SYNC_UNREF(sync, reason) (sync)->Unref()
+#endif
+
+#endif
+
+#endif /* GRPC_CORE_LIB_IOMGR_CFSTREAM_HANDLE_H */