From 21fa3baf4ea492cfaacedfb7cb3435d41aaae619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Tue, 8 Nov 2022 16:37:10 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D0=B5=D0=B5=20=D0=B2=20PICloudServer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cloud/picloudbase.cpp | 2 +- libs/cloud/picloudserver.cpp | 20 +++++++++----------- main_picloud_test.cpp | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libs/cloud/picloudbase.cpp b/libs/cloud/picloudbase.cpp index 10110a31..658613c2 100644 --- a/libs/cloud/picloudbase.cpp +++ b/libs/cloud/picloudbase.cpp @@ -2,7 +2,7 @@ PICloudBase::PICloudBase() : eth(PIEthernet::TCP_Client), streampacker(ð), tcp(&streampacker) { - eth.setDebug(false); + //eth.setDebug(false); } diff --git a/libs/cloud/picloudserver.cpp b/libs/cloud/picloudserver.cpp index 220473a1..2c00d2f8 100644 --- a/libs/cloud/picloudserver.cpp +++ b/libs/cloud/picloudserver.cpp @@ -25,6 +25,7 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode) tcp.setRole(PICloud::TCP::Server); tcp.setServerName(server_name); setName("cloud_server__" + server_name); + eth.setReopenEnabled(false); CONNECT1(void, PIByteArray, &streampacker, packetReceiveEvent, this, _readed); CONNECTL(ð, connected, [this](){opened_ = true; piCoutObj << "connected" << ð tcp.sendStart();}); CONNECTL(ð, disconnected, [this](bool){ @@ -44,8 +45,10 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode) PICloudServer::~PICloudServer() { piCoutObj << "~PICloudServer ..." << this; - stopAndWait(); + stop(); close(); + piCout << "wait"; + waitThreadedReadFinished(); piCoutObj << "~PICloudServer done" << this; } @@ -69,10 +72,11 @@ bool PICloudServer::openDevice() { eth.startThreadedRead(); ping_timer.start(5000); return true; + } else { + ping_timer.stop(false); + eth.close(); + return false; } - ping_timer.stop(false); - eth.close(); - return false; } @@ -80,12 +84,6 @@ bool PICloudServer::closeDevice() { piCoutObj << "closeDevice" << this; eth.stopAndWait(); ping_timer.stop(false); - clients_mutex.lock(); - for (auto c : clients_) { - c->stopAndWait(); - c->close(); - } - clients_mutex.unlock(); eth.close(); for (auto c : clients_) { delete c; @@ -98,7 +96,7 @@ bool PICloudServer::closeDevice() { ssize_t PICloudServer::readDevice(void * read_to, ssize_t max_size) { //piCoutObj << "readDevice"; if (!opened_) openDevice(); - else piMSleep(eth.readTimeout()); + //else piMSleep(eth.readTimeout()); return -1; } diff --git a/main_picloud_test.cpp b/main_picloud_test.cpp index c94886b0..208fd746 100644 --- a/main_picloud_test.cpp +++ b/main_picloud_test.cpp @@ -52,7 +52,7 @@ int main(int argc, char * argv[]) { })); CONNECTL(cl, closed, ([&clients, cl](){ piCout << "[Server] client closed ..." << cl; - cl->stopAndWait(); + cl->stop(); clients.removeAll(cl); piCout << "[Server] client closed ok" << cl; }));