PIEthernet error 232

PICloud many fixes
PIBroadcast recursive fix
This commit is contained in:
2021-08-20 10:55:47 +03:00
parent 3c20728210
commit 0e65151e9f
5 changed files with 69 additions and 45 deletions

View File

@@ -28,7 +28,7 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
CONNECTU(&streampacker, packetReceiveEvent, this, _readed);
CONNECTL(&eth, connected, [this](){tcp.sendStart();});
CONNECTL(&eth, disconnected, [this](bool){
piCoutObj << "disconnected";
//piCoutObj << "disconnected";
opened_ = false;
piMSleep(100);
});
@@ -57,7 +57,7 @@ PIVector<PICloudServer::Client *> PICloudServer::clients() const {
bool PICloudServer::openDevice() {
piCout << "PICloudServer open device" << path();
//piCout << "PICloudServer open device" << path();
bool op = eth.connect(PIEthernet::Address::resolve(path()), false);
if (op) {
eth.startThreadedRead();
@@ -143,10 +143,12 @@ bool PICloudServer::Client::closeDevice() {
int PICloudServer::Client::readDevice(void * read_to, int max_size) {
if (!is_connected) return -1;
mutex_buff.lock();
cond_buff.wait(mutex_buff, [this](){return !buff.isEmpty();});
cond_buff.wait(mutex_buff, [this](){return !buff.isEmpty() || !is_connected;});
int sz = piMini(max_size, buff.size());
memcpy(read_to, buff.data(), sz);
buff.remove(0, sz);
if (sz > 0) {
memcpy(read_to, buff.data(), sz);
buff.remove(0, sz);
}
mutex_buff.unlock();
return sz;
}
@@ -179,7 +181,7 @@ void PICloudServer::_readed(PIByteArray & ba) {
if (oc) {
tcp.sendDisconnected(id);
} else {
piCoutObj << "new Client" << id;
//piCoutObj << "new Client" << id;
Client * c = new Client(this, id);
CONNECTU(c, deleted, this, clientDeleted);
clients_mutex.lock();
@@ -191,7 +193,7 @@ void PICloudServer::_readed(PIByteArray & ba) {
} break;
case PICloud::TCP::Disconnect: {
uint id = tcp.parseDisconnect(ba);
piCoutObj << "remove Client" << id;
//piCoutObj << "remove Client" << id;
clients_mutex.lock();
Client * oc = index_clients.value(id, nullptr);
clients_mutex.unlock();