PICloud small patches
This commit is contained in:
@@ -74,6 +74,8 @@ bool PICloudServer::closeDevice() {
|
||||
}
|
||||
clients_mutex.unlock();
|
||||
eth.close();
|
||||
for (auto c : clients_)
|
||||
delete c;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -102,6 +104,8 @@ int PICloudServer::sendData(const PIByteArray & data, uint client_id) {
|
||||
|
||||
|
||||
PICloudServer::Client::Client(PICloudServer * srv, uint id) : server(srv), client_id(id) {
|
||||
setMode(PIIODevice::ReadWrite);
|
||||
setReopenEnabled(false);
|
||||
is_connected = true;
|
||||
}
|
||||
|
||||
@@ -132,7 +136,6 @@ bool PICloudServer::Client::closeDevice() {
|
||||
|
||||
|
||||
int PICloudServer::Client::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();});
|
||||
@@ -180,9 +183,10 @@ void PICloudServer::_readed(PIByteArray & ba) {
|
||||
clients_mutex.unlock();
|
||||
newConnection(c);
|
||||
}
|
||||
} break;
|
||||
} break;
|
||||
case PICloud::TCP::Disconnect: {
|
||||
uint id = tcp.parseDisconnect(ba);
|
||||
piCoutObj << "remove Client" << id;
|
||||
clients_mutex.lock();
|
||||
Client * oc = index_clients.value(id, nullptr);
|
||||
clients_mutex.unlock();
|
||||
@@ -190,16 +194,16 @@ void PICloudServer::_readed(PIByteArray & ba) {
|
||||
oc->is_connected = false;
|
||||
oc->close();
|
||||
}
|
||||
} break;
|
||||
} break;
|
||||
case PICloud::TCP::Data: {
|
||||
PIPair<uint, PIByteArray> d = tcp.parseDataServer(ba);
|
||||
clients_mutex.lock();
|
||||
Client * oc = index_clients.value(d.first, nullptr);
|
||||
clients_mutex.unlock();
|
||||
//piCoutObj << "data for" << d.first << d.second.toHex();
|
||||
if (oc && !d.second.isEmpty()) oc->pushBuffer(d.second);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user