убрал лишнее в PICloudServer

This commit is contained in:
Бычков Андрей
2022-11-08 16:37:10 +03:00
parent b17510218b
commit 21fa3baf4e
3 changed files with 11 additions and 13 deletions

View File

@@ -2,7 +2,7 @@
PICloudBase::PICloudBase() : eth(PIEthernet::TCP_Client), streampacker(&eth), tcp(&streampacker) {
eth.setDebug(false);
//eth.setDebug(false);
}

View File

@@ -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(&eth, connected, [this](){opened_ = true; piCoutObj << "connected" << &eth; tcp.sendStart();});
CONNECTL(&eth, 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;
}

View File

@@ -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;
}));