Commit d0fe3b0b authored by Pavel Vainerman's avatar Pavel Vainerman

(libev): рефакторинг работы с ev::timer,

исправил ошибку в CommonEventLoop
parent b42665ff
......@@ -19,6 +19,7 @@ static struct option longopts[] =
{ "verbose", no_argument, 0, 'v' },
{ "delay", required_argument, 0, 'd' },
{ "max-sessions", required_argument, 0, 'm' },
{ "silent", no_argument, 0, 's' },
{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
......@@ -31,6 +32,7 @@ static void print_help()
printf("[-p|--port] port - Bind port.\n");
printf("[-d|--delay] msec - Delay for generate message. Default 5000.\n");
printf("[-m|--max-sessions] num - Maximum count sessions for server. Default: 5\n");
printf("[-s|--silent] - Silent mode. Not write logs..\n");
}
// --------------------------------------------------------------------------
int main( int argc, char** argv )
......@@ -45,12 +47,13 @@ int main( int argc, char** argv )
//int tout = 2000;
timeout_t delay = 5000;
int msess = 5;
bool silent = false;
try
{
while(1)
{
opt = getopt_long(argc, argv, "hvi:p:d:m:", longopts, &optindex);
opt = getopt_long(argc, argv, "hvi:p:d:m:s", longopts, &optindex);
if( opt == -1 )
break;
......@@ -81,6 +84,10 @@ int main( int argc, char** argv )
verb = 1;
break;
case 's':
silent = true;
break;
case '?':
default:
printf("? argumnet\n");
......@@ -192,22 +199,25 @@ int main( int argc, char** argv )
while( true )
// for( int n=0; n<2; n++ )
{
dlog->any() << "[" << ++i << "] Test message for log" << endl;
dlog->info() << ": dlog : INFO message" << endl;
dlog->warn() << ": dlog : WARN message" << endl;
dlog->crit() << ": dlog : CRIT message" << endl;
dlog2->info() << ": dlog2: INFO message" << endl;
dlog2->warn() << ": dlog2: WARN message" << endl;
dlog2->crit() << ": dlog2: CRIT message" << endl;
dlog3->info() << ": dlog3: INFO message" << endl;
dlog3->warn() << ": dlog3: WARN message" << endl;
dlog3->crit() << ": dlog3: CRIT message" << endl;
dlog4->info() << ": dlog4: INFO message" << endl;
dlog4->warn() << ": dlog4: WARN message" << endl;
dlog4->crit() << ": dlog4: CRIT message" << endl;
if( !silent )
{
dlog->any() << "[" << ++i << "] Test message for log" << endl;
dlog->info() << ": dlog : INFO message" << endl;
dlog->warn() << ": dlog : WARN message" << endl;
dlog->crit() << ": dlog : CRIT message" << endl;
dlog2->info() << ": dlog2: INFO message" << endl;
dlog2->warn() << ": dlog2: WARN message" << endl;
dlog2->crit() << ": dlog2: CRIT message" << endl;
dlog3->info() << ": dlog3: INFO message" << endl;
dlog3->warn() << ": dlog3: WARN message" << endl;
dlog3->crit() << ": dlog3: CRIT message" << endl;
dlog4->info() << ": dlog4: INFO message" << endl;
dlog4->warn() << ": dlog4: WARN message" << endl;
dlog4->crit() << ": dlog4: CRIT message" << endl;
}
msleep(delay);
}
......
......@@ -511,6 +511,9 @@ rm -f %buildroot%_libdir/*.la
* Tue Sep 12 2017 Alexei Takaseev <taf@altlinux.org> 2.6-alt19.1
- Rebuild with poco 1.7.9
# * Wed May 31 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt25
# - test build (devel)
# * Wed May 31 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt24
# - minor release
......
......@@ -312,8 +312,6 @@ namespace uniset
if( dlog->is_crit() )
dlog->crit() << myname << "(onTimer): " << ex.what() << endl;
}
t.start(tmTime); // restart timer
}
// -------------------------------------------------------------------------
......
......@@ -163,11 +163,12 @@ namespace uniset
ioTimeout.start(sessTimeout); // restart timer..
}
// -------------------------------------------------------------------------
void ModbusTCPSession::onTimeout( ev::timer& watcher, int revents )
void ModbusTCPSession::onTimeout( ev::timer& t, int revents )
{
if( dlog->is_info() )
dlog->info() << peername << ": timeout connection activity..(terminate session)" << endl;
t.stop();
terminate();
}
// -------------------------------------------------------------------------
......
......@@ -568,7 +568,7 @@ namespace uniset
}
}
// -------------------------------------------------------------------------
void LogSession::onCmdTimeout( ev::timer& watcher, int revents ) noexcept
void LogSession::onCmdTimeout( ev::timer& t, int revents ) noexcept
{
if( EV_ERROR & revents )
{
......@@ -578,11 +578,12 @@ namespace uniset
return;
}
t.stop();
io.set(ev::WRITE);
asyncEvent.start();
}
// -------------------------------------------------------------------------
void LogSession::onCheckConnectionTimer( ev::timer& watcher, int revents ) noexcept
void LogSession::onCheckConnectionTimer( ev::timer& t, int revents ) noexcept
{
if( EV_ERROR & revents )
{
......@@ -595,10 +596,7 @@ namespace uniset
std::unique_lock<std::mutex> lk(logbuf_mutex);
if( !logbuf.empty() )
{
checkConnectionTimer.start( checkConnectionTime ); // restart timer
return;
}
// если клиент уже отвалился.. то при попытке write.. сессия будет закрыта.
......@@ -612,7 +610,6 @@ namespace uniset
catch(...) {}
io.set(ev::WRITE);
checkConnectionTimer.start( checkConnectionTime ); // restart timer
}
// -------------------------------------------------------------------------
void LogSession::final() noexcept
......
......@@ -277,6 +277,7 @@ namespace uniset
evterm.stop();
evprep.stop();
evruntimer.stop();
term_notify = true;
term_event.notify_all();
......
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