Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
6dff7fc9
Commit
6dff7fc9
authored
Sep 25, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogDB): исправил ошибку с некорректным завершением процесса
parent
6dd29f3d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
8 deletions
+81
-8
SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.cc
+4
-1
LogDB.cc
extensions/LogDB/LogDB.cc
+57
-4
LogDB.h
extensions/LogDB/LogDB.h
+20
-3
No files found.
extensions/DBServer-SQLite/SQLiteInterface.cc
View file @
6dff7fc9
...
...
@@ -46,7 +46,10 @@ SQLiteInterface::~SQLiteInterface()
}
catch
(
...
)
// пропускаем все необработанные исключения, если требуется обработать нужно вызывать close() до деструктора
{
cerr
<<
"MySQLInterface::~MySQLInterface(): an error occured while closing connection!"
<<
endl
;
std
::
exception_ptr
p
=
std
::
current_exception
();
cerr
<<
"(SQLiteInterface::~SQLiteInterface): "
<<
(
p
?
p
.
__cxa_exception_type
()
->
name
()
:
"an error occured while closing connection!"
)
<<
std
::
endl
;
}
}
...
...
extensions/LogDB/LogDB.cc
View file @
6dff7fc9
...
...
@@ -110,6 +110,9 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
flushBufferTimer
.
set
<
LogDB
,
&
LogDB
::
onCheckBuffer
>
(
this
);
wsactivate
.
set
<
LogDB
,
&
LogDB
::
onActivate
>
(
this
);
sigTERM
.
set
<
LogDB
,
&
LogDB
::
onTerminate
>
(
this
);
sigQUIT
.
set
<
LogDB
,
&
LogDB
::
onTerminate
>
(
this
);
sigINT
.
set
<
LogDB
,
&
LogDB
::
onTerminate
>
(
this
);
bool
dbDisabled
=
(
uniset
::
findArgParam
(
"--"
+
prefix
+
"db-disable"
,
argc
,
argv
)
!=
-
1
);
...
...
@@ -225,7 +228,7 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
httpParams
->
setMaxQueued
(
maxQ
);
httpParams
->
setMaxThreads
(
maxT
);
httpserv
=
std
::
make_shared
<
Poco
::
Net
::
HTTPServer
>
(
this
,
Poco
::
Net
::
ServerSocket
(
sa
),
httpParams
);
httpserv
=
std
::
make_shared
<
Poco
::
Net
::
HTTPServer
>
(
new
LogDBRequestHandlerFactory
(
this
)
,
Poco
::
Net
::
ServerSocket
(
sa
),
httpParams
);
}
catch
(
std
::
exception
&
ex
)
{
...
...
@@ -249,6 +252,49 @@ LogDB::~LogDB()
db
->
close
();
}
//--------------------------------------------------------------------------------------------
void
LogDB
::
onTerminate
(
ev
::
sig
&
evsig
,
int
revents
)
{
if
(
EV_ERROR
&
revents
)
{
dbcrit
<<
myname
<<
"(onTerminate): invalid event"
<<
endl
;
return
;
}
dbinfo
<<
myname
<<
"(onTerminate): terminate..."
<<
endl
;
try
{
flushBuffer
();
}
catch
(
std
::
exception
&
ex
)
{
dbinfo
<<
myname
<<
"(onTerminate): "
<<
ex
.
what
()
<<
endl
;
}
evsig
.
stop
();
//evsig.loop.break_loop();
try
{
httpserv
->
stop
();
}
catch
(
std
::
exception
&
ex
)
{
dbinfo
<<
myname
<<
"(onTerminate): "
<<
ex
.
what
()
<<
endl
;
}
try
{
evstop
();
}
catch
(
std
::
exception
&
ex
)
{
dbinfo
<<
myname
<<
"(onTerminate): "
<<
ex
.
what
()
<<
endl
;
}
}
//--------------------------------------------------------------------------------------------
void
LogDB
::
flushBuffer
()
{
if
(
!
db
||
qbuf
.
empty
()
||
!
db
->
isConnection
()
)
...
...
@@ -428,6 +474,13 @@ void LogDB::evprepare()
for
(
const
auto
&
s
:
logservers
)
s
->
set
(
loop
);
sigTERM
.
set
(
loop
);
sigTERM
.
start
(
SIGTERM
);
sigQUIT
.
set
(
loop
);
sigQUIT
.
start
(
SIGQUIT
);
sigINT
.
set
(
loop
);
sigINT
.
start
(
SIGINT
);
}
// -----------------------------------------------------------------------------
void
LogDB
::
onCheckBuffer
(
ev
::
timer
&
t
,
int
revents
)
...
...
@@ -716,12 +769,12 @@ class LogDBWebSocketRequestHandler:
LogDB
*
logdb
;
};
// -----------------------------------------------------------------------------
Poco
::
Net
::
HTTPRequestHandler
*
LogDB
::
createRequestHandler
(
const
Poco
::
Net
::
HTTPServerRequest
&
req
)
Poco
::
Net
::
HTTPRequestHandler
*
LogDB
::
LogDBRequestHandlerFactory
::
createRequestHandler
(
const
Poco
::
Net
::
HTTPServerRequest
&
req
)
{
if
(
req
.
find
(
"Upgrade"
)
!=
req
.
end
()
&&
Poco
::
icompare
(
req
[
"Upgrade"
],
"websocket"
)
==
0
)
return
new
LogDBWebSocketRequestHandler
(
this
);
return
new
LogDBWebSocketRequestHandler
(
logdb
);
return
new
LogDBRequestHandler
(
this
);
return
new
LogDBRequestHandler
(
logdb
);
}
// -----------------------------------------------------------------------------
void
LogDB
::
handleRequest
(
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
)
...
...
extensions/LogDB/LogDB.h
View file @
6dff7fc9
...
...
@@ -120,7 +120,7 @@ namespace uniset
\section sec_LogDB_WEBSOCK LogDB Поддержка web socket
В LogDB встроена возможность просмотра логов в реальном времени, через websocket.
Список
доступных для подключения
лог-серверов доступен по адресу:
Список лог-серверов доступен по адресу:
\code
ws://host:port/logdb/ws/
\endcode
...
...
@@ -171,7 +171,6 @@ namespace uniset
public
EventLoopServer
#ifndef DISABLE_REST_API
,
public
Poco
::
Net
::
HTTPRequestHandler
,
public
Poco
::
Net
::
HTTPRequestHandlerFactory
#endif
{
public
:
...
...
@@ -191,7 +190,6 @@ namespace uniset
void
run
(
bool
async
);
#ifndef DISABLE_REST_API
Poco
::
Net
::
HTTPRequestHandler
*
createRequestHandler
(
const
Poco
::
Net
::
HTTPServerRequest
&
req
);
virtual
void
handleRequest
(
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
)
override
;
void
onWebSocketSession
(
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
);
#endif
...
...
@@ -251,6 +249,11 @@ namespace uniset
size_t
maxdbRecords
=
{
200
*
1000
};
size_t
numOverflow
=
{
0
};
// вычисляется из параметра "overflow factor"(float)
ev
::
sig
sigTERM
;
ev
::
sig
sigQUIT
;
ev
::
sig
sigINT
;
void
onTerminate
(
ev
::
sig
&
evsig
,
int
revents
);
ev
::
async
wsactivate
;
// активация LogWebSocket-ов
class
Log
...
...
@@ -391,6 +394,20 @@ namespace uniset
std
::
list
<
std
::
shared_ptr
<
LogWebSocket
>>
wsocks
;
uniset
::
uniset_rwmutex
wsocksMutex
;
size_t
maxwsocks
=
{
50
};
// максимальное количество websocket-ов
class
LogDBRequestHandlerFactory
:
public
Poco
::
Net
::
HTTPRequestHandlerFactory
{
public
:
LogDBRequestHandlerFactory
(
LogDB
*
l
)
:
logdb
(
l
)
{}
virtual
~
LogDBRequestHandlerFactory
()
{};
virtual
Poco
::
Net
::
HTTPRequestHandler
*
createRequestHandler
(
const
Poco
::
Net
::
HTTPServerRequest
&
req
)
override
;
private
:
LogDB
*
logdb
;
};
#endif
private
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment