mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 09:11:28 -05:00
added embedded test for FS
This commit is contained in:
parent
8e4a9e6a38
commit
c77b9d1e1f
@ -248,7 +248,8 @@ int FsBioInterface::readdata(void *data, int len)
|
||||
|
||||
int FsBioInterface::senddata(void *data, int len)
|
||||
{
|
||||
return isactive();
|
||||
int written = write(mCLintConnt, data, len);
|
||||
return written;
|
||||
}
|
||||
int FsBioInterface::netstatus()
|
||||
{
|
||||
@ -281,7 +282,8 @@ FsClient::FsClient(const std::string& address)
|
||||
|
||||
bool FsClient::sendItem(RsItem *item)
|
||||
{
|
||||
// request a connection
|
||||
// open a connection
|
||||
|
||||
int CreateSocket = 0,n = 0;
|
||||
char dataReceived[1024];
|
||||
struct sockaddr_in ipOfServer;
|
||||
@ -300,24 +302,48 @@ bool FsClient::sendItem(RsItem *item)
|
||||
|
||||
if(connect(CreateSocket, (struct sockaddr *)&ipOfServer, sizeof(ipOfServer))<0)
|
||||
{
|
||||
printf("Connection failed due to port and ip problems\n");
|
||||
return 1;
|
||||
printf("Connection failed due to port and ip problems, or server is not available\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
while((n = read(CreateSocket, dataReceived, sizeof(dataReceived)-1)) > 0)
|
||||
// Serialise the item and send it.
|
||||
|
||||
uint32_t size = RsSerialiser::MAX_SERIAL_SIZE;
|
||||
RsTemporaryMemory data(size);
|
||||
|
||||
if(!data)
|
||||
{
|
||||
dataReceived[n] = 0;
|
||||
if(fputs(dataReceived, stdout) == EOF)
|
||||
RsErr() << "Cannot allocate memory to send item!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
FsSerializer *fss = new FsSerializer;
|
||||
RsSerialiser rss;
|
||||
rss.addSerialType(fss);
|
||||
|
||||
FsSerializer().serialise(item,data,&size);
|
||||
|
||||
write(CreateSocket,data,size);
|
||||
|
||||
// Now attempt to read and deserialize anything that comes back from that connexion
|
||||
|
||||
FsBioInterface bio(CreateSocket);
|
||||
pqistreamer pqi(&rss,RsPeerId(),&bio,BIN_FLAGS_READABLE);
|
||||
pqithreadstreamer p(&pqi,&rss,RsPeerId(),&bio,BIN_FLAGS_READABLE);
|
||||
p.start();
|
||||
|
||||
while(true)
|
||||
{
|
||||
RsItem *item = p.GetItem();
|
||||
|
||||
if(!item)
|
||||
{
|
||||
printf("\nStandard output error");
|
||||
rstime::rs_usleep(1000*200);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if( n < 0)
|
||||
{
|
||||
printf("Standard input error \n");
|
||||
std::cerr << "Got a response item: " << std::endl;
|
||||
std::cerr << *item << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -26,6 +26,9 @@
|
||||
|
||||
#include "friendserver.h"
|
||||
|
||||
// debug
|
||||
#include "fsitem.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
RsInfo() << "\n" <<
|
||||
@ -54,8 +57,20 @@ int main(int argc, char* argv[])
|
||||
fs.start();
|
||||
|
||||
while(fs.isRunning())
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
|
||||
// send one request for testing to see what happens
|
||||
|
||||
RsFriendServerClientPublishItem *item = new RsFriendServerClientPublishItem();
|
||||
item->long_invite = std::string("[Long Invite]");
|
||||
item->n_requested_friends = 10;
|
||||
|
||||
std::cerr << "Sending fake request item for testing..." << std::endl;
|
||||
FsClient(std::string("127.0.0.1")).sendItem(item);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(4));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user