Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
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
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-incubator
Commits
b5c3fb8a
Commit
b5c3fb8a
authored
Jan 17, 2020
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement read retries for tcp
parent
6344cacd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
26 deletions
+34
-26
libcaf_net/caf/net/stream_transport.hpp
libcaf_net/caf/net/stream_transport.hpp
+28
-26
libcaf_net/caf/net/transport_base.hpp
libcaf_net/caf/net/transport_base.hpp
+6
-0
No files found.
libcaf_net/caf/net/stream_transport.hpp
View file @
b5c3fb8a
...
...
@@ -23,7 +23,6 @@
#include "caf/fwd.hpp"
#include "caf/logger.hpp"
#include "caf/net/defaults.hpp"
#include "caf/net/endpoint_manager.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/receive_policy.hpp"
...
...
@@ -74,31 +73,36 @@ public:
// -- member functions -------------------------------------------------------
bool
handle_read_event
(
endpoint_manager
&
)
override
{
auto
buf
=
this
->
read_buf_
.
data
()
+
this
->
collected_
;
size_t
len
=
this
->
read_threshold_
-
this
->
collected_
;
CAF_LOG_TRACE
(
CAF_ARG2
(
"handle"
,
this
->
handle
().
id
)
<<
CAF_ARG2
(
"missing"
,
len
));
auto
ret
=
read
(
this
->
handle_
,
make_span
(
buf
,
len
));
// Update state.
if
(
auto
num_bytes
=
get_if
<
size_t
>
(
&
ret
))
{
CAF_LOG_DEBUG
(
CAF_ARG
(
len
)
<<
CAF_ARG
(
this
->
handle_
.
id
)
<<
CAF_ARG
(
*
num_bytes
));
this
->
collected_
+=
*
num_bytes
;
if
(
this
->
collected_
>=
this
->
read_threshold_
)
{
if
(
auto
err
=
this
->
next_layer_
.
handle_data
(
*
this
,
make_span
(
this
->
read_buf_
)))
{
CAF_LOG_ERROR
(
"handle_data failed: "
<<
CAF_ARG
(
err
));
size_t
reads
=
0
;
while
(
reads
++
<
this
->
max_consecutive_reads_
)
{
auto
buf
=
this
->
read_buf_
.
data
()
+
this
->
collected_
;
size_t
len
=
this
->
read_threshold_
-
this
->
collected_
;
CAF_LOG_TRACE
(
CAF_ARG2
(
"handle"
,
this
->
handle
().
id
)
<<
CAF_ARG2
(
"missing"
,
len
));
auto
ret
=
read
(
this
->
handle_
,
make_span
(
buf
,
len
));
// Update state.
if
(
auto
num_bytes
=
get_if
<
size_t
>
(
&
ret
))
{
CAF_LOG_DEBUG
(
CAF_ARG
(
len
)
<<
CAF_ARG
(
this
->
handle_
.
id
)
<<
CAF_ARG
(
*
num_bytes
));
this
->
collected_
+=
*
num_bytes
;
if
(
this
->
collected_
>=
this
->
read_threshold_
)
{
if
(
auto
err
=
this
->
next_layer_
.
handle_data
(
*
this
,
make_span
(
this
->
read_buf_
)))
{
CAF_LOG_ERROR
(
"handle_data failed: "
<<
CAF_ARG
(
err
));
return
false
;
}
this
->
prepare_next_read
();
}
}
else
{
auto
err
=
get
<
sec
>
(
ret
);
if
(
err
==
sec
::
unavailable_or_would_block
)
{
break
;
}
else
{
CAF_LOG_DEBUG
(
"read failed"
<<
CAF_ARG
(
err
));
this
->
next_layer_
.
handle_error
(
err
);
return
false
;
}
this
->
prepare_next_read
();
}
}
else
{
auto
err
=
get
<
sec
>
(
ret
);
if
(
err
!=
sec
::
unavailable_or_would_block
)
{
CAF_LOG_DEBUG
(
"read failed"
<<
CAF_ARG
(
err
));
this
->
next_layer_
.
handle_error
(
err
);
return
false
;
}
}
return
true
;
...
...
@@ -214,8 +218,6 @@ private:
size_t
collected_
;
size_t
max_
;
receive_policy_flag
rd_flag_
;
// TODO implement retries using this member!
// size_t max_consecutive_reads_;
};
}
// namespace caf::net
libcaf_net/caf/net/transport_base.hpp
View file @
b5c3fb8a
...
...
@@ -18,6 +18,7 @@
#pragma once
#include "caf/defaults.hpp"
#include "caf/detail/overload.hpp"
#include "caf/fwd.hpp"
#include "caf/logger.hpp"
...
...
@@ -100,6 +101,9 @@ public:
CAF_LOG_TRACE
(
""
);
manager_
=
&
parent
;
auto
&
cfg
=
system
().
config
();
max_consecutive_reads_
=
get_or
(
this
->
system
().
config
(),
"middleman.max-consecutive-reads"
,
defaults
::
middleman
::
max_consecutive_reads
);
auto
max_header_bufs
=
get_or
(
cfg
,
"middleman.max-header-buffers"
,
defaults
::
middleman
::
max_header_buffers
);
header_bufs_
.
reserve
(
max_header_bufs
);
...
...
@@ -224,6 +228,8 @@ protected:
buffer_type
read_buf_
;
endpoint_manager
*
manager_
;
size_t
max_consecutive_reads_
;
};
}
// namespace caf::net
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