Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
5aa9cfb2
Commit
5aa9cfb2
authored
Mar 06, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix resuming with buffered data
parent
1ac28307
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
17 deletions
+31
-17
libcaf_net/caf/net/stream_transport.hpp
libcaf_net/caf/net/stream_transport.hpp
+31
-17
No files found.
libcaf_net/caf/net/stream_transport.hpp
View file @
5aa9cfb2
...
...
@@ -373,6 +373,30 @@ public:
};
// Keep track of how many bytes of data are still pending in the policy.
auto
internal_buffer_size
=
policy_
.
buffered
();
// Convenience lambda for refilling read_buf_ with data from the policy's
// internal buffer.
auto
refill
=
[
this
,
&
parent
,
&
internal_buffer_size
]
{
if
(
internal_buffer_size
>
0
&&
max_read_size_
>
offset_
)
{
// Make sure our buffer has sufficient space.
if
(
read_buf_
.
size
()
<
max_read_size_
)
read_buf_
.
resize
(
max_read_size_
);
// Fetch already buffered data to 'refill' the buffer as we go.
auto
n
=
std
::
min
(
internal_buffer_size
,
max_read_size_
-
static_cast
<
size_t
>
(
offset_
));
auto
rdb
=
make_span
(
read_buf_
.
data
()
+
offset_
,
n
);
auto
rd
=
policy_
.
read
(
parent
->
handle
(),
rdb
);
if
(
rd
<
0
)
return
false
;
offset_
+=
rd
;
internal_buffer_size
-=
rd
;
CAF_ASSERT
(
internal_buffer_size
==
policy_
.
buffered
());
}
return
true
;
};
if
(
!
refill
())
return
fail
(
make_error
(
caf
::
sec
::
runtime_error
,
"policy error: reading buffered data "
"may not result in an error"
));
// The offset_ may change as a result of invoking the upper layer. Hence,
// need to run this in a loop to push data up for as long as we have
// buffered data available.
...
...
@@ -385,6 +409,7 @@ public:
// sure to consume the buffer because the OS does not know about it and
// will not trigger a read event based on data available there.
do
{
// Push data to the next layer.
ptrdiff_t
consumed
=
invoke_upper_layer
(
read_buf_
.
data
(),
offset_
,
delta_offset_
);
CAF_LOG_DEBUG
(
CAF_ARG2
(
"socket"
,
parent
->
handle
().
id
)
...
...
@@ -408,25 +433,14 @@ public:
delta_offset_
=
0
;
}
// Stop if the application asked for it.
if
(
max_read_size_
==
0
)
if
(
max_read_size_
==
0
)
{
return
read_result
::
stop
;
if
(
internal_buffer_size
>
0
&&
max_read_size_
>
offset_
)
{
// Make sure our buffer has sufficient space.
if
(
read_buf_
.
size
()
<
max_read_size_
)
read_buf_
.
resize
(
max_read_size_
);
// Fetch already buffered data to 'refill' the buffer as we go.
auto
n
=
std
::
min
(
internal_buffer_size
,
max_read_size_
-
static_cast
<
size_t
>
(
offset_
));
auto
rdb
=
make_span
(
read_buf_
.
data
()
+
offset_
,
n
);
auto
rd
=
policy_
.
read
(
parent
->
handle
(),
rdb
);
if
(
rd
<
0
)
}
// Prepare next loop iteration.
if
(
!
refill
())
return
fail
(
make_error
(
caf
::
sec
::
runtime_error
,
"policy error: reading buffered data "
"may not result in an error"
));
offset_
+=
rd
;
internal_buffer_size
-=
rd
;
CAF_ASSERT
(
internal_buffer_size
==
policy_
.
buffered
());
}
}
while
(
internal_buffer_size
>
0
);
}
return
read_result
::
again
;
...
...
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