socket_mutator.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18 
20 
22 
24 #include <grpc/support/log.h>
25 #include <grpc/support/sync.h>
26 
29 
32  mutator->vtable = vtable;
33  gpr_ref_init(&mutator->refcount, 1);
34 }
35 
37  gpr_ref(&mutator->refcount);
38  return mutator;
39 }
40 
43  if (mutator->vtable->mutate_fd_2 != nullptr) {
45  return mutator->vtable->mutate_fd_2(&info, mutator);
46  }
47  switch (usage) {
49  return true;
52  return mutator->vtable->mutate_fd(fd, mutator);
53  }
54  GPR_UNREACHABLE_CODE(return false);
55 }
56 
59  int c = grpc_core::QsortCompare(a, b);
60  if (c != 0) {
61  grpc_socket_mutator* sma = a;
62  grpc_socket_mutator* smb = b;
63  c = grpc_core::QsortCompare(sma->vtable, smb->vtable);
64  if (c == 0) {
65  c = sma->vtable->compare(sma, smb);
66  }
67  }
68  return c;
69 }
70 
72  if (gpr_unref(&mutator->refcount)) {
73  mutator->vtable->destroy(mutator);
74  }
75 }
76 
77 static void* socket_mutator_arg_copy(void* p) {
78  return grpc_socket_mutator_ref(static_cast<grpc_socket_mutator*>(p));
79 }
80 
81 static void socket_mutator_arg_destroy(void* p) {
83 }
84 
85 static int socket_mutator_cmp(void* a, void* b) {
87  static_cast<grpc_socket_mutator*>(b));
88 }
89 
92 
95  const_cast<char*>(GRPC_ARG_SOCKET_MUTATOR), mutator,
97 }
grpc_arg
Definition: grpc_types.h:103
vtable
static const grpc_transport_vtable vtable
Definition: binder_transport.cc:680
log.h
grpc_socket_mutator_init
void grpc_socket_mutator_init(grpc_socket_mutator *mutator, const grpc_socket_mutator_vtable *vtable)
Definition: socket_mutator.cc:30
grpc_socket_mutator_unref
void grpc_socket_mutator_unref(grpc_socket_mutator *mutator)
Definition: socket_mutator.cc:71
useful.h
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
grpc_socket_mutator::vtable
const grpc_socket_mutator_vtable * vtable
Definition: socket_mutator.h:63
xds_manager.p
p
Definition: xds_manager.py:60
grpc_socket_mutator_vtable::mutate_fd
bool(* mutate_fd)(int fd, grpc_socket_mutator *mutator)
Definition: socket_mutator.h:50
socket_mutator_cmp
static int socket_mutator_cmp(void *a, void *b)
Definition: socket_mutator.cc:85
grpc_arg_pointer_vtable
Definition: grpc_types.h:85
grpc_types.h
grpc_socket_mutator_vtable::destroy
void(* destroy)(grpc_socket_mutator *mutator)
Definition: socket_mutator.h:54
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
socket_mutator_arg_vtable
static const grpc_arg_pointer_vtable socket_mutator_arg_vtable
Definition: socket_mutator.cc:90
socket_mutator_arg_copy
static void * socket_mutator_arg_copy(void *p)
Definition: socket_mutator.cc:77
grpc_socket_mutator_ref
grpc_socket_mutator * grpc_socket_mutator_ref(grpc_socket_mutator *mutator)
Definition: socket_mutator.cc:36
grpc_socket_mutator_vtable::mutate_fd_2
bool(* mutate_fd_2)(const grpc_mutate_socket_info *info, grpc_socket_mutator *mutator)
Definition: socket_mutator.h:57
grpc_socket_mutator_vtable::compare
int(* compare)(grpc_socket_mutator *a, grpc_socket_mutator *b)
Definition: socket_mutator.h:52
grpc_socket_mutator_vtable
Definition: socket_mutator.h:48
GPR_UNREACHABLE_CODE
#define GPR_UNREACHABLE_CODE(STATEMENT)
Definition: impl/codegen/port_platform.h:652
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
grpc_socket_mutator_compare
int grpc_socket_mutator_compare(grpc_socket_mutator *a, grpc_socket_mutator *b)
Definition: socket_mutator.cc:57
grpc_socket_mutator
Definition: socket_mutator.h:62
socket_mutator_arg_destroy
static void socket_mutator_arg_destroy(void *p)
Definition: socket_mutator.cc:81
grpc_mutate_socket_info
Definition: socket_mutator.h:40
bloaty::usage
const char usage[]
Definition: bloaty.cc:1843
grpc_socket_mutator_mutate_fd
bool grpc_socket_mutator_mutate_fd(grpc_socket_mutator *mutator, int fd, grpc_fd_usage usage)
Definition: socket_mutator.cc:41
grpc_core::QsortCompare
int QsortCompare(const T &a, const T &b)
Definition: useful.h:95
grpc_fd_usage
grpc_fd_usage
Definition: socket_mutator.h:30
GRPC_FD_CLIENT_CONNECTION_USAGE
@ GRPC_FD_CLIENT_CONNECTION_USAGE
Definition: socket_mutator.h:32
channel_args.h
grpc_socket_mutator_to_arg
grpc_arg grpc_socket_mutator_to_arg(grpc_socket_mutator *mutator)
Definition: socket_mutator.cc:93
GRPC_FD_SERVER_CONNECTION_USAGE
@ GRPC_FD_SERVER_CONNECTION_USAGE
Definition: socket_mutator.h:36
grpc_socket_mutator::refcount
gpr_refcount refcount
Definition: socket_mutator.h:64
gpr_ref_init
GPRAPI void gpr_ref_init(gpr_refcount *r, int n)
Definition: sync.cc:86
gpr_unref
GPRAPI int gpr_unref(gpr_refcount *r)
Definition: sync.cc:103
GRPC_ARG_SOCKET_MUTATOR
#define GRPC_ARG_SOCKET_MUTATOR
Definition: grpc_types.h:311
socket_mutator.h
sync.h
grpc_channel_arg_pointer_create
grpc_arg grpc_channel_arg_pointer_create(char *name, void *value, const grpc_arg_pointer_vtable *vtable)
Definition: channel_args.cc:492
GRPC_FD_SERVER_LISTENER_USAGE
@ GRPC_FD_SERVER_LISTENER_USAGE
Definition: socket_mutator.h:34
gpr_ref
GPRAPI void gpr_ref(gpr_refcount *r)
Definition: sync.cc:88
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:19