Heart
1.4.918.d927d9c
Heart is base back end library for your c++ Qt projects.
Toggle main menu visibility
Loading...
Searching...
No Matches
datasender.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2018-2025 QuasarApp.
3
* Distributed under the lgplv3 software license, see the accompanying
4
* Everyone is permitted to copy and distribute verbatim copies
5
* of this license document, but changing it is not allowed.
6
*/
7
8
9
#include "
datasender.h
"
10
#include <QAbstractSocket>
11
#include <quasarapp.h>
12
#include <QThread>
13
14
namespace
QH
{
15
16
DataSender::DataSender
(QThread *thread):
17
Async
(thread ) {
18
19
}
20
21
bool
DataSender::sendData
(
const
QByteArray &array,
void
*target,
bool
await)
const
{
22
return
asyncLauncher
(std::bind(&DataSender::sendPackagePrivate,
this
, array, target), await);
23
}
24
25
bool
QH::DataSender::sendPackagePrivate(QByteArray array,
void
*target)
const
{
26
auto
ptr =
static_cast<
QAbstractSocket*
>
(target);
27
28
if
(!(ptr && ptr->isValid() && ptr->isWritable())) {
29
qCritical() <<
"Send raw data error. Socket is invalid"
;
30
return
false
;
31
}
32
33
int
wrote = 0;
34
35
while
(wrote < array.length() && ptr->isWritable()) {
36
wrote += ptr->write(array.mid(wrote, array.length()));
37
}
38
39
if
(!ptr->flush()) {
40
qCritical() <<
"Send raw data error. data not flushed"
;
41
return
false
;
42
}
43
44
if
(array.size() != wrote) {
45
qCritical() <<
"Send raw data error. not all data writed"
;
46
return
false
;
47
}
48
49
return
true
;
50
}
51
52
}
QH::Async::Async
Async(QThread *thread)
Async This is default constructor of the async object.
Definition
async.cpp:38
QH::Async::asyncLauncher
bool asyncLauncher(const Job &job, bool await=false, bool freaze=true) const
asyncLauncher This method invoke a job on the thread (using the asyncHandler method) of this object.
Definition
async.cpp:78
QH::DataSender::DataSender
DataSender(QThread *thread)
Definition
datasender.cpp:16
QH::DataSender::sendData
bool sendData(const QByteArray &array, void *target, bool await=false) const
sendPackagePrivate This slot move send package to a main thread.
Definition
datasender.cpp:21
datasender.h
QH
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition
heart.cpp:13
src
private
datasender.cpp
Generated by
1.18.0