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