2013-07-16 19:02:30 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2013 Bolton Software Ltd.
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "server/ClientProxy1_5.h"
|
|
|
|
|
|
|
|
#include "server/Server.h"
|
|
|
|
#include "synergy/ProtocolUtil.h"
|
|
|
|
#include "io/IStream.h"
|
|
|
|
#include "base/Log.h"
|
2013-07-16 19:02:30 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// CClientProxy1_5
|
|
|
|
//
|
|
|
|
|
2013-07-26 12:44:14 +00:00
|
|
|
const UInt16 CClientProxy1_5::m_intervalThreshold = 1;
|
|
|
|
|
2013-07-16 19:02:30 +00:00
|
|
|
CClientProxy1_5::CClientProxy1_5(const CString& name, synergy::IStream* stream, CServer* server, IEventQueue* events) :
|
2013-07-24 16:41:12 +00:00
|
|
|
CClientProxy1_4(name, stream, server, events),
|
2013-07-26 12:44:14 +00:00
|
|
|
m_events(events),
|
|
|
|
m_stopwatch(true),
|
|
|
|
m_elapsedTime(0),
|
|
|
|
m_receivedDataSize(0)
|
2013-07-16 19:02:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CClientProxy1_5::~CClientProxy1_5()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-30 14:38:43 +00:00
|
|
|
void
|
2014-05-01 13:56:07 +00:00
|
|
|
CClientProxy1_5::sendDragInfo(UInt32 fileCount, const char* data, size_t dataSize)
|
2013-08-30 14:38:43 +00:00
|
|
|
{
|
|
|
|
CString info(data, dataSize);
|
|
|
|
|
|
|
|
CProtocolUtil::writef(getStream(), kMsgDDragInfo, fileCount, &info);
|
|
|
|
}
|
|
|
|
|
2013-07-16 19:02:30 +00:00
|
|
|
void
|
2013-07-24 16:41:12 +00:00
|
|
|
CClientProxy1_5::fileChunkSending(UInt8 mark, char* data, size_t dataSize)
|
2013-07-16 19:02:30 +00:00
|
|
|
{
|
2013-07-24 16:41:12 +00:00
|
|
|
CString chunk(data, dataSize);
|
2013-07-16 19:02:30 +00:00
|
|
|
|
|
|
|
switch (mark) {
|
2013-07-24 16:41:12 +00:00
|
|
|
case kFileStart:
|
|
|
|
LOG((CLOG_DEBUG2 "file sending start: size=%s", data));
|
2013-07-16 19:02:30 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-24 16:41:12 +00:00
|
|
|
case kFileChunk:
|
|
|
|
LOG((CLOG_DEBUG2 "file chunk sending: size=%i", chunk.size()));
|
2013-07-16 19:02:30 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-24 16:41:12 +00:00
|
|
|
case kFileEnd:
|
2013-07-16 19:02:30 +00:00
|
|
|
LOG((CLOG_DEBUG2 "file sending finished"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CProtocolUtil::writef(getStream(), kMsgDFileTransfer, mark, &chunk);
|
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
CClientProxy1_5::parseMessage(const UInt8* code)
|
|
|
|
{
|
|
|
|
if (memcmp(code, kMsgDFileTransfer, 4) == 0) {
|
|
|
|
fileChunkReceived();
|
|
|
|
}
|
2013-08-30 19:49:38 +00:00
|
|
|
else if (memcmp(code, kMsgDDragInfo, 4) == 0) {
|
|
|
|
dragInfoReceived();
|
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
else {
|
|
|
|
return CClientProxy1_4::parseMessage(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_5::fileChunkReceived()
|
|
|
|
{
|
|
|
|
// parse
|
2013-08-30 14:38:43 +00:00
|
|
|
UInt8 mark = 0;
|
2013-07-24 16:41:12 +00:00
|
|
|
CString content;
|
|
|
|
CProtocolUtil::readf(getStream(), kMsgDFileTransfer + 4, &mark, &content);
|
|
|
|
|
|
|
|
CServer* server = getServer();
|
|
|
|
switch (mark) {
|
|
|
|
case kFileStart:
|
|
|
|
server->clearReceivedFileData();
|
|
|
|
server->setExpectedFileSize(content);
|
2013-07-26 12:44:14 +00:00
|
|
|
if (CLOG->getFilter() >= kDEBUG2) {
|
|
|
|
LOG((CLOG_DEBUG2 "recv file data from client: file size=%s", content.c_str()));
|
|
|
|
m_stopwatch.start();
|
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kFileChunk:
|
|
|
|
server->fileChunkReceived(content);
|
2013-07-26 12:44:14 +00:00
|
|
|
if (CLOG->getFilter() >= kDEBUG2) {
|
|
|
|
LOG((CLOG_DEBUG2 "recv file data from client: chunck size=%i", content.size()));
|
|
|
|
double interval = m_stopwatch.getTime();
|
|
|
|
m_receivedDataSize += content.size();
|
|
|
|
LOG((CLOG_DEBUG2 "recv file data from client: interval=%f s", interval));
|
|
|
|
if (interval >= m_intervalThreshold) {
|
|
|
|
double averageSpeed = m_receivedDataSize / interval / 1000;
|
|
|
|
LOG((CLOG_DEBUG2 "recv file data from client: average speed=%f kb/s", averageSpeed));
|
|
|
|
|
|
|
|
m_receivedDataSize = 0;
|
|
|
|
m_elapsedTime += interval;
|
|
|
|
m_stopwatch.reset();
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kFileEnd:
|
2013-08-30 14:38:43 +00:00
|
|
|
m_events->addEvent(CEvent(m_events->forIScreen().fileRecieveCompleted(), server));
|
2013-07-26 12:44:14 +00:00
|
|
|
if (CLOG->getFilter() >= kDEBUG2) {
|
|
|
|
LOG((CLOG_DEBUG2 "file data transfer finished"));
|
|
|
|
m_elapsedTime += m_stopwatch.getTime();
|
|
|
|
double averageSpeed = getServer()->getExpectedFileSize() / m_elapsedTime / 1000;
|
|
|
|
LOG((CLOG_DEBUG2 "file data transfer finished: total time consumed=%f s", m_elapsedTime));
|
|
|
|
LOG((CLOG_DEBUG2 "file data transfer finished: total data received=%i kb", getServer()->getExpectedFileSize() / 1000));
|
|
|
|
LOG((CLOG_DEBUG2 "file data transfer finished: total average speed=%f kb/s", averageSpeed));
|
|
|
|
}
|
2013-07-24 16:41:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-30 19:49:38 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_5::dragInfoReceived()
|
|
|
|
{
|
|
|
|
// parse
|
|
|
|
UInt32 fileNum = 0;
|
|
|
|
CString content;
|
|
|
|
CProtocolUtil::readf(getStream(), kMsgDDragInfo + 4, &fileNum, &content);
|
|
|
|
|
|
|
|
m_server->dragInfoReceived(fileNum, content);
|
|
|
|
}
|