A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
serving.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
31#ifndef A11_SERVICE_SERVING_H_
32#define A11_SERVICE_SERVING_H_
33
34#include <functional>
35#include <memory>
36#include <utility>
37
38#include <absl/status/status.h>
39
41#include "a11/service/service.h"
42#include "a11/service/session.h"
43
44namespace a11::service {
45
60template <typename StreamT>
61std::function<a11::Task(std::shared_ptr<StreamT>)> AcceptInto(
62 const std::shared_ptr<Service>& service,
64 std::weak_ptr<Service> weak = service;
65 return [weak = std::move(weak),
66 mode](std::shared_ptr<StreamT> stream) -> a11::Task {
67 std::shared_ptr<Service> resolved = weak.lock();
68 if (resolved == nullptr) {
69 return a11::FailedTask(absl::FailedPreconditionError(
70 "The service this server was bound to is gone"));
71 }
72 return resolved->Serve(std::move(stream), mode);
73 };
74}
75
76} // namespace a11::service
77
78#endif // A11_SERVICE_SERVING_H_
Completion values used by every asynchronous A11 operation.
Definition action.h:74
StreamMode
Whether this side starts (kStart) or accepts (kAccept) a stream during its startup handshake.
Definition session.h:112
std::function< a11::Task(std::shared_ptr< StreamT >)> AcceptInto(const std::shared_ptr< Service > &service, StreamMode mode=StreamMode::kAccept)
A callback for any transport's on-stream hook, serving into service.
Definition serving.h:61
Task FailedTask(absl::Status status)
Return an already-failed Task.
Definition future.h:419
Future< Unit > Task
Asynchronous operation whose only successful result is completion itself.
Definition future.h:411
A service: what a peer can call, decoupled from where it listens.
A11's connection-scoped runtime: the Session.