migrate to async IO model

new PIIODevice::interrupt() virtual method
new PIWaitEvent private class
PIEthernet and PISerial basically tested on Windows and Linux
This commit is contained in:
2022-11-05 23:43:07 +03:00
parent e48d0ebaab
commit 8a5e72c723
15 changed files with 498 additions and 209 deletions

View File

@@ -45,10 +45,11 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
PICloudClient::~PICloudClient() {
//piCoutObj << "~PICloudClient()";
softStopThreadedRead();
//softStopThreadedRead();
//eth.close();
//if (is_connected) disconnected();
close();
//close();
stopAndWait();
//piCoutObj << "~PICloudClient() closed";
internalDisconnect();
// stop(false);
@@ -69,6 +70,11 @@ void PICloudClient::setKeepConnection(bool on) {
}
void PICloudClient::interrupt() {
eth.interrupt();
}
bool PICloudClient::openDevice() {
//piCoutObj << "open";// << path();
bool op = eth.connect(PIEthernet::Address::resolve(path()), false);

View File

@@ -41,7 +41,7 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
PICloudServer::~PICloudServer() {
stop();
stopAndWait();
close();
}
@@ -107,6 +107,11 @@ void PICloudServer::stopThreadedReadDevice() {
}
void PICloudServer::interrupt() {
eth.interrupt();
}
void PICloudServer::clientDisconnect(uint client_id) {
tcp.sendDisconnected(client_id);
}
@@ -170,6 +175,11 @@ ssize_t PICloudServer::Client::writeDevice(const void * data, ssize_t size) {
}
void PICloudServer::Client::interrupt() {
cond_buff.notifyOne();
}
void PICloudServer::Client::pushBuffer(const PIByteArray & ba) {
if (!is_connected) return;
mutex_buff.lock();