Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Beyond Protocol
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Maintenance moved to Monday 17.3. at 13:00. ETA 60 - 90 minutes.
Show more breadcrumbs
Beyond AKA
Beyond Protocol
Commits
391c2cee
Commit
391c2cee
authored
2 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
Change net stream buffer mechanism
parent
dcb0b320
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/streams/netstream.cpp
+23
-6
23 additions, 6 deletions
src/streams/netstream.cpp
src/streams/netstream.hpp
+1
-1
1 addition, 1 deletion
src/streams/netstream.hpp
with
24 additions
and
7 deletions
src/streams/netstream.cpp
+
23
−
6
View file @
391c2cee
...
...
@@ -309,12 +309,16 @@ void Net::_run() {
int64_t
cts
=
now
-
state
->
base_local_ts_
;
bool
hasNext
=
false
;
bool
hasDone
=
false
;
// If there are any packets that should be dispatched
// Then create a thread for each and do it.
if
(
state
->
active
==
0
)
{
//if (state->active == 0) {
{
SHARED_LOCK
(
state
->
mtx
,
lk2
);
auto
current
=
state
->
buffer
.
begin
();
while
(
current
!=
state
->
buffer
.
end
())
{
lk2
.
unlock
();
if
(
!
current
->
done
)
{
if
(
state
->
base_local_ts_
==
0
)
{
state
->
base_local_ts_
=
now
;
...
...
@@ -325,7 +329,7 @@ void Net::_run() {
int64_t
pts
=
current
->
packets
.
first
.
timestamp
-
state
->
base_pkt_ts_
+
buffering_
;
// Should the packet be dispatched yet
if
(
pts
<=
cts
)
{
if
(
state
->
active
==
0
&&
pts
<=
cts
)
{
cts
=
pts
;
// Prevent multi frames.
StreamPacket
*
spkt
;
...
...
@@ -346,13 +350,17 @@ void Net::_run() {
hasNext
=
true
;
break
;
}
}
else
{
hasDone
=
true
;
}
lk2
.
lock
();
++
current
;
}
}
else
{
LOG
(
WARNING
)
<<
"Already active"
;
}
/*} else {
LOG(WARNING) << "Already active";
}*/
if
(
!
hasNext
)
{
nextTs
=
std
::
min
(
nextTs
,
now
+
10
);
...
...
@@ -360,8 +368,17 @@ void Net::_run() {
}
// Remove consumed packets.
UNIQUE_LOCK
(
state
->
mtx
,
lk2
);
state
->
buffer
.
remove_if
([](
const
PacketBuffer
&
i
)
{
return
static_cast
<
bool
>
(
i
.
done
);
});
if
(
hasDone
)
{
UNIQUE_LOCK
(
state
->
mtx
,
lk
);
auto
it
=
state
->
buffer
.
begin
();
while
(
it
!=
state
->
buffer
.
end
())
{
if
(
it
->
done
)
{
it
=
state
->
buffer
.
erase
(
it
);
}
else
{
break
;
}
}
}
}
lk
.
unlock
();
...
...
This diff is collapsed.
Click to expand it.
src/streams/netstream.hpp
+
1
−
1
View file @
391c2cee
...
...
@@ -119,7 +119,7 @@ class Net : public Stream {
struct
FrameState
{
ftl
::
protocol
::
FrameID
id
;
std
::
atomic_int
active
=
0
;
MUTEX
mtx
;
SHARED_
MUTEX
mtx
;
std
::
list
<
PacketBuffer
>
buffer
;
int64_t
base_pkt_ts_
=
0
;
int64_t
base_local_ts_
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment