fail reconnect

This commit is contained in:
2021-08-20 18:25:59 +03:00
parent 99e135caa2
commit 5cc8ef1eb0
5 changed files with 35 additions and 36 deletions

View File

@@ -28,7 +28,9 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
CONNECTL(&eth, connected, [this](){opened_ = true; tcp.sendStart();});
CONNECTU(&streampacker, packetReceiveEvent, this, _readed);
CONNECTL(&eth, disconnected, [this](bool){
// piCoutObj << "disconnected";
piCoutObj << "disconnected";
static_cast<PIThread*>(&eth)->stop();
opened_ = false;
if (is_connected) disconnected();
internalDisconnect();
piMSleep(100);
@@ -37,11 +39,12 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
PICloudClient::~PICloudClient() {
piCoutObj << "~PICloudClient()";
PIThread::stop();
eth.close();
if (is_connected) disconnected();
internalDisconnect();
close();
stop();
//close();
//stop(false);
}
@@ -57,22 +60,23 @@ void PICloudClient::setKeepConnection(bool on) {
bool PICloudClient::openDevice() {
// piCout << "PICloudClient open device" << path();
piCout << "PICloudClient open device" << path();
bool op = eth.connect(PIEthernet::Address::resolve(path()), false);
if (op) {
mutex_buff.lock();
mutex_connect.lock();
eth.startThreadedRead();
bool conn_ok = cond_connect.waitFor(mutex_buff, (int)eth.readTimeout());
// piCoutObj << "conn_ok" << conn_ok;
mutex_buff.unlock();
piCoutObj << "connecting...";
bool conn_ok = cond_connect.waitFor(mutex_connect, (int)eth.readTimeout());
piCoutObj << "conn_ok" << conn_ok;
if (!conn_ok) {
eth.stop();
eth.close();
piMSleep(100);
}
return isConnected();
mutex_connect.unlock();
return is_connected;
} else {
eth.close();
//eth.close();
return false;
}
}
@@ -84,15 +88,15 @@ bool PICloudClient::closeDevice() {
internalDisconnect();
}
eth.stop();
if (eth.isOpened()) eth.close();
eth.close();
return true;
}
int PICloudClient::readDevice(void * read_to, int max_size) {
// piCoutObj << "readDevice";
if (!is_connected) return -1;
int sz = -1;
if (!is_connected) return 0;
int sz = 0;
mutex_buff.lock();
cond_buff.wait(mutex_buff, [this](){return !buff.isEmpty() || !is_connected;});
if (is_connected) {
@@ -131,7 +135,6 @@ void PICloudClient::_readed(PIByteArray & ba) {
}
break;
case PICloud::TCP::Disconnect:
is_connected = false;
static_cast<PIThread*>(&eth)->stop();
eth.close();
break;