fail reconnect
This commit is contained in:
@@ -28,7 +28,9 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
CONNECTL(ð, connected, [this](){opened_ = true; tcp.sendStart();});
|
||||
CONNECTU(&streampacker, packetReceiveEvent, this, _readed);
|
||||
CONNECTL(ð, disconnected, [this](bool){
|
||||
// piCoutObj << "disconnected";
|
||||
piCoutObj << "disconnected";
|
||||
static_cast<PIThread*>(ð)->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*>(ð)->stop();
|
||||
eth.close();
|
||||
break;
|
||||
|
||||
@@ -29,6 +29,7 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
CONNECTL(ð, connected, [this](){tcp.sendStart();});
|
||||
CONNECTL(ð, disconnected, [this](bool){
|
||||
piCoutObj << "disconnected";
|
||||
static_cast<PIThread*>(ð)->stop();
|
||||
opened_ = false;
|
||||
piMSleep(100);
|
||||
});
|
||||
@@ -142,8 +143,8 @@ bool PICloudServer::Client::closeDevice() {
|
||||
|
||||
|
||||
int PICloudServer::Client::readDevice(void * read_to, int max_size) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user