mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
83720439f0
Bugfixes for 'sleep' issues under windows. Extra debugging for transfer module. Fixed channel directory creation. (extra 'break' statement) Fixed very slow transfers on Windows platform (uninitialised variable) Ready for win/linux/osx release now. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@830 b45a01b8-16f6-495d-af2f-9b41ad6348cc
94 lines
2.0 KiB
C++
94 lines
2.0 KiB
C++
#include "ftfileprovider.h"
|
|
#include "ftfilecreator.h"
|
|
|
|
#include "util/utest.h"
|
|
#include <stdlib.h>
|
|
|
|
#include "util/rswin.h"
|
|
|
|
INITTEST()
|
|
|
|
int main()
|
|
{
|
|
|
|
/* create a random file */
|
|
uint64_t size = 100000;
|
|
uint32_t max_chunk = 10000;
|
|
uint32_t chunk = 1000;
|
|
uint64_t offset = 0;
|
|
|
|
std::string filename = "/tmp/ft_test.dta";
|
|
std::string filename2 = "/tmp/ft_test.dta.dup";
|
|
|
|
/* use creator to make it */
|
|
|
|
void *data = malloc(max_chunk);
|
|
for(int i = 0; i < max_chunk; i++)
|
|
{
|
|
((uint8_t *) data)[i] = 'a' + i % 27;
|
|
if (i % 27 == 26)
|
|
{
|
|
((uint8_t *) data)[i] = '\n';
|
|
}
|
|
}
|
|
|
|
ftFileCreator *creator = new ftFileCreator(filename, size, "hash", 0);
|
|
for(offset = 0; offset != size; offset += chunk)
|
|
{
|
|
if (!creator->addFileData(offset, chunk, data))
|
|
{
|
|
FAILED("Create Test Data File");
|
|
std::cerr << "Failed to add data (CREATE)";
|
|
std::cerr << std::endl;
|
|
}
|
|
}
|
|
delete creator;
|
|
|
|
std::cerr << "Created file: " << filename << " of size: " << size;
|
|
std::cerr << std::endl;
|
|
|
|
/* load it with file provider */
|
|
creator = new ftFileCreator(filename2, size, "hash", 0);
|
|
ftFileProvider *provider = new ftFileProvider(filename, size, "hash");
|
|
|
|
/* create duplicate with file creator */
|
|
|
|
while(creator->getMissingChunk(offset, chunk))
|
|
{
|
|
if (chunk == 0)
|
|
{
|
|
std::cerr << "All currently allocated .... waiting";
|
|
std::cerr << std::endl;
|
|
sleep(1);
|
|
/* reset chunk size */
|
|
chunk = (uint64_t) max_chunk * (rand() / (1.0 + RAND_MAX));
|
|
std::cerr << "ChunkSize = " << chunk << std::endl;
|
|
continue;
|
|
}
|
|
|
|
if (!provider->getFileData(offset, chunk, data))
|
|
{
|
|
FAILED("Read from Test Data File");
|
|
std::cerr << "Failed to get data";
|
|
std::cerr << std::endl;
|
|
}
|
|
|
|
if (!creator->addFileData(offset, chunk, data))
|
|
{
|
|
FAILED("Write to Duplicate");
|
|
std::cerr << "Failed to add data";
|
|
std::cerr << std::endl;
|
|
}
|
|
|
|
std::cerr << "Transferred: " << chunk << " @ " << offset;
|
|
std::cerr << std::endl;
|
|
|
|
|
|
/* reset chunk size */
|
|
chunk = (uint64_t) max_chunk * (rand() / (1.0 + RAND_MAX));
|
|
|
|
std::cerr << "ChunkSize = " << chunk << std::endl;
|
|
}
|
|
return 1;
|
|
}
|