BIG deep clean

This commit is contained in:
2020-06-10 13:14:16 +03:00
parent f579718e0b
commit c59579d5d5
222 changed files with 2392 additions and 11600 deletions

View File

@@ -1,5 +1,23 @@
#include "pibasetransfer.h"
/*
PIP - Platform Independent Primitives
Base class for reliable send and receive data in fixed packets with error correction, pause and resume
Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pibasetransfer.h"
const uint PIBaseTransfer::signature = 0x54424950;
@@ -16,7 +34,6 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
send_up = 0;
timeout_ = 10.;
diag.setDisconnectTimeout(timeout_ / 10);
//CONNECTU(&diag, qualityChanged, this, diagChanged);
diag.setName("PIBaseTransfer");
diag.start(50);
packets_count = 10;
@@ -144,7 +161,6 @@ void PIBaseTransfer::received(PIByteArray data) {
// piCoutObj << "Done Packet" << h.id;
}
if (is_receiving && h.id == 0) {
// if (checkSession() == 0 && pt == pt_ReplySuccess) finish_receive(true);
if (pt == pt_ReplySuccess) {
mutex_session.lock();
int cs = checkSession();
@@ -183,8 +199,6 @@ void PIBaseTransfer::received(PIByteArray data) {
}
if (is_receiving) {
if (header.session_id != h.session_id) {
//sendBreak(h.session_id);
//return;
piCoutObj << "restart receive";
mutex_header.unlock();
finish_receive(false, true);
@@ -214,7 +228,6 @@ void PIBaseTransfer::received(PIByteArray data) {
replies.fill(pt_Unknown);
pm_string.resize(replies.size(), '-');
diag.reset();
// diag.start(100);
//piCoutObj << "receiveStarted()";
is_receiving = true;
break_ = false;
@@ -261,7 +274,6 @@ bool PIBaseTransfer::send_process() {
packet_header_size = sizeof(PacketHeader) + customHeader().size();
break_ = false;
diag.reset();
// diag.start(100);
sendStarted();
is_sending = true;
int session_size = session.size();
@@ -278,14 +290,12 @@ bool PIBaseTransfer::send_process() {
send_up = 0;
send_tm.reset();
mutex_send.unlock();
//int ltm = 0;
for (int i = 0; i < session_size; i++) {
mutex_send.lock();
int sq = send_queue;
mutex_send.unlock();
if (sq >= packets_count || is_pause) {
--i;
//piMSleep(PIP_MIN_MSLEEP);
if (is_pause) {
piMSleep(40);
//piCout << "send pause";
@@ -368,9 +378,7 @@ bool PIBaseTransfer::send_process() {
send_queue++;
mutex_send.unlock();
}
// if (chk == -1) return finish_send(false);
if (break_) return finish_send(false);
//piMSleep(PIP_MIN_MSLEEP);
}
return finish_send(false);
}
@@ -410,7 +418,6 @@ void PIBaseTransfer::buildSession(PIVector<Part> parts) {
fi.id = parts[i].id;
//piCout << fi.id << state_string;
bytes_all += parts[i].size;
//fi.size = fi.entry.size;
fi.start = 0;
llong rest = parts[i].size - (packet_size - cur_size);
//piCout << i << fi.size << rest << bytes_all;
@@ -494,8 +501,7 @@ bool PIBaseTransfer::getStartRequest() {
mutex_session.lock();
if (replies[0] == pt_ReplySuccess) {
state_string = "send permited!";
//packets_count = piClampi(10 / tm.elapsed_m(), 2, 100);
//piCoutObj << "ping " << tm.elapsed_m() << packets_count;
//piCoutObj << "ping " << tm.elapsed_m();
mutex_session.unlock();
return true;
}
@@ -528,9 +534,7 @@ void PIBaseTransfer::processData(int id, PIByteArray & data) {
while (!data.isEmpty()) {
ba.clear();
data >> fi;
//if (fi.size > 0)
data >> ba;
//fi.fsize = ba.size();
bytes_cur += fi.size;
//piCoutObj << "recv" << fi;
session[id - 1] << fi;
@@ -549,7 +553,6 @@ PIByteArray PIBaseTransfer::build_packet(int id) {
PIByteArray ret;
PIByteArray ba;
//piCoutObj << "session id" << header.session_id;
//ret << header;
ret.append(customHeader());
mutex_session.lock();
for (int i = 0; i < session[id].size_s(); i++) {
@@ -587,7 +590,6 @@ bool PIBaseTransfer::finish_send(bool ok) {
mutex_header.unlock();
//piCoutObj << state_string << PIString::readableSize(bytes_all);
sendFinished(ok);
// diag.stop();
bytes_all = bytes_cur = 0;
return ok;
}
@@ -604,7 +606,6 @@ void PIBaseTransfer::finish_receive(bool ok, bool quet) {
}
//piCoutObj << state_string << PIString::readableSize(bytes_all);
receiveFinished(ok);
// diag.stop();
bytes_all = bytes_cur = 0;
}