17 #ifndef GRPC_CORE_LIB_SURFACE_SERVER_H
18 #define GRPC_CORE_LIB_SURFACE_SERVER_H
25 #include "absl/status/statusor.h"
26 #include "absl/types/optional.h"
83 const std::vector<grpc_pollset*>*
pollsets) = 0;
97 void Orphan() ABSL_LOCKS_EXCLUDED(mu_global_) override;
101 return default_resource_user_;
108 const std::vector<grpc_pollset*>&
pollsets()
const {
return pollsets_; }
111 return config_fetcher_.get();
127 void Start() ABSL_LOCKS_EXCLUDED(mu_global_);
143 std::function<RegisteredCallAllocation()> allocator);
145 std::function<BatchCallAllocation()> allocator);
148 const
char* method, const
char* host,
173 struct ChannelRegisteredMethod {
181 class RequestMatcherInterface;
182 class RealRequestMatcher;
183 class AllocatingRequestMatcherBase;
184 class AllocatingRequestMatcherBatch;
185 class AllocatingRequestMatcherRegistered;
189 ChannelData() =
default;
194 intptr_t channelz_socket_uuid);
198 size_t cq_idx()
const {
return cq_idx_; }
200 ChannelRegisteredMethod* GetRegisteredMethod(
const grpc_slice& host,
210 class ConnectivityWatcher;
213 const void* transport_server_data);
215 void Destroy() ABSL_EXCLUSIVE_LOCKS_REQUIRED(server_->mu_global_);
224 absl::optional<std::list<ChannelData*>::iterator> list_position_;
229 std::unique_ptr<std::vector<ChannelRegisteredMethod>> registered_methods_;
230 uint32_t registered_method_max_probes_;
232 intptr_t channelz_socket_uuid_;
237 enum class CallState {
245 RefCountedPtr<Server> server);
252 void SetState(CallState state);
256 bool MaybeActivate();
260 void Publish(
size_t cq_idx, RequestedCall* rc);
264 void FailCallCreation();
272 static void StartTransportStreamOpBatch(
277 static void RecvInitialMetadataBatchComplete(
void* arg,
288 RefCountedPtr<Server> server_;
292 Atomic<CallState> state_{CallState::NOT_STARTED};
294 absl::optional<grpc_slice> path_;
295 absl::optional<grpc_slice> host_;
300 RequestMatcherInterface* matcher_ =
nullptr;
310 uint32_t recv_initial_metadata_flags_ = 0;
315 bool seen_recv_trailing_metadata_ready_ =
false;
322 CallCombiner* call_combiner_;
326 explicit Listener(OrphanablePtr<ListenerInterface> l)
327 : listener(std::move(l)) {}
328 OrphanablePtr<ListenerInterface> listener;
334 : tag(tag_arg), cq(cq_arg) {}
342 static void DoneShutdownEvent(
void* server,
352 void MaybeFinishShutdown() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_global_)
356 ABSL_EXCLUSIVE_LOCKS_REQUIRED(
mu_call_);
369 bool ShutdownRefOnRequest() {
371 return (old_value & 1) != 0;
377 void ShutdownUnrefOnRequest() ABSL_LOCKS_EXCLUDED(mu_global_) {
379 MutexLock lock(&mu_global_);
380 MaybeFinishShutdown();
383 void ShutdownUnrefOnShutdownCall() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_global_) {
385 MaybeFinishShutdown();
389 bool ShutdownCalled()
const {
396 bool ShutdownReady()
const {
402 RefCountedPtr<channelz::ServerNode> channelz_node_;
403 std::unique_ptr<grpc_server_config_fetcher> config_fetcher_;
405 std::vector<grpc_completion_queue*> cqs_;
406 std::vector<grpc_pollset*> pollsets_;
407 bool started_ =
false;
421 bool starting_ =
false;
422 CondVar starting_cv_;
424 std::vector<std::unique_ptr<RegisteredMethod>> registered_methods_;
427 std::unique_ptr<RequestMatcherInterface> unregistered_request_matcher_;
435 Atomic<int> shutdown_refs_{1};
436 bool shutdown_published_ ABSL_GUARDED_BY(mu_global_) =
false;
437 std::vector<ShutdownTag> shutdown_tags_ ABSL_GUARDED_BY(mu_global_);
439 std::list<ChannelData*> channels_;
441 std::list<Listener> listeners_;
442 size_t listeners_destroyed_ = 0;
487 std::unique_ptr<WatcherInterface>
watcher) = 0;
ClusterWatcher * watcher
Definition: cds.cc:112
Definition: orphanable.h:76
void Unref()
Definition: orphanable.h:103
friend class RefCountedPtr
Definition: orphanable.h:85
Definition: orphanable.h:42
Definition: ref_counted.h:282
Definition: ref_counted_ptr.h:35
Interface for listeners.
Definition: server.h:76
virtual void Start(Server *server, const std::vector< grpc_pollset * > *pollsets)=0
Starts listening.
virtual void SetOnDestroyDone(grpc_closure *on_destroy_done)=0
Sets a closure to be invoked by the listener when its destruction is complete.
virtual channelz::ListenSocketNode * channelz_listen_socket_node() const =0
Returns the channelz node for the listen socket, or null if not supported.
~ListenerInterface() override=default
bool HasOpenConnections() ABSL_LOCKS_EXCLUDED(mu_global_)
Definition: server.cc:647
void SetBatchMethodAllocator(grpc_completion_queue *cq, std::function< BatchCallAllocation()> allocator)
Definition: server.cc:660
void RegisterCompletionQueue(grpc_completion_queue *cq)
Definition: server.cc:668
static const grpc_channel_filter kServerTopFilter
Definition: server.h:46
void AddListener(OrphanablePtr< ListenerInterface > listener)
Definition: server.cc:566
void Orphan() ABSL_LOCKS_EXCLUDED(mu_global_) override
Definition: server.cc:861
void set_config_fetcher(std::unique_ptr< grpc_server_config_fetcher > config_fetcher)
Definition: server.h:114
void Start() ABSL_LOCKS_EXCLUDED(mu_global_)
Definition: server.cc:575
grpc_resource_user * default_resource_user() const
Definition: server.h:100
const grpc_channel_args * channel_args() const
Definition: server.h:99
void CancelAllCalls() ABSL_LOCKS_EXCLUDED(mu_global_)
Definition: server.cc:850
channelz::ServerNode * channelz_node() const
Definition: server.h:103
grpc_call_error RequestCall(grpc_call **call, grpc_call_details *details, grpc_metadata_array *request_metadata, grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag)
Definition: server.cc:929
Server(const grpc_channel_args *args)
Definition: server.cc:546
void ShutdownAndNotify(grpc_completion_queue *cq, void *tag) ABSL_LOCKS_EXCLUDED(mu_global_
Definition: server.cc:807
grpc_server_config_fetcher * config_fetcher() const
Definition: server.h:110
RegisteredMethod * RegisterMethod(const char *method, const char *host, grpc_server_register_method_payload_handling payload_handling, uint32_t flags)
Definition: server.cc:685
void SetRegisteredMethodAllocator(grpc_completion_queue *cq, void *method_tag, std::function< RegisteredCallAllocation()> allocator)
Definition: server.cc:652
const std::vector< grpc_pollset * > & pollsets() const
Definition: server.h:108
~Server() override
Definition: server.cc:551
grpc_error_handle SetupTransport(grpc_transport *transport, grpc_pollset *accepting_pollset, const grpc_channel_args *args, const RefCountedPtr< channelz::SocketNode > &socket_node, grpc_resource_user *resource_user=nullptr)
Definition: server.cc:612
void mu_call_
Definition: server.h:166
grpc_call_error RequestRegisteredCall(RegisteredMethod *rm, grpc_call **call, gpr_timespec *deadline, grpc_metadata_array *request_metadata, grpc_byte_buffer **optional_payload, grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag_new)
Definition: server.cc:946
Definition: channelz.h:343
Definition: channelz.h:231
virtual absl::StatusOr< grpc_channel_args * > UpdateChannelArgsForConnection(grpc_channel_args *args, grpc_endpoint *tcp)=0
virtual void StopServing()=0
virtual void UpdateConnectionManager(grpc_core::RefCountedPtr< ConnectionManager > manager)=0
virtual ~WatcherInterface()=default
#define GRPC_ERROR_NONE
The following "special" errors can be propagated without allocating memory.
Definition: error.h:228
int64_t grpc_millis
Definition: exec_ctx.h:37
#define GRPC_MILLIS_INF_FUTURE
Definition: exec_ctx.h:39
grpc_server_register_method_payload_handling
How to handle payloads for a registered method.
Definition: grpc.h:366
grpc_call_error
Result of a grpc call.
Definition: grpc_types.h:441
grpc_error_handle error
Definition: lame_client.cc:54
Round Robin Policy.
Definition: backend_metric.cc:26
TraceFlag grpc_server_channel_trace(false, "server_channel")
Definition: server.h:41
std::unique_ptr< T, Deleter > OrphanablePtr
Definition: orphanable.h:67
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
grpc_transport_stream_op_batch * batch
Definition: retry_filter.cc:208
Analogous to struct timespec.
Definition: gpr_types.h:47
Definition: grpc_types.h:40
Definition: grpc_types.h:569
Definition: channel_stack.h:76
Definition: channel_stack.h:174
Information about the call upon completion.
Definition: channel_stack.h:91
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Definition: channel_stack.h:68
Definition: channel_stack.h:166
Definition: channel_stack.h:107
Definition: channel.h:105
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
Definition: completion_queue.cc:339
Definition: slice_utils.h:147
grpc_completion_queue * cq
Definition: server.h:58
grpc_call ** call
Definition: server.h:55
grpc_metadata_array * initial_metadata
Definition: server.h:56
void * tag
Definition: server.h:54
grpc_call_details * details
Definition: server.h:57
gpr_timespec * deadline
Definition: server.h:68
grpc_completion_queue * cq
Definition: server.h:70
grpc_metadata_array * initial_metadata
Definition: server.h:67
void * tag
Definition: server.h:65
grpc_call ** call
Definition: server.h:66
grpc_byte_buffer ** optional_payload
Definition: server.h:69
Definition: server.cc:118
Definition: completion_queue.h:39
Definition: endpoint.h:106
Definition: error_internal.h:41
Definition: pollset_custom.cc:40
Definition: resource_quota.cc:65
virtual ~grpc_server_config_fetcher()=default
virtual void StartWatch(std::string listening_address, grpc_channel_args *args, std::unique_ptr< WatcherInterface > watcher)=0
virtual grpc_pollset_set * interested_parties()=0
virtual void CancelWatch(WatcherInterface *watcher)=0
grpc_core::OrphanablePtr< grpc_core::Server > core_server
Definition: server.h:451
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice.h:60
Definition: transport.h:163
Definition: transport_impl.h:66
std::string listening_address
Definition: xds_server_config_fetcher.cc:509