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