State iconsferansfers fixnsfer
git-svn-id: svn://db.shs.com.ru/pip@53 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -146,7 +146,7 @@ bool PIBaseTransfer::send_process() {
|
||||
for (int i = 0; i < session.size_s(); i++) {
|
||||
if (send_queue >= packets_count) {
|
||||
--i;
|
||||
piMSleep(10);
|
||||
piMSleep(1);
|
||||
if (send_tm.elapsed_s() > timeout_) return finish_send(false);
|
||||
if (stm.elapsed_s() > timeout_ / 10.)
|
||||
send_queue = 0;
|
||||
|
||||
@@ -422,5 +422,7 @@ private:
|
||||
};
|
||||
|
||||
inline bool operator <(const PIEthernet::Interface & v0, const PIEthernet::Interface & v1) {return (v0.name < v1.name);}
|
||||
inline bool operator ==(const PIEthernet::Interface & v0, const PIEthernet::Interface & v1) {return (v0.name == v1.name && v0.address == v1.address && v0.netmask == v1.netmask);}
|
||||
inline bool operator !=(const PIEthernet::Interface & v0, const PIEthernet::Interface & v1) {return (v0.name != v1.name || v0.address != v1.address || v0.netmask != v1.netmask);}
|
||||
|
||||
#endif // PIETHERNET_H
|
||||
|
||||
@@ -47,7 +47,7 @@ bool PIFileTransfer::send(PIVector<PIFile::FileInfo> entries) {
|
||||
for (int i = 0; i < entries.size_s(); i++) {
|
||||
allEntries << entries[i];
|
||||
if (entries[i].isDir())
|
||||
allEntries << PIDir::allEntries(dir.absolutePath() + dir.separator + entries[i].path);
|
||||
allEntries << PIDir::allEntries(entries[i].path);
|
||||
}
|
||||
return sendFiles(allEntries);
|
||||
}
|
||||
|
||||
@@ -180,6 +180,7 @@ void PIIODevice::write_func() {
|
||||
|
||||
|
||||
void PIIODevice::terminate() {
|
||||
timer.stop();
|
||||
thread_started_ = false;
|
||||
if (!isInitialized()) return;
|
||||
if (isRunning()) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -159,9 +159,12 @@ private:
|
||||
void sendSelfInfo() {sendPeerInfo(self_info);}
|
||||
void sendSelfRemove() {sendPeerRemove(self_info.name);}
|
||||
void syncPeers();
|
||||
void checkNetwork();
|
||||
void initNetwork();
|
||||
void buildMap();
|
||||
void initEths(PIStringList al);
|
||||
void initMBcasts(PIStringList al);
|
||||
void destroyEths();
|
||||
void destroyMBcasts();
|
||||
void sendMBcast(const PIByteArray & ba);
|
||||
void pingNeighbours();
|
||||
@@ -178,6 +181,7 @@ private:
|
||||
typedef PIPair<PIString, PIVector<PeerInfo * > > napair;
|
||||
|
||||
PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast;
|
||||
PIEthernet::InterfaceList prev_ifaces;
|
||||
PIEthernet eth_send, eth_lo;
|
||||
PITimer timer;
|
||||
PIMutex mc_mutex, eth_mutex, peers_mutex;
|
||||
|
||||
Reference in New Issue
Block a user