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

mendersoftware / mender / 1073264463

15 Nov 2023 10:33AM UTC coverage: 80.186% (+0.1%) from 80.062%
1073264463

push

gitlab-ci

kacf
docs: Restore Update Control XML file for documentation purposes.

This is a partial restore of ee5dc24db79fc57, just to get the XML file
back. The feature is still removed, this is just to be able to keep it
in the documentation with a notice that says it's removed (already
merged to master in 426caf729c3191b).

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>

6969 of 8691 relevant lines covered (80.19%)

9260.9 hits per line

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

88.89
/src/common/events/events_io.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <common/events_io.hpp>
16

17
namespace mender {
18
namespace common {
19
namespace events {
20
namespace io {
21

22
AsyncReaderFromReader::AsyncReaderFromReader(EventLoop &loop, mio::ReaderPtr reader) :
56✔
23
        reader_ {reader},
24
        loop_ {loop} {
112✔
25
}
56✔
26

27
AsyncReaderFromReader::~AsyncReaderFromReader() {
112✔
28
        Cancel();
56✔
29
}
56✔
30

31
error::Error AsyncReaderFromReader::AsyncRead(
756✔
32
        vector<uint8_t>::iterator start, vector<uint8_t>::iterator end, mio::AsyncIoHandler handler) {
33
        cancelled_ = make_shared<bool>(false);
756✔
34
        auto &cancelled = cancelled_;
35
        loop_.Post([this, cancelled, start, end, handler]() {
1,512✔
36
                if (!*cancelled) {
756✔
37
                        in_progress_ = true;
756✔
38
                        // Simple, "cheating" implementation, we just do it synchronously.
39
                        auto result = reader_->Read(start, end);
756✔
40
                        in_progress_ = false;
756✔
41
                        handler(result);
1,512✔
42
                }
43
        });
2,268✔
44

45
        return error::NoError;
756✔
46
}
47

48
void AsyncReaderFromReader::Cancel() {
56✔
49
        // Cancel() is not allowed on normal Readers.
50
        assert(!in_progress_);
51
        if (cancelled_) {
56✔
52
                *cancelled_ = true;
51✔
53
                cancelled_.reset();
51✔
54
        }
55
}
56✔
56

57
AsyncWriterFromWriter::AsyncWriterFromWriter(EventLoop &loop, mio::WriterPtr writer) :
1✔
58
        writer_ {writer},
59
        loop_ {loop} {
2✔
60
}
1✔
61

62
AsyncWriterFromWriter::~AsyncWriterFromWriter() {
2✔
63
        Cancel();
1✔
64
}
1✔
65

66
error::Error AsyncWriterFromWriter::AsyncWrite(
1✔
67
        vector<uint8_t>::const_iterator start,
68
        vector<uint8_t>::const_iterator end,
69
        mio::AsyncIoHandler handler) {
70
        cancelled_ = make_shared<bool>(false);
1✔
71
        auto &cancelled = cancelled_;
72
        loop_.Post([this, cancelled, start, end, handler]() {
2✔
73
                if (!*cancelled) {
1✔
74
                        in_progress_ = true;
1✔
75
                        // Simple, "cheating" implementation, we just do it synchronously.
76
                        auto result = writer_->Write(start, end);
1✔
77
                        in_progress_ = false;
1✔
78
                        handler(result);
2✔
79
                }
80
        });
3✔
81

82
        return error::NoError;
1✔
83
}
84

85
void AsyncWriterFromWriter::Cancel() {
1✔
86
        // Cancel() is not allowed on normal Writers.
87
        assert(!in_progress_);
88
        if (cancelled_) {
1✔
89
                *cancelled_ = true;
1✔
90
                cancelled_.reset();
1✔
91
        }
92
}
1✔
93

94
ReaderFromAsyncReader::ReaderFromAsyncReader(EventLoop &event_loop, mio::AsyncReaderPtr reader) :
53✔
95
        event_loop_(event_loop),
96
        reader_(reader) {
106✔
97
}
53✔
98

99
ReaderFromAsyncReader::ReaderFromAsyncReader(EventLoop &event_loop, mio::AsyncReader &reader) :
×
100
        event_loop_(event_loop),
101
        // For references, just use a destructor-less pointer.
102
        reader_(&reader, [](mio::AsyncReader *) {}) {
×
103
}
×
104

105
mio::ExpectedSize ReaderFromAsyncReader::Read(
53✔
106
        vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) {
107
        mio::ExpectedSize read;
53✔
108
        error::Error err;
53✔
109
        bool finished = false;
53✔
110
        err = reader_->AsyncRead(start, end, [this, &finished, &read](mio::ExpectedSize num_read) {
106✔
111
                read = num_read;
112
                finished = true;
53✔
113
                event_loop_.Stop();
53✔
114
        });
53✔
115
        if (err != error::NoError) {
53✔
116
                return expected::unexpected(err);
×
117
        }
118

119
        // Since the same event loop may have been used to call into this function, run the event
120
        // loop recursively to keep processing events.
121
        event_loop_.Run();
53✔
122

123
        if (!finished) {
53✔
124
                // If this happens then it means that the event loop was stopped by somebody
125
                // else. We have no choice now but to return error, since we have to get out of this
126
                // stack frame. We also need to re-stop the event loop, since the first stop was
127
                // spent on getting here.
128
                event_loop_.Stop();
×
129
                return expected::unexpected(
×
130
                        error::Error(make_error_condition(errc::operation_canceled), "Event loop was stopped"));
×
131
        }
132

133
        return read;
134
}
135

136
} // namespace io
137
} // namespace events
138
} // namespace common
139
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc