3 * Copyright 2016 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <grpc/support/port_platform.h>
21 #include "src/core/lib/iomgr/polling_entity.h"
23 #include <grpc/support/alloc.h>
24 #include <grpc/support/log.h>
26 grpc_polling_entity grpc_polling_entity_create_from_pollset_set(
27 grpc_pollset_set* pollset_set) {
28 grpc_polling_entity pollent;
29 pollent.pollent.pollset_set = pollset_set;
30 pollent.tag = GRPC_POLLS_POLLSET_SET;
34 grpc_polling_entity grpc_polling_entity_create_from_pollset(
35 grpc_pollset* pollset) {
36 grpc_polling_entity pollent;
37 pollent.pollent.pollset = pollset;
38 pollent.tag = GRPC_POLLS_POLLSET;
42 grpc_pollset* grpc_polling_entity_pollset(grpc_polling_entity* pollent) {
43 if (pollent->tag == GRPC_POLLS_POLLSET) {
44 return pollent->pollent.pollset;
49 grpc_pollset_set* grpc_polling_entity_pollset_set(
50 grpc_polling_entity* pollent) {
51 if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
52 return pollent->pollent.pollset_set;
57 bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent) {
58 return pollent->tag == GRPC_POLLS_NONE;
61 void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent,
62 grpc_pollset_set* pss_dst) {
63 if (pollent->tag == GRPC_POLLS_POLLSET) {
64 // CFStream does not use file destriptors. When CFStream is used, the fd
65 // pollset is possible to be null.
66 if (pollent->pollent.pollset != nullptr) {
67 grpc_pollset_set_add_pollset(pss_dst, pollent->pollent.pollset);
69 } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
70 GPR_ASSERT(pollent->pollent.pollset_set != nullptr);
71 grpc_pollset_set_add_pollset_set(pss_dst, pollent->pollent.pollset_set);
73 gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag);
78 void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent,
79 grpc_pollset_set* pss_dst) {
80 if (pollent->tag == GRPC_POLLS_POLLSET) {
82 if (pollent->pollent.pollset != nullptr) {
83 grpc_pollset_set_del_pollset(pss_dst, pollent->pollent.pollset);
86 GPR_ASSERT(pollent->pollent.pollset != nullptr);
87 grpc_pollset_set_del_pollset(pss_dst, pollent->pollent.pollset);
89 } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
90 GPR_ASSERT(pollent->pollent.pollset_set != nullptr);
91 grpc_pollset_set_del_pollset_set(pss_dst, pollent->pollent.pollset_set);
93 gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag);