PICloudClient disconnect
This commit is contained in:
@@ -29,10 +29,8 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
CONNECTU(&streampacker, packetReceiveEvent, this, _readed);
|
||||
CONNECTL(ð, disconnected, [this](bool){
|
||||
// piCoutObj << "disconnected";
|
||||
opened_ = false;
|
||||
is_connected = false;
|
||||
cond_connect.notifyOne();
|
||||
cond_buff.notifyOne();
|
||||
if (is_connected) disconnected();
|
||||
internalDisconnect();
|
||||
piMSleep(100);
|
||||
});
|
||||
}
|
||||
@@ -40,12 +38,8 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
|
||||
PICloudClient::~PICloudClient() {
|
||||
eth.close();
|
||||
if (is_connected) {
|
||||
is_connected = false;
|
||||
disconnected();
|
||||
cond_buff.notifyOne();
|
||||
cond_connect.notifyOne();
|
||||
}
|
||||
if (is_connected) disconnected();
|
||||
internalDisconnect();
|
||||
close();
|
||||
stop();
|
||||
}
|
||||
@@ -87,10 +81,7 @@ bool PICloudClient::openDevice() {
|
||||
bool PICloudClient::closeDevice() {
|
||||
PIThread::stop(false);
|
||||
if (is_connected) {
|
||||
is_connected = false;
|
||||
disconnected();
|
||||
cond_buff.notifyOne();
|
||||
cond_connect.notifyOne();
|
||||
internalDisconnect();
|
||||
}
|
||||
eth.stop();
|
||||
if (eth.isOpened()) eth.close();
|
||||
@@ -120,6 +111,13 @@ int PICloudClient::writeDevice(const void * data, int size) {
|
||||
}
|
||||
|
||||
|
||||
void PICloudClient::internalDisconnect() {
|
||||
is_connected = false;
|
||||
cond_buff.notifyOne();
|
||||
cond_connect.notifyOne();
|
||||
}
|
||||
|
||||
|
||||
void PICloudClient::_readed(PIByteArray & ba) {
|
||||
mutex_buff.lock();
|
||||
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> hdr = tcp.parseHeader(ba);
|
||||
@@ -136,7 +134,6 @@ void PICloudClient::_readed(PIByteArray & ba) {
|
||||
is_connected = false;
|
||||
static_cast<PIThread*>(ð)->stop();
|
||||
eth.close();
|
||||
disconnected();
|
||||
break;
|
||||
case PICloud::TCP::Data:
|
||||
if (is_connected) {
|
||||
@@ -150,6 +147,6 @@ void PICloudClient::_readed(PIByteArray & ba) {
|
||||
//piCoutObj << "readed" << ba.toHex();
|
||||
}
|
||||
mutex_buff.unlock();
|
||||
while (buff.size_s() > threadedReadBufferSize()) piMSleep(100);
|
||||
while (buff.size_s() > threadedReadBufferSize()) piMSleep(100); // FIXME: sleep here is bad
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user