/
githubmirror
/
bitcoin
Обзор
Документация
Войти
/
githubmirror
/
bitcoin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/ipc/libmultiprocess/example/printer.cpp
57 строк
2 KB
Ryan Ofsky
Merge commit '0f01e1577f7c6734eb345139a12aba329ef22a5f' into pr/subtree-6
07 окт 2025, 17:12
07 окт 2025, 17:12
eda91b0
Код
Авторство
О чём код?
// Copyright (c) The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <printer.h> #include <init.capnp.h> #include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep #include <charconv> #include <cstring> #include <fstream> #include <iostream> #include <kj/async.h> #include <kj/common.h> #include <kj/memory.h> #include <memory> #include <mp/proxy-io.h> #include <stdexcept> #include <string> #include <system_error> class PrinterImpl : public Printer { public: void print(const std::string& message) override { std::cout << "mpprinter: " << message << std::endl; } }; class InitImpl : public Init { public: std::unique_ptr<Printer> makePrinter() override { return std::make_unique<PrinterImpl>(); } }; static void LogPrint(mp::LogMessage log_data) { if (log_data.level == mp::Log::Raise) throw std::runtime_error(log_data.message); std::ofstream("debug.log", std::ios_base::app) << log_data.message << std::endl; } int main(int argc, char** argv) { if (argc != 2) { std::cout << "Usage: mpprinter <fd>\n"; return 1; } int fd; if (std::from_chars(argv[1], argv[1] + strlen(argv[1]), fd).ec != std::errc{}) { std::cerr << argv[1] << " is not a number or is larger than an int\n"; return 1; } mp::EventLoop loop("mpprinter", LogPrint); std::unique_ptr<Init> init = std::make_unique<InitImpl>(); mp::ServeStream<InitInterface>(loop, fd, *init); loop.loop(); return 0; }