| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2017 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 |
|
| 19 |
#ifndef GRPC_CORE_LIB_IOMGR_SOCKET_FACTORY_POSIX_H |
| 20 |
#define GRPC_CORE_LIB_IOMGR_SOCKET_FACTORY_POSIX_H |
| 21 |
|
| 22 |
#include <grpc/support/port_platform.h> |
| 23 |
|
| 24 |
#include <grpc/impl/codegen/grpc_types.h> |
| 25 |
#include <grpc/support/sync.h> |
| 26 |
|
| 27 |
#include "src/core/lib/iomgr/resolve_address.h" |
| 28 |
|
| 29 |
/** The virtual table of grpc_socket_factory */ |
| 30 |
struct grpc_socket_factory_vtable { |
| 31 |
/** Replacement for socket(2) */ |
| 32 |
int (*socket)(grpc_socket_factory* factory, int domain, int type, |
| 33 |
int protocol); |
| 34 |
/** Replacement for bind(2) */ |
| 35 |
int (*bind)(grpc_socket_factory* factory, int sockfd, |
| 36 |
const grpc_resolved_address* addr); |
| 37 |
/** Compare socket factory \a a and \a b */ |
| 38 |
int (*compare)(grpc_socket_factory* a, grpc_socket_factory* b); |
| 39 |
/** Destroys the socket factory instance */ |
| 40 |
void (*destroy)(grpc_socket_factory* factory); |
| 41 |
}; |
| 42 |
/** The Socket Factory interface allows changes on socket options */ |
| 43 |
struct grpc_socket_factory { |
| 44 |
const grpc_socket_factory_vtable* vtable; |
| 45 |
gpr_refcount refcount; |
| 46 |
}; |
| 47 |
|
| 48 |
/** called by concrete implementations to initialize the base struct */ |
| 49 |
void grpc_socket_factory_init(grpc_socket_factory* factory, |
| 50 |
const grpc_socket_factory_vtable* vtable); |
| 51 |
|
| 52 |
/** Wrap \a factory as a grpc_arg */ |
| 53 |
grpc_arg grpc_socket_factory_to_arg(grpc_socket_factory* factory); |
| 54 |
|
| 55 |
/** Perform the equivalent of a socket(2) operation using \a factory */ |
| 56 |
int grpc_socket_factory_socket(grpc_socket_factory* factory, int domain, |
| 57 |
int type, int protocol); |
| 58 |
|
| 59 |
/** Perform the equivalent of a bind(2) operation using \a factory */ |
| 60 |
int grpc_socket_factory_bind(grpc_socket_factory* factory, int sockfd, |
| 61 |
const grpc_resolved_address* addr); |
| 62 |
|
| 63 |
/** Compare if \a a and \a b are the same factory or have same settings */ |
| 64 |
int grpc_socket_factory_compare(grpc_socket_factory* a, grpc_socket_factory* b); |
| 65 |
|
| 66 |
grpc_socket_factory* grpc_socket_factory_ref(grpc_socket_factory* factory); |
| 67 |
void grpc_socket_factory_unref(grpc_socket_factory* factory); |
| 68 |
|
| 69 |
#endif /* GRPC_CORE_LIB_IOMGR_SOCKET_FACTORY_POSIX_H */ |