PICloud small patches

This commit is contained in:
2021-07-20 21:11:33 +03:00
parent 511bedf425
commit d0db8012e6
13 changed files with 65 additions and 18 deletions

View File

@@ -4,3 +4,8 @@
PICloudBase::PICloudBase() : eth(PIEthernet::TCP_Client), streampacker(&eth), tcp(&streampacker) {
}
PIString PICloudBase::serverName() const {
return tcp.serverName();
}

View File

@@ -42,6 +42,7 @@ PICloudClient::~PICloudClient() {
eth.close();
if (is_connected) {
is_connected = false;
disconnected();
cond_buff.notifyOne();
cond_connect.notifyOne();
}
@@ -86,6 +87,7 @@ bool PICloudClient::openDevice() {
bool PICloudClient::closeDevice() {
if (is_connected) {
is_connected = false;
disconnected();
cond_buff.notifyOne();
cond_connect.notifyOne();
}
@@ -122,6 +124,7 @@ void PICloudClient::_readed(PIByteArray & ba) {
case PICloud::TCP::Connect:
if (tcp.parseConnect(ba) == 1) {
is_connected = true;
connected();
cond_connect.notifyOne();
}
break;
@@ -129,6 +132,7 @@ void PICloudClient::_readed(PIByteArray & ba) {
is_connected = false;
eth.stop();
eth.close();
disconnected();
break;
case PICloud::TCP::Data:
if (is_connected) {

View File

@@ -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;
}
}
}

View File

@@ -41,8 +41,14 @@ void PICloud::TCP::setRole(PICloud::TCP::Role r) {
}
void PICloud::TCP::setServerName(const PIString & server_name) {
suuid = PICrypt::hash(server_name);
void PICloud::TCP::setServerName(const PIString & server_name_) {
server_name = server_name_;
suuid = PICrypt::hash(server_name_);
}
PIString PICloud::TCP::serverName() const {
return server_name;
}