back to polygonf
git-svn-id: svn://db.shs.com.ru/pip@106 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -371,10 +371,12 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
|||||||
if (pi->isNeighbour()) {
|
if (pi->isNeighbour()) {
|
||||||
sba << int(6) << to << from << addr << time;
|
sba << int(6) << to << from << addr << time;
|
||||||
//piCout << "ping from" << from << addr << ", send back to" << pi->name;
|
//piCout << "ping from" << from << addr << ", send back to" << pi->name;
|
||||||
|
send_mutex.lock();
|
||||||
piForeachC (PeerInfo::Address & a, pi->addresses) {
|
piForeachC (PeerInfo::Address & a, pi->addresses) {
|
||||||
if (eth_send.send(a.address, sba))
|
if (eth_send.send(a.address, sba))
|
||||||
diag_s.received(sba.size_s());
|
diag_s.received(sba.size_s());
|
||||||
}
|
}
|
||||||
|
send_mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -597,9 +599,11 @@ bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) {
|
|||||||
PIString addr = peer->fastestAddress();
|
PIString addr = peer->fastestAddress();
|
||||||
//piCout << "[PIPeer] sendToNeighbour" << peer->name << addr << ba.size_s() << "bytes ...";
|
//piCout << "[PIPeer] sendToNeighbour" << peer->name << addr << ba.size_s() << "bytes ...";
|
||||||
//bool ok = peer->_neth->send(peer->_naddress, ba.data(), ba.size_s());
|
//bool ok = peer->_neth->send(peer->_naddress, ba.data(), ba.size_s());
|
||||||
|
send_mutex.lock();
|
||||||
bool ok = eth_send.send(addr, ba);
|
bool ok = eth_send.send(addr, ba);
|
||||||
//piCout << "[PIPeer] sendToNeighbour" << (ok ? "ok" : "fail");
|
//piCout << "[PIPeer] sendToNeighbour" << (ok ? "ok" : "fail");
|
||||||
if (ok) diag_d.sended(ba.size_s());
|
if (ok) diag_d.sended(ba.size_s());
|
||||||
|
send_mutex.unlock();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,6 +683,7 @@ void PIPeer::pingNeighbours() {
|
|||||||
piForeach (PeerInfo & p, peers) {
|
piForeach (PeerInfo & p, peers) {
|
||||||
//piCout << " ping neighbour" << p.name << p.ping();
|
//piCout << " ping neighbour" << p.name << p.ping();
|
||||||
if (!p.isNeighbour()) continue;
|
if (!p.isNeighbour()) continue;
|
||||||
|
send_mutex.lock();
|
||||||
piForeach (PeerInfo::Address & a, p.addresses) {
|
piForeach (PeerInfo::Address & a, p.addresses) {
|
||||||
//piCout << " address" << a.address << a.wait_ping;
|
//piCout << " address" << a.address << a.wait_ping;
|
||||||
if (a.wait_ping) {
|
if (a.wait_ping) {
|
||||||
@@ -693,6 +698,7 @@ void PIPeer::pingNeighbours() {
|
|||||||
if (eth_send.send(a.address, sba))
|
if (eth_send.send(a.address, sba))
|
||||||
diag_s.sended(sba.size_s());
|
diag_s.sended(sba.size_s());
|
||||||
}
|
}
|
||||||
|
send_mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,6 +760,7 @@ void PIPeer::reinit() {
|
|||||||
PIMutexLocker mbl(mc_mutex);
|
PIMutexLocker mbl(mc_mutex);
|
||||||
PIMutexLocker ethl(eth_mutex);
|
PIMutexLocker ethl(eth_mutex);
|
||||||
PIMutexLocker pl(peers_mutex);
|
PIMutexLocker pl(peers_mutex);
|
||||||
|
PIMutexLocker sl(send_mutex);
|
||||||
initNetwork();
|
initNetwork();
|
||||||
eth_send.close();
|
eth_send.close();
|
||||||
eth_lo.stopThreadedRead();
|
eth_lo.stopThreadedRead();
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ private:
|
|||||||
PIEthernet::InterfaceList prev_ifaces;
|
PIEthernet::InterfaceList prev_ifaces;
|
||||||
PIEthernet eth_send, eth_lo;
|
PIEthernet eth_send, eth_lo;
|
||||||
PITimer timer;
|
PITimer timer;
|
||||||
PIMutex mc_mutex, eth_mutex, peers_mutex;
|
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex;
|
||||||
|
|
||||||
PeerInfo self_info;
|
PeerInfo self_info;
|
||||||
PIVector<PeerInfo> peers;
|
PIVector<PeerInfo> peers;
|
||||||
|
|||||||
@@ -120,6 +120,11 @@ _PITimerImp_Thread::~_PITimerImp_Thread() {
|
|||||||
|
|
||||||
|
|
||||||
void _PITimerImp_Thread::prepareStart(double interval_ms) {
|
void _PITimerImp_Thread::prepareStart(double interval_ms) {
|
||||||
|
if (interval_ms <= 0.) {
|
||||||
|
piCout << "Achtung! Start PITimer with interval <= 0!";
|
||||||
|
piCout << "Achtung! Parent" << parent;
|
||||||
|
assert(interval_ms > 0.);
|
||||||
|
}
|
||||||
st_inc = PISystemTime::fromMilliseconds(interval_ms);
|
st_inc = PISystemTime::fromMilliseconds(interval_ms);
|
||||||
st_odt = st_inc * 5;
|
st_odt = st_inc * 5;
|
||||||
if (st_odt.toSeconds() < 1.) st_odt = PISystemTime::fromSeconds(1.);
|
if (st_odt.toSeconds() < 1.) st_odt = PISystemTime::fromSeconds(1.);
|
||||||
@@ -302,6 +307,7 @@ _PITimerImp_Pool::Pool::~Pool() {
|
|||||||
stop();
|
stop();
|
||||||
if (!waitForFinish(100))
|
if (!waitForFinish(100))
|
||||||
terminate();
|
terminate();
|
||||||
|
unlock();
|
||||||
timers.clear();
|
timers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user