mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-28 23:05:11 +08:00
Used StreamChunker for clipboard and file transfer #4601
Clipboard is not handled at this point
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "server/Server.h"
|
||||
#include "server/ClientListener.h"
|
||||
#include "client/Client.h"
|
||||
#include "synergy/FileChunk.h"
|
||||
#include "synergy/StreamChunker.h"
|
||||
#include "net/SocketMultiplexer.h"
|
||||
#include "net/NetworkAddress.h"
|
||||
@@ -60,7 +61,6 @@ const size_t kMockFileSize = 1024 * 1024 * 10; // 10MB
|
||||
|
||||
void getScreenShape(SInt32& x, SInt32& y, SInt32& w, SInt32& h);
|
||||
void getCursorPos(SInt32& x, SInt32& y);
|
||||
String intToString(size_t i);
|
||||
UInt8* newMockData(size_t size);
|
||||
void createFile(fstream& file, const char* filename, size_t size);
|
||||
|
||||
@@ -415,38 +415,28 @@ void
|
||||
NetworkTests::sendMockData(void* eventTarget)
|
||||
{
|
||||
// send first message (file size)
|
||||
String size = intToString(kMockDataSize);
|
||||
size_t sizeLength = size.size();
|
||||
StreamChunker::Chunk* sizeMessage = new StreamChunker::Chunk(sizeLength + 2);
|
||||
char* chunkData = sizeMessage->m_chunk;
|
||||
|
||||
chunkData[0] = kDataStart;
|
||||
memcpy(&chunkData[1], size.c_str(), sizeLength);
|
||||
chunkData[sizeLength + 1] = '\0';
|
||||
String size = synergy::string::intToString(kMockDataSize);
|
||||
FileChunk* sizeMessage = FileChunk::start(size);
|
||||
|
||||
m_events.addEvent(Event(m_events.forIScreen().fileChunkSending(), eventTarget, sizeMessage));
|
||||
|
||||
// send chunk messages with incrementing chunk size
|
||||
size_t lastSize = 0;
|
||||
size_t sentLength = 0;
|
||||
while (true) {
|
||||
size_t chunkSize = lastSize + kMockDataChunkIncrement;
|
||||
size_t dataSize = lastSize + kMockDataChunkIncrement;
|
||||
|
||||
// make sure we don't read too much from the mock data.
|
||||
if (sentLength + chunkSize > kMockDataSize) {
|
||||
chunkSize = kMockDataSize - sentLength;
|
||||
if (sentLength + dataSize > kMockDataSize) {
|
||||
dataSize = kMockDataSize - sentLength;
|
||||
}
|
||||
|
||||
// first byte is the chunk mark, last is \0
|
||||
StreamChunker::Chunk* fileChunk = new StreamChunker::Chunk(chunkSize + 2);
|
||||
char* chunkData = fileChunk->m_chunk;
|
||||
FileChunk* chunk = FileChunk::data(m_mockData, dataSize);
|
||||
m_events.addEvent(Event(m_events.forIScreen().fileChunkSending(), eventTarget, chunk));
|
||||
|
||||
chunkData[0] = kDataChunk;
|
||||
memcpy(&chunkData[1], &m_mockData[sentLength], chunkSize);
|
||||
chunkData[chunkSize + 1] = '\0';
|
||||
m_events.addEvent(Event(m_events.forIScreen().fileChunkSending(), eventTarget, fileChunk));
|
||||
|
||||
sentLength += chunkSize;
|
||||
lastSize = chunkSize;
|
||||
sentLength += dataSize;
|
||||
lastSize = dataSize;
|
||||
|
||||
if (sentLength == kMockDataSize) {
|
||||
break;
|
||||
@@ -455,11 +445,7 @@ NetworkTests::sendMockData(void* eventTarget)
|
||||
}
|
||||
|
||||
// send last message
|
||||
StreamChunker::Chunk* transferFinished = new StreamChunker::Chunk(2);
|
||||
chunkData = transferFinished->m_chunk;
|
||||
|
||||
chunkData[0] = kDataEnd;
|
||||
chunkData[1] = '\0';
|
||||
FileChunk* transferFinished = FileChunk::end();
|
||||
m_events.addEvent(Event(m_events.forIScreen().fileChunkSending(), eventTarget, transferFinished));
|
||||
}
|
||||
|
||||
@@ -527,12 +513,4 @@ getCursorPos(SInt32& x, SInt32& y)
|
||||
y = 0;
|
||||
}
|
||||
|
||||
String
|
||||
intToString(size_t i)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << i;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
#endif // WINAPI_CARBON
|
||||
|
||||
76
src/test/unittests/synergy/ClipboardChunkTests.cpp
Normal file
76
src/test/unittests/synergy/ClipboardChunkTests.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2015 Synergy Si Inc.
|
||||
*
|
||||
* 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 LICENSE 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/>.
|
||||
*/
|
||||
|
||||
#include "synergy/ClipboardChunk.h"
|
||||
#include "synergy/protocol_types.h"
|
||||
|
||||
#include "test/global/gtest.h"
|
||||
|
||||
TEST(ClipboardChunkTests, start_formatStartChunk)
|
||||
{
|
||||
ClipboardID id = 0;
|
||||
UInt32 sequence = 0;
|
||||
String mockDataSize("10");
|
||||
ClipboardChunk* chunk = ClipboardChunk::start(id, sequence, mockDataSize);
|
||||
|
||||
EXPECT_EQ(id, chunk->m_chunk[0]);
|
||||
EXPECT_EQ(sequence, (UInt32)chunk->m_chunk[1]);
|
||||
EXPECT_EQ(kDataStart, chunk->m_chunk[5]);
|
||||
EXPECT_EQ('1', chunk->m_chunk[6]);
|
||||
EXPECT_EQ('0', chunk->m_chunk[7]);
|
||||
EXPECT_EQ('\0', chunk->m_chunk[8]);
|
||||
|
||||
delete chunk;
|
||||
}
|
||||
|
||||
TEST(ClipboardChunkTests, data_formatDataChunk)
|
||||
{
|
||||
ClipboardID id = 0;
|
||||
UInt32 sequence = 1;
|
||||
String mockData("mock data");
|
||||
ClipboardChunk* chunk = ClipboardChunk::data(id, sequence, mockData);
|
||||
|
||||
EXPECT_EQ(id, chunk->m_chunk[0]);
|
||||
EXPECT_EQ(sequence, (UInt32)chunk->m_chunk[1]);
|
||||
EXPECT_EQ(kDataChunk, chunk->m_chunk[5]);
|
||||
EXPECT_EQ('m', chunk->m_chunk[6]);
|
||||
EXPECT_EQ('o', chunk->m_chunk[7]);
|
||||
EXPECT_EQ('c', chunk->m_chunk[8]);
|
||||
EXPECT_EQ('k', chunk->m_chunk[9]);
|
||||
EXPECT_EQ(' ', chunk->m_chunk[10]);
|
||||
EXPECT_EQ('d', chunk->m_chunk[11]);
|
||||
EXPECT_EQ('a', chunk->m_chunk[12]);
|
||||
EXPECT_EQ('t', chunk->m_chunk[13]);
|
||||
EXPECT_EQ('a', chunk->m_chunk[14]);
|
||||
EXPECT_EQ('\0', chunk->m_chunk[15]);
|
||||
|
||||
delete chunk;
|
||||
}
|
||||
|
||||
TEST(ClipboardChunkTests, end_formatDataChunk)
|
||||
{
|
||||
ClipboardID id = 1;
|
||||
UInt32 sequence = 1;
|
||||
ClipboardChunk* chunk = ClipboardChunk::end(id, sequence);
|
||||
|
||||
EXPECT_EQ(id, chunk->m_chunk[0]);
|
||||
EXPECT_EQ(sequence, (UInt32)chunk->m_chunk[1]);
|
||||
EXPECT_EQ(kDataEnd, chunk->m_chunk[5]);
|
||||
EXPECT_EQ('\0', chunk->m_chunk[6]);
|
||||
|
||||
delete chunk;
|
||||
}
|
||||
Reference in New Issue
Block a user