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
30945503
Commit
30945503
authored
Sep 10, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogServer): попытка решить проблемму с SEGFAULT,
немного переписал работу с shared_ptr
parent
6fd4537e
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
46 additions
and
45 deletions
+46
-45
log.cc
Utilities/ULog/log.cc
+0
-11
libuniset2.spec
conf/libuniset2.spec
+4
-1
start_fg_mbtcpmulti.sh
extensions/ModbusMaster/start_fg_mbtcpmulti.sh
+1
-0
LogReader.h
include/LogReader.h
+2
-1
LogServer.h
include/LogServer.h
+1
-1
LogSession.h
include/LogSession.h
+2
-0
LogReader.cc
src/Log/LogReader.cc
+2
-6
LogServer.cc
src/Log/LogServer.cc
+21
-18
LogSession.cc
src/Log/LogSession.cc
+13
-7
No files found.
Utilities/ULog/log.cc
View file @
30945503
...
...
@@ -76,7 +76,6 @@ int main( int argc, char** argv )
int
cmdonly
=
0
;
timeout_t
tout
=
0
;
timeout_t
rdelay
=
5000
;
bool
cmdlist
=
false
;
try
{
...
...
@@ -140,7 +139,6 @@ int main( int argc, char** argv )
filter
=
string
(
arg2
);
vcmd
.
push_back
(
LogReader
::
Command
(
LogServerTypes
::
cmdList
,
0
,
filter
)
);
cmdlist
=
true
;
}
break
;
...
...
@@ -239,15 +237,6 @@ int main( int argc, char** argv )
lr
.
setinTimeout
(
tout
);
lr
.
setReconnectDelay
(
rdelay
);
/*
if( cmdlist && vcmd.size() == 1 )
{
cmdonly = 1;
lr.setReadCount(1);
lr.sendCommand(addr, port, vcmd, cmdonly, verb);
return 0;
}
*/
if
(
!
vcmd
.
empty
()
)
lr
.
sendCommand
(
addr
,
port
,
vcmd
,
cmdonly
,
verb
);
...
...
conf/libuniset2.spec
View file @
30945503
...
...
@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.1
Release: alt2
3
Release: alt2
4
Summary: UniSet - library for building distributed industrial control systems
...
...
@@ -456,6 +456,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Thu Sep 10 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt24
- (LogServer): refactoring (more use shared_ptr)
* Mon Sep 07 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt23
- (ModbusPersistentSlave): fixed bug in end connection processing
- (uniset-log): fixed bug in end connection processing
...
...
extensions/ModbusMaster/start_fg_mbtcpmulti.sh
View file @
30945503
...
...
@@ -14,6 +14,7 @@
--mbtcp-force-out
1
\
--mbtcp-log-add-levels
any
\
--mbtcp-persistent-connection
1
\
--mbtcp-run-logserver
\
$*
#--mbtcp-exchange-mode-id MB1_Mode_AS \
...
...
include/LogReader.h
View file @
30945503
...
...
@@ -2,6 +2,7 @@
#define LogReader_H_
// -------------------------------------------------------------------------
#include <string>
#include <memory>
#include <queue>
#include <vector>
#include <cc++/socket.h>
...
...
@@ -73,7 +74,7 @@ class LogReader
timeout_t
reconDelay
;
private
:
UTCPStream
*
tcp
;
std
::
shared_ptr
<
UTCPStream
>
tcp
;
std
::
string
iaddr
;
ost
::
tpport_t
port
;
bool
cmdonly
;
...
...
include/LogServer.h
View file @
30945503
...
...
@@ -113,7 +113,7 @@ class LogServer
DebugStream
mylog
;
std
::
shared_ptr
<
ThreadCreator
<
LogServer
>
>
thr
;
ost
::
TCPSocket
*
tcp
;
std
::
shared_ptr
<
ost
::
TCPSocket
>
tcp
;
std
::
shared_ptr
<
DebugStream
>
elog
;
std
::
shared_ptr
<
NullLogSession
>
nullsess
;
};
...
...
include/LogSession.h
View file @
30945503
...
...
@@ -70,6 +70,8 @@ class LogSession:
std
::
shared_ptr
<
LogAgregator
>
alog
;
sigc
::
connection
conn
;
std
::
shared_ptr
<
LogSession
>
myptr
;
// PassiveTimer ptSessionTimeout;
FinalSlot
slFin
;
std
::
atomic_bool
cancelled
;
...
...
src/Log/LogReader.cc
View file @
30945503
...
...
@@ -13,7 +13,6 @@ LogReader::LogReader():
inTimeout
(
10000
),
outTimeout
(
6000
),
reconDelay
(
5000
),
tcp
(
0
),
iaddr
(
""
),
cmdonly
(
false
),
readcount
(
0
)
...
...
@@ -50,9 +49,8 @@ void LogReader::connect( ost::InetAddress addr, ost::tpport_t _port, timeout_t m
{
if
(
tcp
)
{
(
*
tcp
)
<<
endl
;
(
*
tcp
.
get
()
)
<<
endl
;
disconnect
();
delete
tcp
;
tcp
=
0
;
}
...
...
@@ -71,7 +69,7 @@ void LogReader::connect( ost::InetAddress addr, ost::tpport_t _port, timeout_t m
try
{
tcp
=
new
UTCPStream
();
tcp
=
make_shared
<
UTCPStream
>
();
tcp
->
create
(
iaddr
,
port
,
true
,
500
);
tcp
->
setTimeout
(
msec
);
tcp
->
setKeepAlive
(
true
);
...
...
@@ -85,7 +83,6 @@ void LogReader::connect( ost::InetAddress addr, ost::tpport_t _port, timeout_t m
rlog
.
crit
()
<<
s
.
str
()
<<
std
::
endl
;
}
delete
tcp
;
tcp
=
0
;
}
catch
(
...
)
...
...
@@ -110,7 +107,6 @@ void LogReader::disconnect()
rlog
.
info
()
<<
iaddr
<<
"(LogReader): disconnect."
<<
endl
;
tcp
->
disconnect
();
delete
tcp
;
tcp
=
0
;
}
// -------------------------------------------------------------------------
...
...
src/Log/LogServer.cc
View file @
30945503
...
...
@@ -29,10 +29,11 @@ LogServer::~LogServer()
tcp
->
reject
();
if
(
thr
)
{
thr
->
stop
();
delete
tcp
;
tcp
=
0
;
if
(
thr
->
isRunning
()
)
thr
->
join
()
;
}
}
// -------------------------------------------------------------------------
LogServer
::
LogServer
(
std
::
shared_ptr
<
LogAgregator
>
log
)
:
...
...
@@ -74,17 +75,7 @@ void LogServer::run( const std::string& addr, ost::tpport_t port, bool thread )
try
{
ost
::
InetAddress
iaddr
(
addr
.
c_str
());
tcp
=
new
ost
::
TCPSocket
(
iaddr
,
port
);
#if 0
if( !nullsess )
{
ostringstream err;
err << "(LOG SERVER): Exceeded the limit on the number of sessions = " << sessMaxCount << endl;
nullsess = make_shared<NullLogSession>(err.str());
}
#endif
tcp
=
make_shared
<
ost
::
TCPSocket
>
(
iaddr
,
port
);
}
catch
(
ost
::
Socket
*
socket
)
{
...
...
@@ -138,26 +129,28 @@ void LogServer::work()
ostringstream
err
;
err
<<
"(LOG SERVER): Exceeded the limit on the number of sessions = "
<<
sessMaxCount
<<
endl
;
nullsess
=
make_shared
<
NullLogSession
>
(
err
.
str
());
nullsess
->
detach
();
// start();
//nullsess->detach();
nullsess
->
start
();
}
else
nullsess
->
setMessage
(
err
.
str
());
nullsess
->
add
(
*
tcp
);
nullsess
->
add
(
*
(
tcp
.
get
()));
// опасно передавать "сырой указатель", теряем контроль
continue
;
}
}
if
(
cancelled
)
break
;
auto
s
=
make_shared
<
LogSession
>
(
*
tcp
,
elog
,
sessTimeout
,
cmdTimeout
,
outTimeout
);
auto
s
=
make_shared
<
LogSession
>
(
*
(
tcp
.
get
())
,
elog
,
sessTimeout
,
cmdTimeout
,
outTimeout
);
s
->
setSessionLogLevel
(
sessLogLevel
);
{
uniset_rwmutex_wrlock
l
(
mutSList
);
slist
.
push_back
(
s
);
}
s
->
connectFinalSession
(
sigc
::
mem_fun
(
this
,
&
LogServer
::
sessionFinished
)
);
s
->
detach
();
//s->detach();
s
->
start
();
}
}
catch
(
ost
::
Socket
*
socket
)
...
...
@@ -175,6 +168,10 @@ void LogServer::work()
else
cerr
<<
"client socket failed"
<<
endl
;
}
catch
(
const
std
::
exception
&
ex
)
{
cerr
<<
"catch exception: "
<<
ex
.
what
()
<<
endl
;
}
}
{
...
...
@@ -185,6 +182,12 @@ void LogServer::work()
if
(
nullsess
)
nullsess
->
cancel
();
}
for
(
const
auto
&
i
:
slist
)
{
if
(
i
->
isRunning
()
)
i
->
ost
::
Thread
::
join
();
}
}
// -------------------------------------------------------------------------
void
LogServer
::
sessionFinished
(
std
::
shared_ptr
<
LogSession
>
s
)
...
...
src/Log/LogSession.cc
View file @
30945503
...
...
@@ -18,9 +18,9 @@ using namespace UniSetTypes;
// -------------------------------------------------------------------------
LogSession
::~
LogSession
()
{
cancelled
=
true
;
if
(
isRunning
()
)
{
cancelled
=
true
;
ost
::
Thread
::
join
();
disconnect
();
}
...
...
@@ -73,6 +73,10 @@ void LogSession::run()
if
(
cancelled
)
return
;
// удерживаем указатель на себя, пока работает поток..
myptr
=
shared_from_this
();
cancelled
=
false
;
{
ost
::
tpport_t
p
;
ost
::
InetAddress
iaddr
=
getIPV4Peer
(
&
p
);
...
...
@@ -95,7 +99,7 @@ void LogSession::run()
setKeepAlive
(
true
);
// Команды могут посылаться только в начале сессии..
while
(
isPending
(
Socket
::
pendingInput
,
cmdTimeout
)
)
while
(
!
cancelled
&&
isPending
(
Socket
::
pendingInput
,
cmdTimeout
)
)
{
LogServerTypes
::
lsMessage
msg
;
...
...
@@ -242,8 +246,6 @@ void LogSession::run()
#endif
cancelled
=
false
;
while
(
!
cancelled
&&
isConnected
()
)
// !ptSessionTimeout.checkTime()
{
// проверка только ради проверки "целостности" соединения
...
...
@@ -307,18 +309,22 @@ void LogSession::run()
disconnect
();
cancelled
=
true
;
if
(
slog
.
debugging
(
Debug
::
INFO
)
)
slog
[
Debug
::
INFO
]
<<
peername
<<
"(run): thread stopping..."
<<
endl
;
myptr
=
0
;
}
// -------------------------------------------------------------------------
void
LogSession
::
final
()
{
tcp
()
->
sync
();
cancelled
=
true
;
try
{
auto
s
=
shared_from_this
();
if
(
s
)
slFin
(
s
);
}
...
...
@@ -344,8 +350,8 @@ NullLogSession::~NullLogSession()
{
cancelled
=
true
;
if
(
isRunning
()
)
exit
();
// terminate();
//
if( isRunning() )
//
exit(); // terminate();
}
// ---------------------------------------------------------------------
void
NullLogSession
::
add
(
ost
::
TCPSocket
&
sock
)
...
...
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