Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #ifndef GRPC_CORE_LIB_IOMGR_SOCKET_MUTATOR_H |
| 20 | #define GRPC_CORE_LIB_IOMGR_SOCKET_MUTATOR_H |
| 21 | |
| 22 | #include <grpc/impl/codegen/grpc_types.h> |
| 23 | #include <grpc/support/sync.h> |
| 24 | |
Craig Tiller | 100539f | 2017-04-14 15:20:34 -0700 | [diff] [blame] | 25 | #include <stdbool.h> |
| 26 | |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | /** The virtual table of grpc_socket_mutator */ |
| 32 | typedef struct { |
| 33 | /** Mutates the socket opitons of \a fd */ |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 34 | bool (*mutate_fd)(int fd, grpc_socket_mutator* mutator); |
Yuchen Zeng | 7810898 | 2016-11-08 14:28:03 -0800 | [diff] [blame] | 35 | /** Compare socket mutator \a a and \a b */ |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 36 | int (*compare)(grpc_socket_mutator* a, grpc_socket_mutator* b); |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 37 | /** Destroys the socket mutator instance */ |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 38 | void (*destory)(grpc_socket_mutator* mutator); |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 39 | } grpc_socket_mutator_vtable; |
| 40 | |
| 41 | /** The Socket Mutator interface allows changes on socket options */ |
| 42 | struct grpc_socket_mutator { |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 43 | const grpc_socket_mutator_vtable* vtable; |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 44 | gpr_refcount refcount; |
| 45 | }; |
| 46 | |
| 47 | /** called by concrete implementations to initialize the base struct */ |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 48 | void grpc_socket_mutator_init(grpc_socket_mutator* mutator, |
| 49 | const grpc_socket_mutator_vtable* vtable); |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 50 | |
| 51 | /** Wrap \a mutator as a grpc_arg */ |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 52 | grpc_arg grpc_socket_mutator_to_arg(grpc_socket_mutator* mutator); |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 53 | |
| 54 | /** Perform the file descriptor mutation operation of \a mutator on \a fd */ |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 55 | bool grpc_socket_mutator_mutate_fd(grpc_socket_mutator* mutator, int fd); |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 56 | |
Yuchen Zeng | 7810898 | 2016-11-08 14:28:03 -0800 | [diff] [blame] | 57 | /** Compare if \a a and \a b are the same mutator or have same settings */ |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 58 | int grpc_socket_mutator_compare(grpc_socket_mutator* a, grpc_socket_mutator* b); |
Yuchen Zeng | 7810898 | 2016-11-08 14:28:03 -0800 | [diff] [blame] | 59 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 60 | grpc_socket_mutator* grpc_socket_mutator_ref(grpc_socket_mutator* mutator); |
| 61 | void grpc_socket_mutator_unref(grpc_socket_mutator* mutator); |
Yuchen Zeng | de3daf5 | 2016-10-13 17:26:26 -0700 | [diff] [blame] | 62 | |
| 63 | #ifdef __cplusplus |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | #endif /* GRPC_CORE_LIB_IOMGR_SOCKET_MUTATOR_H */ |