небольшая чистка и улучшение кода, попытка исправить picloud
This commit is contained in:
@@ -45,10 +45,7 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
|
||||
PICloudClient::~PICloudClient() {
|
||||
//piCoutObj << "~PICloudClient()";
|
||||
//softStopThreadedRead();
|
||||
//eth.close();
|
||||
//if (is_connected) disconnected();
|
||||
//close();
|
||||
|
||||
stopAndWait();
|
||||
//piCoutObj << "~PICloudClient() closed";
|
||||
internalDisconnect();
|
||||
@@ -71,7 +68,8 @@ void PICloudClient::setKeepConnection(bool on) {
|
||||
|
||||
|
||||
void PICloudClient::interrupt() {
|
||||
eth.interrupt();
|
||||
cond_buff.notifyOne();
|
||||
cond_connect.notifyOne();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +85,7 @@ bool PICloudClient::openDevice() {
|
||||
mutex_connect.unlock();
|
||||
if (!conn_ok) {
|
||||
mutex_connect.lock();
|
||||
eth.stop();
|
||||
eth.stopAndWait();
|
||||
eth.close();
|
||||
mutex_connect.unlock();
|
||||
}
|
||||
@@ -104,7 +102,7 @@ bool PICloudClient::closeDevice() {
|
||||
if (is_connected) {
|
||||
internalDisconnect();
|
||||
}
|
||||
eth.stop();
|
||||
eth.stopAndWait();
|
||||
eth.close();
|
||||
return true;
|
||||
}
|
||||
@@ -116,11 +114,15 @@ ssize_t PICloudClient::readDevice(void * read_to, ssize_t max_size) {
|
||||
if (!is_connected && eth.isClosed()) openDevice();
|
||||
ssize_t sz = -1;
|
||||
mutex_buff.lock();
|
||||
cond_buff.wait(mutex_buff, [this](){return !buff.isEmpty() || !is_connected;});
|
||||
cond_buff.wait(mutex_buff);
|
||||
if (is_connected) {
|
||||
sz = piMini(max_size, buff.size());
|
||||
memcpy(read_to, buff.data(), sz);
|
||||
buff.remove(0, sz);
|
||||
if (buff.isEmpty()) {
|
||||
sz = 0;
|
||||
} else {
|
||||
sz = piMini(max_size, buff.size());
|
||||
memcpy(read_to, buff.data(), sz);
|
||||
buff.remove(0, sz);
|
||||
}
|
||||
}
|
||||
mutex_buff.unlock();
|
||||
if (!is_connected) opened_ = false;
|
||||
@@ -136,11 +138,6 @@ ssize_t PICloudClient::writeDevice(const void * data, ssize_t size) {
|
||||
}
|
||||
|
||||
|
||||
void PICloudClient::stopThreadedReadDevice() {
|
||||
cond_buff.notifyOne();
|
||||
}
|
||||
|
||||
|
||||
void PICloudClient::internalDisconnect() {
|
||||
is_connected = false;
|
||||
cond_buff.notifyOne();
|
||||
|
||||
Reference in New Issue
Block a user