Bitcoin Core 31.99.0
P2P Digital Currency
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 <functional>
12#include <memory>
13#include <typeindex>
14
15namespace ipc {
16struct Context;
17
23{
24public:
25 virtual ~Protocol() = default;
26
36 virtual std::unique_ptr<interfaces::Init> connect(mp::Stream stream) = 0;
37
41 virtual void listen(mp::SocketId listen_fd, interfaces::Init& init) = 0;
42
57 virtual void serve(interfaces::Init& init, const std::function<mp::Stream()>& make_stream) = 0;
58
60 virtual mp::Stream makeStream(mp::SocketId socket) = 0;
61
63 virtual void disconnectIncoming() = 0;
64
67 virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
68
70 virtual Context& context() = 0;
71};
72} // namespace ipc
73
74#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:32
IPC protocol interface for calling IPC methods over sockets.
Definition: protocol.h:23
virtual void listen(mp::SocketId listen_fd, interfaces::Init &init)=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:8
Definition: ipc.h:13
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