keepassxc

Форк
0
/
FailDevice.cpp 
61 строка · 1.6 Кб
1
/*
2
 *  Copyright (C) 2015 Felix Geyer <debfx@fobos.de>
3
 *
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation, either version 2 or (at your option)
7
 *  version 3 of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
#include "FailDevice.h"
19

20
FailDevice::FailDevice(int failAfter, QObject* parent)
21
    : QBuffer(parent)
22
    , m_failAfter(failAfter)
23
    , m_readCount(0)
24
    , m_writeCount(0)
25
{
26
}
27

28
bool FailDevice::open(QIODevice::OpenMode openMode)
29
{
30
    return QBuffer::open(openMode | QIODevice::Unbuffered);
31
}
32

33
qint64 FailDevice::readData(char* data, qint64 len)
34
{
35
    if (m_readCount >= m_failAfter) {
36
        setErrorString("FAILDEVICE");
37
        return -1;
38
    } else {
39
        qint64 result = QBuffer::readData(data, len);
40
        if (result != -1) {
41
            m_readCount += result;
42
        }
43

44
        return result;
45
    }
46
}
47

48
qint64 FailDevice::writeData(const char* data, qint64 len)
49
{
50
    if (m_writeCount >= m_failAfter) {
51
        setErrorString("FAILDEVICE");
52
        return -1;
53
    } else {
54
        qint64 result = QBuffer::writeData(data, len);
55
        if (result != -1) {
56
            m_writeCount += result;
57
        }
58

59
        return result;
60
    }
61
}
62

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.