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
6f233f54
Commit
6f233f54
authored
Jun 23, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(UNetReceiver): вторая версия механизма "паузы на инициализацию"
на основе ev::timer, вместо PasiveTimer
parent
4d19698b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
29 deletions
+54
-29
UNetReceiver.cc
extensions/UNetUDP/UNetReceiver.cc
+44
-13
UNetReceiver.h
extensions/UNetUDP/UNetReceiver.h
+10
-16
No files found.
extensions/UNetUDP/UNetReceiver.cc
View file @
6f233f54
...
...
@@ -83,8 +83,7 @@ UNetReceiver::UNetReceiver(const std::string& s_host, int _port, const std::shar
evStatistic
.
set
<
UNetReceiver
,
&
UNetReceiver
::
statisticsEvent
>
(
this
);
evUpdate
.
set
<
UNetReceiver
,
&
UNetReceiver
::
updateEvent
>
(
this
);
ptInitOK
.
setTiming
(
initPause
);
evInitPause
.
set
<
UNetReceiver
,
&
UNetReceiver
::
initEvent
>
(
this
);
}
// -----------------------------------------------------------------------------
UNetReceiver
::~
UNetReceiver
()
...
...
@@ -148,8 +147,7 @@ void UNetReceiver::setEvrunTimeout( timeout_t msec ) noexcept
// -----------------------------------------------------------------------------
void
UNetReceiver
::
setInitPause
(
timeout_t
msec
)
noexcept
{
initPause
=
msec
;
ptInitOK
.
setTiming
(
initPause
);
initPause
=
(
msec
/
1000.0
);
}
// -----------------------------------------------------------------------------
void
UNetReceiver
::
setRespondID
(
uniset
::
ObjectId
id
,
bool
invert
)
noexcept
...
...
@@ -174,9 +172,14 @@ void UNetReceiver::setLockUpdate( bool st ) noexcept
ptPrepare
.
reset
();
}
// -----------------------------------------------------------------------------
bool
UNetReceiver
::
isLockUpdate
()
const
noexcept
{
return
lockUpdate
;
}
// -----------------------------------------------------------------------------
bool
UNetReceiver
::
isInitOK
()
const
noexcept
{
return
ptInitOK
.
checkTime
();
return
initOK
.
load
();
}
// -----------------------------------------------------------------------------
void
UNetReceiver
::
resetTimeout
()
noexcept
...
...
@@ -186,6 +189,16 @@ void UNetReceiver::resetTimeout() noexcept
trTimeout
.
change
(
false
);
}
// -----------------------------------------------------------------------------
bool
UNetReceiver
::
isRecvOK
()
const
noexcept
{
return
!
ptRecvTimeout
.
checkTime
();
}
// -----------------------------------------------------------------------------
size_t
UNetReceiver
::
getLostPacketsNum
()
const
noexcept
{
return
lostPackets
;
}
// -----------------------------------------------------------------------------
bool
UNetReceiver
::
createConnection
(
bool
throwEx
)
{
if
(
!
activated
)
...
...
@@ -251,10 +264,7 @@ void UNetReceiver::start()
}
if
(
upStrategy
==
useUpdateThread
&&
!
upThread
->
isRunning
()
)
{
ptInitOK
.
reset
();
upThread
->
start
();
}
}
else
forceUpdate
();
...
...
@@ -264,7 +274,8 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop ) noexcept
{
evStatistic
.
set
(
eloop
);
evStatistic
.
start
(
0
,
1.0
);
// раз в сек
ptInitOK
.
reset
();
evInitPause
.
set
(
eloop
);
if
(
upStrategy
==
useUpdateEventLoop
)
{
...
...
@@ -276,11 +287,13 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop ) noexcept
{
evCheckConnection
.
set
(
eloop
);
evCheckConnection
.
start
(
0
,
checkConnectionTime
);
evInitPause
.
stop
();
}
else
{
evReceive
.
set
(
eloop
);
evReceive
.
start
(
udp
->
getSocket
(),
ev
::
READ
);
evInitPause
.
start
(
0
);
}
}
// -----------------------------------------------------------------------------
...
...
@@ -336,6 +349,18 @@ void UNetReceiver::statisticsEvent(ev::periodic& tm, int revents) noexcept
tm
.
again
();
}
// -----------------------------------------------------------------------------
void
UNetReceiver
::
initEvent
(
ev
::
timer
&
tmr
,
int
revents
)
noexcept
{
if
(
EV_ERROR
&
revents
)
{
unetcrit
<<
myname
<<
"(initEvent): EVENT ERROR.."
<<
endl
;
return
;
}
initOK
.
store
(
true
);
tmr
.
stop
();
}
// -----------------------------------------------------------------------------
void
UNetReceiver
::
update
()
noexcept
{
UniSetUDP
::
UDPMessage
p
;
...
...
@@ -513,8 +538,11 @@ void UNetReceiver::updateThread() noexcept
{
try
{
bool
r
=
respondInvert
?
!
isRecvOK
()
:
isRecvOK
();
shm
->
localSetValue
(
itRespond
,
sidRespond
,
(
r
?
1
:
0
),
shm
->
ID
());
if
(
isInitOK
()
)
{
bool
r
=
respondInvert
?
!
isRecvOK
()
:
isRecvOK
();
shm
->
localSetValue
(
itRespond
,
sidRespond
,
(
r
?
1
:
0
),
shm
->
ID
());
}
}
catch
(
const
std
::
exception
&
ex
)
{
...
...
@@ -630,8 +658,11 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
{
try
{
bool
r
=
respondInvert
?
!
isRecvOK
()
:
isRecvOK
();
shm
->
localSetValue
(
itRespond
,
sidRespond
,
(
r
?
1
:
0
),
shm
->
ID
());
if
(
isInitOK
()
)
{
bool
r
=
respondInvert
?
!
isRecvOK
()
:
isRecvOK
();
shm
->
localSetValue
(
itRespond
,
sidRespond
,
(
r
?
1
:
0
),
shm
->
ID
());
}
}
catch
(
const
std
::
exception
&
ex
)
{
...
...
extensions/UNetUDP/UNetReceiver.h
View file @
6f233f54
...
...
@@ -114,23 +114,13 @@ namespace uniset
// блокировать сохранение данных в SM
void
setLockUpdate
(
bool
st
)
noexcept
;
inline
bool
isLockUpdate
()
const
noexcept
{
return
lockUpdate
;
}
bool
isInitOK
()
const
noexcept
;
bool
isLockUpdate
()
const
noexcept
;
void
resetTimeout
()
noexcept
;
inline
bool
isRecvOK
()
const
noexcept
{
return
!
ptRecvTimeout
.
checkTime
();
}
inline
size_t
getLostPacketsNum
()
const
noexcept
{
return
lostPackets
;
}
bool
isInitOK
()
const
noexcept
;
bool
isRecvOK
()
const
noexcept
;
size_t
getLostPacketsNum
()
const
noexcept
;
void
setReceiveTimeout
(
timeout_t
msec
)
noexcept
;
void
setReceivePause
(
timeout_t
msec
)
noexcept
;
...
...
@@ -219,6 +209,7 @@ namespace uniset
void
updateEvent
(
ev
::
periodic
&
watcher
,
int
revents
)
noexcept
;
void
checkConnectionEvent
(
ev
::
periodic
&
watcher
,
int
revents
)
noexcept
;
void
statisticsEvent
(
ev
::
periodic
&
watcher
,
int
revents
)
noexcept
;
void
initEvent
(
ev
::
timer
&
watcher
,
int
revents
)
noexcept
;
virtual
void
evprepare
(
const
ev
::
loop_ref
&
eloop
)
noexcept
override
;
virtual
void
evfinish
(
const
ev
::
loop_ref
&
eloop
)
noexcept
override
;
virtual
std
::
string
wname
()
const
noexcept
override
...
...
@@ -260,6 +251,7 @@ namespace uniset
ev
::
periodic
evCheckConnection
;
ev
::
periodic
evStatistic
;
ev
::
periodic
evUpdate
;
ev
::
timer
evInitPause
;
UpdateStrategy
upStrategy
=
{
useUpdateEventLoop
};
...
...
@@ -281,12 +273,14 @@ namespace uniset
PassiveTimer
ptRecvTimeout
;
PassiveTimer
ptPrepare
;
PassiveTimer
ptInitOK
;
timeout_t
recvTimeout
=
{
5000
};
// msec
timeout_t
prepareTime
=
{
2000
};
timeout_t
evrunTimeout
=
{
15000
};
timeout_t
lostTimeout
=
{
200
};
timeout_t
initPause
=
{
5000
};
// пауза на начальную инициализацию
double
initPause
=
{
5
.
0
};
// пауза на начальную инициализацию (сек)
std
::
atomic_bool
initOK
=
{
false
};
PassiveTimer
ptLostTimeout
;
size_t
lostPackets
=
{
0
};
/*!< счётчик потерянных пакетов */
...
...
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