back to polygonf

git-svn-id: svn://db.shs.com.ru/pip@105 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-04-17 07:19:36 +00:00
parent 022b76bc29
commit 353dbedf77
25 changed files with 143 additions and 106 deletions

View File

@@ -81,7 +81,7 @@ public:
PIDeque<T> * parent;
size_t pos;
public:
iterator(): parent(0) {}
iterator(): parent(0), pos(0) {}
T & operator *() {return (*parent)[pos];}
const T & operator *() const {return (*parent)[pos];}
void operator ++() {++pos;}
@@ -99,7 +99,7 @@ public:
const PIDeque<T> * parent;
size_t pos;
public:
const_iterator(): parent(0) {}
const_iterator(): parent(0), pos(0) {}
//T & operator *() {return (*parent)[pos];}
const T & operator *() const {return (*parent)[pos];}
void operator ++() {++pos;}
@@ -117,7 +117,7 @@ public:
PIDeque<T> * parent;
size_t pos;
public:
reverse_iterator(): parent(0) {}
reverse_iterator(): parent(0), pos(0) {}
T & operator *() {return (*parent)[pos];}
const T & operator *() const {return (*parent)[pos];}
void operator ++() {--pos;}
@@ -135,7 +135,7 @@ public:
const PIDeque<T> * parent;
size_t pos;
public:
const_reverse_iterator(): parent(0) {}
const_reverse_iterator(): parent(0), pos(0) {}
//T & operator *() {return (*parent)[pos];}
const T & operator *() const {return (*parent)[pos];}
void operator ++() {--pos;}
@@ -333,7 +333,7 @@ private:
for (size_t i = 0; i < s; ++i)
elementNew(dst + i, src[i]);
}
inline T * newRaw(size_t s) {
static T * newRaw(size_t s) {
//std::cout << std::dec << " ![("<<this<<")newRaw " << s << " elements ... <" << std::endl;
//uchar * ret = new uchar[s * sizeof(T)];
uchar * ret = (uchar*)(malloc(s * sizeof(T)));//new uchar[];
@@ -354,13 +354,13 @@ private:
}
//cout << " > ok]~" << endl;
}
inline void deleteRaw(T *& d) {
static void deleteRaw(T *& d) {
//cout << " ~[("<<this<<")deleteRaw " << std::dec << pid_rsize << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
if ((uchar*)d != 0) free((uchar*)d);
d = 0;
//cout << " > ok]~" << endl;
}
void zeroRaw(T * d, size_t s) {
static void zeroRaw(T * d, size_t s) {
//cout << " ~[("<<this<<")zeroRaw " << std::dec << s << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
if ((uchar*)d != 0) memset(d, 0, s*sizeof(T));
//cout << " > ok]~" << endl;

View File

@@ -77,7 +77,7 @@ public:
const PIMap<Key, T> * parent;
ssize_t pos;
public:
iterator(): parent(0) {}
iterator(): parent(0), pos(0) {}
const Key & key() const {return const_cast<PIMap<Key, T> * >(parent)->_key(pos);}
T & value() const {return const_cast<PIMap<Key, T> * >(parent)->_value(pos);}
void operator ++() {++pos;}
@@ -95,7 +95,7 @@ public:
const PIMap<Key, T> * parent;
ssize_t pos;
public:
reverse_iterator(): parent(0) {}
reverse_iterator(): parent(0), pos(0) {}
const Key & key() const {return const_cast<PIMap<Key, T> * >(parent)->_key(pos);}
T & value() const {return const_cast<PIMap<Key, T> * >(parent)->_value(pos);}
void operator ++() {--pos;}
@@ -113,7 +113,7 @@ public:
const PIMap<Key, T> * parent;
ssize_t pos;
public:
const_iterator(): parent(0) {}
const_iterator(): parent(0), pos(0) {}
const PIMap<Key, T>::value_type operator *() const {return parent->_pair(pos);}
const PIMap<Key, T>::value_type* operator ->() const {cval = parent->_pair(pos); return &cval;}
void operator ++() {++pos;}
@@ -132,7 +132,7 @@ public:
const PIMap<Key, T> * parent;
ssize_t pos;
public:
const_reverse_iterator(): parent(0) {}
const_reverse_iterator(): parent(0), pos(0) {}
const PIMap<Key, T>::value_type operator *() const {return parent->_pair(pos);}
const PIMap<Key, T>::value_type* operator ->() const {cval = parent->_pair(pos); return &cval;}
void operator ++() {--pos;}
@@ -422,7 +422,7 @@ template<typename Key, typename Type>
inline std::ostream & operator <<(std::ostream & s, const PIMap<Key, Type> & v) {
s << "{";
bool first = true;
for (typename PIMap<Key, Type>::const_iterator i = v.begin(); i != v.end(); i++) {
for (typename PIMap<Key, Type>::const_iterator i = v.begin(); i != v.end(); ++i) {
if (!first)
s << ", ";
first = false;
@@ -438,7 +438,7 @@ inline PICout operator <<(PICout s, const PIMap<Key, Type> & v) {
s.setControl(0, true);
s << "{";
bool first = true;
for (typename PIMap<Key, Type>::const_iterator i = v.begin(); i != v.end(); i++) {
for (typename PIMap<Key, Type>::const_iterator i = v.begin(); i != v.end(); ++i) {
if (!first)
s << ", ";
first = false;

View File

@@ -103,7 +103,7 @@ public:
PIVector<T> * parent;
size_t pos;
public:
iterator(): parent(0) {}
iterator(): parent(0), pos(0) {}
T & operator *() {return (*parent)[pos];}
const T & operator *() const {return (*parent)[pos];}
void operator ++() {++pos;}
@@ -121,7 +121,7 @@ public:
const PIVector<T> * parent;
size_t pos;
public:
const_iterator(): parent(0) {}
const_iterator(): parent(0), pos(0) {}
//T & operator *() {return (*parent)[pos];}
const T & operator *() const {return (*parent)[pos];}
void operator ++() {++pos;}
@@ -139,7 +139,7 @@ public:
PIVector<T> * parent;
size_t pos;
public:
reverse_iterator(): parent(0) {}
reverse_iterator(): parent(0), pos(0) {}
T & operator *() {return (*parent)[pos];}
const T & operator *() const {return (*parent)[pos];}
void operator ++() {--pos;}
@@ -157,7 +157,7 @@ public:
const PIVector<T> * parent;
size_t pos;
public:
const_reverse_iterator(): parent(0) {}
const_reverse_iterator(): parent(0), pos(0) {}
//T & operator *() {return (*parent)[pos];}
const T & operator *() const {return (*parent)[pos];}
void operator ++() {--pos;}
@@ -331,13 +331,13 @@ private:
}
//cout << " > ok]~" << endl;
}
void deleteRaw(T *& d) {
inline void deleteRaw(T *& d) {
//cout << " ~[("<<this<<")deleteRaw " << std::dec << piv_rsize << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
if ((uchar*)d != 0) free((uchar*)d);
d = 0;
//cout << " > ok]~" << endl;
}
void zeroRaw(T * d, size_t s) {
inline void zeroRaw(T * d, size_t s) {
//cout << " ~[("<<this<<")zeroRaw " << std::dec << s << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
if ((uchar*)d != 0) memset(d, 0, s*sizeof(T));
//cout << " > ok]~" << endl;

View File

@@ -91,7 +91,7 @@ public:
void operator =(const ullong & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
private:
uint bytesInBits(const uint & bits) const {return (bits + 7) / 8;}
static uint bytesInBits(const uint & bits) {return (bits + 7) / 8;}
PIVector<uchar> data_;
uint size_;

View File

@@ -154,7 +154,7 @@ PICout PICout::operator <<(const PICoutAction v) {
memset(line, ' ', dx);
line[dx] = 0;
printf("%s", line);
delete line;
delete[] line;
}
SetConsoleCursorPosition(__Private__::hOut, coord);
#else

View File

@@ -175,7 +175,7 @@ public:
PICout operator <<(const PICoutManipulators::PICoutSpecialChar v);
//! Output operator for \a PIFlags<PICoutFormat> values
PICout operator <<(const PIFlags<PICoutManipulators::PICoutFormat> v) {
PICout operator <<(const PIFlags<PICoutManipulators::PICoutFormat> & v) {
if (v[PICoutManipulators::Bin]) cnb_ = 2;
if (v[PICoutManipulators::Oct]) cnb_ = 8;
if (v[PICoutManipulators::Dec]) cnb_ = 10;

View File

@@ -110,7 +110,7 @@ void PIString::appendFromChars(const char * c, int s, const char * cp) {
//printf("appendFromChars %d -> %d\n", s, rs);
for (int i = 0; i < rs; ++i)
push_back(PIChar(ucs[i]));
delete ucs;
delete[] ucs;
ucnv_close(cc);
return;
}
@@ -510,7 +510,7 @@ int PIString::find(const char str, const int start) const {
}
int PIString::find(const PIString str, const int start) const {
int PIString::find(const PIString & str, const int start) const {
int l = str.length();
for (int i = start; i < length() - l + 1; ++i)
if (mid(i, l) == str)
@@ -527,7 +527,7 @@ int PIString::findLast(const char str, const int start) const {
}
int PIString::findLast(const PIString str, const int start) const {
int PIString::findLast(const PIString & str, const int start) const {
int l = str.length();
for (int i = length() - l; i >= start; --i)
if (mid(i, l) == str)

View File

@@ -529,7 +529,7 @@ public:
//! \brief Search substring "str" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::find
int find(const PIString str, const int start = 0) const;
int find(const PIString & str, const int start = 0) const;
//! \brief Search substring "str" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::find
@@ -541,7 +541,7 @@ public:
//! \brief Search substring "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const PIString str, const int start = 0) const;
int findLast(const PIString & str, const int start = 0) const;
//! \brief Search substring "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findLast

View File

@@ -208,7 +208,7 @@ PISystemTime::PISystemTime(const FILETIME & t) {
PISystemTime PISystemTime::abs() const {
if (seconds < 0)
return PISystemTime(piAbsl(seconds) - 1, 1e+9 - piAbsl(nanoseconds));
return PISystemTime(piAbsl(seconds) - 1, 1000000000l - piAbsl(nanoseconds));
else
return PISystemTime(piAbsl(seconds), piAbsl(nanoseconds));
}

View File

@@ -298,10 +298,10 @@ public:
//! \brief Returns PISystemTime elapsed from last \a reset() execution or from timer measurer creation.
PISystemTime elapsed();
double reset_time_n() {return t_st.toNanoseconds();}
double reset_time_u() {return t_st.toMicroseconds();}
double reset_time_m() {return t_st.toMilliseconds();}
double reset_time_s() {return t_st.toSeconds();}
double reset_time_n() const {return t_st.toNanoseconds();}
double reset_time_u() const {return t_st.toMicroseconds();}
double reset_time_m() const {return t_st.toMilliseconds();}
double reset_time_s() const {return t_st.toSeconds();}
//! \brief Returns time mark of last \a reset() execution or timer measurer creation.
PISystemTime reset_time() {return t_st;}

View File

@@ -35,7 +35,7 @@ void PIBaseTransfer::stopSend() {
void PIBaseTransfer::stopReceive() {
if (!is_receiving) return;
break_ = true;
piCoutObj << "stopReceive()";
//piCoutObj << "stopReceive()";
finish_receive(false);
}
@@ -62,7 +62,7 @@ void PIBaseTransfer::received(PIByteArray data) {
diag.received(data.size(), false);
return;
} else diag.received(data.size(), true);
piCoutObj << "receive" << h.session_id << h.type << h.id;
//piCoutObj << "receive" << h.session_id << h.type << h.id;
switch (pt) {
case pt_Unknown: break;
case pt_Data:
@@ -75,7 +75,7 @@ void PIBaseTransfer::received(PIByteArray data) {
if (rcrc != ccrc) {
header.id = h.id;
sendReply(pt_ReplyInvalid);
piCoutObj << "invalid CRC";
//piCoutObj << "invalid CRC";
} else {
processData(h.id, data);
}
@@ -103,7 +103,7 @@ void PIBaseTransfer::received(PIByteArray data) {
break;
case pt_Break:
break_ = true;
piCoutObj << "BREAK";
//piCoutObj << "BREAK";
if (is_receiving) {
stopReceive();
return;
@@ -129,7 +129,7 @@ void PIBaseTransfer::received(PIByteArray data) {
if (header.session_id != h.session_id) {
//sendBreak(h.session_id);
//return;
piCoutObj << "restart receive";
//piCoutObj << "restart receive";
finish_receive(false, true);
} else return;
}
@@ -148,7 +148,7 @@ void PIBaseTransfer::received(PIByteArray data) {
replies.fill(pt_Unknown);
diag.reset();
diag.start(100);
piCoutObj << "receiveStarted()";
//piCoutObj << "receiveStarted()";
is_receiving = true;
break_ = false;
receiveStarted();
@@ -160,16 +160,16 @@ void PIBaseTransfer::received(PIByteArray data) {
break;
case pt_Pause:
if (header.session_id == h.session_id) {
piCout << "receive pause";
//piCout << "receive pause";
if (!is_pause && pause_tm.elapsed_s() < timeout_/10) {
piCout << "resume";
//piCout << "resume";
sendReply(pt_Start);
return;
}
if (!is_pause) paused();
is_pause = true;
if (is_receiving && pause_tm.elapsed_m() > 40) {
piCout << "send pause";
//piCout << "send pause";
sendReply(pt_Pause);
}
if (is_sending) send_tm.reset();
@@ -203,7 +203,7 @@ bool PIBaseTransfer::send_process() {
piMSleep(1);
if (is_pause) {
piMSleep(40);
piCout << "send pause";
//piCout << "send pause";
sendReply(pt_Pause);
if (pause_tm.elapsed_s() > timeout())return finish_send(false);
}
@@ -232,7 +232,7 @@ bool PIBaseTransfer::send_process() {
}
if (is_pause) {
piMSleep(40);
piCout << "send pause";
//piCout << "send pause";
sendReply(pt_Pause);
if (pause_tm.elapsed_s() > timeout())return finish_send(false);
else continue;
@@ -240,7 +240,7 @@ bool PIBaseTransfer::send_process() {
prev_chk = chk;
if (chk > 0) {
if (tm2.elapsed_s() > timeout_ / 10.) {
piCoutObj << "recovery packet" << chk;
//piCoutObj << "recovery packet" << chk;
if (send_queue >= packets_count) {
piMSleep(10);
continue;
@@ -270,7 +270,7 @@ int PIBaseTransfer::checkSession() {
if (replies[i] != pt_ReplySuccess) return i;
}
if (miss > 0) {
piCoutObj << "missing" << miss << "packets";
//piCoutObj << "missing" << miss << "packets";
return -miss;
} else return 0;
}
@@ -289,12 +289,12 @@ void PIBaseTransfer::buildSession(PIVector<Part> parts) {
for (int i = 0; i < parts.size_s(); i++) {
state_string = "calculating parts ... " + PIString::fromNumber(i) + " of " + PIString::fromNumber(parts.size());
fi.id = parts[i].id;
piCout << fi.id << state_string;
//piCout << fi.id << state_string;
bytes_all += parts[i].size;
//fi.size = fi.entry.size;
fi.start = 0;
llong rest = parts[i].size - (packet_size - cur_size);
piCout << i << fi.size << rest << bytes_all;
//piCout << i << fi.size << rest << bytes_all;
if (rest <= 0) {
fi.size = parts[i].size;
lfi << fi;
@@ -334,7 +334,7 @@ void PIBaseTransfer::buildSession(PIVector<Part> parts) {
void PIBaseTransfer::sendBreak(int session_id) {
piCoutObj << "sendBreak";
//piCoutObj << "sendBreak";
uint psid = header.session_id;
header.session_id = session_id;
sendReply(pt_Break);
@@ -343,7 +343,7 @@ void PIBaseTransfer::sendBreak(int session_id) {
void PIBaseTransfer::sendReply(PacketType reply) {
piCoutObj << "sendReply" << reply;
//piCoutObj << "sendReply" << reply;
header.type = reply;
PIByteArray ba;
ba << header;
@@ -379,7 +379,7 @@ bool PIBaseTransfer::getStartRequest() {
void PIBaseTransfer::processData(int id, PIByteArray & data) {
piCoutObj << "received packet" << id << ", size" << data.size();
//piCoutObj << "received packet" << id << ", size" << data.size();
if (id < 1 || id > replies.size_s()) return;
if (!session[id - 1].isEmpty()) {
header.id = id;
@@ -402,7 +402,7 @@ void PIBaseTransfer::processData(int id, PIByteArray & data) {
data >> ba;
//fi.fsize = ba.size();
bytes_cur += fi.size;
piCoutObj << "recv" << fi;
//piCoutObj << "recv" << fi;
session[id - 1] << fi;
state_string = "receiving...";
receivePart(fi, ba, pheader);
@@ -419,13 +419,13 @@ PIByteArray PIBaseTransfer::build_packet(int id) {
PIByteArray ba;
header.id = id + 1;
header.type = pt_Data;
piCoutObj << "session id" << header.session_id;
//piCoutObj << "session id" << header.session_id;
//ret << header;
ret.append(customHeader());
for (int i = 0; i < session[id].size_s(); i++) {
Part fi = session[id][i];
ret << fi;
piCout << "biuld" << fi;
//piCout << "biuld" << fi;
ba = buildPacket(fi);
bytes_cur += ba.size();
if (ba.size() != fi.size) piCoutObj << "***error while build packet, wrong part size";
@@ -434,7 +434,7 @@ PIByteArray PIBaseTransfer::build_packet(int id) {
header.crc = crc.calculate(ret);
PIByteArray hdr; hdr << header;
ret.insert(0, hdr);
piCoutObj << "Packet" << header.id << ret.size();
//piCoutObj << "Packet" << header.id << ret.size();
return ret;
}
@@ -443,7 +443,7 @@ bool PIBaseTransfer::finish_send(bool ok) {
is_sending = false;
if (ok) state_string = "send done";
else state_string = "send failed";
piCoutObj << state_string << PIString::readableSize(bytes_all);
//piCoutObj << state_string << PIString::readableSize(bytes_all);
header.id = 0;
if (!ok) sendBreak(header.session_id);
else sendReply(pt_ReplySuccess);
@@ -458,7 +458,7 @@ void PIBaseTransfer::finish_receive(bool ok, bool quet) {
is_receiving = false;
if (ok) state_string = "receive done";
else state_string = "receive failed";
piCoutObj << state_string << PIString::readableSize(bytes_all);
//piCoutObj << state_string << PIString::readableSize(bytes_all);
if (!ok && !quet) sendBreak(header.session_id);
receiveFinished(ok);
diag.stop();
@@ -469,7 +469,7 @@ void PIBaseTransfer::finish_receive(bool ok, bool quet) {
void PIBaseTransfer::diagChanged(PIDiagnostics::Quality new_quality, PIDiagnostics::Quality old_quality) {
if (is_receiving) {
if (new_quality == PIDiagnostics::Failure) {
piCout << "disconnected!";
//piCout << "disconnected!";
break_ = true;
is_receiving = false;
state_string = "receive failed";

View File

@@ -274,9 +274,9 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
# endif
for (int i = 0; i < cnt; ++i) {
l << PIFile::fileInfo(dp + PIString(list[i]->d_name));
delete list[i];
free(list[i]);
}
delete list;
free(list);
#endif
return l;
}

View File

@@ -532,13 +532,14 @@ int PIEthernet::read(void * read_to, int max_size) {
case UDP:
memset(&PRIVATE->raddr_, 0, sizeof(PRIVATE->raddr_));
rs = ethRecvfrom(sock, read_to, max_size, 0, (sockaddr*)&PRIVATE->raddr_);
//piCout << "eth" << path() << "read return" << rs << errorString();
if (rs > 0) {
port_r = ntohs(PRIVATE->raddr_.sin_port);
ip_r = PIStringAscii(inet_ntoa(PRIVATE->raddr_.sin_addr));
//piCoutObj << "read from" << ip_r << ":" << port_r << rs << "bytes";
//piCout << "received from" << lastReadAddress();
received(read_to, rs);
}
//else piCoutObj << "read returt" << rs << ", error" << ethErrorString();
return rs;
//return ::read(sock, read_to, max_size);
default: break;
@@ -582,7 +583,7 @@ int PIEthernet::write(const void * data, int max_size) {
/*if (params[PIEthernet::Broadcast]) PRIVATE->saddr_.sin_addr.s_addr = INADDR_BROADCAST;
else*/ PRIVATE->saddr_.sin_addr.s_addr = inet_addr(ip_s.dataAscii());
PRIVATE->saddr_.sin_family = AF_INET;
//piCout << "[PIEth] write to" << ip_s << ":" << port_s << "socket" << sock_s << max_size << "bytes ...";
//piCoutObj << "write to" << ip_s << ":" << port_s << "socket" << sock_s << max_size << "bytes ...";
return ethSendto(sock_s, data, max_size, 0, (sockaddr * )&PRIVATE->saddr_, sizeof(PRIVATE->saddr_));
//piCout << "[PIEth] write to" << ip_s << ":" << port_s << "ok";
case TCP_Client:
@@ -819,7 +820,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
ifc.ifc_buf = new char[ifc.ifc_len];
if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
piCout << "[PIEthernet] Can`t get interfaces:" << errorString();
delete ifc.ifc_buf;
delete[] ifc.ifc_buf;
return il;
}
int icnt = ifc.ifc_len / sizeof(ifreq);

View File

@@ -487,7 +487,7 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
if (!info.perm_user.write) attr |= FILE_ATTRIBUTE_READONLY;
if (SetFileAttributes((LPCTSTR)(fp.data()), attr) == 0) {
piCout << "[PIFile] applyFileInfo: \"SetFileAttributes\" error:" << errorString();
return false;
//return false;
}
HANDLE hFile = 0;
if ((attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
@@ -515,11 +515,11 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
if (info.perm_other.exec) mode |= S_IXOTH;
if (chmod(fp.data(), mode) != 0) {
piCout << "[PIFile] applyFileInfo: \"chmod\" error:" << errorString();
return false;
//return false;
}
if (chown(fp.data(), info.id_user, info.id_group) != 0) {
piCout << "[PIFile] applyFileInfo: \"chown\" error:" << errorString();
return false;
//return false;
}
struct timeval tm[2];
PISystemTime st = info.time_access.toSystemTime();
@@ -530,7 +530,7 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
tm[1].tv_usec = st.nanoseconds / 1000;
if (utimes(fp.data(), tm) != 0) {
piCout << "[PIFile] applyFileInfo: \"utimes\" error:" << errorString();
return false;
//return false;
}
#endif
return true;

View File

@@ -243,7 +243,7 @@ PIByteArray PIIODevice::readForTime(double timeout_ms) {
if (ret <= 0) msleep(1);
else str.append(td, ret);
}
delete td;
delete[] td;
return str;
}

View File

@@ -43,7 +43,9 @@ PIPeer::PeerData::PeerData(const PIString & n): PIObject(n) {
PIPeer::PeerData::~PeerData() {
t.stop();
dt_in.stop();
dt_out.stop();
t.stop(true);
}
@@ -55,6 +57,7 @@ void PIPeer::PeerData::dtThread() {
bool PIPeer::PeerData::send(const PIByteArray & d) {
piCout << "send ..." << t.isRunning();
if (t.isRunning()) return false;
data = d;
t.startOnce();
@@ -335,7 +338,7 @@ bool PIPeer::sendInternal(const PIString & to, const PIByteArray & data) {
}
PIByteArray ba;
ba << int(4) << self_info.name << to << int(0) << data;
//piCoutObj << "sendInternal" << to << data.size_s() << int(data.front());
piCoutObj << "sendInternal to" << to << data.size_s() << int(data.front());
if (!sendToNeighbour(dp, ba)) return false;
return true;
}
@@ -355,7 +358,7 @@ bool PIPeer::dataRead(uchar * readed, int size) {
PIString from, to;
ba >> type;
PIMutexLocker locker(eth_mutex);
//piCout << "[PIPeer \"" + name_ + "\"] Received packet" << type;
piCoutObj << "received data from" << from << "packet" << type;
if (type == 5) { // ping request
PIString addr;
PISystemTime time;
@@ -456,7 +459,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
if (type <= 0 || type >= 4) return true;
PeerInfo pi;
ba >> pi.name;
//piCout << "read type" << type << "from" << pi.name;
piCoutObj << "received mb from" << pi.name << "packet" << type;
if (pi.name == self_info.name) return true;
PIMutexLocker locker(mc_mutex);
diag_s.received(size);
@@ -743,6 +746,11 @@ void PIPeer::checkNetwork() {
PIEthernet::InterfaceList ifaces = PIEthernet::interfaces();
if (prev_ifaces == ifaces) return;
prev_ifaces = ifaces;
reinit();
}
void PIPeer::reinit() {
PIMutexLocker mbl(mc_mutex);
PIMutexLocker ethl(eth_mutex);
PIMutexLocker pl(peers_mutex);

View File

@@ -129,6 +129,7 @@ public:
const PeerInfo & selfInfo() const {return self_info;}
const PIMap<PIString, PIVector<PeerInfo * > > & _peerMap() const {return addresses_map;}
void reinit();
void lock() {peers_mutex.lock();}
void unlock() {peers_mutex.unlock();}

View File

@@ -123,19 +123,18 @@ bool PIThread::start(int timer_delay) {
pthread_attr_t attr;
pthread_attr_init(&attr);
# ifndef ANDROID
pthread_attr_setschedparam(&attr, &sparam);
//pthread_attr_setschedparam(&attr, &sparam);
# endif
if (pthread_create(&thread, &attr, thread_function, this) == 0) {
setPriority(priority_);
running_ = true;
return true;
int ret = pthread_create(&thread, &attr, thread_function, this);
pthread_attr_destroy(&attr);
if (ret == 0) {
#else
thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function, this, 0, 0);
if (thread != 0) {
#endif
setPriority(priority_);
running_ = true;
return true;
#endif
} else {
thread = 0;
piCoutObj << "Error: Can`t start new thread:" << errorString();
@@ -151,19 +150,18 @@ bool PIThread::startOnce() {
pthread_attr_t attr;
pthread_attr_init(&attr);
# ifndef ANDROID
pthread_attr_setschedparam(&attr, &sparam);
//pthread_attr_setschedparam(&attr, &sparam);
# endif
if (pthread_create(&thread, &attr, thread_function_once, this) == 0) {
setPriority(priority_);
running_ = true;
return true;
int ret = pthread_create(&thread, &attr, thread_function_once, this);
pthread_attr_destroy(&attr);
if (ret == 0) {
#else
thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function_once, this, 0, 0);
if (thread != 0) {
#endif
setPriority(priority_);
running_ = true;
return false;
#endif
return true;
} else {
thread = 0;
piCoutObj << "Error: Can`t start new thread:" << errorString();
@@ -180,7 +178,9 @@ void PIThread::terminate() {
pthread_kill(thread, SIGKILL);
# else
//pthread_kill(thread, SIGKILL);
void * ret(0);
pthread_cancel(thread);
pthread_join(thread, &ret);
# endif
#else
TerminateThread(thread, 0);
@@ -230,6 +230,9 @@ void * PIThread::thread_function(void * t) {
if (ct.lockRun) ct.mutex_.unlock();
ct.terminating = ct.running_ = false;
//cout << "thread " << t << " exiting ... " << endl;
#ifndef WINDOWS
pthread_detach(ct.thread);
#endif
ct.thread = 0;
#ifndef WINDOWS
pthread_exit(0);
@@ -261,6 +264,9 @@ void * PIThread::thread_function_once(void * t) {
ct.end();
ct.terminating = ct.running_ = false;
//cout << "thread " << t << " exiting ... " << endl;
#ifndef WINDOWS
pthread_detach(ct.thread);
#endif
ct.thread = 0;
#ifndef WINDOWS
pthread_exit(0);
@@ -303,7 +309,7 @@ int PIThread::priority2System(PIThread::Priority p) {
void PIThread::setPriority(PIThread::Priority prior) {
priority_ = prior;
#ifndef WINDOWS
if (!running_ && thread != 0) return;
if (!running_ && (thread != 0)) return;
pthread_getschedparam(thread, &policy_, &sparam);
sparam.
# ifndef LINUX
@@ -314,7 +320,7 @@ void PIThread::setPriority(PIThread::Priority prior) {
= priority2System(priority_);
pthread_setschedparam(thread, policy_, &sparam);
#else
if (!running_ && thread != 0) return;
if (!running_ && (thread != 0)) return;
SetThreadPriority(thread, priority2System(priority_));
#endif
}

View File

@@ -53,6 +53,8 @@
_PITimerBase::_PITimerBase() {
interval_ = deferred_delay = 0.;
running_ = deferred_ = deferred_mode = false;
tfunc = 0;
parent = 0;
}
@@ -188,6 +190,10 @@ bool _PITimerImp_Thread::threadFunc() {
return false;
}
st_time += st_inc;
if (!parent->isPIObject()) {
piCout << "Achtung! PITimer \"parent\" is not PIObject!";
return false;
}
tfunc(parent);
return true;
}