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
98dd5641
Commit
98dd5641
authored
Aug 26, 2020
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement consume for length prefix framing
parent
48cb551e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
libcaf_net/caf/net/length_prefix_framing.hpp
libcaf_net/caf/net/length_prefix_framing.hpp
+21
-10
No files found.
libcaf_net/caf/net/length_prefix_framing.hpp
View file @
98dd5641
...
@@ -24,7 +24,10 @@
...
@@ -24,7 +24,10 @@
#include "caf/byte.hpp"
#include "caf/byte.hpp"
#include "caf/detail/network_order.hpp"
#include "caf/detail/network_order.hpp"
#include "caf/error.hpp"
#include "caf/net/receive_policy.hpp"
#include "caf/sec.hpp"
#include "caf/sec.hpp"
#include "caf/span.hpp"
#include "caf/tag/message_oriented.hpp"
#include "caf/tag/message_oriented.hpp"
#include "caf/tag/stream_oriented.hpp"
#include "caf/tag/stream_oriented.hpp"
...
@@ -38,13 +41,15 @@ namespace caf::net {
...
@@ -38,13 +41,15 @@ namespace caf::net {
template
<
class
UpperLayer
>
template
<
class
UpperLayer
>
class
length_prefix_framing
{
class
length_prefix_framing
{
public:
public:
using
byte_span
=
span
<
const
byte
>
;
using
input_tag
=
tag
::
stream_oriented
;
using
input_tag
=
tag
::
stream_oriented
;
using
output_tag
=
tag
::
message_oriented
;
using
output_tag
=
tag
::
message_oriented
;
using
length_prefix_type
=
uint32_t
;
using
length_prefix_type
=
uint32_t
;
constexpr
size_t
max_message_length
=
INT32_MAX
;
static
constexpr
size_t
max_message_length
=
INT32_MAX
;
// -- interface for the upper layer ------------------------------------------
// -- interface for the upper layer ------------------------------------------
...
@@ -52,7 +57,7 @@ public:
...
@@ -52,7 +57,7 @@ public:
class
access
{
class
access
{
public:
public:
access
(
LowerLayer
*
lower_layer
,
length_prefix_framing
*
this_layer
)
access
(
LowerLayer
*
lower_layer
,
length_prefix_framing
*
this_layer
)
:
lower_layer_
(
lower_layer
),
this_layer
(
this_layer
)
{
:
lower_layer_
(
lower_layer
),
this_layer
_
(
this_layer
)
{
// nop
// nop
}
}
...
@@ -64,10 +69,10 @@ public:
...
@@ -64,10 +69,10 @@ public:
}
}
byte_buffer
&
message_buffer
()
{
byte_buffer
&
message_buffer
()
{
return
lower_layer_
->
output_buffer
.
size
();
return
lower_layer_
->
output_buffer
();
}
}
void
end_message
()
{
bool
end_message
()
{
using
detail
::
to_network_order
;
using
detail
::
to_network_order
;
auto
&
buf
=
message_buffer
();
auto
&
buf
=
message_buffer
();
auto
msg_begin
=
buf
.
begin
()
+
message_offset_
;
auto
msg_begin
=
buf
.
begin
()
+
message_offset_
;
...
@@ -93,11 +98,7 @@ public:
...
@@ -93,11 +98,7 @@ public:
}
}
void
configure_read
(
receive_policy
policy
)
{
void
configure_read
(
receive_policy
policy
)
{
if
(
policy
.
max_size
>
0
&&
transport_
->
max_read_size_
==
0
)
lower_layer_
->
configure_read
(
policy
);
parent_
->
register_reading
();
transport_
->
min_read_size_
=
policy
.
min_size
;
transport_
->
max_read_size_
=
policy
.
max_size
;
transport_
->
read_buf_
.
resize
(
policy
.
max_size
);
}
}
private:
private:
...
@@ -136,7 +137,17 @@ public:
...
@@ -136,7 +137,17 @@ public:
}
}
template
<
class
LowerLayer
>
template
<
class
LowerLayer
>
ptrdiff_t
consume
(
LowerLayer
&
down
,
byte_span
buffer
,
byte_span
delta
)
{
ptrdiff_t
consume
(
LowerLayer
&
down
,
byte_span
buffer
,
byte_span
)
{
using
detail
::
from_network_order
;
if
(
buffer
.
size
()
<
4
)
return
0
;
auto
u32_size
=
0
;
memcpy
(
&
u32_size
,
buffer
.
data
(),
4
);
auto
msg_size
=
static_cast
<
size_t
>
(
from_network_order
(
u32_size
));
if
(
buffer
.
size
()
<
msg_size
+
4
)
return
0
;
upper_layer_
.
consume
(
down
,
make_span
(
buffer
.
data
()
+
4
,
msg_size
));
return
msg_size
+
4
;
}
}
private:
private:
...
...
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