picloud fix segfault on close
This commit is contained in:
@@ -32,13 +32,20 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
opened_ = false;
|
||||
is_connected = false;
|
||||
cond_connect.notifyOne();
|
||||
cond_buff.notifyOne();
|
||||
piMSleep(100);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
PICloudClient::~PICloudClient() {
|
||||
stop();
|
||||
eth.close();
|
||||
if (is_connected) {
|
||||
is_connected = false;
|
||||
cond_buff.notifyOne();
|
||||
cond_connect.notifyOne();
|
||||
}
|
||||
//stop();
|
||||
close();
|
||||
}
|
||||
|
||||
@@ -55,8 +62,9 @@ void PICloudClient::setKeepConnection(bool on) {
|
||||
|
||||
|
||||
bool PICloudClient::openDevice() {
|
||||
piCout << "PICloudClient open device" << path();
|
||||
bool op = eth.connect(path(), false);
|
||||
PIString p = path();
|
||||
piCout << "PICloudClient open device" << p;
|
||||
bool op = eth.connect(p, false);
|
||||
if (op) {
|
||||
mutex_buff.lock();
|
||||
eth.startThreadedRead();
|
||||
@@ -77,15 +85,20 @@ bool PICloudClient::openDevice() {
|
||||
|
||||
|
||||
bool PICloudClient::closeDevice() {
|
||||
is_connected = false;
|
||||
if (is_connected) {
|
||||
is_connected = false;
|
||||
cond_buff.notifyOne();
|
||||
cond_connect.notifyOne();
|
||||
}
|
||||
eth.stop();
|
||||
eth.close();
|
||||
if (eth.isOpened()) eth.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int PICloudClient::readDevice(void * read_to, int max_size) {
|
||||
piCoutObj << "readDevice";
|
||||
if (!is_connected) return -1;
|
||||
mutex_buff.lock();
|
||||
cond_buff.wait(mutex_buff, [this](){return !buff.isEmpty();});
|
||||
int sz = piMini(max_size, buff.size());
|
||||
@@ -96,8 +109,9 @@ int PICloudClient::readDevice(void * read_to, int max_size) {
|
||||
}
|
||||
|
||||
|
||||
int PICloudClient::writeDevice(const void * data, int max_size) {
|
||||
return eth.write(data, max_size);
|
||||
int PICloudClient::writeDevice(const void * data, int size) {
|
||||
piCoutObj << "writeDevice";
|
||||
return tcp.sendData(PIByteArray(data, size));
|
||||
}
|
||||
|
||||
|
||||
@@ -118,8 +132,10 @@ void PICloudClient::_readed(PIByteArray & ba) {
|
||||
eth.close();
|
||||
break;
|
||||
case PICloud::TCP::Data:
|
||||
buff.append(ba);
|
||||
cond_buff.notifyOne();
|
||||
if (is_connected) {
|
||||
buff.append(ba);
|
||||
cond_buff.notifyOne();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user