• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

llnl / dftracer-utils / 29806785540

21 Jul 2026 06:21AM UTC coverage: 52.837% (+0.2%) from 52.66%
29806785540

Pull #99

github

web-flow
Merge 28252dedf into 06bc84ec9
Pull Request #99: Support CM time_metric (NS/MS/SEC/US) across reader and viz

41074 of 100799 branches covered (40.75%)

Branch coverage included in aggregate %.

1063 of 1183 new or added lines in 30 files covered. (89.86%)

32 existing lines in 7 files now uncovered.

36302 of 45643 relevant lines covered (79.53%)

23461.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.92
/src/dftracer/utils/server/cancel.cpp
1
#include <dftracer/utils/server/cancel.h>
2
#include <sys/socket.h>
3

4
#include <cerrno>
5

6
namespace dftracer::utils::server {
7

8
namespace {
9

10
// Non-blocking peek: true if the peer has closed or reset the connection.
11
bool peer_disconnected(int fd) {
48✔
12
    char b;
13
    ssize_t n = ::recv(fd, &b, 1, MSG_PEEK | MSG_DONTWAIT);
48!
14
    if (n == 0) return true;                     // orderly shutdown (FIN)
48✔
15
    if (n < 0) {
46✔
16
        int e = errno;
46✔
17
        return e != EAGAIN && e != EWOULDBLOCK;  // reset/error vs. no data yet
46!
18
    }
NEW
19
    return false;  // data buffered (e.g. a pipelined request): still connected
×
20
}
24✔
21

22
}  // namespace
23

24
bool CancelToken::cancelled() const {
360✔
25
    if (!state_) return false;
360✔
26
    if (state_->flag.load(std::memory_order_relaxed)) return true;
316✔
27
    if (state_->peer_fd < 0) return false;
306✔
28
    // Probe the socket only every 16th check to keep the hot path cheap.
29
    if ((state_->probe_tick.fetch_add(1, std::memory_order_relaxed) & 0xF) != 0)
456✔
30
        return false;
256✔
31
    if (peer_disconnected(state_->peer_fd)) {
48✔
32
        state_->flag.store(true, std::memory_order_relaxed);
2✔
33
        return true;
2✔
34
    }
35
    return false;
46✔
36
}
180✔
37

38
CancelRegistry& CancelRegistry::instance() {
222✔
39
    static CancelRegistry registry;
222✔
40
    return registry;
222✔
41
}
42

43
CancelToken CancelRegistry::create(const std::string& id, int peer_fd) {
126✔
44
    auto state = std::make_shared<CancelState>();
126!
45
    state->peer_fd = peer_fd;
126✔
46
    if (!id.empty()) {
126✔
47
        std::lock_guard<std::mutex> lock(mu_);
16!
48
        tokens_[id] = state;
16!
49
    }
16✔
50
    return CancelToken(state);
189!
51
}
126✔
52

53
void CancelRegistry::remove(const std::string& id) {
112✔
54
    if (id.empty()) return;
112✔
55
    std::lock_guard<std::mutex> lock(mu_);
4!
56
    tokens_.erase(id);
4!
57
}
58✔
58

59
bool CancelRegistry::cancel(const std::string& id) {
14✔
60
    if (id.empty()) return false;
14✔
61
    std::shared_ptr<CancelState> state;
12✔
62
    {
63
        std::lock_guard<std::mutex> lock(mu_);
12!
64
        auto it = tokens_.find(id);
12!
65
        if (it == tokens_.end()) return false;
12✔
66
        state = it->second;
6!
67
    }
12✔
68
    state->flag.store(true, std::memory_order_relaxed);
6✔
69
    return true;
6✔
70
}
13✔
71

72
std::size_t CancelRegistry::size() const {
6✔
73
    std::lock_guard<std::mutex> lock(mu_);
6!
74
    return tokens_.size();
9✔
75
}
6✔
76

77
}  // namespace dftracer::utils::server
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc