mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 17:21:27 -05:00
use recv(...,MSG_DONTWAIT), since read() may return multiple times the same data apparently
This commit is contained in:
parent
01da2fbe9e
commit
62655779e5
@ -39,7 +39,7 @@ int FsBioInterface::tick()
|
||||
char inBuffer[1025];
|
||||
memset(inBuffer,0,1025);
|
||||
|
||||
int readbytes = read(mCLintConnt, inBuffer, sizeof(inBuffer));
|
||||
ssize_t readbytes = recv(mCLintConnt, inBuffer, sizeof(inBuffer),MSG_DONTWAIT);
|
||||
|
||||
if(readbytes == 0)
|
||||
{
|
||||
|
@ -157,6 +157,8 @@ 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. " ;
|
||||
@ -171,6 +173,7 @@ bool FsClient::sendItem(const std::string& address,uint16_t port,RsItem *item,st
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
|
@ -93,11 +93,19 @@ void FsNetworkInterface::threadTick()
|
||||
|
||||
// 2 - tick all streamers
|
||||
|
||||
std::list<RsPeerId> to_close;
|
||||
|
||||
RS_STACK_MUTEX(mFsNiMtx);
|
||||
for(auto& it:mConnections)
|
||||
if(it.second.bio->isactive())
|
||||
it.second.pqi_thread->tick();
|
||||
else
|
||||
to_close.push_back(it.first);
|
||||
|
||||
rstime::rs_usleep(1000*200);
|
||||
for(const auto& pid:to_close)
|
||||
closeConnection(pid);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
static RsPeerId makePeerId(int t)
|
||||
@ -216,6 +224,8 @@ void FsNetworkInterface::closeConnection(const RsPeerId& peer_id)
|
||||
{
|
||||
RS_STACK_MUTEX(mFsNiMtx);
|
||||
|
||||
RsDbg() << "Closing connection to virtual peer " << peer_id ;
|
||||
|
||||
const auto& it = mConnections.find(peer_id);
|
||||
|
||||
if(it == mConnections.end())
|
||||
|
Loading…
x
Reference in New Issue
Block a user