From 30f96b9fbb76f30bd89aa5b871bc30cc20989afe Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Mon, 18 May 2015 10:17:22 -0700 Subject: [PATCH] Renamed FileChunker to StreamChunker #4601 --- src/lib/client/Client.cpp | 10 +++++----- src/lib/server/ClientProxy1_5.cpp | 2 +- src/lib/server/Server.cpp | 8 ++++---- .../{FileChunker.cpp => StreamChunker.cpp} | 15 ++++++++------- .../synergy/{FileChunker.h => StreamChunker.h} | 12 ++++++------ src/test/integtests/net/NetworkTests.cpp | 8 ++++---- 6 files changed, 28 insertions(+), 27 deletions(-) rename src/lib/synergy/{FileChunker.cpp => StreamChunker.cpp} (87%) rename src/lib/synergy/{FileChunker.h => StreamChunker.h} (83%) diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 849dd102..944c06aa 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -27,7 +27,7 @@ #include "synergy/ProtocolUtil.h" #include "synergy/protocol_types.h" #include "synergy/XSynergy.h" -#include "synergy/FileChunker.h" +#include "synergy/StreamChunker.h" #include "synergy/IPlatformScreen.h" #include "mt/Thread.h" #include "net/TCPSocket.h" @@ -422,12 +422,12 @@ Client::sendConnectionFailedEvent(const char* msg) void Client::sendFileChunk(const void* data) { - FileChunker::FileChunk* fileChunk = reinterpret_cast(const_cast(data)); - LOG((CLOG_DEBUG1 "sendFileChunk")); + StreamChunker::Chunk* chunk = reinterpret_cast(const_cast(data)); + LOG((CLOG_DEBUG1 "send file chunk")); assert(m_server != NULL); // relay - m_server->fileChunkSending(fileChunk->m_chunk[0], &(fileChunk->m_chunk[1]), fileChunk->m_dataSize); + m_server->fileChunkSending(chunk->m_chunk[0], &(chunk->m_chunk[1]), chunk->m_size); } void @@ -821,7 +821,7 @@ Client::sendFileThread(void* filename) { try { char* name = reinterpret_cast(filename); - FileChunker::sendFileChunks(name, m_events, this); + StreamChunker::sendFileChunks(name, m_events, this); } catch (std::runtime_error error) { LOG((CLOG_ERR "failed sending file chunks: %s", error.what())); diff --git a/src/lib/server/ClientProxy1_5.cpp b/src/lib/server/ClientProxy1_5.cpp index 5c01b5d5..4135375b 100644 --- a/src/lib/server/ClientProxy1_5.cpp +++ b/src/lib/server/ClientProxy1_5.cpp @@ -18,7 +18,7 @@ #include "server/ClientProxy1_5.h" #include "server/Server.h" -#include "synergy/FileChunker.h" +#include "synergy/StreamChunker.h" #include "synergy/ProtocolUtil.h" #include "io/IStream.h" #include "base/Log.h" diff --git a/src/lib/server/Server.cpp b/src/lib/server/Server.cpp index 999a97b4..c3c98f4b 100644 --- a/src/lib/server/Server.cpp +++ b/src/lib/server/Server.cpp @@ -2033,13 +2033,13 @@ Server::onMouseWheel(SInt32 xDelta, SInt32 yDelta) void Server::onFileChunkSending(const void* data) { - FileChunker::FileChunk* fileChunk = reinterpret_cast(const_cast(data)); + StreamChunker::Chunk* chunk = reinterpret_cast(const_cast(data)); - LOG((CLOG_DEBUG1 "onFileChunkSending")); + LOG((CLOG_DEBUG1 "sending file chunk")); assert(m_active != NULL); // relay - m_active->fileChunkSending(fileChunk->m_chunk[0], &(fileChunk->m_chunk[1]), fileChunk->m_dataSize); + m_active->fileChunkSending(chunk->m_chunk[0], &(chunk->m_chunk[1]), chunk->m_size); } void @@ -2376,7 +2376,7 @@ Server::sendFileThread(void* data) try { char* filename = reinterpret_cast(data); LOG((CLOG_DEBUG "sending file to client, filename=%s", filename)); - FileChunker::sendFileChunks(filename, m_events, this); + StreamChunker::sendFileChunks(filename, m_events, this); } catch (std::runtime_error error) { LOG((CLOG_ERR "failed sending file chunks, error: %s", error.what())); diff --git a/src/lib/synergy/FileChunker.cpp b/src/lib/synergy/StreamChunker.cpp similarity index 87% rename from src/lib/synergy/FileChunker.cpp rename to src/lib/synergy/StreamChunker.cpp index d0289eca..ab105053 100644 --- a/src/lib/synergy/FileChunker.cpp +++ b/src/lib/synergy/StreamChunker.cpp @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -#include "synergy/FileChunker.h" +#include "synergy/StreamChunker.h" #include "synergy/protocol_types.h" #include "base/EventTypes.h" @@ -33,10 +33,10 @@ using namespace std; -const size_t FileChunker::m_chunkSize = 512 * 1024; // 512kb +const size_t StreamChunker::m_chunkSize = 512 * 1024; // 512kb void -FileChunker::sendFileChunks(char* filename, IEventQueue* events, void* eventTarget) +StreamChunker::sendFileChunks(char* filename, IEventQueue* events, void* eventTarget) { std::fstream file(reinterpret_cast(filename), std::ios::in | std::ios::binary); @@ -51,7 +51,7 @@ FileChunker::sendFileChunks(char* filename, IEventQueue* events, void* eventTarg // send first message (file size) String fileSize = intToString(size); size_t sizeLength = fileSize.size(); - FileChunk* sizeMessage = new FileChunk(sizeLength + 2); + Chunk* sizeMessage = new Chunk(sizeLength + 2); char* chunkData = sizeMessage->m_chunk; chunkData[0] = kDataStart; @@ -73,7 +73,7 @@ FileChunker::sendFileChunks(char* filename, IEventQueue* events, void* eventTarg } // for fileChunk->m_chunk, the first byte is the chunk mark, last is \0 - FileChunk* fileChunk = new FileChunk(chunkSize + 2); + Chunk* fileChunk = new Chunk(chunkSize + 2); char* chunkData = fileChunk->m_chunk; chunkData[0] = kDataChunk; @@ -93,7 +93,7 @@ FileChunker::sendFileChunks(char* filename, IEventQueue* events, void* eventTarg } // send last message - FileChunk* transferFinished = new FileChunk(2); + Chunk* transferFinished = new Chunk(2); chunkData = transferFinished->m_chunk; chunkData[0] = kDataEnd; @@ -104,8 +104,9 @@ FileChunker::sendFileChunks(char* filename, IEventQueue* events, void* eventTarg } String -FileChunker::intToString(size_t i) +StreamChunker::intToString(size_t i) { + //TODO: this should be in string stringstream ss; ss << i; return ss.str(); diff --git a/src/lib/synergy/FileChunker.h b/src/lib/synergy/StreamChunker.h similarity index 83% rename from src/lib/synergy/FileChunker.h rename to src/lib/synergy/StreamChunker.h index 38db8166..0560347f 100644 --- a/src/lib/synergy/FileChunker.h +++ b/src/lib/synergy/StreamChunker.h @@ -21,20 +21,20 @@ class IEventQueue; -class FileChunker { +class StreamChunker { public: //! FileChunk data - class FileChunk { + class Chunk { public: - FileChunk(size_t chunkSize) : m_dataSize(chunkSize - 2) + Chunk(size_t size) : m_size(size - 2) { - m_chunk = new char[chunkSize]; + m_chunk = new char[size]; } - ~FileChunk() { delete[] m_chunk; } + ~Chunk() { delete[] m_chunk; } public: - const size_t m_dataSize; + const size_t m_size; char* m_chunk; }; diff --git a/src/test/integtests/net/NetworkTests.cpp b/src/test/integtests/net/NetworkTests.cpp index fb358bde..21097163 100644 --- a/src/test/integtests/net/NetworkTests.cpp +++ b/src/test/integtests/net/NetworkTests.cpp @@ -28,7 +28,7 @@ #include "server/Server.h" #include "server/ClientListener.h" #include "client/Client.h" -#include "synergy/FileChunker.h" +#include "synergy/StreamChunker.h" #include "net/SocketMultiplexer.h" #include "net/NetworkAddress.h" #include "net/TCPSocketFactory.h" @@ -417,7 +417,7 @@ NetworkTests::sendMockData(void* eventTarget) // send first message (file size) String size = intToString(kMockDataSize); size_t sizeLength = size.size(); - FileChunker::FileChunk* sizeMessage = new FileChunker::FileChunk(sizeLength + 2); + StreamChunker::Chunk* sizeMessage = new StreamChunker::Chunk(sizeLength + 2); char* chunkData = sizeMessage->m_chunk; chunkData[0] = kDataStart; @@ -437,7 +437,7 @@ NetworkTests::sendMockData(void* eventTarget) } // first byte is the chunk mark, last is \0 - FileChunker::FileChunk* fileChunk = new FileChunker::FileChunk(chunkSize + 2); + StreamChunker::Chunk* fileChunk = new StreamChunker::Chunk(chunkSize + 2); char* chunkData = fileChunk->m_chunk; chunkData[0] = kDataChunk; @@ -455,7 +455,7 @@ NetworkTests::sendMockData(void* eventTarget) } // send last message - FileChunker::FileChunk* transferFinished = new FileChunker::FileChunk(2); + StreamChunker::Chunk* transferFinished = new StreamChunker::Chunk(2); chunkData = transferFinished->m_chunk; chunkData[0] = kDataEnd;