Commit c82b9bb1 authored by Pavel Vainerman's avatar Pavel Vainerman

(unet2): Сделал "сброс таймера" через mutex, т.к.

ведётся работа из разных потоков. Добавил дополнительные информационные логи..
parent 73ff04a1
......@@ -206,6 +206,9 @@ sender2(0)
throw SystemError(err.str());
}
}
dlog[Debug::INFO] << myname << "(init): (node='" << n << "') add receiver "
<< h2 << ":" << p2 << endl;
UNetReceiver* r = new UNetReceiver(h,p,shm);
// на всякий принудительно разблокируем,
......@@ -227,7 +230,7 @@ sender2(0)
{
if( !h2.empty() ) // создаём читателя впо второму каналу
{
dlog[Debug::INFO] << myname << "(init): add reserv receiver "
dlog[Debug::INFO] << myname << "(init): (node='" << n << "') add reserv receiver "
<< h2 << ":" << p2 << endl;
r2 = new UNetReceiver(h2,p2,shm);
......
#include <sstream>
#include <iomanip>
#include "Exceptions.h"
#include "Extensions.h"
#include "UNetReceiver.h"
......@@ -44,7 +45,7 @@ a_cache_init_ok(false)
{
{
ostringstream s;
s << "R(" << s_host << ":" << port << ")";
s << "R(" << setw(15) << s_host << ":" << setw(4) << port << ")";
myname = s.str();
}
......@@ -135,6 +136,13 @@ void UNetReceiver::setLockUpdate( bool st )
lockUpdate = st;
}
// -----------------------------------------------------------------------------
void UNetReceiver::resetTimeout()
{
uniset_mutex_lock l(tmMutex,200);
ptRecvTimeout.reset();
trTimeout.change(false);
}
// -----------------------------------------------------------------------------
void UNetReceiver::start()
{
if( !activated )
......@@ -356,12 +364,16 @@ void UNetReceiver::receive()
{
dlog[Debug::INFO] << myname << ": ******************* receive start" << endl;
ptRecvTimeout.setTiming(recvTimeout);
bool tout = false;
while( activated )
{
try
{
if( recv() )
{
uniset_mutex_lock l(tmMutex,100);
ptRecvTimeout.reset();
}
}
catch( UniSetTypes::Exception& ex)
{
......@@ -376,9 +388,16 @@ void UNetReceiver::receive()
dlog[Debug::WARN] << myname << "(receive): catch ..." << std::endl;
}
if( trTimeout.change(ptRecvTimeout.checkTime()) )
// делаем через промежуточную переменную
// чтобы поскорее освободить mutex
{
uniset_mutex_lock l(tmMutex,100);
tout = ptRecvTimeout.checkTime();
}
if( trTimeout.change(tout) )
{
if( ptRecvTimeout.checkTime() )
if( tout )
slEvent(this,evTimeout);
else
slEvent(this,evOK);
......
......@@ -64,7 +64,7 @@ class UNetReceiver
// блокировать сохранение данный в SM
void setLockUpdate( bool st );
inline void resetTimeout(){ ptRecvTimeout.reset(); trTimeout.change(false); }
void resetTimeout();
inline bool isRecvOK(){ return ptRecvTimeout.checkTime(); }
inline unsigned long getLostPacketsNum(){ return lostPackets; }
......@@ -162,6 +162,7 @@ class UNetReceiver
EventSlot slEvent;
Trigger trTimeout;
UniSetTypes::uniset_mutex tmMutex;
struct ItemInfo
{
......
#include <sstream>
#include <iomanip>
#include "Exceptions.h"
#include "Extensions.h"
#include "UNetSender.h"
......@@ -23,7 +24,7 @@ s_thr(0)
{
ostringstream s;
s << "S(" << s_host << ":" << port << ")";
s << "S(" << setw(15) << s_host << ":" << setw(4) << port << ")";
myname = s.str();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment