Inserted keep alive msg among data transfer #4584

This commit is contained in:
Jerry (Xinyu Hou) 2015-06-05 13:48:06 -07:00
parent bbf53bb9b8
commit 756c3b4463
3 changed files with 38 additions and 17 deletions

View File

@ -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;

View File

@ -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 <sstream>
@ -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<ClientProxy1_3>(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();

View File

@ -31,7 +31,8 @@
#include <fstream>
#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();
}
}