Coverage Report

Created: 2026-05-30 09:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/support/events.h
Line
Count
Source
1
// Copyright (c) 2016-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_SUPPORT_EVENTS_H
6
#define BITCOIN_SUPPORT_EVENTS_H
7
8
#include <ios>
9
#include <memory>
10
11
#include <event2/event.h>
12
#include <event2/http.h>
13
14
#define MAKE_RAII(type) \
15
/* deleter */\
16
struct type##_deleter {\
17
5
    void operator()(struct type* ob) {\
18
5
        type##_free(ob);\
19
5
    }\
event_base_deleter::operator()(event_base*)
Line
Count
Source
17
3
    void operator()(struct type* ob) {\
18
3
        type##_free(ob);\
19
3
    }\
event_deleter::operator()(event*)
Line
Count
Source
17
2
    void operator()(struct type* ob) {\
18
2
        type##_free(ob);\
19
2
    }\
Unexecuted instantiation: evhttp_deleter::operator()(evhttp*)
20
};\
21
/* unique ptr typedef */\
22
typedef std::unique_ptr<struct type, type##_deleter> raii_##type
23
24
MAKE_RAII(event_base);
25
MAKE_RAII(event);
26
MAKE_RAII(evhttp);
27
28
1.11k
inline raii_event_base obtain_event_base() {
29
1.11k
    auto result = raii_event_base(event_base_new());
30
1.11k
    if (!result.get())
31
0
        throw std::runtime_error("cannot create event_base");
32
1.11k
    return result;
33
1.11k
}
34
35
2
inline raii_event obtain_event(struct event_base* base, evutil_socket_t s, short events, event_callback_fn cb, void* arg) {
36
2
    return raii_event(event_new(base, s, events, cb, arg));
37
2
}
38
39
1.11k
inline raii_evhttp obtain_evhttp(struct event_base* base) {
40
1.11k
    return raii_evhttp(evhttp_new(base));
41
1.11k
}
42
43
#endif // BITCOIN_SUPPORT_EVENTS_H