grpc
src
cpp
server
external_connection_acceptor_impl.cc
Go to the documentation of this file.
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
#include "
src/cpp/server/external_connection_acceptor_impl.h
"
20
21
#include <memory>
22
#include <utility>
23
24
#include <
grpc/support/log.h
>
25
#include <
grpcpp/server_builder.h
>
26
#include <
grpcpp/support/byte_buffer.h
>
27
#include <
grpcpp/support/channel_arguments.h
>
28
29
namespace
grpc
{
30
namespace
internal
{
31
namespace
{
32
// The actual type to return to user. It co-owns the internal impl object with
33
// the server.
34
class
AcceptorWrapper :
public
experimental::ExternalConnectionAcceptor {
35
public
:
36
explicit
AcceptorWrapper(std::shared_ptr<ExternalConnectionAcceptorImpl> impl)
37
:
impl_
(
std
::
move
(impl)) {}
38
void
HandleNewConnection(NewConnectionParameters* p)
override
{
39
impl_
->HandleNewConnection(p);
40
}
41
42
private
:
43
std::shared_ptr<ExternalConnectionAcceptorImpl>
impl_
;
44
};
45
}
// namespace
46
47
ExternalConnectionAcceptorImpl::ExternalConnectionAcceptorImpl
(
48
const
std::string
&
name
,
49
ServerBuilder::experimental_type::ExternalConnectionType
type
,
50
std::shared_ptr<ServerCredentials> creds)
51
:
name_
(
name
),
creds_
(
std
::
move
(creds)) {
52
GPR_ASSERT
(
type
==
53
ServerBuilder::experimental_type::ExternalConnectionType::FROM_FD
);
54
}
55
56
std::unique_ptr<experimental::ExternalConnectionAcceptor>
57
ExternalConnectionAcceptorImpl::GetAcceptor
() {
58
grpc_core::MutexLock
lock(&
mu_
);
59
GPR_ASSERT
(!
has_acceptor_
);
60
has_acceptor_
=
true
;
61
return
std::unique_ptr<experimental::ExternalConnectionAcceptor>(
62
new
AcceptorWrapper(shared_from_this()));
63
}
64
65
void
ExternalConnectionAcceptorImpl::HandleNewConnection
(
66
experimental::ExternalConnectionAcceptor::NewConnectionParameters
* p) {
67
grpc_core::MutexLock
lock(&
mu_
);
68
if
(
shutdown_
|| !
started_
) {
69
// TODO(yangg) clean up.
70
gpr_log
(
71
GPR_ERROR
,
72
"NOT handling external connection with fd %d, started %d, shutdown %d"
,
73
p->fd,
started_
,
shutdown_
);
74
return
;
75
}
76
if
(
handler_
) {
77
handler_
->
Handle
(p->listener_fd, p->fd, p->read_buffer.c_buffer());
78
}
79
}
80
81
void
ExternalConnectionAcceptorImpl::Shutdown
() {
82
grpc_core::MutexLock
lock(&
mu_
);
83
shutdown_
=
true
;
84
}
85
86
void
ExternalConnectionAcceptorImpl::Start
() {
87
grpc_core::MutexLock
lock(&
mu_
);
88
GPR_ASSERT
(!
started_
);
89
GPR_ASSERT
(
has_acceptor_
);
90
GPR_ASSERT
(!
shutdown_
);
91
started_
=
true
;
92
}
93
94
void
ExternalConnectionAcceptorImpl::SetToChannelArgs
(
ChannelArguments
*
args
) {
95
args
->SetPointer(
name_
.c_str(), &
handler_
);
96
}
97
98
}
// namespace internal
99
}
// namespace grpc
grpc::experimental::ExternalConnectionAcceptor::NewConnectionParameters
Definition:
grpcpp/server_builder.h:69
log.h
grpc::ServerBuilder::experimental_type::ExternalConnectionType::FROM_FD
@ FROM_FD
grpc::internal::ExternalConnectionAcceptorImpl::mu_
grpc_core::Mutex mu_
Definition:
external_connection_acceptor_impl.h:63
grpc
Definition:
grpcpp/alarm.h:33
grpc_core::MutexLock
Definition:
src/core/lib/gprpp/sync.h:88
grpc::internal::ExternalConnectionAcceptorImpl::has_acceptor_
bool has_acceptor_
Definition:
external_connection_acceptor_impl.h:64
testing::internal::string
::std::string string
Definition:
bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::internal::ExternalConnectionAcceptorImpl::HandleNewConnection
void HandleNewConnection(experimental::ExternalConnectionAcceptor::NewConnectionParameters *p)
Definition:
external_connection_acceptor_impl.cc:65
external_connection_acceptor_impl.h
setup.name
name
Definition:
setup.py:542
grpc::internal::ExternalConnectionAcceptorImpl::SetToChannelArgs
void SetToChannelArgs(grpc::ChannelArguments *args)
Definition:
external_connection_acceptor_impl.cc:94
name_
const std::string name_
Definition:
priority.cc:233
grpc::internal::ExternalConnectionAcceptorImpl::Start
void Start()
Definition:
external_connection_acceptor_impl.cc:86
grpc::internal::ExternalConnectionAcceptorImpl::name_
const std::string name_
Definition:
external_connection_acceptor_impl.h:60
asyncio_get_stats.args
args
Definition:
asyncio_get_stats.py:40
grpc::internal::ExternalConnectionAcceptorImpl::ExternalConnectionAcceptorImpl
ExternalConnectionAcceptorImpl(const std::string &name, ServerBuilder::experimental_type::ExternalConnectionType type, std::shared_ptr< ServerCredentials > creds)
Definition:
external_connection_acceptor_impl.cc:47
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition:
abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition:
include/grpc/impl/codegen/log.h:94
channel_arguments.h
creds_
std::shared_ptr< ChannelCredentials > creds_
Definition:
client_lb_end2end_test.cc:523
impl_
std::shared_ptr< ExternalConnectionAcceptorImpl > impl_
Definition:
external_connection_acceptor_impl.cc:43
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
grpc::internal::ExternalConnectionAcceptorImpl::shutdown_
bool shutdown_
Definition:
external_connection_acceptor_impl.h:66
GPR_ERROR
#define GPR_ERROR
Definition:
include/grpc/impl/codegen/log.h:57
grpc::internal::ExternalConnectionAcceptorImpl::GetAcceptor
std::unique_ptr< experimental::ExternalConnectionAcceptor > GetAcceptor()
Definition:
external_connection_acceptor_impl.cc:57
grpc::internal::ExternalConnectionAcceptorImpl::handler_
grpc_core::TcpServerFdHandler * handler_
Definition:
external_connection_acceptor_impl.h:62
grpc::internal::ExternalConnectionAcceptorImpl::Shutdown
void Shutdown()
Definition:
external_connection_acceptor_impl.cc:81
grpc::ChannelArguments
Definition:
grpcpp/support/channel_arguments.h:39
grpc::internal::ExternalConnectionAcceptorImpl::started_
bool started_
Definition:
external_connection_acceptor_impl.h:65
std
Definition:
grpcpp/impl/codegen/async_unary_call.h:407
internal
Definition:
benchmark/test/output_test_helper.cc:20
grpc_core::TcpServerFdHandler::Handle
virtual void Handle(int listener_fd, int fd, grpc_byte_buffer *pending_read)=0
grpc::ServerBuilder::experimental_type::ExternalConnectionType
ExternalConnectionType
Definition:
grpcpp/server_builder.h:268
asyncio_get_stats.type
type
Definition:
asyncio_get_stats.py:37
server_builder.h
byte_buffer.h
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:21