State iconsferansfers fixnsfer
git-svn-id: svn://db.shs.com.ru/pip@53 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -131,13 +131,11 @@ PIPeer::PIPeer(const PIString & name_): PIObject() {
|
||||
srand(uint(PISystemTime::current(true).toMicroseconds()));
|
||||
//id_ = self_info.name + "_" + PIString::fromNumber(rand());
|
||||
CONNECTU(&timer, tickEvent, this, timerEvent);
|
||||
PIStringList sl = PIEthernet::allAddresses();
|
||||
initEths(sl);
|
||||
sl.removeAll("127.0.0.1");
|
||||
initMBcasts(sl);
|
||||
initNetwork();
|
||||
sendSelfInfo();
|
||||
prev_ifaces = PIEthernet::interfaces();
|
||||
timer.addDelimiter(5);
|
||||
timer.start(200);
|
||||
timer.start(1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -145,11 +143,7 @@ PIPeer::~PIPeer() {
|
||||
timer.stop();
|
||||
diag_s.stop();
|
||||
diag_d.stop();
|
||||
piForeach (PIEthernet * i, eths_traffic) {
|
||||
i->stopThreadedRead();
|
||||
delete i;
|
||||
}
|
||||
eths_traffic.clear();
|
||||
destroyEths();
|
||||
piForeach (PIEthernet * i, eths_mcast)
|
||||
i->stopThreadedRead();
|
||||
piForeach (PIEthernet * i, eths_bcast)
|
||||
@@ -163,9 +157,12 @@ PIPeer::~PIPeer() {
|
||||
|
||||
void PIPeer::timerEvent(void * data, int delim) {
|
||||
switch (delim) {
|
||||
case 5: // 1 s
|
||||
case 1: // every 1 s
|
||||
syncPeers();
|
||||
break;
|
||||
case 5: // every 5 s
|
||||
checkNetwork();
|
||||
break;
|
||||
}
|
||||
//send("broadcast", 9);
|
||||
}
|
||||
@@ -260,14 +257,29 @@ void PIPeer::initMBcasts(PIStringList al) {
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::destroyMBcasts() {
|
||||
piForeach (PIEthernet * i, eths_mcast) {
|
||||
i->leaveMulticastGroup(_PIPEER_MULTICAST_IP);
|
||||
void PIPeer::destroyEths() {
|
||||
piForeach (PIEthernet * i, eths_traffic) {
|
||||
i->stopThreadedRead();
|
||||
i->close();
|
||||
delete i;
|
||||
}
|
||||
piForeach (PIEthernet * i, eths_bcast)
|
||||
eths_traffic.clear();
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::destroyMBcasts() {
|
||||
piForeach (PIEthernet * i, eths_mcast) {
|
||||
i->stopThreadedRead();
|
||||
i->leaveMulticastGroup(_PIPEER_MULTICAST_IP);
|
||||
i->close();
|
||||
delete i;
|
||||
eth_lo.stop();
|
||||
}
|
||||
piForeach (PIEthernet * i, eths_bcast) {
|
||||
i->stopThreadedRead();
|
||||
i->close();
|
||||
delete i;
|
||||
}
|
||||
eth_lo.stopThreadedRead();
|
||||
eth_lo.close();
|
||||
eths_mcast.clear();
|
||||
eths_bcast.clear();
|
||||
@@ -335,7 +347,7 @@ void PIPeer::dtReceived(const PIString & from, const PIByteArray & data) {
|
||||
bool PIPeer::dataRead(uchar * readed, int size) {
|
||||
if (size < 16) return true;
|
||||
PIByteArray ba(readed, size), sba, pba;
|
||||
int type, cnt, rec_size;
|
||||
int type, cnt;
|
||||
PIString from, to;
|
||||
ba >> type;
|
||||
PIMutexLocker locker(eth_mutex);
|
||||
@@ -718,6 +730,28 @@ void PIPeer::syncPeers() {
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::checkNetwork() {
|
||||
PIEthernet::InterfaceList ifaces = PIEthernet::interfaces();
|
||||
if (prev_ifaces == ifaces) return;
|
||||
prev_ifaces = ifaces;
|
||||
PIMutexLocker mbl(mc_mutex);
|
||||
PIMutexLocker ethl(eth_mutex);
|
||||
initNetwork();
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::initNetwork() {
|
||||
destroyEths();
|
||||
destroyMBcasts();
|
||||
piCoutObj << "initNetwork";
|
||||
self_info.addresses.clear();
|
||||
PIStringList sl = PIEthernet::allAddresses();
|
||||
initEths(sl);
|
||||
sl.removeAll("127.0.0.1");
|
||||
initMBcasts(sl);
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::buildMap() {
|
||||
//piCout << "[PIPeer \"" + name_ + "\"] buildMap";
|
||||
peers_map.clear();
|
||||
|
||||
Reference in New Issue
Block a user