From ff9ad5554a854c329b52221e65dda27326a52b3b Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 22 May 2015 13:30:50 -0700 Subject: [PATCH] Used different chunk size for SSL and non-SSL socket #4601 --- src/lib/synergy/ArgParser.cpp | 2 ++ src/lib/synergy/StreamChunker.cpp | 21 +++++++++++++++++---- src/lib/synergy/StreamChunker.h | 3 ++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp index bcc731ab..a2021481 100644 --- a/src/lib/synergy/ArgParser.cpp +++ b/src/lib/synergy/ArgParser.cpp @@ -17,6 +17,7 @@ #include "synergy/ArgParser.h" +#include "synergy/StreamChunker.h" #include "synergy/App.h" #include "synergy/ServerArgs.h" #include "synergy/ClientArgs.h" @@ -288,6 +289,7 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i) } else if (isArg(i, argc, argv, NULL, "--enable-crypto")) { argsBase().m_enableCrypto = true; + StreamChunker::updateChunkSize(true); } else if (isArg(i, argc, argv, NULL, "--profile-dir", 1)) { argsBase().m_profileDirectory = argv[++i]; diff --git a/src/lib/synergy/StreamChunker.cpp b/src/lib/synergy/StreamChunker.cpp index 60700407..4058385e 100644 --- a/src/lib/synergy/StreamChunker.cpp +++ b/src/lib/synergy/StreamChunker.cpp @@ -35,7 +35,10 @@ using namespace std; -const size_t StreamChunker::m_chunkSize = 512 * 1024; // 512kb +#define SOCKET_CHUNK_SIZE 512 * 1024; // 512kb +#define SECURE_SOCKET_CHUNK_SIZE 2 * 1024; // 2kb + +size_t StreamChunker::s_chunkSize = SOCKET_CHUNK_SIZE; void StreamChunker::sendFile( @@ -61,7 +64,7 @@ StreamChunker::sendFile( // send chunk messages with a fixed chunk size size_t sentLength = 0; - size_t chunkSize = m_chunkSize; + size_t chunkSize = s_chunkSize; Stopwatch stopwatch; stopwatch.start(); file.seekg (0, std::ios::beg); @@ -115,9 +118,8 @@ StreamChunker::sendClipboard( events->addEvent(Event(events->forClipboard().clipboardSending(), eventTarget, sizeMessage)); // send clipboard chunk with a fixed size - // TODO: 4096 fails and this shouldn't a magic number size_t sentLength = 0; - size_t chunkSize = 2048; + size_t chunkSize = s_chunkSize; Stopwatch stopwatch; stopwatch.start(); while (true) { @@ -147,3 +149,14 @@ StreamChunker::sendClipboard( events->addEvent(Event(events->forClipboard().clipboardSending(), eventTarget, end)); } + +void +StreamChunker::updateChunkSize(bool useSecureSocket) +{ + if (useSecureSocket) { + s_chunkSize = SECURE_SOCKET_CHUNK_SIZE; + } + else { + s_chunkSize = SOCKET_CHUNK_SIZE; + } +} diff --git a/src/lib/synergy/StreamChunker.h b/src/lib/synergy/StreamChunker.h index e0b2e1fa..a4be2714 100644 --- a/src/lib/synergy/StreamChunker.h +++ b/src/lib/synergy/StreamChunker.h @@ -35,7 +35,8 @@ public: UInt32 sequence, IEventQueue* events, void* eventTarget); + static void updateChunkSize(bool useSecureSocket); private: - static const size_t m_chunkSize; + static size_t s_chunkSize; };