diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bb8a833..851d2bc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(pip) set(pip_MAJOR 2) -set(pip_MINOR 29) +set(pip_MINOR 30) set(pip_REVISION 0) set(pip_SUFFIX ) set(pip_COMPANY SHS) diff --git a/libs/cloud/picloudclient.cpp b/libs/cloud/picloudclient.cpp index b69ab812..fd2e5cd3 100644 --- a/libs/cloud/picloudclient.cpp +++ b/libs/cloud/picloudclient.cpp @@ -31,11 +31,13 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode) CONNECTU(&streampacker, packetReceiveEvent, this, _readed); CONNECTL(ð, disconnected, [this](bool){ if (is_deleted) return; + bool need_disconn = is_connected; //piCoutObj << "eth disconnected"; static_cast(ð)->stop(); opened_ = false; - if (is_connected) disconnected(); internalDisconnect(); + if (need_disconn) + disconnected(); //piCoutObj << "eth disconnected done"; }); } @@ -45,8 +47,7 @@ PICloudClient::~PICloudClient() { //piCoutObj << "~PICloudClient()"; PIThread::stop(); //eth.close(); - if (is_connected) disconnected(); - is_connected = false; + //if (is_connected) disconnected(); close(); //piCoutObj << "~PICloudClient() closed"; internalDisconnect(); @@ -133,22 +134,24 @@ void PICloudClient::internalDisconnect() { is_connected = false; cond_buff.notifyOne(); cond_connect.notifyOne(); + streampacker.clear(); + buff.clear(); } void PICloudClient::_readed(PIByteArray & ba) { if (is_deleted) return; - //piCoutObj << "_readed"; PIPair hdr = tcp.parseHeader(ba); + //piCoutObj << "_readed" << ba.size() << hdr.first << hdr.second; if (hdr.second == tcp.role()) { switch (hdr.first) { case PICloud::TCP::Connect: if (tcp.parseConnect(ba) == 1) { mutex_connect.lock(); is_connected = true; - connected(); mutex_connect.unlock(); cond_connect.notifyOne(); + connected(); } break; case PICloud::TCP::Disconnect: diff --git a/libs/cloud/picloudtcp.cpp b/libs/cloud/picloudtcp.cpp index 035d7129..178560fe 100644 --- a/libs/cloud/picloudtcp.cpp +++ b/libs/cloud/picloudtcp.cpp @@ -62,9 +62,9 @@ void PICloud::TCP::sendStart() { PIByteArray ba; ba << header; ba.append(suuid); - mutex_send.lock(); + //mutex_send.lock(); streampacker->send(ba); - mutex_send.unlock(); + //mutex_send.unlock(); } diff --git a/libs/io_utils/pistreampacker.cpp b/libs/io_utils/pistreampacker.cpp index 366ac4c0..be4649dd 100644 --- a/libs/io_utils/pistreampacker.cpp +++ b/libs/io_utils/pistreampacker.cpp @@ -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) { if (data.isEmpty()) return; PIByteArray cd; @@ -94,31 +101,12 @@ void PIStreamPacker::send(const PIByteArray & data) { hdr << int(cd.size_s()); cd.insert(0, hdr); 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) { if (i == pcnt - 1) part = PIByteArray(cd.data(pst), cd.size_s() - pst); else part = PIByteArray(cd.data(pst), max_packet_size); //piCout << "send" << part.size(); sendRequest(part); 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; if (packet_size == 0) 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; } else { int ps = piMini(stream.size_s(), packet_size - packet.size_s()); 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); if (packet.size_s() == packet_size) { PIByteArray cd; @@ -211,9 +187,6 @@ void PIStreamPacker::received(const PIByteArray & data) { } packet.clear(); 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(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.; -} diff --git a/libs/main/io_utils/pistreampacker.h b/libs/main/io_utils/pistreampacker.h index e124d476..933c0c0d 100644 --- a/libs/main/io_utils/pistreampacker.h +++ b/libs/main/io_utils/pistreampacker.h @@ -36,22 +36,6 @@ public: //! Contructs packer and try to assign \"dev\" 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 void setMaxPacketSize(int max_size) {max_packet_size = max_size;} @@ -83,6 +67,8 @@ public: bool cryptSizeEnabled() const {return crypt_size;} void setCryptSizeEnabled(bool on); + void clear(); + //! Prepare data for send and raise \a sendRequest() events void send(const PIByteArray & data); @@ -97,12 +83,6 @@ public: //! and \a sendRequest() event to \"dev\" \a PIIODevice::write() handler 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(sendRequest, PIByteArray, data) @@ -139,7 +119,6 @@ private: int packet_size, crypt_frag_size; ushort packet_sign; int max_packet_size, size_crypted_size; - Progress prog_s, prog_r; mutable PIMutex prog_s_mutex, prog_r_mutex; };