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 "fd=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/// E.g. "fd=3", "tcp:connect=localhost:20000", "tcp:listen=[::1]:0". Such
30/// strings typically reach a process as a command-line argument, but nothing
31/// in the grammar or the parser assumes that.
32///
33/// A spec describes what the process reading it does, so the two ends of one
34/// connection carry different specs: an executor told "tcp:listen=:0" pairs
35/// with a controller told "tcp:connect=<host>:<port>".
36///
37/// The parser only checks punctuation: the transport and action names are
38/// opaque tokens, and the descriptor's syntax is entirely up to the
39/// transport. Splitting the action from the transport is confined to the
40/// text before the first '=', which lets a descriptor contain ':' and '='
41/// unescaped (e.g. "tcp:listen=[::1]:0", "unix:listen=/tmp/a=b.sock").
42///
43/// All three fields are preserved verbatim, so callers matching a transport
44/// or action name against a known set do so case-sensitively.
45class ConnectionSpec {
46public:
47 /// Parses Spec as <transport>[:<action>]=<descriptor>.
49
50 /// The transport name, e.g. "tcp". Never empty.
51 StringRef getTransport() const { return Transport; }
52
53 /// The action name, e.g. "listen" or "connect". May be empty: direction is
54 /// degenerate for some transports (an inherited socket fd is already
55 /// connected), so single-mode transports omit it.
56 StringRef getAction() const { return Action; }
57
58 /// The transport-specific address. May be empty (e.g. "fd=").
59 StringRef getDescriptor() const { return Descriptor; }
60
61private:
62 ConnectionSpec(std::string Transport, std::string Action,
63 std::string Descriptor)
64 : Transport(std::move(Transport)), Action(std::move(Action)),
65 Descriptor(std::move(Descriptor)) {}
66
67 std::string Transport;
68 std::string Action;
69 std::string Descriptor;
70};
71
72} // namespace llvm::orc
73
74#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.
StringRef getTransport() const
The transport name, e.g. "tcp". Never empty.
static LLVM_ABI Expected< ConnectionSpec > parse(StringRef Spec)
Parses Spec as <transport>[:<action>]=<descriptor>.
StringRef getDescriptor() const
The transport-specific address. May be empty (e.g. "fd=").
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