version 2.30
PIStreamPacker remove progresses picloud various fixes
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
|||||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||||
project(pip)
|
project(pip)
|
||||||
set(pip_MAJOR 2)
|
set(pip_MAJOR 2)
|
||||||
set(pip_MINOR 29)
|
set(pip_MINOR 30)
|
||||||
set(pip_REVISION 0)
|
set(pip_REVISION 0)
|
||||||
set(pip_SUFFIX )
|
set(pip_SUFFIX )
|
||||||
set(pip_COMPANY SHS)
|
set(pip_COMPANY SHS)
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
|
|||||||
CONNECTU(&streampacker, packetReceiveEvent, this, _readed);
|
CONNECTU(&streampacker, packetReceiveEvent, this, _readed);
|
||||||
CONNECTL(ð, disconnected, [this](bool){
|
CONNECTL(ð, disconnected, [this](bool){
|
||||||
if (is_deleted) return;
|
if (is_deleted) return;
|
||||||
|
bool need_disconn = is_connected;
|
||||||
//piCoutObj << "eth disconnected";
|
//piCoutObj << "eth disconnected";
|
||||||
static_cast<PIThread*>(ð)->stop();
|
static_cast<PIThread*>(ð)->stop();
|
||||||
opened_ = false;
|
opened_ = false;
|
||||||
if (is_connected) disconnected();
|
|
||||||
internalDisconnect();
|
internalDisconnect();
|
||||||
|
if (need_disconn)
|
||||||
|
disconnected();
|
||||||
//piCoutObj << "eth disconnected done";
|
//piCoutObj << "eth disconnected done";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -45,8 +47,7 @@ PICloudClient::~PICloudClient() {
|
|||||||
//piCoutObj << "~PICloudClient()";
|
//piCoutObj << "~PICloudClient()";
|
||||||
PIThread::stop();
|
PIThread::stop();
|
||||||
//eth.close();
|
//eth.close();
|
||||||
if (is_connected) disconnected();
|
//if (is_connected) disconnected();
|
||||||
is_connected = false;
|
|
||||||
close();
|
close();
|
||||||
//piCoutObj << "~PICloudClient() closed";
|
//piCoutObj << "~PICloudClient() closed";
|
||||||
internalDisconnect();
|
internalDisconnect();
|
||||||
@@ -133,22 +134,24 @@ void PICloudClient::internalDisconnect() {
|
|||||||
is_connected = false;
|
is_connected = false;
|
||||||
cond_buff.notifyOne();
|
cond_buff.notifyOne();
|
||||||
cond_connect.notifyOne();
|
cond_connect.notifyOne();
|
||||||
|
streampacker.clear();
|
||||||
|
buff.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PICloudClient::_readed(PIByteArray & ba) {
|
void PICloudClient::_readed(PIByteArray & ba) {
|
||||||
if (is_deleted) return;
|
if (is_deleted) return;
|
||||||
//piCoutObj << "_readed";
|
|
||||||
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
|
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
|
||||||
|
//piCoutObj << "_readed" << ba.size() << hdr.first << hdr.second;
|
||||||
if (hdr.second == tcp.role()) {
|
if (hdr.second == tcp.role()) {
|
||||||
switch (hdr.first) {
|
switch (hdr.first) {
|
||||||
case PICloud::TCP::Connect:
|
case PICloud::TCP::Connect:
|
||||||
if (tcp.parseConnect(ba) == 1) {
|
if (tcp.parseConnect(ba) == 1) {
|
||||||
mutex_connect.lock();
|
mutex_connect.lock();
|
||||||
is_connected = true;
|
is_connected = true;
|
||||||
connected();
|
|
||||||
mutex_connect.unlock();
|
mutex_connect.unlock();
|
||||||
cond_connect.notifyOne();
|
cond_connect.notifyOne();
|
||||||
|
connected();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PICloud::TCP::Disconnect:
|
case PICloud::TCP::Disconnect:
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ void PICloud::TCP::sendStart() {
|
|||||||
PIByteArray ba;
|
PIByteArray ba;
|
||||||
ba << header;
|
ba << header;
|
||||||
ba.append(suuid);
|
ba.append(suuid);
|
||||||
mutex_send.lock();
|
//mutex_send.lock();
|
||||||
streampacker->send(ba);
|
streampacker->send(ba);
|
||||||
mutex_send.unlock();
|
//mutex_send.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,13 @@ void PIStreamPacker::setCryptSizeEnabled(bool on) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIStreamPacker::clear() {
|
||||||
|
packet.clear();
|
||||||
|
packet_size = -1;
|
||||||
|
stream.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIStreamPacker::send(const PIByteArray & data) {
|
void PIStreamPacker::send(const PIByteArray & data) {
|
||||||
if (data.isEmpty()) return;
|
if (data.isEmpty()) return;
|
||||||
PIByteArray cd;
|
PIByteArray cd;
|
||||||
@@ -94,31 +101,12 @@ void PIStreamPacker::send(const PIByteArray & data) {
|
|||||||
hdr << int(cd.size_s());
|
hdr << int(cd.size_s());
|
||||||
cd.insert(0, hdr);
|
cd.insert(0, hdr);
|
||||||
int pcnt = (cd.size_s() - 1) / max_packet_size + 1, pst = 0;
|
int pcnt = (cd.size_s() - 1) / max_packet_size + 1, pst = 0;
|
||||||
if (pcnt > 1) {
|
|
||||||
prog_s_mutex.lock();
|
|
||||||
prog_s.active = true;
|
|
||||||
prog_s.bytes_all = data.size_s();
|
|
||||||
prog_s.bytes_current = 0;
|
|
||||||
prog_s.progress = 0.;
|
|
||||||
prog_s_mutex.unlock();
|
|
||||||
}
|
|
||||||
for (int i = 0; i < pcnt; ++i) {
|
for (int i = 0; i < pcnt; ++i) {
|
||||||
if (i == pcnt - 1) part = PIByteArray(cd.data(pst), cd.size_s() - pst);
|
if (i == pcnt - 1) part = PIByteArray(cd.data(pst), cd.size_s() - pst);
|
||||||
else part = PIByteArray(cd.data(pst), max_packet_size);
|
else part = PIByteArray(cd.data(pst), max_packet_size);
|
||||||
//piCout << "send" << part.size();
|
//piCout << "send" << part.size();
|
||||||
sendRequest(part);
|
sendRequest(part);
|
||||||
pst += max_packet_size;
|
pst += max_packet_size;
|
||||||
if (pcnt > 1) {
|
|
||||||
prog_s_mutex.lock();
|
|
||||||
prog_s.bytes_current += part.size_s();
|
|
||||||
prog_s.progress = (double)prog_s.bytes_current / prog_s.bytes_all;
|
|
||||||
prog_s_mutex.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pcnt > 1) {
|
|
||||||
prog_s_mutex.lock();
|
|
||||||
prog_s.active = false;
|
|
||||||
prog_s_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,22 +154,10 @@ void PIStreamPacker::received(const PIByteArray & data) {
|
|||||||
packet_size = sz;
|
packet_size = sz;
|
||||||
if (packet_size == 0)
|
if (packet_size == 0)
|
||||||
packet_size = -1;
|
packet_size = -1;
|
||||||
else {
|
|
||||||
prog_r_mutex.lock();
|
|
||||||
prog_r.active = true;
|
|
||||||
prog_r.bytes_all = packet_size;
|
|
||||||
prog_r.bytes_current = 0;
|
|
||||||
prog_r.progress = 0.;
|
|
||||||
prog_r_mutex.unlock();
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
int ps = piMini(stream.size_s(), packet_size - packet.size_s());
|
int ps = piMini(stream.size_s(), packet_size - packet.size_s());
|
||||||
packet.append(stream.data(), ps);
|
packet.append(stream.data(), ps);
|
||||||
prog_r_mutex.lock();
|
|
||||||
prog_r.bytes_current = packet.size_s();
|
|
||||||
prog_r.progress = (double)prog_r.bytes_current / piMaxi(1, prog_r.bytes_all);
|
|
||||||
prog_r_mutex.unlock();
|
|
||||||
stream.remove(0, ps);
|
stream.remove(0, ps);
|
||||||
if (packet.size_s() == packet_size) {
|
if (packet.size_s() == packet_size) {
|
||||||
PIByteArray cd;
|
PIByteArray cd;
|
||||||
@@ -211,9 +187,6 @@ void PIStreamPacker::received(const PIByteArray & data) {
|
|||||||
}
|
}
|
||||||
packet.clear();
|
packet.clear();
|
||||||
packet_size = -1;
|
packet_size = -1;
|
||||||
prog_r_mutex.lock();
|
|
||||||
prog_r.active = false;
|
|
||||||
prog_r_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,30 +200,3 @@ void PIStreamPacker::assignDevice(PIIODevice * dev) {
|
|||||||
CONNECTU(dev, threadedReadEvent, this, received);
|
CONNECTU(dev, threadedReadEvent, this, received);
|
||||||
CONNECTU(this, sendRequest, dev, write);
|
CONNECTU(this, sendRequest, dev, write);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIStreamPacker::Progress PIStreamPacker::progressSend() const {
|
|
||||||
PIStreamPacker::Progress ret;
|
|
||||||
prog_s_mutex.lock();
|
|
||||||
ret = prog_s;
|
|
||||||
prog_s_mutex.unlock();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PIStreamPacker::Progress PIStreamPacker::progressReceive() const {
|
|
||||||
PIStreamPacker::Progress ret;
|
|
||||||
prog_r_mutex.lock();
|
|
||||||
ret = prog_r;
|
|
||||||
prog_r_mutex.unlock();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PIStreamPacker::Progress::Progress() {
|
|
||||||
active = false;
|
|
||||||
bytes_all = bytes_current = 0;
|
|
||||||
progress = 0.;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -36,22 +36,6 @@ public:
|
|||||||
//! Contructs packer and try to assign \"dev\"
|
//! Contructs packer and try to assign \"dev\"
|
||||||
PIStreamPacker(PIIODevice * dev = 0);
|
PIStreamPacker(PIIODevice * dev = 0);
|
||||||
|
|
||||||
//! Progress info
|
|
||||||
struct PIP_IO_UTILS_EXPORT Progress {
|
|
||||||
Progress();
|
|
||||||
|
|
||||||
//! Is send/receive in progress
|
|
||||||
bool active;
|
|
||||||
|
|
||||||
//! Overall send/receive packet size
|
|
||||||
int bytes_all;
|
|
||||||
|
|
||||||
//! Current send/receive size
|
|
||||||
int bytes_current;
|
|
||||||
|
|
||||||
//! Current send/receive progress from 0 to 1
|
|
||||||
double progress;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Set maximum size of single packet
|
//! Set maximum size of single packet
|
||||||
void setMaxPacketSize(int max_size) {max_packet_size = max_size;}
|
void setMaxPacketSize(int max_size) {max_packet_size = max_size;}
|
||||||
@@ -83,6 +67,8 @@ public:
|
|||||||
bool cryptSizeEnabled() const {return crypt_size;}
|
bool cryptSizeEnabled() const {return crypt_size;}
|
||||||
void setCryptSizeEnabled(bool on);
|
void setCryptSizeEnabled(bool on);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
|
||||||
//! Prepare data for send and raise \a sendRequest() events
|
//! Prepare data for send and raise \a sendRequest() events
|
||||||
void send(const PIByteArray & data);
|
void send(const PIByteArray & data);
|
||||||
@@ -97,12 +83,6 @@ public:
|
|||||||
//! and \a sendRequest() event to \"dev\" \a PIIODevice::write() handler
|
//! and \a sendRequest() event to \"dev\" \a PIIODevice::write() handler
|
||||||
void assignDevice(PIIODevice * dev);
|
void assignDevice(PIIODevice * dev);
|
||||||
|
|
||||||
//! Returns \a Progress info about sending
|
|
||||||
Progress progressSend() const;
|
|
||||||
|
|
||||||
//! Returns \a Progress info about receiving
|
|
||||||
Progress progressReceive() const;
|
|
||||||
|
|
||||||
EVENT1(packetReceiveEvent, PIByteArray &, data)
|
EVENT1(packetReceiveEvent, PIByteArray &, data)
|
||||||
EVENT1(sendRequest, PIByteArray, data)
|
EVENT1(sendRequest, PIByteArray, data)
|
||||||
|
|
||||||
@@ -139,7 +119,6 @@ private:
|
|||||||
int packet_size, crypt_frag_size;
|
int packet_size, crypt_frag_size;
|
||||||
ushort packet_sign;
|
ushort packet_sign;
|
||||||
int max_packet_size, size_crypted_size;
|
int max_packet_size, size_crypted_size;
|
||||||
Progress prog_s, prog_r;
|
|
||||||
mutable PIMutex prog_s_mutex, prog_r_mutex;
|
mutable PIMutex prog_s_mutex, prog_r_mutex;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user