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

This commit is contained in:
2017-04-19 17:11:09 +00:00
parent d8b8487dd7
commit fda6fcab79
4 changed files with 15 additions and 6 deletions

View File

@@ -541,8 +541,8 @@ bool PIBaseTransfer::finish_send(bool ok) {
if (!ok) sendBreak(header.session_id); if (!ok) sendBreak(header.session_id);
else sendReply(pt_ReplySuccess); else sendReply(pt_ReplySuccess);
mutex_header.unlock(); mutex_header.unlock();
sendFinished(ok);
piCoutObj << state_string << PIString::readableSize(bytes_all); piCoutObj << state_string << PIString::readableSize(bytes_all);
sendFinished(ok);
// diag.stop(); // diag.stop();
bytes_all = bytes_cur = 0; bytes_all = bytes_cur = 0;
return ok; return ok;
@@ -558,8 +558,8 @@ void PIBaseTransfer::finish_receive(bool ok, bool quet) {
sendBreak(header.session_id); sendBreak(header.session_id);
mutex_header.unlock(); mutex_header.unlock();
} }
receiveFinished(ok);
piCoutObj << state_string << PIString::readableSize(bytes_all); piCoutObj << state_string << PIString::readableSize(bytes_all);
receiveFinished(ok);
// diag.stop(); // diag.stop();
bytes_all = bytes_cur = 0; bytes_all = bytes_cur = 0;
} }

View File

@@ -79,6 +79,7 @@ bool PIFileTransfer::sendFiles(const PIVector<PFTFileInfo> &files) {
// piCout << "prepare" << i << files_[i].path << files_[i].dest_path << files_[i].name(); // piCout << "prepare" << i << files_[i].path << files_[i].dest_path << files_[i].name();
} }
randomize(); randomize();
step_mutex.lock();
pftheader.session_id = randomi(); pftheader.session_id = randomi();
sendFilesStarted(); sendFilesStarted();
cur_file_string = "build session"; cur_file_string = "build session";
@@ -87,17 +88,20 @@ bool PIFileTransfer::sendFiles(const PIVector<PFTFileInfo> &files) {
pftheader.step = pft_Description; pftheader.step = pft_Description;
buildSession(PIVector<Part>() << Part(0, desc.size())); buildSession(PIVector<Part>() << Part(0, desc.size()));
cur_file_string = ""; cur_file_string = "";
step_mutex.unlock();
if (!send_process()) { if (!send_process()) {
sendFilesFinished(false); sendFilesFinished(false);
started_ = false; started_ = false;
return false; return false;
} }
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();
bool ok = send_process(); bool ok = send_process();
sendFilesFinished(ok); sendFilesFinished(ok);
started_ = false; started_ = false;
@@ -222,6 +226,7 @@ void PIFileTransfer::receivePart(PIBaseTransfer::Part fi, PIByteArray ba, PIByte
// piCout << pheader.size() << sizeof(PFTHeader); // piCout << pheader.size() << sizeof(PFTHeader);
pheader >> h; pheader >> h;
// piCout << h.session_id; // piCout << h.session_id;
PIMutexLocker ml(step_mutex);
StepType st = (StepType)h.step; StepType st = (StepType)h.step;
pftheader.step = st; pftheader.step = st;
if (!h.check_sig()) { if (!h.check_sig()) {
@@ -275,7 +280,10 @@ void PIFileTransfer::receive_started() {
void PIFileTransfer::receive_finished(bool ok) { void PIFileTransfer::receive_finished(bool ok) {
if (pftheader.step == pft_Description) { step_mutex.lock();
StepType st = (StepType)pftheader.step;
step_mutex.unlock();
if (st == pft_Description) {
bool user_ok = true; bool user_ok = true;
if (ok) { if (ok) {
// piCoutObj << desc.size() << PICoutManipulators::Hex << desc; // piCoutObj << desc.size() << PICoutManipulators::Hex << desc;
@@ -293,7 +301,7 @@ void PIFileTransfer::receive_finished(bool ok) {
started_ = false; started_ = false;
} else resume(); } else resume();
} }
if (pftheader.step == pft_Data) { if (st == pft_Data) {
//piCoutObj << "file close"; //piCoutObj << "file close";
work_file.close(); work_file.close();
receiveFilesFinished(ok); receiveFilesFinished(ok);

View File

@@ -95,6 +95,7 @@ private:
PIByteArray desc; PIByteArray desc;
PIDir scan_dir; PIDir scan_dir;
bool started_, scanning; bool started_, scanning;
PIMutex step_mutex;
bool sendFiles(const PIVector<PFTFileInfo> &files); bool sendFiles(const PIVector<PFTFileInfo> &files);
void processFile(int id, ullong start, PIByteArray &data); void processFile(int id, ullong start, PIByteArray &data);

View File

@@ -650,7 +650,7 @@ void Daemon::peerDisconnected(const PIString & p_name) {
void Daemon::filesReceived(const PIString & p_name, bool ok) { void Daemon::filesReceived(const PIString & p_name, bool ok) {
piCoutObj << "filesReceived"; piCout << "filesReceived";
closeFileDialog(p_name, ok); closeFileDialog(p_name, ok);
PIMutexLocker ml(remote_mutex); PIMutexLocker ml(remote_mutex);
Remote * r = remotes.value(p_name, 0); Remote * r = remotes.value(p_name, 0);
@@ -660,7 +660,7 @@ void Daemon::filesReceived(const PIString & p_name, bool ok) {
void Daemon::filesSended(const PIString & p_name, bool ok) { void Daemon::filesSended(const PIString & p_name, bool ok) {
piCoutObj << "filesSended"; piCout << "filesSended";
closeFileDialog(p_name, ok); closeFileDialog(p_name, ok);
} }