version 4.0.0_alpha
in almost all methods removed timeouts in milliseconds, replaced to PISystemTime PITimer rewrite, remove internal impl, now only thread implementation, API similar to PIThread PITimer API no longer pass void* PIPeer, PIConnection improved stability on reinit and exit PISystemTime new methods pisd now exit without hanging
This commit is contained in:
@@ -21,7 +21,9 @@
|
||||
|
||||
#include "piconfig.h"
|
||||
#include "pidatatransfer.h"
|
||||
#include "piliterals_time.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "pitime.h"
|
||||
|
||||
#define _PIPEER_MSG_SIZE 4000
|
||||
#define _PIPEER_MSG_TTL 100
|
||||
@@ -85,7 +87,7 @@ PIPeer::PeerData::~PeerData() {
|
||||
dt_in.stop();
|
||||
dt_out.stop();
|
||||
t.stop();
|
||||
if (!t.waitForFinish(1000)) t.terminate();
|
||||
if (!t.waitForFinish(1_s)) t.terminate();
|
||||
}
|
||||
|
||||
|
||||
@@ -182,12 +184,12 @@ PIPeer::PIPeer(const PIString & n)
|
||||
PIMutexLocker pl(peers_mutex);
|
||||
PIMutexLocker sl(send_mutex);
|
||||
changeName(n);
|
||||
setReopenTimeout(100);
|
||||
setReopenTimeout(100_ms);
|
||||
read_buffer_size = 128;
|
||||
self_info.dist = 0;
|
||||
self_info.time = PISystemTime::current();
|
||||
randomize();
|
||||
CONNECT2(void, void *, int, &sync_timer, tickEvent, this, timerEvent);
|
||||
CONNECT1(void, int, &sync_timer, tickEvent, this, timerEvent);
|
||||
prev_ifaces = PIEthernet::interfaces();
|
||||
no_timer = false;
|
||||
sync_timer.addDelimiter(5);
|
||||
@@ -199,9 +201,9 @@ PIPeer::~PIPeer() {
|
||||
stop();
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
sync_timer.stop();
|
||||
diag_s.stop();
|
||||
diag_d.stop();
|
||||
sync_timer.stopAndWait();
|
||||
diag_s.stopAndWait();
|
||||
diag_d.stopAndWait();
|
||||
PIMutexLocker ml(peers_mutex);
|
||||
piForeach(PeerInfo & p, peers)
|
||||
if (p._data) {
|
||||
@@ -212,15 +214,15 @@ PIPeer::~PIPeer() {
|
||||
destroyEths();
|
||||
piForeach(PIEthernet * i, eths_mcast) {
|
||||
if (!i) continue;
|
||||
i->stopThreadedRead();
|
||||
i->stopAndWait();
|
||||
}
|
||||
piForeach(PIEthernet * i, eths_bcast) {
|
||||
if (!i) continue;
|
||||
i->stopThreadedRead();
|
||||
i->stopAndWait();
|
||||
}
|
||||
eth_lo.stopThreadedRead();
|
||||
eth_tcp_srv.stopThreadedRead();
|
||||
eth_tcp_cli.stopThreadedRead();
|
||||
eth_lo.stopAndWait();
|
||||
eth_tcp_srv.stopAndWait();
|
||||
eth_tcp_cli.stopAndWait();
|
||||
sendSelfRemove();
|
||||
destroyMBcasts();
|
||||
eth_send.close();
|
||||
@@ -229,7 +231,7 @@ PIPeer::~PIPeer() {
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::timerEvent(void * data, int delim) {
|
||||
void PIPeer::timerEvent(int delim) {
|
||||
// piCoutObj << "timerEvent" << delim;
|
||||
if (no_timer) return;
|
||||
switch (delim) {
|
||||
@@ -362,46 +364,32 @@ void PIPeer::initMBcasts(PIStringList al) {
|
||||
|
||||
|
||||
void PIPeer::destroyEths() {
|
||||
piForeach(PIEthernet * i, eths_traffic) {
|
||||
for (auto * i: eths_traffic) {
|
||||
if (!i) continue;
|
||||
((PIThread *)i)->stop();
|
||||
((PIThread *)i)->waitForFinish(100);
|
||||
i->stopThreadedRead();
|
||||
i->stopAndWait();
|
||||
i->close();
|
||||
delete i;
|
||||
i = 0;
|
||||
}
|
||||
eths_traffic.clear();
|
||||
piDeleteAllAndClear(eths_traffic);
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::destroyMBcasts() {
|
||||
piForeach(PIEthernet * i, eths_mcast) {
|
||||
for (auto * i: eths_mcast) {
|
||||
if (!i) continue;
|
||||
((PIThread *)i)->stop();
|
||||
((PIThread *)i)->waitForFinish(100);
|
||||
i->stopThreadedRead();
|
||||
i->leaveMulticastGroup(_PIPEER_MULTICAST_IP);
|
||||
i->stopAndWait();
|
||||
i->close();
|
||||
delete i;
|
||||
i = 0;
|
||||
}
|
||||
eths_mcast.clear();
|
||||
piForeach(PIEthernet * i, eths_bcast) {
|
||||
for (auto * i: eths_bcast) {
|
||||
if (!i) continue;
|
||||
((PIThread *)i)->stop();
|
||||
((PIThread *)i)->waitForFinish(100);
|
||||
i->stopThreadedRead();
|
||||
i->stopAndWait();
|
||||
i->close();
|
||||
delete i;
|
||||
i = 0;
|
||||
}
|
||||
eths_bcast.clear();
|
||||
((PIThread *)ð_lo)->stop();
|
||||
((PIThread *)ð_lo)->waitForFinish(100);
|
||||
eth_lo.stopThreadedRead();
|
||||
piDeleteAllAndClear(eths_mcast);
|
||||
piDeleteAllAndClear(eths_bcast);
|
||||
eth_lo.stopAndWait();
|
||||
eth_lo.close();
|
||||
eth_tcp_srv.stop();
|
||||
eth_tcp_srv.stopAndWait();
|
||||
}
|
||||
|
||||
|
||||
@@ -918,7 +906,7 @@ void PIPeer::reinit() {
|
||||
initNetwork();
|
||||
sendSelfInfo();
|
||||
no_timer = false;
|
||||
if (!sync_timer.isRunning()) sync_timer.start(1000);
|
||||
if (!sync_timer.isRunning()) sync_timer.start(1_Hz);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user