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
dff48ceb
Commit
dff48ceb
authored
Oct 09, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add packet_writer_interface
parent
01c487f1
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
22 deletions
+142
-22
libcaf_net/caf/net/packet_writer.hpp
libcaf_net/caf/net/packet_writer.hpp
+55
-0
libcaf_net/caf/net/packet_writer_impl.hpp
libcaf_net/caf/net/packet_writer_impl.hpp
+20
-4
libcaf_net/caf/net/stream_transport.hpp
libcaf_net/caf/net/stream_transport.hpp
+27
-2
libcaf_net/caf/net/transport_worker.hpp
libcaf_net/caf/net/transport_worker.hpp
+15
-15
libcaf_net/caf/net/transport_worker_dispatcher.hpp
libcaf_net/caf/net/transport_worker_dispatcher.hpp
+1
-1
libcaf_net/test/transport_worker.cpp
libcaf_net/test/transport_worker.cpp
+12
-0
libcaf_net/test/transport_worker_dispatcher.cpp
libcaf_net/test/transport_worker_dispatcher.cpp
+12
-0
No files found.
libcaf_net/caf/net/packet_writer.hpp
0 → 100644
View file @
dff48ceb
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include <vector>
#include "caf/byte.hpp"
#include "caf/net/fwd.hpp"
#include "caf/span.hpp"
namespace
caf
{
namespace
net
{
class
packet_writer
{
public:
using
buffer_type
=
std
::
vector
<
byte
>
;
// virtual ~packet_writer() = default;
virtual
buffer_type
next_header_buffer
()
=
0
;
virtual
buffer_type
next_buffer
()
=
0
;
// TODO: some documentation
// First buffer is header.
// Following buffers are one or more payload buffers for this packet.
/// @warning takes ownership of `buffers`.
template
<
class
...
Ts
>
void
write_packet
(
Ts
...
buffers
)
{
buffer_type
*
bufs
[]
=
{
&
buffers
...};
write_impl
(
make_span
(
bufs
,
sizeof
...(
Ts
)));
}
protected:
virtual
void
write_impl
(
span
<
buffer_type
*>
buffers
)
=
0
;
};
}
// namespace net
}
// namespace caf
libcaf_net/caf/net/
write_packet_decorator
.hpp
→
libcaf_net/caf/net/
packet_writer_impl
.hpp
View file @
dff48ceb
...
...
@@ -18,6 +18,8 @@
#pragma once
#include "caf/net/packet_writer.hpp"
#include "caf/byte.hpp"
#include "caf/span.hpp"
...
...
@@ -27,7 +29,7 @@ namespace net {
/// Implements the interface for transport and application policies and
/// dispatches member functions either to `decorator` or `parent`.
template
<
class
Object
,
class
Parent
>
class
write_packet_decorato
r
{
class
packet_writer_impl
final
:
public
packet_write
r
{
public:
// -- member types -----------------------------------------------------------
...
...
@@ -37,7 +39,7 @@ public:
// -- constructors, destructors, and assignment operators --------------------
write_packet_decorator
(
Object
&
object
,
Parent
&
parent
)
packet_writer_impl
(
Object
&
object
,
Parent
&
parent
)
:
object_
(
object
),
parent_
(
parent
)
{
// nop
}
...
...
@@ -56,6 +58,14 @@ public:
return
parent_
.
manager
();
}
buffer_type
next_header_buffer
()
override
{
return
transport
().
next_header_buffer
();
}
buffer_type
next_buffer
()
override
{
return
transport
().
next_buffer
();
}
// -- member functions -------------------------------------------------------
template
<
class
...
Ts
>
...
...
@@ -74,14 +84,20 @@ public:
return
parent_
.
set_timeout
(
tout
,
type
,
std
::
forward
<
Ts
>
(
xs
)...);
}
protected:
// TODO: this should replace the current `write_packet()`
void
write_impl
(
span
<
buffer_type
*>
)
override
{
// parent_.write_packet(buffers);
}
private:
Object
&
object_
;
Parent
&
parent_
;
};
template
<
class
Object
,
class
Parent
>
write_packet_decorator
<
Object
,
Parent
>
make_write_packet_decorator
(
Object
&
object
,
Parent
&
parent
)
{
packet_writer_impl
<
Object
,
Parent
>
make_packet_writer_impl
(
Object
&
object
,
Parent
&
parent
)
{
return
{
object
,
parent
};
}
...
...
libcaf_net/caf/net/stream_transport.hpp
View file @
dff48ceb
...
...
@@ -45,6 +45,8 @@ public:
using
worker_type
=
transport_worker
<
application_type
>
;
using
buffer_type
=
std
::
vector
<
byte
>
;
// -- constructors, destructors, and assignment operators --------------------
stream_transport
(
stream_socket
handle
,
application_type
application
)
...
...
@@ -206,6 +208,26 @@ public:
write_buf_
.
insert
(
write_buf_
.
end
(),
payload
.
begin
(),
payload
.
end
());
}
// -- buffer recycling -------------------------------------------------------
buffer_type
next_header_buffer
()
{
return
next_buffer_impl
(
free_header_bufs_
);
}
buffer_type
next_buffer
()
{
return
next_buffer_impl
(
free_bufs_
);
}
buffer_type
next_buffer_impl
(
std
::
deque
<
buffer_type
>&
container
)
{
if
(
container
.
empty
())
{
return
{};
}
else
{
auto
buf
=
std
::
move
(
container
.
front
());
container
.
pop_front
();
return
buf
;
}
}
private:
// -- private member functions -----------------------------------------------
...
...
@@ -239,8 +261,11 @@ private:
worker_type
worker_
;
stream_socket
handle_
;
std
::
vector
<
byte
>
read_buf_
;
std
::
vector
<
byte
>
write_buf_
;
std
::
deque
<
buffer_type
>
free_header_bufs_
;
std
::
deque
<
buffer_type
>
free_bufs_
;
buffer_type
read_buf_
;
buffer_type
write_buf_
;
// TODO implement retries using this member!
// size_t max_consecutive_reads_;
...
...
libcaf_net/caf/net/transport_worker.hpp
View file @
dff48ceb
...
...
@@ -22,7 +22,7 @@
#include "caf/ip_endpoint.hpp"
#include "caf/net/endpoint_manager.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/
write_packet_decorator
.hpp"
#include "caf/net/
packet_writer_impl
.hpp"
#include "caf/span.hpp"
#include "caf/unit.hpp"
...
...
@@ -64,46 +64,46 @@ public:
template
<
class
Parent
>
error
init
(
Parent
&
parent
)
{
auto
decorator
=
make_write_packet_decorator
(
*
this
,
parent
);
return
application_
.
init
(
decorato
r
);
auto
writer
=
make_packet_writer_impl
(
*
this
,
parent
);
return
application_
.
init
(
write
r
);
}
template
<
class
Parent
>
error
handle_data
(
Parent
&
parent
,
span
<
const
byte
>
data
)
{
auto
decorator
=
make_write_packet_decorator
(
*
this
,
parent
);
return
application_
.
handle_data
(
decorato
r
,
data
);
auto
writer
=
make_packet_writer_impl
(
*
this
,
parent
);
return
application_
.
handle_data
(
write
r
,
data
);
}
template
<
class
Parent
>
void
write_message
(
Parent
&
parent
,
std
::
unique_ptr
<
endpoint_manager_queue
::
message
>
msg
)
{
auto
decorator
=
make_write_packet_decorator
(
*
this
,
parent
);
application_
.
write_message
(
decorato
r
,
std
::
move
(
msg
));
auto
writer
=
make_packet_writer_impl
(
*
this
,
parent
);
application_
.
write_message
(
write
r
,
std
::
move
(
msg
));
}
template
<
class
Parent
>
void
resolve
(
Parent
&
parent
,
string_view
path
,
const
actor
&
listener
)
{
auto
decorator
=
make_write_packet_decorator
(
*
this
,
parent
);
application_
.
resolve
(
decorato
r
,
path
,
listener
);
auto
writer
=
make_packet_writer_impl
(
*
this
,
parent
);
application_
.
resolve
(
write
r
,
path
,
listener
);
}
template
<
class
Parent
>
void
new_proxy
(
Parent
&
parent
,
const
node_id
&
,
actor_id
id
)
{
auto
decorator
=
make_write_packet_decorator
(
*
this
,
parent
);
application_
.
new_proxy
(
decorato
r
,
id
);
auto
writer
=
make_packet_writer_impl
(
*
this
,
parent
);
application_
.
new_proxy
(
write
r
,
id
);
}
template
<
class
Parent
>
void
local_actor_down
(
Parent
&
parent
,
const
node_id
&
,
actor_id
id
,
error
reason
)
{
auto
decorator
=
make_write_packet_decorator
(
*
this
,
parent
);
application_
.
local_actor_down
(
decorato
r
,
id
,
std
::
move
(
reason
));
auto
writer
=
make_packet_writer_impl
(
*
this
,
parent
);
application_
.
local_actor_down
(
write
r
,
id
,
std
::
move
(
reason
));
}
template
<
class
Parent
>
void
timeout
(
Parent
&
parent
,
atom_value
value
,
uint64_t
id
)
{
auto
decorator
=
make_write_packet_decorator
(
*
this
,
parent
);
application_
.
timeout
(
decorato
r
,
value
,
id
);
auto
writer
=
make_packet_writer_impl
(
*
this
,
parent
);
application_
.
timeout
(
write
r
,
value
,
id
);
}
void
handle_error
(
sec
error
)
{
...
...
libcaf_net/caf/net/transport_worker_dispatcher.hpp
View file @
dff48ceb
...
...
@@ -24,8 +24,8 @@
#include "caf/ip_endpoint.hpp"
#include "caf/net/endpoint_manager.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/packet_writer_impl.hpp"
#include "caf/net/transport_worker.hpp"
#include "caf/net/write_packet_decorator.hpp"
#include "caf/span.hpp"
#include "caf/unit.hpp"
...
...
libcaf_net/test/transport_worker.cpp
View file @
dff48ceb
...
...
@@ -130,6 +130,18 @@ public:
res_
->
ep
=
ep
;
}
transport_type
&
transport
()
{
return
*
this
;
}
std
::
vector
<
byte
>
next_buffer
()
{
return
{};
}
std
::
vector
<
byte
>
next_header_buffer
()
{
return
{};
}
private:
std
::
shared_ptr
<
transport_result
>
res_
;
};
...
...
libcaf_net/test/transport_worker_dispatcher.cpp
View file @
dff48ceb
...
...
@@ -130,6 +130,18 @@ struct dummy_transport {
buf_
->
insert
(
buf_
->
end
(),
payload
.
begin
(),
payload
.
end
());
}
transport_type
&
transport
()
{
return
*
this
;
}
std
::
vector
<
byte
>
next_buffer
()
{
return
{};
}
std
::
vector
<
byte
>
next_header_buffer
()
{
return
{};
}
private:
std
::
shared_ptr
<
std
::
vector
<
byte
>>
buf_
;
};
...
...
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