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

wirenboard / wb-mqtt-serial / 680

05 Aug 2025 11:42AM UTC coverage: 73.001% (-0.002%) from 73.003%
680

push

github

web-flow
Use response_timeout_ms from port settings for RPC requests (#978)

6493 of 9259 branches covered (70.13%)

16 of 26 new or added lines in 6 files covered. (61.54%)

12408 of 16997 relevant lines covered (73.0%)

373.17 hits per line

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

80.36
/src/port.cpp
1
#include "port.h"
2
#include "log.h"
3

4
void TPort::Reopen()
×
5
{
6
    if (IsOpen()) {
×
7
        Close();
×
8
        Open();
×
9
    }
10
}
11

12
void TPort::WriteBytes(const std::vector<uint8_t>& buf)
108✔
13
{
14
    WriteBytes(&buf[0], buf.size());
108✔
15
}
108✔
16

17
void TPort::WriteBytes(const std::string& buf)
×
18
{
19
    WriteBytes(reinterpret_cast<const uint8_t*>(buf.c_str()), buf.size());
×
20
}
21

22
std::chrono::microseconds TPort::GetSendTimeBytes(double bytesNumber) const
×
23
{
24
    return std::chrono::microseconds::zero();
×
25
}
26

27
std::chrono::microseconds TPort::GetSendTimeBits(size_t bitsNumber) const
267✔
28
{
29
    return std::chrono::microseconds::zero();
267✔
30
}
31

32
void TPort::ApplySerialPortSettings(const TSerialPortConnectionSettings& settings)
10✔
33
{}
10✔
34

35
void TPort::ResetSerialPortSettings()
3✔
36
{}
3✔
37

38
void TPort::SetMinimalResponseTimeout(const std::chrono::microseconds& value)
94✔
39
{
40
    MinimalResponseTimeout = value;
94✔
41
}
94✔
42

43
const std::chrono::microseconds& TPort::GetMinimalResponseTimeout() const
13✔
44
{
45
    return MinimalResponseTimeout;
13✔
46
}
47

48
std::chrono::microseconds TPort::CalcResponseTimeout(const std::chrono::microseconds& timeoutFromCall) const
1✔
49
{
50
    auto responseTimeout = std::max(GetMinimalResponseTimeout(), timeoutFromCall);
1✔
51
    if (responseTimeout.count() < 0) {
1✔
NEW
52
        return DEFAULT_RESPONSE_TIMEOUT;
×
53
    }
54
    return responseTimeout;
1✔
55
}
56

57
TPortOpenCloseLogic::TPortOpenCloseLogic(const TPortOpenCloseLogic::TSettings& settings, util::TGetNowFn nowFn)
99✔
58
    : Settings(settings),
59
      NowFn(nowFn)
99✔
60
{}
99✔
61

62
void TPortOpenCloseLogic::OpenIfAllowed(PPort port)
620✔
63
{
64
    if (port->IsOpen()) {
620✔
65
        return;
536✔
66
    }
67

68
    auto currentTime = NowFn();
85✔
69
    if (NextOpenTryTime > currentTime) {
85✔
70
        return;
1✔
71
    }
72

73
    try {
74
        port->Open();
84✔
75
    } catch (...) {
6✔
76
        NextOpenTryTime = currentTime + Settings.ReopenTimeout;
3✔
77
        throw;
3✔
78
    }
79
    LastSuccessfulCycle = NowFn();
81✔
80
    RemainingFailCycles = Settings.ConnectionMaxFailCycles;
81✔
81
}
82

83
void TPortOpenCloseLogic::CloseIfNeeded(PPort port, bool allPreviousDataExchangeWasFailed)
616✔
84
{
85
    if (!port->IsOpen()) {
616✔
86
        return;
×
87
    }
88

89
    // disable reconnect functionality option
90
    if (Settings.MaxFailTime.count() < 0 || Settings.ConnectionMaxFailCycles < 0) {
616✔
91
        return;
×
92
    }
93

94
    auto currentTime = NowFn();
616✔
95
    if (!allPreviousDataExchangeWasFailed) {
616✔
96
        LastSuccessfulCycle = currentTime;
590✔
97
        RemainingFailCycles = Settings.ConnectionMaxFailCycles;
590✔
98
    }
99

100
    if (RemainingFailCycles > 0) {
616✔
101
        --RemainingFailCycles;
608✔
102
    }
103

104
    if ((currentTime - LastSuccessfulCycle > Settings.MaxFailTime) && RemainingFailCycles == 0) {
616✔
105
        Warn.Log() << port->GetDescription() << ": closed due to repetitive errors";
2✔
106
        port->Close();
2✔
107
    }
108
}
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