git-svn-id: svn://db.shs.com.ru/pip@526 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-07-15 17:52:29 +00:00
parent 69e067e0d2
commit bc65af3b9c
7 changed files with 42 additions and 35 deletions

Binary file not shown.

View File

@@ -3,15 +3,11 @@
int main(int argc, char *argv[]) {
PIVector2D<double> v(2, 2, PIVector<double>() << 1 << 2 << 3 << 4);
piCout << v;
PIByteArray ba;
ba << v;
piCout << ba.size();
PIVector2D<double> v2;
ba >> v2;
piCout << v2;
piCout << v2[0][1];
PIDir dir("");
PIVector<PIFile::FileInfo> el = dir.entries();
/*piCout << el.size();
piForeachC (PIFile::FileInfo & i, el)
piCout << i;*/
return 0;
}

View File

@@ -169,6 +169,8 @@ inline PIByteArray & operator <<(PIByteArray & s, const float v) {PBA_OPERATOR_T
inline PIByteArray & operator <<(PIByteArray & s, const double & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const ldouble & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator
template<typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIFlags<T> & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()); if (v.size_s() > 0) memcpy(s.data(os), v.data(), v.size()); return s;}
//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details
@@ -205,6 +207,8 @@ inline PIByteArray & operator >>(PIByteArray & s, float & v) {assert(s.size() >=
inline PIByteArray & operator >>(PIByteArray & s, double & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, ldouble & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator
template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIFlags<T> & v) {PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); if (sz > 0) memcpy(v.data(), s.data(), v.size()); s.remove(0, v.size()); return s;}
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details

View File

@@ -515,7 +515,7 @@ PIByteArray PIBaseTransfer::build_packet(int id) {
for (int i = 0; i < session[id].size_s(); i++) {
Part fi = session[id][i];
ret << fi;
//piCout << "biuld" << fi;
//piCout << "build" << fi;
ba = buildPacket(fi);
bytes_cur += ba.size();
if (ba.size() != fi.size) piCoutObj << "***error while build packet, wrong part size";

View File

@@ -73,9 +73,13 @@ bool PIFileTransfer::sendFiles(const PIVector<PFTFileInfo> &files) {
//piCoutObj << "prepare to send" << files_.size() << "files";
for (int i = 0; i < files_.size_s(); i++) {
//files_[i].path = dir.relative(files_[i].path);
if (names.contains(files_[i].path)) {files_.remove(i); i--;}
if (names.contains(files_[i].path)) {
files_.remove(i);
--i;
}
else names << files_[i].path;
if (files_[i].isDir()) files_[i].size = 0;
if (files_[i].isDir())
files_[i].size = 0;
//piCout << "prepare" << i << files_[i].path << files_[i].dest_path << files_[i].name();
}
randomize();
@@ -120,7 +124,7 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
if (fi.isDir()) {
//piCoutObj << "make dir" << fi.entry.path;
if (!PIDir::make(path)) {
cur_file_string = "ERROR! while create directory " + path;
cur_file_string = "Error: While create directory \"" + path + "\"";
piCoutObj << cur_file_string;
stopReceive();
return;
@@ -132,7 +136,7 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
work_file.close();
//piCout << "new file" << path << work_file.path() << work_file.isOpened();
if (!work_file.open(path, PIIODevice::ReadWrite)) {
cur_file_string = "ERROR! while open file " + path;
cur_file_string = "Error: While open file \"" + path + "\"";
piCoutObj << cur_file_string;
stopReceive();
return;
@@ -161,7 +165,7 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
work_file.seek(start);
int rs = work_file.write(data.data(), data.size());
if (rs != data.size_s()) {
cur_file_string = "ERROR! while write file " + fi.path + " (must " + PIString::fromNumber(data.size()) + ", but write " + PIString::fromNumber(rs) + ")";
cur_file_string = "Error: While write file \"" + fi.path + "\" (must " + PIString::fromNumber(data.size()) + ", but write " + PIString::fromNumber(rs) + ")";
piCoutObj << cur_file_string;
stopReceive();
return;
@@ -191,7 +195,7 @@ PIByteArray PIFileTransfer::buildPacket(Part p) {
if (work_file.path() != path || !work_file.isOpened()) {
if (!work_file.open(path, PIIODevice::ReadOnly)) {
break_ = true;
cur_file_string = "ERROR! while open file " + fi.path;
cur_file_string = "Error: While open file \"" + fi.path + "\"";
piCoutObj << cur_file_string;
stopSend();
return PIByteArray();
@@ -202,7 +206,7 @@ PIByteArray PIFileTransfer::buildPacket(Part p) {
int rs = work_file.read(ba.data(), ba.size());
if ((llong)rs != (llong)p.size) {
break_ = true;
cur_file_string = "ERROR! while read file " + fi.path + " (must " + PIString::fromNumber(p.size) + ", but read " + PIString::fromNumber(rs) + ")";
cur_file_string = "Error: While read file \"" + fi.path + "\" (must " + PIString::fromNumber(p.size) + ", but read " + PIString::fromNumber(rs) + ")";
piCoutObj << cur_file_string;
stopSend();
return PIByteArray();
@@ -230,7 +234,7 @@ void PIFileTransfer::receivePart(PIBaseTransfer::Part fi, PIByteArray ba, PIByte
StepType st = (StepType)h.step;
pftheader.step = st;
if (!h.check_sig()) {
cur_file_string = "ERROR check signature: File Transfer incompatable or invalid version!";
cur_file_string = "Error: Check signature: File Transfer incompatable or invalid version!";
piCoutObj << cur_file_string;
stopReceive();
return;

View File

@@ -36,6 +36,7 @@ public:
~PIFileTransfer();
enum StepType {pft_None, pft_Description, pft_Data};
struct PFTFileInfo: public PIFile::FileInfo {
PFTFileInfo(const PIFile::FileInfo &fi = PIFile::FileInfo()): PIFile::FileInfo(fi) {}
PIString dest_path;
@@ -112,9 +113,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::PFTHeade
inline PIByteArray & operator >>(PIByteArray & s, PIFileTransfer::PFTHeader & v) {s >> v.raw_sig >> v.step >> v.session_id; return s;}
inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::PFTFileInfo & v) {s << v.dest_path << v.size << v.time_access << v.time_modification <<
(int)v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;}
v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIFileTransfer::PFTFileInfo & v) {s >> v.dest_path >> v.size >> v.time_access >> v.time_modification >>
*(int*)(&(v.flags)) >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;}
v.flags >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;}
inline PICout operator <<(PICout s, const PIFileTransfer::PFTFileInfo & v) {
s.setControl(0, true);

View File

@@ -212,6 +212,8 @@ void PIIODevice::terminate() {
void PIIODevice::begin() {
//cout << " begin\n";
if (threadedReadBufferSize() == 0)
piCoutObj << "Warning: threadedReadBufferSize() == 0, read may be useless!";
thread_started_ = false;
if (!opened_) {
if (open()) {