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[]) { int main(int argc, char *argv[]) {
PIVector2D<double> v(2, 2, PIVector<double>() << 1 << 2 << 3 << 4); PIDir dir("");
piCout << v; PIVector<PIFile::FileInfo> el = dir.entries();
PIByteArray ba; /*piCout << el.size();
ba << v; piForeachC (PIFile::FileInfo & i, el)
piCout << ba.size(); piCout << i;*/
PIVector2D<double> v2;
ba >> v2;
piCout << v2;
piCout << v2[0][1];
return 0; 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;} inline PIByteArray & operator <<(PIByteArray & s, const double & v) {PBA_OPERATOR_TO return s;}
//! \relatesalso PIByteArray \brief Store operator //! \relatesalso PIByteArray \brief Store operator
inline PIByteArray & operator <<(PIByteArray & s, const ldouble & v) {PBA_OPERATOR_TO return s;} 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 //! \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;} 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 //! \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;} inline PIByteArray & operator >>(PIByteArray & s, double & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;}
//! \relatesalso PIByteArray \brief Restore operator //! \relatesalso PIByteArray \brief Restore operator
inline PIByteArray & operator >>(PIByteArray & s, ldouble & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;} 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 //! \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;} 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 //! \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++) { for (int i = 0; i < session[id].size_s(); i++) {
Part fi = session[id][i]; Part fi = session[id][i];
ret << fi; ret << fi;
//piCout << "biuld" << fi; //piCout << "build" << fi;
ba = buildPacket(fi); ba = buildPacket(fi);
bytes_cur += ba.size(); bytes_cur += ba.size();
if (ba.size() != fi.size) piCoutObj << "***error while build packet, wrong part size"; if (ba.size() != fi.size) piCoutObj << "***error while build packet, wrong part size";

View File

@@ -70,13 +70,17 @@ bool PIFileTransfer::send(PIVector<PIFile::FileInfo> entries) {
bool PIFileTransfer::sendFiles(const PIVector<PFTFileInfo> &files) { bool PIFileTransfer::sendFiles(const PIVector<PFTFileInfo> &files) {
files_ = files; files_ = files;
PIStringList names; PIStringList names;
// piCoutObj << "prepare to send" << files_.size() << "files"; //piCoutObj << "prepare to send" << files_.size() << "files";
for(int i=0; i<files_.size_s(); i++) { for (int i = 0; i < files_.size_s(); i++) {
// files_[i].path = dir.relative(files_[i].path); //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; else names << files_[i].path;
if (files_[i].isDir()) files_[i].size = 0; if (files_[i].isDir())
// piCout << "prepare" << i << files_[i].path << files_[i].dest_path << files_[i].name(); files_[i].size = 0;
//piCout << "prepare" << i << files_[i].path << files_[i].dest_path << files_[i].name();
} }
randomize(); randomize();
step_mutex.lock(); step_mutex.lock();
@@ -97,8 +101,8 @@ bool PIFileTransfer::sendFiles(const PIVector<PFTFileInfo> &files) {
step_mutex.lock(); step_mutex.lock();
pftheader.step = pft_Data; pftheader.step = pft_Data;
PIVector<Part> pts; PIVector<Part> pts;
for (int i=0; i<files_.size_s(); i++) { for (int i = 0; i < files_.size_s(); i++) {
pts << Part(i+1, files_[i].size); pts << Part(i + 1, files_[i].size);
} }
buildSession(pts); buildSession(pts);
step_mutex.unlock(); step_mutex.unlock();
@@ -120,7 +124,7 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
if (fi.isDir()) { if (fi.isDir()) {
//piCoutObj << "make dir" << fi.entry.path; //piCoutObj << "make dir" << fi.entry.path;
if (!PIDir::make(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; piCoutObj << cur_file_string;
stopReceive(); stopReceive();
return; return;
@@ -132,7 +136,7 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
work_file.close(); work_file.close();
//piCout << "new file" << path << work_file.path() << work_file.isOpened(); //piCout << "new file" << path << work_file.path() << work_file.isOpened();
if (!work_file.open(path, PIIODevice::ReadWrite)) { 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; piCoutObj << cur_file_string;
stopReceive(); stopReceive();
return; return;
@@ -161,7 +165,7 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) {
work_file.seek(start); work_file.seek(start);
int rs = work_file.write(data.data(), data.size()); int rs = work_file.write(data.data(), data.size());
if (rs != data.size_s()) { 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; piCoutObj << cur_file_string;
stopReceive(); stopReceive();
return; return;
@@ -183,15 +187,15 @@ PIByteArray PIFileTransfer::buildPacket(Part p) {
memcpy(ba.data(), desc.data(p.start), p.size); memcpy(ba.data(), desc.data(p.start), p.size);
return ba; return ba;
case pft_Data: case pft_Data:
// piCout << "send data" << p.id << files_.size(); //piCout << "send data" << p.id << files_.size();
PIFile::FileInfo fi = files_[p.id-1]; PIFile::FileInfo fi = files_[p.id-1];
if (fi.isFile()) { if (fi.isFile()) {
// piCout << "send file" << fi.name() << fi.size; //piCout << "send file" << fi.name() << fi.size;
PIString path = fi.path; PIString path = fi.path;
if (work_file.path() != path || !work_file.isOpened()) { if (work_file.path() != path || !work_file.isOpened()) {
if (!work_file.open(path, PIIODevice::ReadOnly)) { if (!work_file.open(path, PIIODevice::ReadOnly)) {
break_ = true; break_ = true;
cur_file_string = "ERROR! while open file " + fi.path; cur_file_string = "Error: While open file \"" + fi.path + "\"";
piCoutObj << cur_file_string; piCoutObj << cur_file_string;
stopSend(); stopSend();
return PIByteArray(); return PIByteArray();
@@ -202,16 +206,16 @@ PIByteArray PIFileTransfer::buildPacket(Part p) {
int rs = work_file.read(ba.data(), ba.size()); int rs = work_file.read(ba.data(), ba.size());
if ((llong)rs != (llong)p.size) { if ((llong)rs != (llong)p.size) {
break_ = true; 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; piCoutObj << cur_file_string;
stopSend(); stopSend();
return PIByteArray(); return PIByteArray();
} }
} }
// if (fi.isDir()) { //if (fi.isDir()) {
// piCout << "create dir" << fi.path; // piCout << "create dir" << fi.path;
// dir.make(fi.path); // dir.make(fi.path);
// } //}
cur_file_string = fi.path; cur_file_string = fi.path;
bytes_file_all = fi.size; bytes_file_all = fi.size;
bytes_file_cur = p.start; bytes_file_cur = p.start;
@@ -230,7 +234,7 @@ void PIFileTransfer::receivePart(PIBaseTransfer::Part fi, PIByteArray ba, PIByte
StepType st = (StepType)h.step; StepType st = (StepType)h.step;
pftheader.step = st; pftheader.step = st;
if (!h.check_sig()) { 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; piCoutObj << cur_file_string;
stopReceive(); stopReceive();
return; return;

View File

@@ -28,7 +28,7 @@
#define __PIFILETRANSFER_VERSION 2 #define __PIFILETRANSFER_VERSION 2
class PIFileTransfer : public PIBaseTransfer class PIFileTransfer: public PIBaseTransfer
{ {
PIOBJECT_SUBCLASS(PIFileTransfer, PIBaseTransfer) PIOBJECT_SUBCLASS(PIFileTransfer, PIBaseTransfer)
public: public:
@@ -36,8 +36,9 @@ public:
~PIFileTransfer(); ~PIFileTransfer();
enum StepType {pft_None, pft_Description, pft_Data}; enum StepType {pft_None, pft_Description, pft_Data};
struct PFTFileInfo : public PIFile::FileInfo {
PFTFileInfo(const PIFile::FileInfo &fi = PIFile::FileInfo()) : PIFile::FileInfo(fi) {} struct PFTFileInfo: public PIFile::FileInfo {
PFTFileInfo(const PIFile::FileInfo &fi = PIFile::FileInfo()): PIFile::FileInfo(fi) {}
PIString dest_path; 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, 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 << 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 >> 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) { inline PICout operator <<(PICout s, const PIFileTransfer::PFTFileInfo & v) {
s.setControl(0, true); s.setControl(0, true);

View File

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