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:
@@ -20,8 +20,10 @@
|
||||
#include "pibinarylog.h"
|
||||
|
||||
#include "pidir.h"
|
||||
#include "piliterals.h"
|
||||
#include "piliterals_bytes.h"
|
||||
#include "piliterals_time.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "pitime.h"
|
||||
|
||||
#define PIBINARYLOG_VERSION_OLD 0x31
|
||||
|
||||
@@ -259,9 +261,9 @@ PIString PIBinaryLog::getLogfilePath(const PIString & log_dir, const PIString &
|
||||
<< "Creating directory" << dir.path();
|
||||
dir.make(true);
|
||||
}
|
||||
const PIString npath = log_dir + PIDir::separator + prefix + PIDateTime::current().toString("yyyy_MM_dd__hh_mm_ss");
|
||||
PIString cnpath = npath + ".binlog";
|
||||
int i = 1;
|
||||
const PIString npath = log_dir + PIDir::separator + prefix + PIDateTime::current().toString("yyyy_MM_dd__hh_mm_ss");
|
||||
PIString cnpath = npath + ".binlog";
|
||||
int i = 1;
|
||||
while (PIFile::isExists(cnpath)) {
|
||||
cnpath = npath + '_' + PIString::fromNumber(i) + ".binlog";
|
||||
i++;
|
||||
@@ -644,9 +646,9 @@ void PIBinaryLog::parseLog(PIFile * f, PIBinaryLog::BinLogInfo * info, PIVector<
|
||||
}
|
||||
PIByteArray ba;
|
||||
Record br;
|
||||
br.id = 0;
|
||||
br.size = 0;
|
||||
bool first = true;
|
||||
br.id = 0;
|
||||
br.size = 0;
|
||||
bool first = true;
|
||||
constexpr size_t hdr_size = sizeof(Record) - sizeof(PIByteArray);
|
||||
ba.resize(hdr_size);
|
||||
while (1) {
|
||||
@@ -977,16 +979,16 @@ void PIBinaryLog::configureFromVariantDevice(const PIPropertyStorage & d) {
|
||||
|
||||
|
||||
void PIBinaryLog::propertyChanged(const char * s) {
|
||||
default_id = property("defaultID").toInt();
|
||||
rapid_start = property("rapidStart").toBool();
|
||||
play_mode = (PlayMode)property("playMode").toInt();
|
||||
const double ps = property("playSpeed").toDouble();
|
||||
play_speed = ps > 0. ? 1. / ps : 0.;
|
||||
play_delay = property("playDelay").toSystemTime();
|
||||
split_mode = (SplitMode)property("splitMode").toInt();
|
||||
split_time = property("splitTime").toSystemTime();
|
||||
split_size = property("splitFileSize").toLLong();
|
||||
split_count = property("splitRecordCount").toInt();
|
||||
default_id = property("defaultID").toInt();
|
||||
rapid_start = property("rapidStart").toBool();
|
||||
play_mode = (PlayMode)property("playMode").toInt();
|
||||
const double ps = property("playSpeed").toDouble();
|
||||
play_speed = ps > 0. ? 1. / ps : 0.;
|
||||
play_delay = property("playDelay").toSystemTime();
|
||||
split_mode = (SplitMode)property("splitMode").toInt();
|
||||
split_time = property("splitTime").toSystemTime();
|
||||
split_size = property("splitFileSize").toLLong();
|
||||
split_count = property("splitRecordCount").toInt();
|
||||
// piCoutObj << "propertyChanged" << s << play_mode;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,8 +163,8 @@ void PIEthernet::construct() {
|
||||
setOption(BlockingWrite);
|
||||
connected_ = connecting_ = listen_threaded = server_bounded = false;
|
||||
sock = sock_s = -1;
|
||||
setReadTimeout(10000.);
|
||||
setWriteTimeout(10000.);
|
||||
setReadTimeout(10_s);
|
||||
setWriteTimeout(10_s);
|
||||
setTTL(64);
|
||||
setMulticastTTL(1);
|
||||
server_thread_.setData(this);
|
||||
@@ -331,7 +331,7 @@ void PIEthernet::closeSocket(int & sd) {
|
||||
|
||||
void PIEthernet::applyTimeouts() {
|
||||
if (sock < 0) return;
|
||||
double rtm = readTimeout(), wtm = writeTimeout();
|
||||
PISystemTime rtm = readTimeout(), wtm = writeTimeout();
|
||||
applyTimeout(sock, SO_RCVTIMEO, rtm);
|
||||
applyTimeout(sock, SO_SNDTIMEO, wtm);
|
||||
if (sock_s != sock && sock_s != -1) {
|
||||
@@ -341,17 +341,15 @@ void PIEthernet::applyTimeouts() {
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::applyTimeout(int fd, int opt, double ms) {
|
||||
void PIEthernet::applyTimeout(int fd, int opt, PISystemTime tm) {
|
||||
if (fd == 0) return;
|
||||
// piCoutObj << "setReadIsBlocking" << yes;
|
||||
#ifdef WINDOWS
|
||||
DWORD _tm = ms;
|
||||
DWORD _tm = tm.toMilliseconds();
|
||||
#else
|
||||
double s = ms / 1000.;
|
||||
timeval _tm;
|
||||
_tm.tv_sec = piFloord(s);
|
||||
s -= _tm.tv_sec;
|
||||
_tm.tv_usec = s * 1000000.;
|
||||
_tm.tv_sec = tm.seconds;
|
||||
_tm.tv_usec = tm.nanoseconds / 1000;
|
||||
#endif
|
||||
ethSetsockopt(fd, SOL_SOCKET, opt, &_tm, sizeof(_tm));
|
||||
}
|
||||
|
||||
@@ -174,16 +174,16 @@ public:
|
||||
Type type() const { return eth_type; }
|
||||
|
||||
//! Returns read timeout
|
||||
double readTimeout() const { return property("readTimeout").toDouble(); }
|
||||
PISystemTime readTimeout() const { return property("readTimeout").toSystemTime(); }
|
||||
|
||||
//! Returns write timeout
|
||||
double writeTimeout() const { return property("writeTimeout").toDouble(); }
|
||||
PISystemTime writeTimeout() const { return property("writeTimeout").toSystemTime(); }
|
||||
|
||||
//! Set timeout for read
|
||||
void setReadTimeout(double ms) { setProperty("readTimeout", ms); }
|
||||
void setReadTimeout(PISystemTime tm) { setProperty("readTimeout", tm); }
|
||||
|
||||
//! Set timeout for write
|
||||
void setWriteTimeout(double ms) { setProperty("writeTimeout", ms); }
|
||||
void setWriteTimeout(PISystemTime tm) { setProperty("writeTimeout", tm); }
|
||||
|
||||
|
||||
//! Returns TTL (Time To Live)
|
||||
@@ -437,11 +437,11 @@ public:
|
||||
//! \brief ethernet parameters
|
||||
int parameters;
|
||||
|
||||
//! \brief read timeout, default 1000 ms
|
||||
double readTimeout;
|
||||
//! \brief read timeout, default 10 s
|
||||
PISystemTime readTimeout;
|
||||
|
||||
//! \brief write timeout, default 1000 ms
|
||||
double writeTimeout;
|
||||
//! \brief write timeout, default 10 s
|
||||
PISystemTime writeTimeout;
|
||||
|
||||
//! \brief time-to-live, default 64
|
||||
int TTL;
|
||||
@@ -475,7 +475,7 @@ protected:
|
||||
bool closeDevice() override;
|
||||
void closeSocket(int & sd);
|
||||
void applyTimeouts();
|
||||
void applyTimeout(int fd, int opt, double ms);
|
||||
void applyTimeout(int fd, int opt, PISystemTime tm);
|
||||
void applyOptInt(int level, int opt, int val);
|
||||
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
|
||||
@@ -20,9 +20,11 @@
|
||||
#include "piiodevice.h"
|
||||
|
||||
#include "piconfig.h"
|
||||
#include "piconnection.h"
|
||||
#include "piliterals.h"
|
||||
#include "piliterals_bytes.h"
|
||||
#include "piliterals_string.h"
|
||||
#include "piliterals_time.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "pitime.h"
|
||||
|
||||
|
||||
//! \class PIIODevice piiodevice.h
|
||||
@@ -158,9 +160,9 @@ void PIIODevice::setReopenEnabled(bool yes) {
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::setReopenTimeout(int msecs) {
|
||||
setProperty("reopenTimeout", msecs);
|
||||
reopen_timeout = msecs;
|
||||
void PIIODevice::setReopenTimeout(PISystemTime timeout) {
|
||||
setProperty("reopenTimeout", timeout);
|
||||
reopen_timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -231,11 +233,13 @@ void PIIODevice::terminateThreadedRead() {
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::waitThreadedReadFinished(int timeout_ms) {
|
||||
bool PIIODevice::waitThreadedReadFinished(PISystemTime timeout) {
|
||||
PITimeMeasurer tm, tm_intr;
|
||||
while (read_thread.isRunning()) {
|
||||
if (tm.elapsed_m() > timeout_ms) return false;
|
||||
if (tm_intr.elapsed_m() > 100.) {
|
||||
if (timeout.isNotNull()) {
|
||||
if (tm.elapsed() > timeout) return false;
|
||||
}
|
||||
if (tm_intr.elapsed() > 100_ms) {
|
||||
tm_intr.reset();
|
||||
interrupt();
|
||||
}
|
||||
@@ -266,8 +270,8 @@ void PIIODevice::terminateThreadedWrite() {
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::waitThreadedWriteFinished(int timeout_ms) {
|
||||
return write_thread.waitForFinish(timeout_ms);
|
||||
bool PIIODevice::waitThreadedWriteFinished(PISystemTime timeout) {
|
||||
return write_thread.waitForFinish(timeout);
|
||||
}
|
||||
|
||||
|
||||
@@ -290,10 +294,10 @@ void PIIODevice::stop() {
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stopAndWait(int timeout_ms) {
|
||||
void PIIODevice::stopAndWait(PISystemTime timeout) {
|
||||
stop();
|
||||
waitThreadedReadFinished(timeout_ms);
|
||||
waitThreadedWriteFinished(timeout_ms);
|
||||
waitThreadedReadFinished(timeout);
|
||||
waitThreadedWriteFinished(timeout);
|
||||
}
|
||||
|
||||
|
||||
@@ -327,7 +331,7 @@ void PIIODevice::_init() {
|
||||
opened_ = false;
|
||||
setOptions(0);
|
||||
setReopenEnabled(true);
|
||||
setReopenTimeout(1000);
|
||||
setReopenTimeout(1_s);
|
||||
#ifdef MICRO_PIP
|
||||
threaded_read_buffer_size = 512;
|
||||
#else
|
||||
@@ -375,7 +379,7 @@ void PIIODevice::read_func() {
|
||||
piMSleep(10);
|
||||
bool ok = false;
|
||||
if (reopen_enabled) {
|
||||
if (reopen_tm.elapsed_m() >= reopen_timeout) {
|
||||
if (reopen_tm.elapsed() >= reopen_timeout) {
|
||||
reopen_tm.reset();
|
||||
ok = open();
|
||||
}
|
||||
@@ -394,14 +398,14 @@ void PIIODevice::read_func() {
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIODevice::readForTime(double timeout_ms) {
|
||||
PIByteArray PIIODevice::readForTime(PISystemTime timeout) {
|
||||
PIByteArray str;
|
||||
if (timeout_ms <= 0.) return str;
|
||||
if (timeout.isNull()) return str;
|
||||
ssize_t ret;
|
||||
uchar * td = new uchar[threaded_read_buffer_size];
|
||||
bool was_br = setOption(BlockingRead, false);
|
||||
tm.reset();
|
||||
while (tm.elapsed_m() < timeout_ms) {
|
||||
while (tm.elapsed() < timeout) {
|
||||
ret = read(td, threaded_read_buffer_size);
|
||||
if (ret <= 0)
|
||||
piMinSleep();
|
||||
@@ -477,13 +481,13 @@ bool PIIODevice::configure(const PIString & config_file, const PIString & sectio
|
||||
if (ep != 0) {
|
||||
setReopenEnabled(ep->getValue("reopenEnabled", isReopenEnabled(), &ex).toBool());
|
||||
if (!ex) setReopenEnabled(em.getValue("reopenEnabled", isReopenEnabled()).toBool());
|
||||
setReopenTimeout(ep->getValue("reopenTimeout", reopenTimeout(), &ex).toInt());
|
||||
if (!ex) setReopenTimeout(em.getValue("reopenTimeout", reopenTimeout()).toInt());
|
||||
setReopenTimeout(PISystemTime::fromMilliseconds(ep->getValue("reopenTimeout", reopenTimeout().toMilliseconds(), &ex).toInt()));
|
||||
if (!ex) setReopenTimeout(PISystemTime::fromMilliseconds(em.getValue("reopenTimeout", reopenTimeout().toMilliseconds()).toInt()));
|
||||
setThreadedReadBufferSize(ep->getValue("threadedReadBufferSize", int(threaded_read_buffer_size), &ex).toInt());
|
||||
if (!ex) setThreadedReadBufferSize(em.getValue("threadedReadBufferSize", int(threaded_read_buffer_size)).toInt());
|
||||
} else {
|
||||
setReopenEnabled(em.getValue("reopenEnabled", isReopenEnabled()).toBool());
|
||||
setReopenTimeout(em.getValue("reopenTimeout", reopenTimeout()).toInt());
|
||||
setReopenTimeout(PISystemTime::fromMilliseconds(em.getValue("reopenTimeout", reopenTimeout().toMilliseconds()).toInt()));
|
||||
setThreadedReadBufferSize(em.getValue("threadedReadBufferSize", int(threaded_read_buffer_size)).toInt());
|
||||
}
|
||||
return configureDevice(&em, ep);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "piinit.h"
|
||||
#include "piqueue.h"
|
||||
#include "pitimer.h"
|
||||
#include "pithread.h"
|
||||
|
||||
/// TODO: написать документацию, тут ничего не понятно
|
||||
// function executed from threaded read, pass readedData, sizeOfData, ThreadedReadData
|
||||
@@ -201,21 +201,17 @@ public:
|
||||
//! \~russian Устанавливает возможность вызова \a open() при потоковом чтении на закрытом устройстве
|
||||
void setReopenEnabled(bool yes = true);
|
||||
|
||||
//! \~english Set timeout in milliseconds between \a open() tryings if reopen is enabled
|
||||
//! \~russian Устанавливает задержку в миллисекундах между вызовами \a open() если переоткрытие активно
|
||||
void setReopenTimeout(int msecs);
|
||||
|
||||
//! \~english Set timeout between \a open() tryings if reopen is enabled
|
||||
//! \~russian Устанавливает задержку между вызовами \a open() если переоткрытие активно
|
||||
void setReopenTimeout(PISystemTime timeout) { setReopenTimeout(timeout.toMilliseconds()); }
|
||||
void setReopenTimeout(PISystemTime timeout);
|
||||
|
||||
//! \~english Returns reopen enable
|
||||
//! \~russian Возвращает активно ли переоткрытие
|
||||
bool isReopenEnabled() const { return property("reopenEnabled").toBool(); }
|
||||
|
||||
//! \~english Returns reopen timeout in milliseconds
|
||||
//! \~russian Возвращает задержку переоткрытия в миллисекундах
|
||||
int reopenTimeout() { return property("reopenTimeout").toInt(); }
|
||||
//! \~english Returns reopen timeout
|
||||
//! \~russian Возвращает задержку переоткрытия
|
||||
PISystemTime reopenTimeout() { return property("reopenTimeout").toSystemTime(); }
|
||||
|
||||
|
||||
//! \~english Set threaded read callback
|
||||
@@ -266,13 +262,9 @@ public:
|
||||
//! \~russian Старайтесь не использовать! Этот метод может привести к повреждению памяти!
|
||||
void terminateThreadedRead();
|
||||
|
||||
//! \~english Wait for threaded read finish no longer than "timeout_ms" milliseconds.
|
||||
//! \~russian Ожидает завершения потокового чтения в течении не более "timeout_ms" миллисекунд.
|
||||
bool waitThreadedReadFinished(int timeout_ms = -1);
|
||||
|
||||
//! \~english Wait for threaded read finish no longer than "timeout".
|
||||
//! \~russian Ожидает завершения потокового чтения в течении не более "timeout".
|
||||
bool waitThreadedReadFinished(PISystemTime timeout) { return waitThreadedReadFinished(timeout.toMilliseconds()); }
|
||||
bool waitThreadedReadFinished(PISystemTime timeout = {});
|
||||
|
||||
|
||||
//! \~english Returns if threaded write is started
|
||||
@@ -294,13 +286,9 @@ public:
|
||||
//! \~russian Старайтесь не использовать! Этот метод может привести к повреждению памяти!
|
||||
void terminateThreadedWrite();
|
||||
|
||||
//! \~english Wait for threaded write finish no longer than "timeout_ms" milliseconds.
|
||||
//! \~russian Ожидает завершения потоковой записи в течении не более "timeout_ms" миллисекунд.
|
||||
bool waitThreadedWriteFinished(int timeout_ms = -1);
|
||||
|
||||
//! \~english Wait for threaded write finish no longer than "timeout".
|
||||
//! \~russian Ожидает завершения потоковой записи в течении не более "timeout".
|
||||
bool waitThreadedWriteFinished(PISystemTime timeout) { return waitThreadedWriteFinished(timeout.toMilliseconds()); }
|
||||
bool waitThreadedWriteFinished(PISystemTime timeout = {});
|
||||
|
||||
//! \~english Clear threaded write task queue
|
||||
//! \~russian Очищает очередь потоковой записи
|
||||
@@ -317,11 +305,7 @@ public:
|
||||
|
||||
//! \~english Stop both threaded read and threaded write and wait for finish.
|
||||
//! \~russian Останавливает потоковое чтение и запись и ожидает завершения.
|
||||
void stopAndWait(int timeout_ms = -1);
|
||||
|
||||
//! \~english Stop both threaded read and threaded write and wait for finish.
|
||||
//! \~russian Останавливает потоковое чтение и запись и ожидает завершения.
|
||||
void stopAndWait(PISystemTime timeout) { return stopAndWait(timeout.toMilliseconds()); }
|
||||
void stopAndWait(PISystemTime timeout = {});
|
||||
|
||||
//! \~english Interrupt blocking operation.
|
||||
//! \~russian Прерывает блокирующую операцию.
|
||||
@@ -355,15 +339,9 @@ public:
|
||||
//! \~russian Пишет в устройство не более "max_size" байт из "data"
|
||||
ssize_t write(const void * data, ssize_t max_size);
|
||||
|
||||
//! \~english Read from device for "timeout_ms" milliseconds and return readed data as PIByteArray.
|
||||
//! Timeout should to be greater than 0
|
||||
//! \~russian Читает из устройства в течении "timeout_ms" миллисекунд и возвращает данные как PIByteArray.
|
||||
//! Таймаут должен быть больше 0
|
||||
PIByteArray readForTime(double timeout_ms);
|
||||
|
||||
//! \~english Read from device for "timeout" and return readed data as PIByteArray.
|
||||
//! \~russian Читает из устройства в течении "timeout" и возвращает данные как PIByteArray.
|
||||
PIByteArray readForTime(PISystemTime timeout) { return readForTime(timeout.toMilliseconds()); }
|
||||
PIByteArray readForTime(PISystemTime timeout);
|
||||
|
||||
|
||||
//! \~english Add task to threaded write queue and return task ID
|
||||
@@ -506,8 +484,8 @@ public:
|
||||
//! \~russian setReopenEnabled, по умолчанию "true"
|
||||
bool reopenEnabled;
|
||||
|
||||
//! \~english setReopenTimeout in milliseconds, default 1000
|
||||
//! \~russian setReopenTimeout в миллисекундах, по умолчанию 1000
|
||||
//! \~english setReopenTimeout, default 1_s
|
||||
//! \~russian setReopenTimeout, по умолчанию 1_s
|
||||
int reopenTimeout;
|
||||
|
||||
//! \~english setThreadedReadBufferSize in bytes, default 4096
|
||||
@@ -609,8 +587,9 @@ private:
|
||||
PIThread read_thread, write_thread;
|
||||
PIByteArray buffer_in, buffer_tr;
|
||||
PIQueue<PIPair<PIByteArray, ullong>> write_queue;
|
||||
PISystemTime reopen_timeout;
|
||||
ullong tri = 0;
|
||||
uint threaded_read_buffer_size, reopen_timeout = 1000;
|
||||
uint threaded_read_buffer_size;
|
||||
bool reopen_enabled = true, destroying = false;
|
||||
|
||||
static PIMutex nfp_mutex;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ protected:
|
||||
EVENT_HANDLER2(bool, mbcastRead, const uchar *, readed, ssize_t, size);
|
||||
|
||||
private:
|
||||
EVENT_HANDLER2(void, timerEvent, void *, data, int, delim);
|
||||
EVENT_HANDLER1(void, timerEvent, int, delim);
|
||||
EVENT_HANDLER2(bool, sendInternal, const PIString &, to, const PIByteArray &, data);
|
||||
EVENT_HANDLER2(void, dtReceived, const PIString &, from, const PIByteArray &, data);
|
||||
EVENT_HANDLER1(void, newTcpClient, PIEthernet *, client);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "pidir.h"
|
||||
#include "piincludes_p.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "pitime.h"
|
||||
#include "piwaitevent_p.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
Reference in New Issue
Block a user