mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 17:21:27 -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)
|
int FsBioInterface::senddata(void *data, int len)
|
||||||
{
|
{
|
||||||
return isactive();
|
int written = write(mCLintConnt, data, len);
|
||||||
|
return written;
|
||||||
}
|
}
|
||||||
int FsBioInterface::netstatus()
|
int FsBioInterface::netstatus()
|
||||||
{
|
{
|
||||||
@ -281,7 +282,8 @@ FsClient::FsClient(const std::string& address)
|
|||||||
|
|
||||||
bool FsClient::sendItem(RsItem *item)
|
bool FsClient::sendItem(RsItem *item)
|
||||||
{
|
{
|
||||||
// request a connection
|
// open a connection
|
||||||
|
|
||||||
int CreateSocket = 0,n = 0;
|
int CreateSocket = 0,n = 0;
|
||||||
char dataReceived[1024];
|
char dataReceived[1024];
|
||||||
struct sockaddr_in ipOfServer;
|
struct sockaddr_in ipOfServer;
|
||||||
@ -300,24 +302,48 @@ bool FsClient::sendItem(RsItem *item)
|
|||||||
|
|
||||||
if(connect(CreateSocket, (struct sockaddr *)&ipOfServer, sizeof(ipOfServer))<0)
|
if(connect(CreateSocket, (struct sockaddr *)&ipOfServer, sizeof(ipOfServer))<0)
|
||||||
{
|
{
|
||||||
printf("Connection failed due to port and ip problems\n");
|
printf("Connection failed due to port and ip problems, or server is not available\n");
|
||||||
return 1;
|
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;
|
RsErr() << "Cannot allocate memory to send item!" << std::endl;
|
||||||
if(fputs(dataReceived, stdout) == EOF)
|
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");
|
std::cerr << "Got a response item: " << std::endl;
|
||||||
}
|
std::cerr << *item << std::endl;
|
||||||
|
|
||||||
if( n < 0)
|
|
||||||
{
|
|
||||||
printf("Standard input error \n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
#include "friendserver.h"
|
#include "friendserver.h"
|
||||||
|
|
||||||
|
// debug
|
||||||
|
#include "fsitem.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
RsInfo() << "\n" <<
|
RsInfo() << "\n" <<
|
||||||
@ -54,8 +57,20 @@ int main(int argc, char* argv[])
|
|||||||
fs.start();
|
fs.start();
|
||||||
|
|
||||||
while(fs.isRunning())
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user