From 756c3b446300d4345f575c0ffaaec1612e288aa4 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 5 Jun 2015 13:48:06 -0700 Subject: [PATCH] Inserted keep alive msg among data transfer #4584 --- src/lib/server/ClientProxy1_3.h | 5 ++-- src/lib/server/ClientProxy1_5.cpp | 9 ++++++- src/lib/synergy/StreamChunker.cpp | 41 +++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/lib/server/ClientProxy1_3.h b/src/lib/server/ClientProxy1_3.h index 4ec434c2..bd337966 100644 --- a/src/lib/server/ClientProxy1_3.h +++ b/src/lib/server/ClientProxy1_3.h @@ -29,6 +29,8 @@ public: // IClient overrides virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta); + void handleKeepAlive(const Event&, void*); + protected: // ClientProxy overrides virtual bool parseMessage(const UInt8* code); @@ -39,9 +41,6 @@ protected: virtual void removeHeartbeatTimer(); virtual void keepAlive(); -private: - void handleKeepAlive(const Event&, void*); - private: double m_keepAliveRate; EventQueueTimer* m_keepAliveTimer; diff --git a/src/lib/server/ClientProxy1_5.cpp b/src/lib/server/ClientProxy1_5.cpp index 60fc8aa4..4d04f887 100644 --- a/src/lib/server/ClientProxy1_5.cpp +++ b/src/lib/server/ClientProxy1_5.cpp @@ -22,6 +22,7 @@ #include "synergy/StreamChunker.h" #include "synergy/ProtocolUtil.h" #include "io/IStream.h" +#include "base/TMethodEventJob.h" #include "base/Log.h" #include @@ -34,10 +35,16 @@ ClientProxy1_5::ClientProxy1_5(const String& name, synergy::IStream* stream, Ser ClientProxy1_4(name, stream, server, events), m_events(events) { + + m_events->adoptHandler(m_events->forFile().keepAlive(), + this, + new TMethodEventJob(this, + &ClientProxy1_3::handleKeepAlive, NULL)); } ClientProxy1_5::~ClientProxy1_5() { + m_events->removeHandler(m_events->forFile().keepAlive(), this); } void @@ -81,7 +88,7 @@ ClientProxy1_5::fileChunkReceived() if (result == kFinish) { - m_events->addEvent(Event(m_events->forIScreen().fileRecieveCompleted(), server)); + m_events->addEvent(Event(m_events->forFile().fileRecieveCompleted(), server)); } else if (result == kStart) { String filename = server->getFakeDragFileList().at(0).getFilename(); diff --git a/src/lib/synergy/StreamChunker.cpp b/src/lib/synergy/StreamChunker.cpp index 9a94758c..d8474309 100644 --- a/src/lib/synergy/StreamChunker.cpp +++ b/src/lib/synergy/StreamChunker.cpp @@ -31,7 +31,8 @@ #include -#define PAUSE_TIME_HACK 0.1f +#define KEEP_ALIVE_THRESHOLD 1 +#define SEND_THRESHOLD 0.005f using namespace std; @@ -67,14 +68,17 @@ StreamChunker::sendFile( String fileSize = synergy::string::sizeTypeToString(size); FileChunk* sizeMessage = FileChunk::start(fileSize); - events->addEvent(Event(events->forIScreen().fileChunkSending(), eventTarget, sizeMessage)); + events->addEvent(Event(events->forFile().fileChunkSending(), eventTarget, sizeMessage)); // send chunk messages with a fixed chunk size size_t sentLength = 0; size_t chunkSize = s_chunkSize; - Stopwatch stopwatch; - stopwatch.start(); + Stopwatch keepAliveStopwatch; + Stopwatch sendStopwatch; + keepAliveStopwatch.start(); + sendStopwatch.start(); file.seekg (0, std::ios::beg); + while (true) { if (s_interruptFile) { s_interruptFile = false; @@ -82,7 +86,12 @@ StreamChunker::sendFile( break; } - if (stopwatch.getTime() > PAUSE_TIME_HACK) { + if (keepAliveStopwatch.getTime() > KEEP_ALIVE_THRESHOLD) { + events->addEvent(Event(events->forFile().keepAlive(), eventTarget)); + keepAliveStopwatch.reset(); + } + + if (sendStopwatch.getTime() > SEND_THRESHOLD) { // make sure we don't read too much from the mock data. if (sentLength + chunkSize > size) { chunkSize = size - sentLength; @@ -94,7 +103,7 @@ StreamChunker::sendFile( FileChunk* fileChunk = FileChunk::data(data, chunkSize); delete[] chunkData; - events->addEvent(Event(events->forIScreen().fileChunkSending(), eventTarget, fileChunk)); + events->addEvent(Event(events->forFile().fileChunkSending(), eventTarget, fileChunk)); sentLength += chunkSize; file.seekg (sentLength, std::ios::beg); @@ -103,14 +112,14 @@ StreamChunker::sendFile( break; } - stopwatch.reset(); + sendStopwatch.reset(); } } // send last message FileChunk* end = FileChunk::end(); - events->addEvent(Event(events->forIScreen().fileChunkSending(), eventTarget, end)); + events->addEvent(Event(events->forFile().fileChunkSending(), eventTarget, end)); file.close(); @@ -137,8 +146,10 @@ StreamChunker::sendClipboard( // send clipboard chunk with a fixed size size_t sentLength = 0; size_t chunkSize = s_chunkSize; - Stopwatch stopwatch; - stopwatch.start(); + Stopwatch keepAliveStopwatch; + Stopwatch sendStopwatch; + keepAliveStopwatch.start(); + sendStopwatch.start(); while (true) { if (s_interruptClipboard) { @@ -147,7 +158,12 @@ StreamChunker::sendClipboard( break; } - if (stopwatch.getTime() > PAUSE_TIME_HACK) { + if (keepAliveStopwatch.getTime() > KEEP_ALIVE_THRESHOLD) { + events->addEvent(Event(events->forFile().keepAlive(), eventTarget)); + keepAliveStopwatch.reset(); + } + + if (sendStopwatch.getTime() > SEND_THRESHOLD) { // make sure we don't read too much from the mock data. if (sentLength + chunkSize > size) { chunkSize = size - sentLength; @@ -159,12 +175,11 @@ StreamChunker::sendClipboard( events->addEvent(Event(events->forClipboard().clipboardSending(), eventTarget, dataChunk)); sentLength += chunkSize; - if (sentLength == size) { break; } - stopwatch.reset(); + sendStopwatch.reset(); } }