mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 08:59:37 -05:00
fixed two-ways communication between client and server
This commit is contained in:
parent
aff7912f41
commit
25ddbe099d
@ -127,12 +127,8 @@ bool FsClient::sendItem(const std::string& address,uint16_t port,RsItem *item,st
|
||||
RsSerialiser *rss = new RsSerialiser(); // deleted by ~pqistreamer()
|
||||
rss->addSerialType(fss);
|
||||
|
||||
FsSerializer().serialise(item,data,&size);
|
||||
write(CreateSocket,data,size); // shouldn't we use the pqistreamer in R/W mode instead?
|
||||
|
||||
RsDbg() << "Item sent. Waiting for response..." ;
|
||||
|
||||
// Now attempt to read and deserialize anything that comes back from that connexion until it gets closed by the server.
|
||||
// FsSerializer().serialise(item,data,&size);
|
||||
// write(CreateSocket,data,size); // shouldn't we use the pqistreamer in R/W mode instead?
|
||||
|
||||
FsBioInterface *bio = new FsBioInterface(CreateSocket); // deleted by ~pqistreamer()
|
||||
|
||||
@ -141,7 +137,10 @@ bool FsClient::sendItem(const std::string& address,uint16_t port,RsItem *item,st
|
||||
|
||||
uint32_t ss;
|
||||
p.SendItem(item,ss);
|
||||
bool should_close = false;
|
||||
|
||||
RsDbg() << "Item sent. Waiting for response..." ;
|
||||
|
||||
// Now attempt to read and deserialize anything that comes back from that connexion until it gets closed by the server.
|
||||
|
||||
while(true)
|
||||
{
|
||||
@ -157,37 +156,21 @@ bool FsClient::sendItem(const std::string& address,uint16_t port,RsItem *item,st
|
||||
std::cerr << "Got a response item: " << std::endl;
|
||||
std::cerr << *item << std::endl;
|
||||
|
||||
should_close = true; // always close the socket after one packet
|
||||
|
||||
if(dynamic_cast<RsFriendServerStatusItem*>(item) != nullptr)
|
||||
{
|
||||
RsDbg() << "End of transmission. " ;
|
||||
should_close = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!bio->isactive()) // socket has probably closed
|
||||
{
|
||||
RsDbg() << "(client side) Socket has been closed by server.";
|
||||
should_close =true;
|
||||
break;
|
||||
}
|
||||
RsDbg() << "End of transmission. " ;
|
||||
break;
|
||||
}
|
||||
else
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
if(should_close)
|
||||
{
|
||||
RsDbg() << " Stopping/killing pqistreamer" ;
|
||||
p.fullstop();
|
||||
RsDbg() << " Stopping/killing pqistreamer" ;
|
||||
p.fullstop();
|
||||
|
||||
RsDbg() << " Closing socket." ;
|
||||
close(CreateSocket);
|
||||
CreateSocket=0;
|
||||
RsDbg() << " Closing socket." ;
|
||||
close(CreateSocket);
|
||||
CreateSocket=0;
|
||||
|
||||
RsDbg() << " Exiting loop." ;
|
||||
}
|
||||
RsDbg() << " Exiting loop." ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -64,6 +64,8 @@ void FriendServer::threadTick()
|
||||
|
||||
void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *item)
|
||||
{
|
||||
// We always respond with exactly one item, be it an error item or a list of friends to connect to.
|
||||
|
||||
try
|
||||
{
|
||||
RsDbg() << "Received a client publish item from " << item->PeerId() << ":";
|
||||
@ -107,19 +109,6 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it
|
||||
mni->SendItem(status_item);
|
||||
return;
|
||||
}
|
||||
|
||||
// Close client connection from server side, to tell the client that nothing more is coming.
|
||||
|
||||
RsDbg() << "Sending end-of-stream item to " << item->PeerId() ;
|
||||
|
||||
RsFriendServerStatusItem *status_item = new RsFriendServerStatusItem;
|
||||
status_item->status = RsFriendServerStatusItem::END_OF_TRANSMISSION;
|
||||
status_item->PeerId(item->PeerId());
|
||||
|
||||
mni->SendItem(status_item);
|
||||
|
||||
RsDbg() << "Closing client connection." ;
|
||||
mni->closeConnection(item->PeerId());
|
||||
}
|
||||
|
||||
std::map<std::string, bool> FriendServer::computeListOfFriendInvites(uint32_t nb_reqs_invites, const RsPeerId &pid, const RsPgpFingerprint &fpr)
|
||||
@ -332,7 +321,7 @@ void FriendServer::autoWash()
|
||||
|
||||
std::list<RsPeerId> to_remove;
|
||||
|
||||
for(std::map<RsPeerId,PeerInfo>::iterator it(mCurrentClientPeers.begin());it!=mCurrentClientPeers.end();)
|
||||
for(std::map<RsPeerId,PeerInfo>::iterator it(mCurrentClientPeers.begin());it!=mCurrentClientPeers.end();++it)
|
||||
if(it->second.last_connection_TS + MAXIMUM_PEER_INACTIVE_DELAY < now)
|
||||
{
|
||||
RsDbg() << "Removing client peer " << it->first << " because it's inactive for more than " << MAXIMUM_PEER_INACTIVE_DELAY << " seconds." ;
|
||||
|
@ -240,20 +240,22 @@ void FsNetworkInterface::locked_closeConnection(const RsPeerId& peer_id)
|
||||
|
||||
if(!it->second.incoming_items.empty())
|
||||
{
|
||||
RsErr() << " Trying to close an incoming connection with incoming items still pending! The items will be lost." << std::endl;
|
||||
RsErr() << " Trying to close an incoming connection with incoming items still pending! The items will be lost:" << std::endl;
|
||||
|
||||
for(auto& item:it->second.incoming_items)
|
||||
{
|
||||
RsErr() << *item;
|
||||
delete item;
|
||||
}
|
||||
|
||||
it->second.incoming_items.clear();
|
||||
}
|
||||
// Close the socket and delete everything.
|
||||
|
||||
close(it->second.socket);
|
||||
it->second.pqi_thread->fullstop();
|
||||
it->second.bio->close();
|
||||
|
||||
close(it->second.socket);
|
||||
|
||||
delete it->second.pqi_thread;
|
||||
|
||||
mConnections.erase(it);
|
||||
|
Loading…
Reference in New Issue
Block a user