1 /* 2 * 3 * Copyright 2019 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 SRC_CPP_SERVER_EXTERNAL_CONNECTION_ACCEPTOR_IMPL_H_ 20 #define SRC_CPP_SERVER_EXTERNAL_CONNECTION_ACCEPTOR_IMPL_H_ 21 22 #include <memory> 23 24 #include <grpc/impl/codegen/grpc_types.h> 25 #include <grpcpp/security/server_credentials.h> 26 #include <grpcpp/security/server_credentials_impl.h> 27 #include <grpcpp/server_builder.h> 28 #include <grpcpp/support/channel_arguments.h> 29 30 #include "src/core/lib/gprpp/sync.h" 31 #include "src/core/lib/iomgr/tcp_server.h" 32 33 namespace grpc { 34 namespace internal { 35 36 class ExternalConnectionAcceptorImpl 37 : public std::enable_shared_from_this<ExternalConnectionAcceptorImpl> { 38 public: 39 ExternalConnectionAcceptorImpl( 40 const std::string& name, 41 ServerBuilder::experimental_type::ExternalConnectionType type, 42 std::shared_ptr<ServerCredentials> creds); 43 // Should only be called once. 44 std::unique_ptr<experimental::ExternalConnectionAcceptor> GetAcceptor(); 45 46 void HandleNewConnection( 47 experimental::ExternalConnectionAcceptor::NewConnectionParameters* p); 48 49 void Shutdown(); 50 51 void Start(); 52 name()53 const char* name() { return name_.c_str(); } 54 GetCredentials()55 ServerCredentials* GetCredentials() { return creds_.get(); } 56 57 void SetToChannelArgs(::grpc::ChannelArguments* args); 58 59 private: 60 const std::string name_; 61 std::shared_ptr<ServerCredentials> creds_; 62 grpc_core::TcpServerFdHandler* handler_ = nullptr; // not owned 63 grpc_core::Mutex mu_; 64 bool has_acceptor_ = false; 65 bool started_ = false; 66 bool shutdown_ = false; 67 }; 68 69 } // namespace internal 70 } // namespace grpc 71 72 #endif // SRC_CPP_SERVER_EXTERNAL_CONNECTION_ACCEPTOR_IMPL_H_ 73