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
9971d016
Commit
9971d016
authored
Nov 12, 2016
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Found a problem with the unified enpoints
parent
958471aa
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
47 deletions
+58
-47
libcaf_io/caf/io/endpoint.hpp
libcaf_io/caf/io/endpoint.hpp
+1
-1
libcaf_io/caf/io/network/datagram_sink_manager.hpp
libcaf_io/caf/io/network/datagram_sink_manager.hpp
+4
-0
libcaf_io/caf/io/network/datagram_source_manager.hpp
libcaf_io/caf/io/network/datagram_source_manager.hpp
+2
-4
libcaf_io/caf/io/network/default_multiplexer.hpp
libcaf_io/caf/io/network/default_multiplexer.hpp
+2
-2
libcaf_io/caf/io/network/endpoint_manager.hpp
libcaf_io/caf/io/network/endpoint_manager.hpp
+1
-1
libcaf_io/src/default_multiplexer.cpp
libcaf_io/src/default_multiplexer.cpp
+48
-39
No files found.
libcaf_io/caf/io/endpoint.hpp
View file @
9971d016
...
...
@@ -57,7 +57,7 @@ public:
virtual
std
::
vector
<
char
>&
rd_buf
()
=
0
;
bool
consume
(
execution_unit
*
ctx
,
const
void
*
buf
,
size_t
besize
)
override
;
void
datagram_sent
(
execution_unit
*
ctx
,
size_t
num_bytes
)
override
;
void
io_failure
(
execution_unit
*
ctx
,
network
::
operation
op
)
override
;
...
...
libcaf_io/caf/io/network/datagram_sink_manager.hpp
View file @
9971d016
...
...
@@ -34,6 +34,10 @@ public:
~
datagram_sink_manager
();
/// Called by the underlying I/O device whenever it received data.
/// @returns `true` if the manager accepts further reads, otherwise `false`.
virtual
bool
consume
(
execution_unit
*
ctx
,
const
void
*
buf
,
size_t
besize
)
=
0
;
/// Called by the underlying I/O device whenever it sent a datagram.
virtual
void
datagram_sent
(
execution_unit
*
ctx
,
size_t
num_bytes
)
=
0
;
};
...
...
libcaf_io/caf/io/network/datagram_source_manager.hpp
View file @
9971d016
...
...
@@ -32,11 +32,9 @@ class datagram_source_manager : public manager {
public:
datagram_source_manager
(
abstract_broker
*
ptr
);
~
datagram_source_manager
();
~
datagram_source_manager
();
/// Called by the underlying I/O device whenever it received data.
/// @returns `true` if the manager accepts further reads, otherwise `false`.
virtual
bool
consume
(
execution_unit
*
ctx
,
const
void
*
buf
,
size_t
besize
)
=
0
;
virtual
bool
new_endpoint
()
=
0
;
};
}
// namespace network
...
...
libcaf_io/caf/io/network/default_multiplexer.hpp
View file @
9971d016
...
...
@@ -570,7 +570,7 @@ private:
};
class
datagram_h
dl
r
:
public
event_handler
{
class
datagram_h
andle
r
:
public
event_handler
{
public:
/// A manager type providing the TODO
using
manager_type
=
endpoint_manager
;
...
...
@@ -582,7 +582,7 @@ public:
/// interface to `std::vector`.
using
buffer_type
=
std
::
vector
<
char
>
;
datagram_h
dl
r
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
);
datagram_h
andle
r
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
);
void
ack_writes
(
bool
x
);
...
...
libcaf_io/caf/io/network/endpoint_manager.hpp
View file @
9971d016
...
...
@@ -40,7 +40,7 @@ public:
virtual
bool
consume
(
execution_unit
*
ctx
,
const
void
*
buf
,
size_t
bsize
)
=
0
;
/// Called by the underlying I/O device whenever it sent a datagram.
virtual
void
datagram_sent
(
execution_unit
*
ctx
,
size_t
num_bytes
)
=
0
;
virtual
void
datagram_sent
(
execution_unit
*
ctx
,
size_t
num_bytes
)
=
0
;
};
}
// namespace network
...
...
libcaf_io/src/default_multiplexer.cpp
View file @
9971d016
...
...
@@ -933,10 +933,10 @@ endpoint_handle default_multiplexer::add_endpoint(abstract_broker* self,
}
private:
bool
launched_
;
network
::
datagram_h
dl
r
handler_
;
network
::
datagram_h
andle
r
handler_
;
};
auto
ptr
=
make_counted
<
impl
>
(
self
,
*
this
,
fd
);
self
->
add_endpoint
(
ptr
);
self
->
add_endpoint
(
ptr
);
return
ptr
->
hdl
();
}
...
...
@@ -1165,9 +1165,9 @@ default_multiplexer::new_remote_endpoint(const std::string& host,
auto
fd
=
new_remote_endpoint_impl
(
host
,
port
);
if
(
!
fd
)
return
std
::
move
(
fd
.
error
());
// TODO: add endpoint to endpoints vector of middleman!
// Maybe this should be done in the new_remote_enpoint_impl
return
endpoint_handle
::
from_int
(
int64_from_native_socket
(
*
fd
))
;
auto
hdl
=
endpoint_handle
::
from_int
(
int64_from_native_socket
(
*
fd
));
remote_endpoints_
[
std
::
make_pair
(
host
,
port
)]
=
hdl
;
return
hdl
;
}
expected
<
std
::
pair
<
endpoint_handle
,
uint16_t
>>
...
...
@@ -1196,9 +1196,9 @@ default_multiplexer::add_remote_endpoint(abstract_broker* self,
auto
fd
=
new_remote_endpoint_impl
(
host
,
port
);
if
(
!
fd
)
return
std
::
move
(
fd
.
error
());
// TODO: add endpoint to endpoints vector of middleman!
// Maybe this should be done in the new_remote_enpoint_impl
return
add_endpoint
(
self
,
*
fd
)
;
auto
hdl
=
add_endpoint
(
self
,
*
fd
);
remote_endpoints_
[
std
::
make_pair
(
host
,
port
)]
=
hdl
;
return
hdl
;
}
expected
<
std
::
pair
<
endpoint_handle
,
uint16_t
>>
...
...
@@ -1800,8 +1800,8 @@ void datagram_receiver::prepare_next_read() {
rd_buf_
.
resize
(
buf_size_
);
}
datagram_h
dlr
::
datagram_hdl
r
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
datagram_h
andler
::
datagram_handle
r
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
:
event_handler
(
backend_ref
,
sockfd
),
buf_size_
(
0
),
ack_writes_
(
false
),
...
...
@@ -1810,22 +1810,22 @@ datagram_hdlr::datagram_hdlr(default_multiplexer& backend_ref,
configure_datagram_size
(
1500
);
}
void
datagram_h
dl
r
::
ack_writes
(
bool
x
)
{
void
datagram_h
andle
r
::
ack_writes
(
bool
x
)
{
ack_writes_
=
x
;
}
void
datagram_h
dl
r
::
write
(
const
void
*
buf
,
size_t
num_bytes
)
{
void
datagram_h
andle
r
::
write
(
const
void
*
buf
,
size_t
num_bytes
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
num_bytes
));
auto
first
=
reinterpret_cast
<
const
char
*>
(
buf
);
auto
last
=
first
+
num_bytes
;
wr_offline_buf_
.
insert
(
wr_offline_buf_
.
end
(),
first
,
last
);
}
void
datagram_h
dl
r
::
configure_datagram_size
(
size_t
buf_size
)
{
void
datagram_h
andle
r
::
configure_datagram_size
(
size_t
buf_size
)
{
buf_size_
=
buf_size
;
}
std
::
pair
<
std
::
string
,
uint16_t
>
datagram_h
dl
r
::
get_sender
()
{
std
::
pair
<
std
::
string
,
uint16_t
>
datagram_h
andle
r
::
get_sender
()
{
char
addr
[
INET6_ADDRSTRLEN
];
std
::
string
host
;
uint16_t
port
=
0
;
...
...
@@ -1854,7 +1854,7 @@ std::pair<std::string,uint16_t> datagram_hdlr::get_sender() {
return
std
::
make_pair
(
std
::
move
(
host
),
port
);
}
void
datagram_h
dl
r
::
flush
(
const
manager_ptr
&
mgr
)
{
void
datagram_h
andle
r
::
flush
(
const
manager_ptr
&
mgr
)
{
CAF_ASSERT
(
mgr
!=
nullptr
);
CAF_LOG_TRACE
(
CAF_ARG
(
wr_offline_buf_
.
size
()));
if
(
!
wr_offline_buf_
.
empty
()
&&
!
writing_
)
{
...
...
@@ -1865,12 +1865,12 @@ void datagram_hdlr::flush(const manager_ptr& mgr) {
}
}
void
datagram_h
dl
r
::
start
(
manager_type
*
mgr
)
{
void
datagram_h
andle
r
::
start
(
manager_type
*
mgr
)
{
CAF_ASSERT
(
mgr
!=
nullptr
);
activate
(
mgr
);
}
void
datagram_h
dl
r
::
activate
(
manager_type
*
mgr
)
{
void
datagram_h
andle
r
::
activate
(
manager_type
*
mgr
)
{
if
(
!
reader_
)
{
reader_
.
reset
(
mgr
);
event_handler
::
activate
();
...
...
@@ -1878,13 +1878,13 @@ void datagram_hdlr::activate(manager_type* mgr) {
}
}
void
datagram_h
dl
r
::
stop_reading
()
{
void
datagram_h
andle
r
::
stop_reading
()
{
CAF_LOG_TRACE
(
""
);
close_read_channel
();
passivate
();
}
void
datagram_h
dl
r
::
removed_from_loop
(
operation
op
)
{
void
datagram_h
andle
r
::
removed_from_loop
(
operation
op
)
{
switch
(
op
)
{
case
operation
:
:
read
:
reader_
.
reset
();
break
;
case
operation
:
:
write
:
writer_
.
reset
();
break
;
...
...
@@ -1892,7 +1892,7 @@ void datagram_hdlr::removed_from_loop(operation op) {
}
}
void
datagram_h
dl
r
::
handle_event
(
operation
op
)
{
void
datagram_h
andle
r
::
handle_event
(
operation
op
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
op
));
switch
(
op
)
{
case
operation
:
:
read
:
{
...
...
@@ -1906,28 +1906,35 @@ void datagram_hdlr::handle_event(operation op) {
}
if
(
rb
==
0
)
return
;
// TODO: find responsible (remote) endpoint to deliver datagram
/*
auto& endpoints = backend().endpoints();
// Find responsible (remote) endpoint to deliver datagram.
auto
sender
=
get_sender
();
auto endpoint = endpoints.find(sender);
if (endpoint == endpoints.end()) {
auto new_endpoint = backend().add_datagram_sink(reader_->parent(),
sender.first,
sender.second);
if (!new_endpoint) {
// TODO: error handling
CAF_LOG_DEBUG("Could not create endpoint for new sender.");
return;
bool
consumed
=
false
;
if
(
reader_
->
addr
()
==
sender
.
first
&&
reader_
->
port
()
==
sender
.
second
)
{
// Our assigned endpoint is respoinsible
consumed
=
reader_
->
consume
(
&
backend
(),
rd_buf_
.
data
(),
rb
);
}
else
{
// Search for the responsible endpoint or create a new one.
auto
&
endpoints
=
backend
().
endpoints
();
auto
endpoint
=
endpoints
.
find
(
sender
);
if
(
endpoint
==
endpoints
.
end
())
{
auto
new_endpoint
=
backend
().
add_remote_endpoint
(
reader_
->
parent
(),
sender
.
first
,
sender
.
second
);
if
(
!
new_endpoint
)
{
// TODO: error handling
CAF_LOG_DEBUG
(
"Could not create endpoint for new sender."
);
return
;
}
endpoint
=
endpoints
.
emplace
(
sender
,
*
new_endpoint
).
first
;
}
endpoint = endpoints.emplace(sender, *new_endpoint).first;
auto
hdl
=
endpoint
->
second
;
// TODO: requires the multiplexer to be single threaded!
reader_
->
consume_as
(
hdl
,
&
backend
(),
rd_buf_
.
data
(),
rb
);
}
auto hdl = endpoint->second;
*/
auto
res
=
reader_
->
consume
(
&
backend
(),
rd_buf_
.
data
(),
rb
);
packet_size_
=
rb
;
prepare_next_read
();
if
(
!
res
)
{
if
(
!
consumed
)
{
passivate
();
return
;
}
...
...
@@ -1946,6 +1953,8 @@ void datagram_hdlr::handle_event(operation op) {
}
else
{
// TODO: remove this if sure that datagrams are either written
// as a whole or not at all
// Could the handler propagte the knowledge if it know how
// much it can actually write?
std
::
cerr
<<
"Partial datagram wrtten: "
<<
wb
<<
" of "
<<
wr_buf_
.
size
()
<<
std
::
endl
;
if
(
writer_
)
...
...
@@ -1965,7 +1974,7 @@ void datagram_hdlr::handle_event(operation op) {
}
}
void
datagram_h
dl
r
::
prepare_next_read
()
{
void
datagram_h
andle
r
::
prepare_next_read
()
{
CAF_LOG_TRACE
(
CAF_ARG
(
wr_buf_
.
size
())
<<
CAF_ARG
(
wr_offline_buf_
.
size
()));
wr_buf_
.
clear
();
if
(
wr_offline_buf_
.
empty
())
{
...
...
@@ -1975,7 +1984,7 @@ void datagram_hdlr::prepare_next_read() {
}
}
void
datagram_h
dl
r
::
prepare_next_write
()
{
void
datagram_h
andle
r
::
prepare_next_write
()
{
rd_buf_
.
resize
(
buf_size_
);
}
...
...
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