BIG deep clean
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Peer - named I/O ethernet node
|
||||
PIP - Platform Independent Primitives
|
||||
Peer - named I/O ethernet node
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pipeer.h"
|
||||
@@ -79,7 +79,6 @@ PIPeer::PeerData::~PeerData() {
|
||||
|
||||
|
||||
void PIPeer::PeerData::dtThread() {
|
||||
// << "send DT ...";
|
||||
dt_out.send(data);
|
||||
//piCoutObj << "send DT done";
|
||||
}
|
||||
@@ -172,13 +171,10 @@ PIPeer::PIPeer(const PIString & n): PIIODevice(), inited__(false), eth_tcp_srv(P
|
||||
read_buffer_size = 128;
|
||||
self_info.dist = 0;
|
||||
self_info.time = PISystemTime::current();
|
||||
//joinMulticastGroup("239.240.241.242");
|
||||
randomize();
|
||||
//id_ = self_info.name + "_" + PIString::fromNumber(randomi());
|
||||
CONNECTU(&sync_timer, tickEvent, this, timerEvent);
|
||||
prev_ifaces = PIEthernet::interfaces();
|
||||
no_timer = false;
|
||||
// initNetwork();
|
||||
sync_timer.addDelimiter(5);
|
||||
}
|
||||
|
||||
@@ -231,7 +227,6 @@ void PIPeer::timerEvent(void * data, int delim) {
|
||||
checkNetwork();
|
||||
break;
|
||||
}
|
||||
//send("broadcast", 9);
|
||||
}
|
||||
|
||||
|
||||
@@ -269,7 +264,6 @@ void PIPeer::initEths(PIStringList al) {
|
||||
|
||||
|
||||
void PIPeer::initMBcasts(PIStringList al) {
|
||||
// destroyMBcasts();
|
||||
PIEthernet * ce;
|
||||
const PIEthernet::Interface * cint;
|
||||
PIString nm;
|
||||
@@ -316,7 +310,6 @@ void PIPeer::initMBcasts(PIStringList al) {
|
||||
//piCoutObj << "invalid address for bcast" << a;
|
||||
}
|
||||
}
|
||||
// eth_lo.setDebug(false);
|
||||
eth_lo.setName("__S__PIPeer_eth_loopback");
|
||||
eth_lo.setParameters(PIEthernet::SeparateSockets);
|
||||
eth_lo.init();
|
||||
@@ -398,17 +391,6 @@ PIPeer::PeerInfo * PIPeer::quickestPeer(const PIString & to) {
|
||||
if (!peers_map.contains(to)) return 0;
|
||||
//piCout << "*** search quickest peer" << to;
|
||||
PIVector<PeerInfo * > tp = addresses_map.value(to);
|
||||
/*PeerInfo * dp = 0;
|
||||
int mping = 0x7FFFFFFF;
|
||||
for (int i = 0; i < tp.size_s(); ++i) {
|
||||
int p = tp[i]->ping();
|
||||
if (mping > p && p > 0) {
|
||||
mping = p;
|
||||
dp = tp[i];
|
||||
}
|
||||
}
|
||||
//piCout << "*** search quickest peer: found" << (dp ? dp->name : "0");
|
||||
return dp;*/
|
||||
if (tp.isEmpty()) return 0;
|
||||
return tp.back();
|
||||
}
|
||||
@@ -471,7 +453,6 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
||||
int type, cnt;
|
||||
PIString from, to;
|
||||
ba >> type;
|
||||
// PIMutexLocker locker(eth_mutex);
|
||||
eth_mutex.lock();
|
||||
// piCout << "dataRead lock";
|
||||
if (type == 5) { // ping request
|
||||
@@ -728,10 +709,8 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
||||
|
||||
|
||||
bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) {
|
||||
//if (peer->_neth == 0) return false;
|
||||
PIEthernet::Address addr = peer->fastestAddress();
|
||||
//piCout << "[PIPeer] sendToNeighbour" << peer->name << addr << ba.size_s() << "bytes ...";
|
||||
//bool ok = peer->_neth->send(peer->_naddress, ba.data(), ba.size_s());
|
||||
send_mutex.lock();
|
||||
bool ok = eth_send.send(addr, ba);
|
||||
//piCout << "[PIPeer] sendToNeighbour" << (ok ? "ok" : "fail");
|
||||
@@ -745,17 +724,11 @@ void PIPeer::sendMBcast(const PIByteArray & ba) {
|
||||
send_mc_mutex.lock();
|
||||
// piCout << "sendMBcast" << ba.size() << "bytes ...";
|
||||
piForeach (PIEthernet * e, eths_mcast) {
|
||||
//errorClear();
|
||||
//piCout << "send to" << e->path() << e->sendAddress();// << e->send(ba);
|
||||
//piCout << PIEthernet::ethErrorString();
|
||||
if (e->isOpened())
|
||||
if (e->send(ba))
|
||||
diag_s.sended(ba.size_s());
|
||||
}
|
||||
piForeach (PIEthernet * e, eths_bcast) {
|
||||
//errorClear();
|
||||
//piCout << "send to" << e->path() << e->sendAddress();// << e->send(ba);
|
||||
//piCout << PIEthernet::ethErrorString();
|
||||
if (e->isOpened())
|
||||
if (e->send(ba))
|
||||
diag_s.sended(ba.size_s());
|
||||
@@ -864,10 +837,6 @@ bool PIPeer::openDevice() {
|
||||
diag_s.reset();
|
||||
//piCoutObj << "open...";
|
||||
return true;
|
||||
// PIMutexLocker ml(peers_mutex);
|
||||
// if (trust_peer.isEmpty())
|
||||
// return !peers.isEmpty();
|
||||
// return hasPeer(trust_peer);
|
||||
}
|
||||
|
||||
|
||||
@@ -931,8 +900,6 @@ void PIPeer::checkNetwork() {
|
||||
|
||||
void PIPeer::reinit() {
|
||||
no_timer = true;
|
||||
// timer.stop();
|
||||
// timer.clearDelimiters();
|
||||
PIMutexLocker mbl(mc_mutex);
|
||||
PIMutexLocker ethl(eth_mutex);
|
||||
// piCout << "reinit lock";
|
||||
@@ -940,14 +907,6 @@ void PIPeer::reinit() {
|
||||
PIMutexLocker sl(send_mutex);
|
||||
initNetwork();
|
||||
sendSelfInfo();
|
||||
// eth_send.close();
|
||||
// eth_lo.stopThreadedRead();
|
||||
// eth_lo.close();
|
||||
// eth_send.init();
|
||||
// eth_send.open();
|
||||
// eth_lo.startThreadedRead();
|
||||
// timer.addDelimiter(5);
|
||||
// timer.start(1000);
|
||||
no_timer = false;
|
||||
if (!sync_timer.isRunning()) sync_timer.start(1000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user