important:

* PIThread::~PIThread() now unregister itself from introspection, if terminates than show warning
 * PISystemMonitor now correctly stops
 * PIPeer now can correctly stopAndWait
 * PIPeer::destroy(), protected method for close all eths and threads
 * new PIINTROSPECTION_STOP macro
 * Introspection now can be correctly stopped by macro, more safety

ClientServer:
 * ClientBase::close() stop and disconnect channel
 * Server clients clean-up now event-based
 * No warnings on client destructor
This commit is contained in:
2024-09-12 17:07:48 +03:00
parent da4b09be9e
commit 996b7ea403
17 changed files with 189 additions and 99 deletions

View File

@@ -33,15 +33,11 @@ PRIVATE_DEFINITION_END(PIIntrospectionServer)
PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) {
PRIVATE->process_info = PIIntrospection::getInfo();
sysmon = 0;
}
PIIntrospectionServer::~PIIntrospectionServer() {
PIPeer::stop();
if (sysmon)
if (sysmon->property("__iserver__").toBool()) delete sysmon;
sysmon = 0;
// stop();
}
@@ -69,6 +65,15 @@ void PIIntrospectionServer::start(const PIString & server_name) {
}
void PIIntrospectionServer::stop() {
PIPeer::stopAndWait();
PIPeer::destroy();
if (sysmon)
if (sysmon->property("__iserver__").toBool()) delete sysmon;
sysmon = nullptr;
}
PIString PIIntrospectionServer::genName() {
randomize();
return "__introspection__server_" + PIString::fromNumber(randomi() % 1000);
@@ -102,7 +107,7 @@ void PIIntrospectionServer::dataReceived(const PIString & from, const PIByteArra
void PIIntrospectionServer::sysmonDeleted() {
PIMutexLocker _ml(sysmon_mutex);
sysmon = 0;
sysmon = nullptr;
}
#endif // PIP_INTROSPECTION

View File

@@ -33,6 +33,11 @@
//! \~russian Запускает сервер интроспекции с именем "name"
# define PIINTROSPECTION_START(name)
//! \ingroup Introspection
//! \~english Stop introspection server
//! \~russian Останавливает сервер интроспекции
# define PIINTROSPECTION_STOP
#else
# if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
@@ -44,6 +49,7 @@ class PISystemMonitor;
# define PIINTROSPECTION_SERVER (PIIntrospectionServer::instance())
# define PIINTROSPECTION_START(name) PIINTROSPECTION_SERVER->start(#name);
# define PIINTROSPECTION_STOP PIINTROSPECTION_SERVER->stop();
class PIP_EXPORT PIIntrospectionServer: public PIPeer {
PIOBJECT_SUBCLASS(PIIntrospectionServer, PIPeer);
@@ -52,6 +58,7 @@ public:
static PIIntrospectionServer * instance();
void start(const PIString & server_name);
void stop();
private:
PIIntrospectionServer();
@@ -59,17 +66,17 @@ private:
NO_COPY_CLASS(PIIntrospectionServer);
PIString genName();
virtual void dataReceived(const PIString & from, const PIByteArray & data);
void dataReceived(const PIString & from, const PIByteArray & data) override;
EVENT_HANDLER(void, sysmonDeleted);
PRIVATE_DECLARATION(PIP_EXPORT)
PITimer itimer;
PISystemMonitor * sysmon;
PISystemMonitor * sysmon = nullptr;
PIMutex sysmon_mutex;
};
# else
# define PIINTROSPECTION_START(name)
# define PIINTROSPECTION_STOP
# endif
#endif // DOXYGEN

View File

@@ -139,8 +139,10 @@ PIByteArray PIIntrospection::packThreads() {
PIMap<PIThread *, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
auto it = tm.makeIterator();
while (it.next()) {
it.value().classname = PIStringAscii(it.key()->className());
it.value().name = it.key()->name();
if (it.key()->isPIObject()) {
it.value().classname = PIStringAscii(it.key()->className());
it.value().name = it.key()->name();
}
}
ret << tm.values();
p->mutex.unlock();