Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
protocol.h
Go to the documentation of this file.
1// Copyright (c) 2021-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_IPC_PROTOCOL_H
6#define BITCOIN_IPC_PROTOCOL_H
7
8#include <interfaces/init.h>
9#include <ipc/util.h>
10
11#include <cstddef>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <typeindex>
16
17namespace ipc {
18struct Context;
19
25{
26public:
27 virtual ~Protocol() = default;
28
38 virtual std::unique_ptr<interfaces::Init> connect(mp::Stream stream) = 0;
39
43 virtual void listen(mp::SocketId listen_fd, interfaces::Init& init, std::optional<size_t> max_connections = std::nullopt) = 0;
44
59 virtual void serve(interfaces::Init& init, const std::function<mp::Stream()>& make_stream) = 0;
60
63
65 virtual void disconnectIncoming() = 0;
66
69 virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
70
72 virtual Context& context() = 0;
73};
74} // namespace ipc
75
76#endif // BITCOIN_IPC_PROTOCOL_H
Initial interface created when a process is first started, and used to give and get access to other i...
Definition init.h:39
IPC protocol interface for calling IPC methods over sockets.
Definition protocol.h:25
virtual void listen(mp::SocketId listen_fd, interfaces::Init &init, std::optional< size_t > max_connections=std::nullopt)=0
Listen for connections on provided socket id, accept them, and handle requests on accepted connection...
virtual void disconnectIncoming()=0
Disconnect any incoming connections that are still connected.
virtual void addCleanup(std::type_index type, void *iface, std::function< void()> cleanup)=0
Add cleanup callback to interface that will run when the interface is deleted.
virtual Context & context()=0
Context accessor.
virtual void serve(interfaces::Init &init, const std::function< mp::Stream()> &make_stream)=0
Handle requests from a stream provided by the make_stream callback, forwarding them to the provided I...
virtual std::unique_ptr< interfaces::Init > connect(mp::Stream stream)=0
Return Init interface that forwards requests over given connection stream.
virtual ~Protocol()=default
virtual mp::Stream makeStream(mp::SocketId socket)=0
Make stream object from socket id.
Definition basic.cpp:11
Definition ipc.h:17
SocketId Stream
Definition util.h:30
int SocketId
Definition util.h:27
Context struct used to give IPC protocol implementations or implementation hooks access to applicatio...
Definition context.h:15
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82