LLVM 24.0.0git
ConnectionSpec.h
Go to the documentation of this file.
1//===- ConnectionSpec.h - Connection spec parsing ---------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// A ConnectionSpec describes one connection a process should establish with
10// its peer, e.g. "tcp:connect=localhost:20000" or "socket:adopt=3".
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_CONNECTIONSPEC_H
15#define LLVM_EXECUTIONENGINE_ORC_SHARED_CONNECTIONSPEC_H
16
17#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Error.h"
20#include <string>
21
22namespace llvm::orc {
23
24/// The parsed form of a string describing one connection a process should
25/// establish with its peer:
26///
27/// <transport>[:<action>]=<descriptor>
28///
29/// transport what kind of thing the descriptor names: "tcp" for a host:port
30/// endpoint, "socket" for a handle this process already holds.
31/// action what this process does with it: "connect", "listen", or
32/// "adopt" for a handle it was handed.
33/// descriptor the thing itself, in whatever syntax the transport defines.
34///
35/// E.g. "tcp:connect=localhost:20000", "tcp:listen=[::1]:0", "socket:adopt=3".
36///
37/// A spec says what the process reading it does, so the two ends of one
38/// connection carry different specs: an executor told
39/// "tcp:connect=<host>:<port>" pairs with a controller told "tcp:listen=:0".
40///
41/// Parsing checks punctuation only: transport and action are opaque tokens, the
42/// descriptor's syntax belongs to the transport, and all three fields are kept
43/// verbatim -- so a caller matching a name against a known set does so
44/// case-sensitively. Only the text before the first '=' is searched for the
45/// ':', which lets a descriptor hold ':' and '=' unescaped.
46class ConnectionSpec {
47public:
48 /// Parses Spec as <transport>[:<action>]=<descriptor>.
50
51 /// The transport name, e.g. "tcp". Never empty.
52 StringRef getTransport() const { return Transport; }
53
54 /// The action name, e.g. "connect" or "adopt". May be empty.
55 StringRef getAction() const { return Action; }
56
57 /// The thing the transport names, in whatever syntax that transport defines.
58 /// Opaque here: the parser neither splits nor validates it. May be empty.
59 StringRef getDescriptor() const { return Descriptor; }
60
61 /// Rebuilds the original connection string, e.g. "tcp:connect=host:port".
62 std::string str() const {
63 std::string S = Transport;
64 if (!Action.empty()) {
65 S += ':';
66 S += Action;
67 }
68 S += '=';
69 S += Descriptor;
70 return S;
71 }
72
73private:
74 ConnectionSpec(std::string Transport, std::string Action,
75 std::string Descriptor)
76 : Transport(std::move(Transport)), Action(std::move(Action)),
77 Descriptor(std::move(Descriptor)) {}
78
79 std::string Transport;
80 std::string Action;
81 std::string Descriptor;
82};
83
84} // namespace llvm::orc
85
86#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_CONNECTIONSPEC_H
#define LLVM_ABI
Definition Compiler.h:215
Tagged union holding either a T or a Error.
Definition Error.h:485
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The parsed form of a string describing one connection a process should establish with its peer:
StringRef getAction() const
The action name, e.g. "connect" or "adopt". May be empty.
StringRef getTransport() const
The transport name, e.g. "tcp". Never empty.
std::string str() const
Rebuilds the original connection string, e.g. "tcp:connect=host:port".
static LLVM_ABI Expected< ConnectionSpec > parse(StringRef Spec)
Parses Spec as <transport>[:<action>]=<descriptor>.
StringRef getDescriptor() const
The thing the transport names, in whatever syntax that transport defines.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878