CCF
Loading...
Searching...
No Matches
handle_ring_buffer.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "../ds/files.h"
6#include "../enclave/interface.h"
7#include "ccf/ds/logger.h"
8#include "timer.h"
9
10#include <chrono>
11#include <ctime>
12#include <iomanip>
13#include <nlohmann/json.hpp>
14#include <string>
15#include <sys/types.h>
16#include <unistd.h>
17
18namespace asynchost
19{
21 {
22 private:
23 // Maximum number of outbound ringbuffer messages which will be processed in
24 // a single iteration
25 static constexpr size_t max_messages = 256;
26
30
31 public:
36 bp(bp),
37 r(r),
38 nbwf(nbwf)
39 {
41 bp,
42 AdminMessage::fatal_error_msg,
43 [](const uint8_t* data, size_t size) {
44 auto [msg] =
45 ringbuffer::read_message<AdminMessage::fatal_error_msg>(data, size);
46
47 std::cerr << msg << std::endl << std::flush;
48 throw std::logic_error(msg);
49 });
50
52 bp, AdminMessage::stopped, [](const uint8_t*, size_t) {
53 uv_stop(uv_default_loop());
54 LOG_INFO_FMT("Host stopped successfully");
55 });
56 }
57
58 void on_timer()
59 {
60 // Regularly read (and process) some outbound ringbuffer messages...
61 bp.read_n(max_messages, r);
62
63 // ...flush any pending inbound messages...
64 nbwf.flush_all_inbound();
65 }
66 };
67
69}
Definition handle_ring_buffer.h:21
HandleRingbufferImpl(messaging::BufferProcessor &bp, ringbuffer::Reader &r, ringbuffer::NonBlockingWriterFactory &nbwf)
Definition handle_ring_buffer.h:32
void on_timer()
Definition handle_ring_buffer.h:58
Definition proxy.h:51
Definition messaging.h:211
size_t read_n(size_t max_messages, ringbuffer::Reader &r)
Definition messaging.h:240
Definition non_blocking.h:193
bool flush_all_inbound()
Definition non_blocking.h:256
Definition ring_buffer.h:175
#define LOG_INFO_FMT
Definition logger.h:362
#define DISPATCHER_SET_MESSAGE_HANDLER(DISP, MSG,...)
Definition messaging.h:316
Definition after_io.h:8