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
2690ac42
Commit
2690ac42
authored
Nov 10, 2016
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on datagram propagation
parent
6b717efd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
7 deletions
+98
-7
libcaf_io/caf/io/abstract_broker.hpp
libcaf_io/caf/io/abstract_broker.hpp
+3
-3
libcaf_io/caf/io/accept_handle.hpp
libcaf_io/caf/io/accept_handle.hpp
+1
-1
libcaf_io/caf/io/datagram_sink_handle.hpp
libcaf_io/caf/io/datagram_sink_handle.hpp
+20
-2
libcaf_io/caf/io/network/default_multiplexer.hpp
libcaf_io/caf/io/network/default_multiplexer.hpp
+14
-0
libcaf_io/caf/io/system_messages.hpp
libcaf_io/caf/io/system_messages.hpp
+11
-0
libcaf_io/src/default_multiplexer.cpp
libcaf_io/src/default_multiplexer.cpp
+49
-1
No files found.
libcaf_io/caf/io/abstract_broker.hpp
View file @
2690ac42
...
...
@@ -264,15 +264,15 @@ public:
/// Returns the handle associated to given local `port` or `none`.
accept_handle
hdl_by_port
(
uint16_t
port
);
/// Returns the remote address associated to `hdl`
/// or empty string if `hdl` is invalid.
std
::
string
remote_addr
(
datagram_sink_handle
hdl
);
/// Returns the remote port associated to `hdl`
/// or `0` if `hdl` is invalid.
uint16_t
remote_port
(
datagram_sink_handle
hdl
);
/// Returns the local port associated to `hdl` or `0` if `hdl` is invalid.
uint16_t
local_port
(
datagram_source_handle
hdl
);
...
...
libcaf_io/caf/io/accept_handle.hpp
View file @
2690ac42
...
...
@@ -70,7 +70,7 @@ private:
}
// namespace ios
}
// namespace caf
namespace
std
{
namespace
std
{
template
<
>
struct
hash
<
caf
::
io
::
accept_handle
>
{
...
...
libcaf_io/caf/io/datagram_sink_handle.hpp
View file @
2690ac42
...
...
@@ -49,11 +49,11 @@ public:
using
super
=
handle
<
datagram_sink_handle
,
invalid_datagram_sink_handle_t
>
;
constexpr
datagram_sink_handle
()
{
datagram_sink_handle
()
:
port_
{
0
}
{
// nop
}
constexpr
datagram_sink_handle
(
const
invalid_datagram_sink_handle_t
&
)
{
datagram_sink_handle
(
const
invalid_datagram_sink_handle_t
&
)
:
port_
{
0
}
{
// nop
}
...
...
@@ -63,10 +63,28 @@ public:
return
f
(
meta
::
type_name
(
"datagram_sink_handle"
),
x
.
id_
);
}
const
std
::
string
&
host
()
const
{
return
host_
;
}
void
set_host
(
std
::
string
host
)
{
host_
=
move
(
host
);
}
uint16_t
port
()
const
{
return
port_
;
}
void
set_port
(
uint16_t
port
)
{
port_
=
port
;
}
private:
inline
datagram_sink_handle
(
int64_t
handle_id
)
:
super
(
handle_id
)
{
// nop
}
std
::
string
host_
;
uint16_t
port_
;
};
}
// namespace io
...
...
libcaf_io/caf/io/network/default_multiplexer.hpp
View file @
2690ac42
...
...
@@ -254,6 +254,8 @@ public:
friend
class
io
::
middleman
;
// disambiguate reference
friend
class
supervisor
;
using
endpoint
=
std
::
pair
<
std
::
string
,
uint16_t
>
;
struct
event
{
native_socket
fd
;
int
mask
;
...
...
@@ -338,6 +340,13 @@ public:
void
del
(
operation
op
,
native_socket
fd
,
event_handler
*
ptr
);
/// @cond PRIVATE
// Used by datagram senders and receivers to manage known endpoints
std
::
map
<
endpoint
,
datagram_sink_handle
>&
endpoints
();
/// @endcond
private:
// platform-dependent additional initialization code
void
init
();
...
...
@@ -397,6 +406,9 @@ private:
multiplexer_poll_shadow_data
shadow_
;
std
::
pair
<
native_socket
,
native_socket
>
pipe_
;
pipe_reader
pipe_reader_
;
// TODO: is this the right place?
// How to maintain endpoints if they close?
std
::
map
<
endpoint
,
datagram_sink_handle
>
remote_endpoints_
;
};
inline
connection_handle
conn_hdl_from_socket
(
native_socket
fd
)
{
...
...
@@ -629,6 +641,8 @@ public:
void
handle_event
(
operation
op
)
override
;
std
::
pair
<
std
::
string
,
uint16_t
>
get_sender
();
private:
void
prepare_next_read
();
...
...
libcaf_io/caf/io/system_messages.hpp
View file @
2690ac42
...
...
@@ -204,6 +204,17 @@ inspect(Inspector& f, datagram_source_passivated_msg& x) {
return
f
(
meta
::
type_name
(
"datagram_source_passivated_msg"
),
x
.
handle
);
}
/// Signalizes that a {@link broker} datagram endpoint was closed.
struct
endpoint_closed_msg
{
endpoint_handle
handle
;
};
/// @relates endpoint_closed_msg
template
<
class
Inspector
>
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
endpoint_closed_msg
&
x
)
{
return
f
(
meta
::
type_name
(
"endpoint_closed_msg"
),
x
.
handle
);
}
}
// namespace io
}
// namespace caf
...
...
libcaf_io/src/default_multiplexer.cpp
View file @
2690ac42
...
...
@@ -622,6 +622,11 @@ void default_multiplexer::del(operation op, native_socket fd,
new_event
(
del_flag
,
op
,
fd
,
ptr
);
}
std
::
map
<
default_multiplexer
::
endpoint
,
datagram_sink_handle
>&
default_multiplexer
::
endpoints
()
{
return
remote_endpoints_
;
}
void
default_multiplexer
::
wr_dispatch_request
(
resumable
*
ptr
)
{
intptr_t
ptrval
=
reinterpret_cast
<
intptr_t
>
(
ptr
);
// on windows, we actually have sockets, otherwise we have file handles
...
...
@@ -1006,7 +1011,7 @@ default_multiplexer::new_tcp_doorman(uint16_t port, const char* in,
}
expected
<
void
>
default_multiplexer
::
assign_tcp_doorman
(
abstract_broker
*
self
,
accept_handle
hdl
)
{
accept_handle
hdl
)
{
add_tcp_doorman
(
self
,
static_cast
<
native_socket
>
(
hdl
.
id
()));
return
unit
;
}
...
...
@@ -1611,6 +1616,21 @@ void datagram_receiver::handle_event(operation op) {
}
if
(
rb
==
0
)
return
;
auto
&
endpoints
=
backend
().
endpoints
();
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
;
}
endpoint
=
endpoints
.
emplace
(
sender
,
*
new_endpoint
).
first
;
}
auto
hdl
=
endpoint
->
second
;
auto
res
=
reader_
->
consume
(
&
backend
(),
rd_buf_
.
data
(),
rb
);
packet_size_
=
rb
;
prepare_next_read
();
...
...
@@ -1633,6 +1653,34 @@ void datagram_receiver::handle_event(operation op) {
}
}
std
::
pair
<
std
::
string
,
uint16_t
>
datagram_receiver
::
get_sender
()
{
char
addr
[
INET6_ADDRSTRLEN
];
std
::
string
host
;
uint16_t
port
=
0
;
switch
(
last_sender
.
ss_family
)
{
case
AF_INET
:
port
=
ntohs
(
reinterpret_cast
<
sockaddr_in
*>
(
&
last_sender
)
->
sin_port
);
inet_ntop
(
AF_INET
,
&
reinterpret_cast
<
sockaddr_in
*>
(
&
last_sender
)
->
sin_addr
,
addr
,
INET_ADDRSTRLEN
);
host
.
insert
(
std
::
begin
(
host
),
std
::
begin
(
addr
),
std
::
begin
(
addr
)
+
INET_ADDRSTRLEN
);
break
;
case
AF_INET6
:
port
=
ntohs
(
reinterpret_cast
<
sockaddr_in6
*>
(
&
last_sender
)
->
sin6_port
);
inet_ntop
(
AF_INET6
,
&
reinterpret_cast
<
sockaddr_in
*>
(
&
last_sender
)
->
sin_addr
,
addr
,
INET6_ADDRSTRLEN
);
host
.
insert
(
std
::
begin
(
host
),
std
::
begin
(
addr
),
std
::
begin
(
addr
)
+
INET6_ADDRSTRLEN
);
break
;
default:
// nop
break
;
}
return
std
::
make_pair
(
std
::
move
(
host
),
port
);
}
void
datagram_receiver
::
prepare_next_read
()
{
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