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
448e9baa
Commit
448e9baa
authored
Dec 05, 2020
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Plain Diff
backported to p9 as 2.8.1-alt0.M90P.1 (with rpmbph script)
parents
8136d52b
2febeb01
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
78 deletions
+39
-78
UNetReceiver.cc
extensions/UNetUDP/UNetReceiver.cc
+35
-62
UNetReceiver.h
extensions/UNetUDP/UNetReceiver.h
+4
-16
No files found.
extensions/UNetUDP/UNetReceiver.cc
View file @
448e9baa
...
...
@@ -49,9 +49,7 @@ UNetReceiver::UNetReceiver(const std::string& s_host, int _port
activated
(
false
),
cbuf
(
cbufSize
),
maxDifferens
(
20
),
lockUpdate
(
false
),
d_cache_init_ok
(
false
),
a_cache_init_ok
(
false
)
lockUpdate
(
false
)
{
{
ostringstream
s
;
...
...
@@ -87,8 +85,11 @@ UNetReceiver::~UNetReceiver()
// -----------------------------------------------------------------------------
void
UNetReceiver
::
setBufferSize
(
size_t
sz
)
noexcept
{
cbufSize
=
sz
;
cbuf
.
resize
(
sz
);
if
(
sz
>
0
)
{
cbufSize
=
sz
;
cbuf
.
resize
(
sz
);
}
}
// -----------------------------------------------------------------------------
void
UNetReceiver
::
setReceiveTimeout
(
timeout_t
msec
)
noexcept
...
...
@@ -398,14 +399,14 @@ void UNetReceiver::update() noexcept
upCount
++
;
// Обработка дискретных
auto
d_iv
=
getDCache
(
p
,
!
d_cache_init_ok
);
auto
d_iv
=
getDCache
(
p
);
for
(
size_t
i
=
0
;
i
<
p
->
dcount
;
i
++
)
{
try
{
s_id
=
p
->
dID
(
i
);
c_it
=
&
d_iv
.
cache
[
i
];
c_it
=
&
(
*
d_iv
)
[
i
];
if
(
c_it
->
id
!=
s_id
)
{
...
...
@@ -439,14 +440,14 @@ void UNetReceiver::update() noexcept
}
// Обработка аналоговых
auto
a_iv
=
getACache
(
p
,
!
a_cache_init_ok
);
auto
a_iv
=
getACache
(
p
);
for
(
size_t
i
=
0
;
i
<
p
->
acount
;
i
++
)
{
try
{
dat
=
&
p
->
a_dat
[
i
];
c_it
=
&
a_iv
.
cache
[
i
];
c_it
=
&
(
*
a_iv
)
[
i
];
if
(
c_it
->
id
!=
dat
->
id
)
{
...
...
@@ -719,7 +720,7 @@ void UNetReceiver::initIterators() noexcept
{
for
(
auto
mit
=
d_icache_map
.
begin
();
mit
!=
d_icache_map
.
end
();
++
mit
)
{
CacheVec
&
d_icache
(
mit
->
second
.
cache
)
;
CacheVec
&
d_icache
=
mit
->
second
;
for
(
auto
&&
it
:
d_icache
)
shm
->
initIterator
(
it
.
ioit
);
...
...
@@ -727,49 +728,35 @@ void UNetReceiver::initIterators() noexcept
for
(
auto
mit
=
a_icache_map
.
begin
();
mit
!=
a_icache_map
.
end
();
++
mit
)
{
CacheVec
&
a_icache
(
mit
->
second
.
cache
)
;
CacheVec
&
a_icache
=
mit
->
second
;
for
(
auto
&&
it
:
a_icache
)
shm
->
initIterator
(
it
.
ioit
);
}
}
// -----------------------------------------------------------------------------
UNetReceiver
::
Cache
Info
&
UNetReceiver
::
getDCache
(
UniSetUDP
::
UDPMessage
*
pack
,
bool
force
)
noexcept
UNetReceiver
::
Cache
Vec
*
UNetReceiver
::
getDCache
(
UniSetUDP
::
UDPMessage
*
pack
)
noexcept
{
// если элемента нет, он будет создан
CacheInfo
&
d_info
=
d_icache_map
[
pack
->
getDataID
()];
auto
dit
=
d_icache_map
.
find
(
pack
->
getDataID
());
if
(
!
force
&&
pack
->
dcount
==
d_info
.
cache
.
size
()
)
return
d_info
;
if
(
d_info
.
cache_init_ok
&&
pack
->
dcount
==
d_info
.
cache
.
size
()
)
if
(
dit
==
d_icache_map
.
end
()
)
{
d_cache_init_ok
=
true
;
auto
it
=
d_icache_map
.
begin
();
for
(
;
it
!=
d_icache_map
.
end
();
++
it
)
{
d_info
=
it
->
second
;
d_cache_init_ok
=
d_cache_init_ok
&&
d_info
.
cache_init_ok
;
auto
p
=
d_icache_map
.
emplace
(
pack
->
getDataID
(),
UNetReceiver
::
CacheVec
());
dit
=
p
.
first
;
}
if
(
d_cache_init_ok
==
false
)
break
;
}
CacheVec
*
d_info
=
&
dit
->
second
;
if
(
pack
->
dcount
==
d_info
->
size
()
)
return
d_info
;
}
unetinfo
<<
myname
<<
": init dcache for "
<<
pack
->
getDataID
()
<<
endl
;
d_info
.
cache_init_ok
=
true
;
d_info
.
cache
.
resize
(
pack
->
dcount
);
size_t
sz
=
d_info
.
cache
.
size
();
auto
conf
=
uniset_conf
();
d_info
->
resize
(
pack
->
dcount
);
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
for
(
size_t
i
=
0
;
i
<
pack
->
dcount
;
i
++
)
{
CacheItem
&
d
(
d_info
.
cache
[
i
])
;
CacheItem
&
d
=
(
*
d_info
)[
i
]
;
if
(
d
.
id
!=
pack
->
d_id
[
i
]
)
{
...
...
@@ -781,42 +768,28 @@ UNetReceiver::CacheInfo& UNetReceiver::getDCache( UniSetUDP::UDPMessage* pack, b
return
d_info
;
}
// -----------------------------------------------------------------------------
UNetReceiver
::
Cache
Info
&
UNetReceiver
::
getACache
(
UniSetUDP
::
UDPMessage
*
pack
,
bool
force
)
noexcept
UNetReceiver
::
Cache
Vec
*
UNetReceiver
::
getACache
(
UniSetUDP
::
UDPMessage
*
pack
)
noexcept
{
// если элемента нет, он будет создан
CacheInfo
&
a_info
=
a_icache_map
[
pack
->
getDataID
()];
if
(
!
force
&&
pack
->
acount
==
a_info
.
cache
.
size
()
)
return
a_info
;
auto
ait
=
a_icache_map
.
find
(
pack
->
getDataID
());
if
(
a
_info
.
cache_init_ok
&&
pack
->
acount
==
a_info
.
cache
.
size
()
)
if
(
a
it
==
a_icache_map
.
end
()
)
{
a_cache_init_ok
=
true
;
auto
it
=
a_icache_map
.
begin
();
for
(
;
it
!=
a_icache_map
.
end
();
++
it
)
{
a_info
=
it
->
second
;
a_cache_init_ok
=
a_cache_init_ok
&&
a_info
.
cache_init_ok
;
auto
p
=
a_icache_map
.
emplace
(
pack
->
getDataID
(),
UNetReceiver
::
CacheVec
());
ait
=
p
.
first
;
}
if
(
a_cache_init_ok
==
false
)
break
;
}
CacheVec
*
a_info
=
&
ait
->
second
;
if
(
pack
->
acount
==
a_info
->
size
()
)
return
a_info
;
}
unetinfo
<<
myname
<<
": init icache for "
<<
pack
->
getDataID
()
<<
endl
;
a_info
.
cache_init_ok
=
true
;
auto
conf
=
uniset_conf
();
a_info
.
cache
.
resize
(
pack
->
acount
)
;
unetinfo
<<
myname
<<
": init acache for "
<<
pack
->
getDataID
()
<<
endl
;
size_t
sz
=
a_info
.
cache
.
size
(
);
a_info
->
resize
(
pack
->
acount
);
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
for
(
size_t
i
=
0
;
i
<
pack
->
acount
;
i
++
)
{
CacheItem
&
d
(
a_info
.
cache
[
i
])
;
CacheItem
&
d
=
(
*
a_info
)[
i
]
;
if
(
d
.
id
!=
pack
->
a_dat
[
i
].
id
)
{
...
...
extensions/UNetUDP/UNetReceiver.h
View file @
448e9baa
...
...
@@ -20,8 +20,7 @@
#include <ostream>
#include <memory>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <unordered_map>
#include <sigc++/sigc++.h>
#include <ev++.h>
...
...
@@ -269,25 +268,14 @@ namespace uniset
};
typedef
std
::
vector
<
CacheItem
>
CacheVec
;
struct
CacheInfo
{
CacheInfo
()
:
cache_init_ok
(
false
)
{}
bool
cache_init_ok
=
{
false
};
CacheVec
cache
;
};
// ключом является UDPMessage::getDataID()
typedef
std
::
unordered_map
<
long
,
Cache
Info
>
CacheMap
;
typedef
std
::
unordered_map
<
long
,
Cache
Vec
>
CacheMap
;
CacheMap
d_icache_map
;
/*!< кэш итераторов для булевых */
CacheMap
a_icache_map
;
/*!< кэш итераторов для аналоговых */
bool
d_cache_init_ok
=
{
false
};
bool
a_cache_init_ok
=
{
false
};
CacheInfo
&
getDCache
(
UniSetUDP
::
UDPMessage
*
pack
,
bool
force
=
false
)
noexcept
;
CacheInfo
&
getACache
(
UniSetUDP
::
UDPMessage
*
pack
,
bool
force
=
false
)
noexcept
;
CacheVec
*
getDCache
(
UniSetUDP
::
UDPMessage
*
pack
)
noexcept
;
CacheVec
*
getACache
(
UniSetUDP
::
UDPMessage
*
pack
)
noexcept
;
};
// --------------------------------------------------------------------------
}
// end of namespace uniset
...
...
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