Commit c82b9bb1 authored by Pavel Vainerman's avatar Pavel Vainerman

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

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