blob: b4103f7e93ad0b2523156abdbaa86dcdcfc01972 [file] [log] [blame]
Yuchen Zengde3daf52016-10-13 17:26:26 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Yuchen Zengde3daf52016-10-13 17:26:26 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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 Zengde3daf52016-10-13 17:26:26 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Yuchen Zengde3daf52016-10-13 17:26:26 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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 Zengde3daf52016-10-13 17:26:26 -070016 *
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 Tiller100539f2017-04-14 15:20:34 -070025#include <stdbool.h>
26
Yuchen Zengde3daf52016-10-13 17:26:26 -070027#ifdef __cplusplus
28extern "C" {
29#endif
30
31/** The virtual table of grpc_socket_mutator */
32typedef struct {
33 /** Mutates the socket opitons of \a fd */
Craig Tillerbaa14a92017-11-03 09:09:36 -070034 bool (*mutate_fd)(int fd, grpc_socket_mutator* mutator);
Yuchen Zeng78108982016-11-08 14:28:03 -080035 /** Compare socket mutator \a a and \a b */
Craig Tillerbaa14a92017-11-03 09:09:36 -070036 int (*compare)(grpc_socket_mutator* a, grpc_socket_mutator* b);
Yuchen Zengde3daf52016-10-13 17:26:26 -070037 /** Destroys the socket mutator instance */
Craig Tillerbaa14a92017-11-03 09:09:36 -070038 void (*destory)(grpc_socket_mutator* mutator);
Yuchen Zengde3daf52016-10-13 17:26:26 -070039} grpc_socket_mutator_vtable;
40
41/** The Socket Mutator interface allows changes on socket options */
42struct grpc_socket_mutator {
Craig Tillerbaa14a92017-11-03 09:09:36 -070043 const grpc_socket_mutator_vtable* vtable;
Yuchen Zengde3daf52016-10-13 17:26:26 -070044 gpr_refcount refcount;
45};
46
47/** called by concrete implementations to initialize the base struct */
Craig Tillerbaa14a92017-11-03 09:09:36 -070048void grpc_socket_mutator_init(grpc_socket_mutator* mutator,
49 const grpc_socket_mutator_vtable* vtable);
Yuchen Zengde3daf52016-10-13 17:26:26 -070050
51/** Wrap \a mutator as a grpc_arg */
Craig Tillerbaa14a92017-11-03 09:09:36 -070052grpc_arg grpc_socket_mutator_to_arg(grpc_socket_mutator* mutator);
Yuchen Zengde3daf52016-10-13 17:26:26 -070053
54/** Perform the file descriptor mutation operation of \a mutator on \a fd */
Craig Tillerbaa14a92017-11-03 09:09:36 -070055bool grpc_socket_mutator_mutate_fd(grpc_socket_mutator* mutator, int fd);
Yuchen Zengde3daf52016-10-13 17:26:26 -070056
Yuchen Zeng78108982016-11-08 14:28:03 -080057/** Compare if \a a and \a b are the same mutator or have same settings */
Craig Tillerbaa14a92017-11-03 09:09:36 -070058int grpc_socket_mutator_compare(grpc_socket_mutator* a, grpc_socket_mutator* b);
Yuchen Zeng78108982016-11-08 14:28:03 -080059
Craig Tillerbaa14a92017-11-03 09:09:36 -070060grpc_socket_mutator* grpc_socket_mutator_ref(grpc_socket_mutator* mutator);
61void grpc_socket_mutator_unref(grpc_socket_mutator* mutator);
Yuchen Zengde3daf52016-10-13 17:26:26 -070062
63#ifdef __cplusplus
64}
65#endif
66
67#endif /* GRPC_CORE_LIB_IOMGR_SOCKET_MUTATOR_H */