use recv(...,MSG_DONTWAIT), since read() may return multiple times the same data apparently

This commit is contained in:
csoler 2021-11-04 20:52:38 +01:00
parent 01da2fbe9e
commit 62655779e5
3 changed files with 19 additions and 6 deletions

View File

@ -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)
{

View File

@ -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));
}

View File

@ -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())