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 #include "src/core/lib/iomgr/resolve_address.h" 27 28 /** The virtual table of grpc_socket_factory */ 29 typedef struct { 30 /** Replacement for socket(2) */ 31 int (*socket)(grpc_socket_factory* factory, int domain, int type, 32 int protocol); 33 /** Replacement for bind(2) */ 34 int (*bind)(grpc_socket_factory* factory, int sockfd, 35 const grpc_resolved_address* addr); 36 /** Compare socket factory \a a and \a b */ 37 int (*compare)(grpc_socket_factory* a, grpc_socket_factory* b); 38 /** Destroys the socket factory instance */ 39 void (*destroy)(grpc_socket_factory* factory); 40 } grpc_socket_factory_vtable; 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 */ 70