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
f4c5842b
Commit
f4c5842b
authored
Sep 20, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Surrender to clang-format
parent
f9451ffc
Changes
92
Show whitespace changes
Inline
Side-by-side
Showing
92 changed files
with
1724 additions
and
1891 deletions
+1724
-1891
libcaf_core/src/decorator/sequencer.cpp
libcaf_core/src/decorator/sequencer.cpp
+12
-9
libcaf_core/src/decorator/splitter.cpp
libcaf_core/src/decorator/splitter.cpp
+22
-22
libcaf_core/src/detail/behavior_impl.cpp
libcaf_core/src/detail/behavior_impl.cpp
+3
-7
libcaf_core/src/detail/behavior_stack.cpp
libcaf_core/src/detail/behavior_stack.cpp
+2
-2
libcaf_core/src/detail/decorated_tuple.cpp
libcaf_core/src/detail/decorated_tuple.cpp
+3
-5
libcaf_core/src/detail/dynamic_message_data.cpp
libcaf_core/src/detail/dynamic_message_data.cpp
+2
-4
libcaf_core/src/detail/get_mac_addresses.cpp
libcaf_core/src/detail/get_mac_addresses.cpp
+49
-54
libcaf_core/src/detail/get_process_id.cpp
libcaf_core/src/detail/get_process_id.cpp
+4
-4
libcaf_core/src/detail/get_root_uuid.cpp
libcaf_core/src/detail/get_root_uuid.cpp
+24
-27
libcaf_core/src/detail/ini_consumer.cpp
libcaf_core/src/detail/ini_consumer.cpp
+15
-17
libcaf_core/src/detail/merged_tuple.cpp
libcaf_core/src/detail/merged_tuple.cpp
+3
-5
libcaf_core/src/detail/parser/chars.cpp
libcaf_core/src/detail/parser/chars.cpp
+0
-1
libcaf_core/src/detail/pretty_type_name.cpp
libcaf_core/src/detail/pretty_type_name.cpp
+7
-7
libcaf_core/src/detail/private_thread.cpp
libcaf_core/src/detail/private_thread.cpp
+4
-4
libcaf_core/src/detail/ripemd_160.cpp
libcaf_core/src/detail/ripemd_160.cpp
+2
-2
libcaf_core/src/detail/set_thread_name.cpp
libcaf_core/src/detail/set_thread_name.cpp
+8
-8
libcaf_core/src/detail/simple_actor_clock.cpp
libcaf_core/src/detail/simple_actor_clock.cpp
+2
-3
libcaf_core/src/detail/sync_request_bouncer.cpp
libcaf_core/src/detail/sync_request_bouncer.cpp
+4
-4
libcaf_core/src/detail/thread_safe_actor_clock.cpp
libcaf_core/src/detail/thread_safe_actor_clock.cpp
+3
-2
libcaf_core/src/detail/tick_emitter.cpp
libcaf_core/src/detail/tick_emitter.cpp
+3
-5
libcaf_core/src/detail/try_match.cpp
libcaf_core/src/detail/try_match.cpp
+1
-2
libcaf_core/src/policy/downstream_messages.cpp
libcaf_core/src/policy/downstream_messages.cpp
+3
-3
libcaf_core/src/policy/work_stealing.cpp
libcaf_core/src/policy/work_stealing.cpp
+16
-16
libcaf_core/src/scheduler/abstract_coordinator.cpp
libcaf_core/src/scheduler/abstract_coordinator.cpp
+9
-14
libcaf_core/src/scheduler/test_coordinator.cpp
libcaf_core/src/scheduler/test_coordinator.cpp
+6
-10
libcaf_core/test/decorator/sequencer.cpp
libcaf_core/test/decorator/sequencer.cpp
+19
-34
libcaf_core/test/decorator/splitter.cpp
libcaf_core/test/decorator/splitter.cpp
+13
-18
libcaf_core/test/detail/limited_vector.cpp
libcaf_core/test/detail/limited_vector.cpp
+14
-13
libcaf_core/test/detail/parser/read_atom.cpp
libcaf_core/test/detail/parser/read_atom.cpp
+2
-2
libcaf_core/test/detail/parser/read_ini.cpp
libcaf_core/test/detail/parser/read_ini.cpp
+1
-1
libcaf_core/test/detail/parser/read_number_or_timespan.cpp
libcaf_core/test/detail/parser/read_number_or_timespan.cpp
+0
-1
libcaf_core/test/detail/parser/read_string.cpp
libcaf_core/test/detail/parser/read_string.cpp
+2
-2
libcaf_core/test/detail/tick_emitter.cpp
libcaf_core/test/detail/tick_emitter.cpp
+2
-3
libcaf_core/test/detail/unique_function.cpp
libcaf_core/test/detail/unique_function.cpp
+1
-1
libcaf_core/test/detail/unordered_flat_map.cpp
libcaf_core/test/detail/unordered_flat_map.cpp
+4
-6
libcaf_core/test/intrusive/drr_cached_queue.cpp
libcaf_core/test/intrusive/drr_cached_queue.cpp
+2
-5
libcaf_core/test/intrusive/fifo_inbox.cpp
libcaf_core/test/intrusive/fifo_inbox.cpp
+2
-6
libcaf_core/test/intrusive/lifo_inbox.cpp
libcaf_core/test/intrusive/lifo_inbox.cpp
+2
-6
libcaf_core/test/intrusive/wdrr_dynamic_multiplexed_queue.cpp
...af_core/test/intrusive/wdrr_dynamic_multiplexed_queue.cpp
+7
-8
libcaf_core/test/intrusive/wdrr_fixed_multiplexed_queue.cpp
libcaf_core/test/intrusive/wdrr_fixed_multiplexed_queue.cpp
+2
-4
libcaf_core/test/policy/categorized.cpp
libcaf_core/test/policy/categorized.cpp
+2
-2
libcaf_io/src/detail/socket_guard.cpp
libcaf_io/src/detail/socket_guard.cpp
+3
-3
libcaf_io/src/io/abstract_broker.cpp
libcaf_io/src/io/abstract_broker.cpp
+11
-12
libcaf_io/src/io/basp/header.cpp
libcaf_io/src/io/basp/header.cpp
+9
-15
libcaf_io/src/io/basp/instance.cpp
libcaf_io/src/io/basp/instance.cpp
+46
-37
libcaf_io/src/io/basp/message_type.cpp
libcaf_io/src/io/basp/message_type.cpp
+2
-7
libcaf_io/src/io/basp/routing_table.cpp
libcaf_io/src/io/basp/routing_table.cpp
+1
-2
libcaf_io/src/io/broker.cpp
libcaf_io/src/io/broker.cpp
+3
-4
libcaf_io/src/io/connection_helper.cpp
libcaf_io/src/io/connection_helper.cpp
+24
-26
libcaf_io/src/io/datagram_servant.cpp
libcaf_io/src/io/datagram_servant.cpp
+0
-1
libcaf_io/src/io/middleman.cpp
libcaf_io/src/io/middleman.cpp
+50
-63
libcaf_io/src/io/middleman_actor.cpp
libcaf_io/src/io/middleman_actor.cpp
+4
-4
libcaf_io/src/io/middleman_actor_impl.cpp
libcaf_io/src/io/middleman_actor_impl.cpp
+17
-18
libcaf_io/src/io/network/acceptor.cpp
libcaf_io/src/io/network/acceptor.cpp
+1
-2
libcaf_io/src/io/network/datagram_handler.cpp
libcaf_io/src/io/network/datagram_handler.cpp
+20
-13
libcaf_io/src/io/network/datagram_manager.cpp
libcaf_io/src/io/network/datagram_manager.cpp
+0
-1
libcaf_io/src/io/network/datagram_servant_impl.cpp
libcaf_io/src/io/network/datagram_servant_impl.cpp
+8
-9
libcaf_io/src/io/network/default_multiplexer.cpp
libcaf_io/src/io/network/default_multiplexer.cpp
+372
-382
libcaf_io/src/io/network/doorman_impl.cpp
libcaf_io/src/io/network/doorman_impl.cpp
+1
-2
libcaf_io/src/io/network/event_handler.cpp
libcaf_io/src/io/network/event_handler.cpp
+2
-2
libcaf_io/src/io/network/interfaces.cpp
libcaf_io/src/io/network/interfaces.cpp
+42
-46
libcaf_io/src/io/network/ip_endpoint.cpp
libcaf_io/src/io/network/ip_endpoint.cpp
+30
-24
libcaf_io/src/io/network/manager.cpp
libcaf_io/src/io/network/manager.cpp
+2
-2
libcaf_io/src/io/network/multiplexer.cpp
libcaf_io/src/io/network/multiplexer.cpp
+1
-2
libcaf_io/src/io/network/native_socket.cpp
libcaf_io/src/io/network/native_socket.cpp
+260
-260
libcaf_io/src/io/network/pipe_reader.cpp
libcaf_io/src/io/network/pipe_reader.cpp
+11
-11
libcaf_io/src/io/network/protocol.cpp
libcaf_io/src/io/network/protocol.cpp
+0
-1
libcaf_io/src/io/network/receive_buffer.cpp
libcaf_io/src/io/network/receive_buffer.cpp
+7
-8
libcaf_io/src/io/network/scribe_impl.cpp
libcaf_io/src/io/network/scribe_impl.cpp
+3
-3
libcaf_io/src/io/network/stream.cpp
libcaf_io/src/io/network/stream.cpp
+16
-13
libcaf_io/src/io/network/test_multiplexer.cpp
libcaf_io/src/io/network/test_multiplexer.cpp
+47
-47
libcaf_io/src/io/scribe.cpp
libcaf_io/src/io/scribe.cpp
+4
-4
libcaf_io/src/policy/tcp.cpp
libcaf_io/src/policy/tcp.cpp
+6
-6
libcaf_io/test/io/basp_broker.cpp
libcaf_io/test/io/basp_broker.cpp
+56
-70
libcaf_io/test/io/broker.cpp
libcaf_io/test/io/broker.cpp
+35
-42
libcaf_io/test/io/http_broker.cpp
libcaf_io/test/io/http_broker.cpp
+18
-17
libcaf_io/test/io/network/ip_endpoint.cpp
libcaf_io/test/io/network/ip_endpoint.cpp
+17
-20
libcaf_io/test/io/receive_buffer.cpp
libcaf_io/test/io/receive_buffer.cpp
+14
-17
libcaf_io/test/io/remote_actor.cpp
libcaf_io/test/io/remote_actor.cpp
+26
-29
libcaf_io/test/io/remote_group.cpp
libcaf_io/test/io/remote_group.cpp
+2
-6
libcaf_io/test/io/remote_spawn.cpp
libcaf_io/test/io/remote_spawn.cpp
+16
-31
libcaf_io/test/io/triggering.cpp
libcaf_io/test/io/triggering.cpp
+19
-31
libcaf_io/test/io/typed_broker.cpp
libcaf_io/test/io/typed_broker.cpp
+32
-38
libcaf_io/test/io/typed_remote_actor.cpp
libcaf_io/test/io/typed_remote_actor.cpp
+15
-18
libcaf_io/test/io/unpublish.cpp
libcaf_io/test/io/unpublish.cpp
+19
-18
libcaf_openssl/src/openssl/manager.cpp
libcaf_openssl/src/openssl/manager.cpp
+6
-4
libcaf_openssl/src/openssl/middleman_actor.cpp
libcaf_openssl/src/openssl/middleman_actor.cpp
+94
-95
libcaf_openssl/src/openssl/publish.cpp
libcaf_openssl/src/openssl/publish.cpp
+2
-3
libcaf_openssl/src/openssl/remote_actor.cpp
libcaf_openssl/src/openssl/remote_actor.cpp
+1
-2
libcaf_openssl/src/openssl/session.cpp
libcaf_openssl/src/openssl/session.cpp
+12
-12
libcaf_openssl/test/openssl/authentication.cpp
libcaf_openssl/test/openssl/authentication.cpp
+38
-39
libcaf_openssl/test/openssl/remote_actor.cpp
libcaf_openssl/test/openssl/remote_actor.cpp
+17
-20
No files found.
libcaf_core/src/decorator/sequencer.cpp
View file @
f4c5842b
...
@@ -38,11 +38,14 @@ sequencer::sequencer(strong_actor_ptr f, strong_actor_ptr g,
...
@@ -38,11 +38,14 @@ sequencer::sequencer(strong_actor_ptr f, strong_actor_ptr g,
// composed actor has dependency on constituent actors by default;
// composed actor has dependency on constituent actors by default;
// if either constituent actor is already dead upon establishing
// if either constituent actor is already dead upon establishing
// the dependency, the actor is spawned dead
// the dependency, the actor is spawned dead
f_
->
get
()
->
attach
(
default_attachable
::
make_monitor
(
actor_cast
<
actor_addr
>
(
f_
),
auto
monitor1
=
default_attachable
::
make_monitor
(
actor_cast
<
actor_addr
>
(
f_
),
address
()));
address
());
if
(
g_
!=
f_
)
f_
->
get
()
->
attach
(
std
::
move
(
monitor1
));
g_
->
get
()
->
attach
(
default_attachable
::
make_monitor
(
actor_cast
<
actor_addr
>
(
g_
),
if
(
g_
!=
f_
)
{
address
()));
auto
monitor2
=
default_attachable
::
make_monitor
(
actor_cast
<
actor_addr
>
(
g_
),
address
());
g_
->
get
()
->
attach
(
std
::
move
(
monitor2
));
}
}
}
void
sequencer
::
enqueue
(
mailbox_element_ptr
what
,
execution_unit
*
context
)
{
void
sequencer
::
enqueue
(
mailbox_element_ptr
what
,
execution_unit
*
context
)
{
...
...
libcaf_core/src/decorator/splitter.cpp
View file @
f4c5842b
...
@@ -19,10 +19,10 @@
...
@@ -19,10 +19,10 @@
#include "caf/decorator/splitter.hpp"
#include "caf/decorator/splitter.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system.hpp"
#include "caf/stateful_actor.hpp"
#include "caf/response_promise.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/default_attachable.hpp"
#include "caf/default_attachable.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/response_promise.hpp"
#include "caf/stateful_actor.hpp"
#include "caf/detail/disposer.hpp"
#include "caf/detail/disposer.hpp"
#include "caf/detail/sync_request_bouncer.hpp"
#include "caf/detail/sync_request_bouncer.hpp"
...
@@ -47,7 +47,8 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
...
@@ -47,7 +47,8 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
// request().await() has LIFO ordering
// request().await() has LIFO ordering
for
(
auto
i
=
workers
.
rbegin
();
i
!=
workers
.
rend
();
++
i
)
for
(
auto
i
=
workers
.
rbegin
();
i
!=
workers
.
rend
();
++
i
)
// TODO: maybe infer some useful timeout or use config parameter?
// TODO: maybe infer some useful timeout or use config parameter?
self
->
request
(
actor_cast
<
actor
>
(
*
i
),
infinite
,
msg
).
await
(
self
->
request
(
actor_cast
<
actor
>
(
*
i
),
infinite
,
msg
)
.
await
(
[
=
]()
{
[
=
]()
{
// nop
// nop
},
},
...
@@ -60,8 +61,7 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
...
@@ -60,8 +61,7 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
self
->
state
.
rp
.
deliver
(
err
);
self
->
state
.
rp
.
deliver
(
err
);
self
->
quit
();
self
->
quit
();
}
}
}
});
);
return
delegated
<
message
>
{};
return
delegated
<
message
>
{};
};
};
self
->
set_default_handler
(
f
);
self
->
set_default_handler
(
f
);
...
...
libcaf_core/src/detail/behavior_impl.cpp
View file @
f4c5842b
...
@@ -20,8 +20,8 @@
...
@@ -20,8 +20,8 @@
#include "caf/detail/behavior_impl.hpp"
#include "caf/detail/behavior_impl.hpp"
#include "caf/message_handler.hpp"
#include "caf/make_type_erased_tuple_view.hpp"
#include "caf/make_type_erased_tuple_view.hpp"
#include "caf/message_handler.hpp"
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
...
@@ -43,9 +43,7 @@ public:
...
@@ -43,9 +43,7 @@ public:
}
}
combinator
(
pointer
p0
,
const
pointer
&
p1
)
combinator
(
pointer
p0
,
const
pointer
&
p1
)
:
behavior_impl
(
p1
->
timeout
()),
:
behavior_impl
(
p1
->
timeout
()),
first
(
std
::
move
(
p0
)),
second
(
p1
)
{
first
(
std
::
move
(
p0
)),
second
(
p1
)
{
// nop
// nop
}
}
...
@@ -82,9 +80,7 @@ behavior_impl::~behavior_impl() {
...
@@ -82,9 +80,7 @@ behavior_impl::~behavior_impl() {
}
}
behavior_impl
::
behavior_impl
(
duration
tout
)
behavior_impl
::
behavior_impl
(
duration
tout
)
:
timeout_
(
tout
),
:
timeout_
(
tout
),
begin_
(
nullptr
),
end_
(
nullptr
)
{
begin_
(
nullptr
),
end_
(
nullptr
)
{
// nop
// nop
}
}
...
...
libcaf_core/src/detail/behavior_stack.cpp
View file @
f4c5842b
...
@@ -18,9 +18,9 @@
...
@@ -18,9 +18,9 @@
#include <iterator>
#include <iterator>
#include "caf/none.hpp"
#include "caf/local_actor.hpp"
#include "caf/detail/behavior_stack.hpp"
#include "caf/detail/behavior_stack.hpp"
#include "caf/local_actor.hpp"
#include "caf/none.hpp"
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
...
...
libcaf_core/src/detail/decorated_tuple.cpp
View file @
f4c5842b
...
@@ -24,9 +24,7 @@ namespace caf {
...
@@ -24,9 +24,7 @@ namespace caf {
namespace
detail
{
namespace
detail
{
decorated_tuple
::
decorated_tuple
(
cow_ptr
&&
d
,
vector_type
&&
v
)
decorated_tuple
::
decorated_tuple
(
cow_ptr
&&
d
,
vector_type
&&
v
)
:
decorated_
(
std
::
move
(
d
)),
:
decorated_
(
std
::
move
(
d
)),
mapping_
(
std
::
move
(
v
)),
type_token_
(
0xFFFFFFFF
)
{
mapping_
(
std
::
move
(
v
)),
type_token_
(
0xFFFFFFFF
)
{
CAF_ASSERT
(
mapping_
.
empty
()
CAF_ASSERT
(
mapping_
.
empty
()
||
*
(
std
::
max_element
(
mapping_
.
begin
(),
mapping_
.
end
()))
||
*
(
std
::
max_element
(
mapping_
.
begin
(),
mapping_
.
end
()))
<
static_cast
<
const
cow_ptr
&>
(
decorated_
)
->
size
());
<
static_cast
<
const
cow_ptr
&>
(
decorated_
)
->
size
());
...
...
libcaf_core/src/detail/dynamic_message_data.cpp
View file @
f4c5842b
...
@@ -30,15 +30,13 @@ dynamic_message_data::dynamic_message_data() : type_token_(0xFFFFFFFF) {
...
@@ -30,15 +30,13 @@ dynamic_message_data::dynamic_message_data() : type_token_(0xFFFFFFFF) {
}
}
dynamic_message_data
::
dynamic_message_data
(
elements
&&
data
)
dynamic_message_data
::
dynamic_message_data
(
elements
&&
data
)
:
elements_
(
std
::
move
(
data
)),
:
elements_
(
std
::
move
(
data
)),
type_token_
(
0xFFFFFFFF
)
{
type_token_
(
0xFFFFFFFF
)
{
for
(
auto
&
e
:
elements_
)
for
(
auto
&
e
:
elements_
)
add_to_type_token
(
e
->
type
().
first
);
add_to_type_token
(
e
->
type
().
first
);
}
}
dynamic_message_data
::
dynamic_message_data
(
const
dynamic_message_data
&
other
)
dynamic_message_data
::
dynamic_message_data
(
const
dynamic_message_data
&
other
)
:
detail
::
message_data
(
other
),
:
detail
::
message_data
(
other
),
type_token_
(
0xFFFFFFFF
)
{
type_token_
(
0xFFFFFFFF
)
{
for
(
auto
&
e
:
other
.
elements_
)
{
for
(
auto
&
e
:
other
.
elements_
)
{
add_to_type_token
(
e
->
type
().
first
);
add_to_type_token
(
e
->
type
().
first
);
elements_
.
emplace_back
(
e
->
copy
());
elements_
.
emplace_back
(
e
->
copy
());
...
...
libcaf_core/src/detail/get_mac_addresses.cpp
View file @
f4c5842b
...
@@ -23,21 +23,21 @@
...
@@ -23,21 +23,21 @@
#if defined(CAF_MACOS) || defined(CAF_BSD) || defined(CAF_IOS)
#if defined(CAF_MACOS) || defined(CAF_BSD) || defined(CAF_IOS)
#
include <sys/types
.h>
#
include <arpa/inet
.h>
#
include <sys/socket.h
>
#
include <cerrno
>
#
include <sys/ioctl.h
>
#
include <cstdio
>
#
include <sys/sysctl.h
>
#
include <cstdlib
>
#
include <net/if.h
>
#
include <memory
>
#
include <net/if_dl
.h>
#
include <net/if
.h>
#
include <netinet/in
.h>
#
include <net/if_dl
.h>
#
include <arpa/inet
.h>
#
include <netinet/in
.h>
#
include <cerrno
>
#
include <sstream
>
#
include <cstdio
>
#
include <sys/ioctl.h
>
#
include <cstdlib
>
#
include <sys/socket.h
>
#
include <memory
>
#
include <sys/sysctl.h
>
#
include <sstream
>
#
include <sys/types.h
>
#include <iostream>
#
include <iostream>
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
...
@@ -99,22 +99,21 @@ std::vector<iface_info> get_mac_addresses() {
...
@@ -99,22 +99,21 @@ std::vector<iface_info> get_mac_addresses() {
#elif defined(CAF_LINUX) || defined(CAF_ANDROID) || defined(CAF_CYGWIN)
#elif defined(CAF_LINUX) || defined(CAF_ANDROID) || defined(CAF_CYGWIN)
#include <vector>
# include <algorithm>
#include <string>
# include <cctype>
#include <cctype>
# include <cstring>
#include <fstream>
# include <fstream>
#include <sstream>
# include <iostream>
#include <iostream>
# include <iterator>
#include <iterator>
# include <net/if.h>
#include <algorithm>
# include <sstream>
#include <stdio.h>
# include <stdio.h>
#include <sys/ioctl.h>
# include <string>
#include <sys/types.h>
# include <sys/ioctl.h>
#include <sys/socket.h>
# include <sys/socket.h>
#include <net/if.h>
# include <sys/types.h>
#include <cstring>
# include <unistd.h>
#include <unistd.h>
# include <vector>
#include <iostream>
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
...
@@ -122,17 +121,15 @@ namespace detail {
...
@@ -122,17 +121,15 @@ namespace detail {
std
::
vector
<
iface_info
>
get_mac_addresses
()
{
std
::
vector
<
iface_info
>
get_mac_addresses
()
{
// get a socket handle
// get a socket handle
int
socktype
=
SOCK_DGRAM
;
int
socktype
=
SOCK_DGRAM
;
#ifdef SOCK_CLOEXEC
#
ifdef SOCK_CLOEXEC
socktype
|=
SOCK_CLOEXEC
;
socktype
|=
SOCK_CLOEXEC
;
#endif
#
endif
int
sck
=
socket
(
AF_INET
,
socktype
,
0
);
int
sck
=
socket
(
AF_INET
,
socktype
,
0
);
if
(
sck
<
0
)
{
if
(
sck
<
0
)
{
perror
(
"socket"
);
perror
(
"socket"
);
return
{};
return
{};
}
}
auto
g
=
make_scope_guard
([
&
]
{
auto
g
=
make_scope_guard
([
&
]
{
close
(
sck
);
});
close
(
sck
);
});
// query available interfaces
// query available interfaces
char
buf
[
1024
]
=
{
0
};
char
buf
[
1024
]
=
{
0
};
ifconf
ifc
;
ifconf
ifc
;
...
@@ -143,9 +140,7 @@ std::vector<iface_info> get_mac_addresses() {
...
@@ -143,9 +140,7 @@ std::vector<iface_info> get_mac_addresses() {
return
{};
return
{};
}
}
std
::
vector
<
iface_info
>
result
;
std
::
vector
<
iface_info
>
result
;
auto
ctoi
=
[](
char
c
)
->
unsigned
{
auto
ctoi
=
[](
char
c
)
->
unsigned
{
return
static_cast
<
unsigned
char
>
(
c
);
};
return
static_cast
<
unsigned
char
>
(
c
);
};
// iterate through interfaces
// iterate through interfaces
auto
ifr
=
ifc
.
ifc_req
;
auto
ifr
=
ifc
.
ifc_req
;
auto
num_ifaces
=
static_cast
<
size_t
>
(
ifc
.
ifc_len
)
/
sizeof
(
ifreq
);
auto
num_ifaces
=
static_cast
<
size_t
>
(
ifc
.
ifc_len
)
/
sizeof
(
ifreq
);
...
@@ -180,22 +175,22 @@ std::vector<iface_info> get_mac_addresses() {
...
@@ -180,22 +175,22 @@ std::vector<iface_info> get_mac_addresses() {
// windows
// windows
#
include <ws2tcpip
.h>
#
include <iphlpapi
.h>
#include <winsock2.h>
#
include <winsock2.h>
#
include <iphlpapi
.h>
#
include <ws2tcpip
.h>
#
include <memory
>
#
include <algorithm
>
#
include <vector
>
#
include <cctype
>
#
include <string
>
#
include <cstdio
>
#
include <cctype
>
#
include <cstdlib
>
#
include <cstdio
>
#
include <cstring
>
#
include <cstdlib
>
#
include <fstream
>
#
include <cstring
>
#
include <iostream
>
#
include <fstream
>
#
include <iterator
>
#
include <sstream
>
#
include <memory
>
#
include <io
stream>
#
include <s
stream>
#
include <iterator
>
#
include <string
>
#
include <algorithm
>
#
include <vector
>
namespace
{
namespace
{
...
@@ -230,7 +225,7 @@ std::vector<iface_info> get_mac_addresses() {
...
@@ -230,7 +225,7 @@ std::vector<iface_info> get_mac_addresses() {
// break condition
// break condition
size_t
iterations
=
0
;
size_t
iterations
=
0
;
do
{
do
{
addresses
.
reset
((
IP_ADAPTER_ADDRESSES
*
)
malloc
(
addresses_len
));
addresses
.
reset
((
IP_ADAPTER_ADDRESSES
*
)
malloc
(
addresses_len
));
if
(
!
addresses
)
{
if
(
!
addresses
)
{
perror
(
"Memory allocation failed for IP_ADAPTER_ADDRESSES struct"
);
perror
(
"Memory allocation failed for IP_ADAPTER_ADDRESSES struct"
);
exit
(
1
);
exit
(
1
);
...
...
libcaf_core/src/detail/get_process_id.cpp
View file @
f4c5842b
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#include "caf/config.hpp"
#include "caf/config.hpp"
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
# include <windows.h>
# include <windows.h>
#else
#else
# include <sys/types.h>
# include <sys/types.h>
...
@@ -31,11 +31,11 @@ namespace caf {
...
@@ -31,11 +31,11 @@ namespace caf {
namespace
detail
{
namespace
detail
{
unsigned
get_process_id
()
{
unsigned
get_process_id
()
{
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
return
GetCurrentProcessId
();
return
GetCurrentProcessId
();
#
else
#else
return
static_cast
<
unsigned
>
(
getpid
());
return
static_cast
<
unsigned
>
(
getpid
());
#
endif
#endif
}
}
}
// namespace detail
}
// namespace detail
...
...
libcaf_core/src/detail/get_root_uuid.cpp
View file @
f4c5842b
...
@@ -16,13 +16,13 @@
...
@@ -16,13 +16,13 @@
* http://www.boost.org/LICENSE_1_0.txt. *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
******************************************************************************/
#include "caf/config.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/config.hpp"
#ifndef CAF_MACOS // not needed on Mac OS X
#ifndef CAF_MACOS // not needed on Mac OS X
namespace
{
namespace
{
constexpr
char
uuid_format
[]
=
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
;
constexpr
char
uuid_format
[]
=
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
;
}
// namespace
<anonmyous>
}
// namespace
#endif // CAF_MACOS
#endif // CAF_MACOS
#if defined(CAF_MACOS)
#if defined(CAF_MACOS)
...
@@ -35,8 +35,7 @@ inline void erase_trailing_newline(std::string& str) {
...
@@ -35,8 +35,7 @@ inline void erase_trailing_newline(std::string& str) {
}
}
}
}
constexpr
const
char
*
s_get_uuid
=
constexpr
const
char
*
s_get_uuid
=
"/usr/sbin/diskutil info / | "
"/usr/sbin/diskutil info / | "
"/usr/bin/awk '$0 ~ /UUID/ { print $3 }'"
;
"/usr/bin/awk '$0 ~ /UUID/ { print $3 }'"
;
}
// namespace
}
// namespace
...
@@ -62,28 +61,27 @@ std::string get_root_uuid() {
...
@@ -62,28 +61,27 @@ std::string get_root_uuid() {
#elif defined(CAF_LINUX) || defined(CAF_BSD) || defined(CAF_CYGWIN)
#elif defined(CAF_LINUX) || defined(CAF_BSD) || defined(CAF_CYGWIN)
#include <vector>
# include <algorithm>
#include <string>
# include <fstream>
#include <fstream>
# include <iostream>
#include <sstream>
# include <iterator>
#include <iostream>
# include <sstream>
#include <iterator>
# include <string>
#include <algorithm>
# include <vector>
#include <iostream>
#include "caf/string_algorithms.hpp"
#
include "caf/string_algorithms.hpp"
using
std
::
vector
;
using
std
::
string
;
using
std
::
ifstream
;
using
std
::
ifstream
;
using
std
::
string
;
using
std
::
vector
;
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
namespace
{
namespace
{
struct
columns_iterator
:
std
::
iterator
<
std
::
forward_iterator_tag
,
struct
columns_iterator
vector
<
string
>>
{
:
std
::
iterator
<
std
::
forward_iterator_tag
,
vector
<
string
>>
{
columns_iterator
(
ifstream
*
s
=
nullptr
)
:
fs
(
s
)
{
columns_iterator
(
ifstream
*
s
=
nullptr
)
:
fs
(
s
)
{
// nop
// nop
}
}
...
@@ -145,12 +143,12 @@ std::string get_root_uuid() {
...
@@ -145,12 +143,12 @@ std::string get_root_uuid() {
#elif defined(CAF_WINDOWS)
#elif defined(CAF_WINDOWS)
#
include <string
>
#
include <algorithm
>
#include <iostream>
#
include <iostream>
#
include <algorithm
>
#
include <string
>
#
include <windows
.h>
#
include <tchar
.h>
#
include <tchar
.h>
#
include <windows
.h>
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
...
@@ -167,8 +165,8 @@ void mv(std::string& lhs, std::string&& rhs) {
...
@@ -167,8 +165,8 @@ void mv(std::string& lhs, std::string&& rhs) {
// if TCHAR is defined as WCHAR, we have to do unicode conversion
// if TCHAR is defined as WCHAR, we have to do unicode conversion
void
mv
(
std
::
string
&
lhs
,
const
std
::
basic_string
<
WCHAR
>&
rhs
)
{
void
mv
(
std
::
string
&
lhs
,
const
std
::
basic_string
<
WCHAR
>&
rhs
)
{
auto
size_needed
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
rhs
.
c_str
(),
auto
size_needed
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
rhs
.
c_str
(),
static_cast
<
int
>
(
rhs
.
size
()),
static_cast
<
int
>
(
rhs
.
size
()),
nullptr
,
nullptr
,
0
,
nullptr
,
nullptr
);
0
,
nullptr
,
nullptr
);
lhs
.
resize
(
size_needed
);
lhs
.
resize
(
size_needed
);
WideCharToMultiByte
(
CP_UTF8
,
0
,
rhs
.
c_str
(),
static_cast
<
int
>
(
rhs
.
size
()),
WideCharToMultiByte
(
CP_UTF8
,
0
,
rhs
.
c_str
(),
static_cast
<
int
>
(
rhs
.
size
()),
&
lhs
[
0
],
size_needed
,
nullptr
,
nullptr
);
&
lhs
[
0
],
size_needed
,
nullptr
,
nullptr
);
...
@@ -210,12 +208,11 @@ std::string get_root_uuid() {
...
@@ -210,12 +208,11 @@ std::string get_root_uuid() {
}
// namespace detail
}
// namespace detail
}
// namespace caf
}
// namespace caf
#elif defined(CAF_IOS) || defined(CAF_ANDROID)
#elif defined(CAF_IOS) || defined(CAF_ANDROID)
// return a randomly-generated UUID on mobile devices
// return a randomly-generated UUID on mobile devices
#include <random>
#
include <random>
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
...
...
libcaf_core/src/detail/ini_consumer.cpp
View file @
f4c5842b
...
@@ -45,8 +45,7 @@ ini_list_consumer abstract_ini_consumer::begin_list() {
...
@@ -45,8 +45,7 @@ ini_list_consumer abstract_ini_consumer::begin_list() {
// -- map_consumer -------------------------------------------------------------
// -- map_consumer -------------------------------------------------------------
ini_map_consumer
::
ini_map_consumer
(
abstract_ini_consumer
*
parent
)
ini_map_consumer
::
ini_map_consumer
(
abstract_ini_consumer
*
parent
)
:
super
(
parent
),
:
super
(
parent
),
i_
(
xs_
.
end
())
{
i_
(
xs_
.
end
())
{
CAF_ASSERT
(
parent
!=
nullptr
);
CAF_ASSERT
(
parent
!=
nullptr
);
}
}
...
@@ -79,8 +78,7 @@ ini_list_consumer::ini_list_consumer(abstract_ini_consumer* parent)
...
@@ -79,8 +78,7 @@ ini_list_consumer::ini_list_consumer(abstract_ini_consumer* parent)
}
}
ini_list_consumer
::
ini_list_consumer
(
ini_list_consumer
&&
other
)
ini_list_consumer
::
ini_list_consumer
(
ini_list_consumer
&&
other
)
:
super
(
other
.
parent
()),
:
super
(
other
.
parent
()),
xs_
(
std
::
move
(
other
.
xs_
))
{
xs_
(
std
::
move
(
other
.
xs_
))
{
// nop
// nop
}
}
...
@@ -107,8 +105,7 @@ void ini_value_consumer::value_impl(config_value&& x) {
...
@@ -107,8 +105,7 @@ void ini_value_consumer::value_impl(config_value&& x) {
ini_category_consumer
::
ini_category_consumer
(
ini_consumer
*
parent
,
ini_category_consumer
::
ini_category_consumer
(
ini_consumer
*
parent
,
std
::
string
category
)
std
::
string
category
)
:
super
(
parent
),
:
super
(
parent
),
category_
(
std
::
move
(
category
))
{
category_
(
std
::
move
(
category
))
{
CAF_ASSERT
(
parent_
!=
nullptr
);
CAF_ASSERT
(
parent_
!=
nullptr
);
}
}
...
@@ -169,13 +166,14 @@ void ini_consumer::value_impl(config_value&& x) {
...
@@ -169,13 +166,14 @@ void ini_consumer::value_impl(config_value&& x) {
using
dict_type
=
config_value
::
dictionary
;
using
dict_type
=
config_value
::
dictionary
;
auto
dict
=
get_if
<
dict_type
>
(
&
x
);
auto
dict
=
get_if
<
dict_type
>
(
&
x
);
if
(
dict
==
nullptr
)
{
if
(
dict
==
nullptr
)
{
warnings_
.
emplace_back
(
make_error
(
pec
::
type_mismatch
,
warnings_
.
emplace_back
(
"expected a dictionary at top level"
));
make_error
(
pec
::
type_mismatch
,
"expected a dictionary at top level"
));
return
;
return
;
}
}
if
(
current_key_
!=
"global"
)
{
if
(
current_key_
!=
"global"
)
{
auto
&
dst
=
cfg_
.
emplace
(
current_key_
,
dict_type
{}).
first
->
second
;
auto
&
dst
=
cfg_
.
emplace
(
current_key_
,
dict_type
{}).
first
->
second
;
if
(
dict
!=
nullptr
&&
!
dict
->
empty
()
&&
holds_alternative
<
dict_type
>
(
dst
))
{
if
(
dict
!=
nullptr
&&
!
dict
->
empty
()
&&
holds_alternative
<
dict_type
>
(
dst
))
{
auto
&
dst_dict
=
get
<
dict_type
>
(
dst
);
auto
&
dst_dict
=
get
<
dict_type
>
(
dst
);
// We need to "merge" values into the destination, because it can already
// We need to "merge" values into the destination, because it can already
// contain any number of unrelated entries.
// contain any number of unrelated entries.
...
...
libcaf_core/src/detail/merged_tuple.cpp
View file @
f4c5842b
...
@@ -36,14 +36,12 @@ merged_tuple::cow_ptr merged_tuple::make(message x, message y) {
...
@@ -36,14 +36,12 @@ merged_tuple::cow_ptr merged_tuple::make(message x, message y) {
else
else
mapping
.
emplace_back
(
0
,
i
);
mapping
.
emplace_back
(
0
,
i
);
}
}
return
cow_ptr
{
make_counted
<
merged_tuple
>
(
std
::
move
(
data
),
return
cow_ptr
{
std
::
move
(
mapping
))};
make_counted
<
merged_tuple
>
(
std
::
move
(
data
),
std
::
move
(
mapping
))};
}
}
merged_tuple
::
merged_tuple
(
data_type
xs
,
mapping_type
ys
)
merged_tuple
::
merged_tuple
(
data_type
xs
,
mapping_type
ys
)
:
data_
(
std
::
move
(
xs
)),
:
data_
(
std
::
move
(
xs
)),
type_token_
(
0xFFFFFFFF
),
mapping_
(
std
::
move
(
ys
))
{
type_token_
(
0xFFFFFFFF
),
mapping_
(
std
::
move
(
ys
))
{
CAF_ASSERT
(
!
data_
.
empty
());
CAF_ASSERT
(
!
data_
.
empty
());
CAF_ASSERT
(
!
mapping_
.
empty
());
CAF_ASSERT
(
!
mapping_
.
empty
());
// calculate type token
// calculate type token
...
...
libcaf_core/src/detail/parser/chars.cpp
View file @
f4c5842b
...
@@ -38,4 +38,3 @@ const char octal_chars[9] = "01234567";
...
@@ -38,4 +38,3 @@ const char octal_chars[9] = "01234567";
}
// namespace parser
}
// namespace parser
}
// namespace detail
}
// namespace detail
}
// namespace caf
}
// namespace caf
libcaf_core/src/detail/pretty_type_name.cpp
View file @
f4c5842b
...
@@ -21,9 +21,9 @@
...
@@ -21,9 +21,9 @@
#include "caf/config.hpp"
#include "caf/config.hpp"
#if defined(CAF_LINUX) || defined(CAF_MACOS)
#if defined(CAF_LINUX) || defined(CAF_MACOS)
#
include <unistd
.h>
#
include <cxxabi
.h>
#
include <cxxabi
.h>
#
include <sys/types
.h>
#
include <sys/types
.h>
#
include <unistd
.h>
#endif
#endif
#include "caf/string_algorithms.hpp"
#include "caf/string_algorithms.hpp"
...
@@ -32,7 +32,7 @@ namespace caf {
...
@@ -32,7 +32,7 @@ namespace caf {
namespace
detail
{
namespace
detail
{
void
prettify_type_name
(
std
::
string
&
class_name
)
{
void
prettify_type_name
(
std
::
string
&
class_name
)
{
//replace_all(class_name, " ", "");
//
replace_all(class_name, " ", "");
replace_all
(
class_name
,
"::"
,
"."
);
replace_all
(
class_name
,
"::"
,
"."
);
replace_all
(
class_name
,
"(anonymous namespace)"
,
"ANON"
);
replace_all
(
class_name
,
"(anonymous namespace)"
,
"ANON"
);
replace_all
(
class_name
,
".__1."
,
"."
);
// gets rid of weird Clang-lib names
replace_all
(
class_name
,
".__1."
,
"."
);
// gets rid of weird Clang-lib names
...
@@ -58,15 +58,15 @@ void prettify_type_name(std::string& class_name) {
...
@@ -58,15 +58,15 @@ void prettify_type_name(std::string& class_name) {
}
}
void
prettify_type_name
(
std
::
string
&
class_name
,
const
char
*
c_class_name
)
{
void
prettify_type_name
(
std
::
string
&
class_name
,
const
char
*
c_class_name
)
{
#
if defined(CAF_LINUX) || defined(CAF_MACOS)
#if defined(CAF_LINUX) || defined(CAF_MACOS)
int
stat
=
0
;
int
stat
=
0
;
std
::
unique_ptr
<
char
,
decltype
(
free
)
*>
real_class_name
{
nullptr
,
free
};
std
::
unique_ptr
<
char
,
decltype
(
free
)
*>
real_class_name
{
nullptr
,
free
};
auto
tmp
=
abi
::
__cxa_demangle
(
c_class_name
,
nullptr
,
nullptr
,
&
stat
);
auto
tmp
=
abi
::
__cxa_demangle
(
c_class_name
,
nullptr
,
nullptr
,
&
stat
);
real_class_name
.
reset
(
tmp
);
real_class_name
.
reset
(
tmp
);
class_name
=
stat
==
0
?
real_class_name
.
get
()
:
c_class_name
;
class_name
=
stat
==
0
?
real_class_name
.
get
()
:
c_class_name
;
#
else
#else
class_name
=
c_class_name
;
class_name
=
c_class_name
;
#
endif
#endif
prettify_type_name
(
class_name
);
prettify_type_name
(
class_name
);
}
}
...
...
libcaf_core/src/detail/private_thread.cpp
View file @
f4c5842b
libcaf_core/src/detail/ripemd_160.cpp
View file @
f4c5842b
...
@@ -54,8 +54,8 @@
...
@@ -54,8 +54,8 @@
* *
* *
\******************************************************************************/
\******************************************************************************/
#include <cstring>
#include "caf/detail/ripemd_160.hpp"
#include "caf/detail/ripemd_160.hpp"
#include <cstring>
namespace
{
namespace
{
...
@@ -378,7 +378,7 @@ void MDfinish(dword* MDbuf, const byte* strptr, dword lswlen, dword mswlen) {
...
@@ -378,7 +378,7 @@ void MDfinish(dword* MDbuf, const byte* strptr, dword lswlen, dword mswlen) {
compress
(
MDbuf
,
X
);
compress
(
MDbuf
,
X
);
}
}
}
// namespace
<anonmyous>
}
// namespace
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
...
...
libcaf_core/src/detail/set_thread_name.cpp
View file @
f4c5842b
...
@@ -21,13 +21,13 @@
...
@@ -21,13 +21,13 @@
#include "caf/config.hpp"
#include "caf/config.hpp"
#ifndef CAF_WINDOWS
#ifndef CAF_WINDOWS
#include <pthread.h>
#
include <pthread.h>
#endif // CAF_WINDOWS
#endif // CAF_WINDOWS
#if defined(CAF_LINUX)
#if defined(CAF_LINUX)
#include <sys/prctl.h>
#
include <sys/prctl.h>
#elif defined(CAF_BSD)
#elif defined(CAF_BSD)
#include <pthread_np.h>
#
include <pthread_np.h>
#endif // defined(...)
#endif // defined(...)
#include <thread>
#include <thread>
...
@@ -43,13 +43,13 @@ void set_thread_name(const char* name) {
...
@@ -43,13 +43,13 @@ void set_thread_name(const char* name) {
#else // CAF_WINDOWS
#else // CAF_WINDOWS
static_assert
(
std
::
is_same
<
std
::
thread
::
native_handle_type
,
pthread_t
>::
value
,
static_assert
(
std
::
is_same
<
std
::
thread
::
native_handle_type
,
pthread_t
>::
value
,
"std::thread not based on pthread_t"
);
"std::thread not based on pthread_t"
);
#if defined(CAF_MACOS)
#
if defined(CAF_MACOS)
pthread_setname_np
(
name
);
pthread_setname_np
(
name
);
#elif defined(CAF_LINUX)
#
elif defined(CAF_LINUX)
prctl
(
PR_SET_NAME
,
name
,
0
,
0
,
0
);
prctl
(
PR_SET_NAME
,
name
,
0
,
0
,
0
);
#elif defined(CAF_BSD)
#
elif defined(CAF_BSD)
pthread_set_name_np
(
pthread_self
(),
name
);
pthread_set_name_np
(
pthread_self
(),
name
);
#endif // defined(...)
#
endif // defined(...)
#endif // CAF_WINDOWS
#endif // CAF_WINDOWS
}
}
...
...
libcaf_core/src/detail/simple_actor_clock.cpp
View file @
f4c5842b
...
@@ -177,9 +177,8 @@ size_t simple_actor_clock::trigger_expired_timeouts() {
...
@@ -177,9 +177,8 @@ size_t simple_actor_clock::trigger_expired_timeouts() {
return
result
;
return
result
;
}
}
void
void
simple_actor_clock
::
add_schedule_entry
(
simple_actor_clock
::
add_schedule_entry
(
time_point
t
,
time_point
t
,
std
::
unique_ptr
<
ordinary_timeout
>
x
)
{
std
::
unique_ptr
<
ordinary_timeout
>
x
)
{
auto
aid
=
x
->
self
->
id
();
auto
aid
=
x
->
self
->
id
();
auto
type
=
x
->
type
;
auto
type
=
x
->
type
;
auto
pred
=
[
&
](
const
actor_lookup_map
::
value_type
&
kvp
)
{
auto
pred
=
[
&
](
const
actor_lookup_map
::
value_type
&
kvp
)
{
...
...
libcaf_core/src/detail/sync_request_bouncer.cpp
View file @
f4c5842b
...
@@ -16,14 +16,14 @@
...
@@ -16,14 +16,14 @@
* http://www.boost.org/LICENSE_1_0.txt. *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
******************************************************************************/
#include "caf/sec.hpp"
#include "caf/atom.hpp"
#include "caf/actor.hpp"
#include "caf/actor.hpp"
#include "caf/config.hpp"
#include "caf/actor_cast.hpp"
#include "caf/actor_cast.hpp"
#include "caf/message_id.hpp"
#include "caf/atom.hpp"
#include "caf/config.hpp"
#include "caf/exit_reason.hpp"
#include "caf/exit_reason.hpp"
#include "caf/mailbox_element.hpp"
#include "caf/mailbox_element.hpp"
#include "caf/message_id.hpp"
#include "caf/sec.hpp"
#include "caf/system_messages.hpp"
#include "caf/system_messages.hpp"
#include "caf/detail/sync_request_bouncer.hpp"
#include "caf/detail/sync_request_bouncer.hpp"
...
...
libcaf_core/src/detail/thread_safe_actor_clock.cpp
View file @
f4c5842b
...
@@ -68,8 +68,9 @@ void thread_safe_actor_clock::schedule_message(time_point t,
...
@@ -68,8 +68,9 @@ void thread_safe_actor_clock::schedule_message(time_point t,
void
thread_safe_actor_clock
::
schedule_message
(
time_point
t
,
group
target
,
void
thread_safe_actor_clock
::
schedule_message
(
time_point
t
,
group
target
,
strong_actor_ptr
sender
,
strong_actor_ptr
sender
,
message
content
)
{
message
content
)
{
push
(
new
group_msg
(
t
,
std
::
move
(
target
),
std
::
move
(
sender
),
auto
ptr
=
new
group_msg
(
t
,
std
::
move
(
target
),
std
::
move
(
sender
),
std
::
move
(
content
)));
std
::
move
(
content
));
push
(
ptr
);
}
}
void
thread_safe_actor_clock
::
cancel_all
()
{
void
thread_safe_actor_clock
::
cancel_all
()
{
...
...
libcaf_core/src/detail/tick_emitter.cpp
View file @
f4c5842b
...
@@ -25,9 +25,7 @@ namespace caf {
...
@@ -25,9 +25,7 @@ namespace caf {
namespace
detail
{
namespace
detail
{
tick_emitter
::
tick_emitter
()
tick_emitter
::
tick_emitter
()
:
start_
(
duration_type
{
0
}),
:
start_
(
duration_type
{
0
}),
interval_
(
0
),
last_tick_id_
(
0
)
{
interval_
(
0
),
last_tick_id_
(
0
)
{
// nop
// nop
}
}
...
@@ -56,8 +54,8 @@ void tick_emitter::interval(duration_type x) {
...
@@ -56,8 +54,8 @@ void tick_emitter::interval(duration_type x) {
size_t
tick_emitter
::
timeouts
(
time_point
now
,
size_t
tick_emitter
::
timeouts
(
time_point
now
,
std
::
initializer_list
<
size_t
>
periods
)
{
std
::
initializer_list
<
size_t
>
periods
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
now
)
<<
CAF_ARG
(
periods
)
CAF_LOG_TRACE
(
CAF_ARG
(
now
)
<<
CAF_ARG
(
interval_
)
<<
CAF_ARG
(
start_
));
<<
CAF_ARG
(
periods
)
<<
CAF_ARG
(
interval_
)
<<
CAF_ARG
(
start_
));
CAF_ASSERT
(
now
>=
start_
);
CAF_ASSERT
(
now
>=
start_
);
size_t
result
=
0
;
size_t
result
=
0
;
auto
f
=
[
&
](
size_t
tick
)
{
auto
f
=
[
&
](
size_t
tick
)
{
...
...
libcaf_core/src/detail/try_match.cpp
View file @
f4c5842b
...
@@ -40,8 +40,7 @@ bool match_atom_constant(const meta_element& me, const type_erased_tuple& xs,
...
@@ -40,8 +40,7 @@ bool match_atom_constant(const meta_element& me, const type_erased_tuple& xs,
return
me
.
v
==
*
reinterpret_cast
<
const
atom_value
*>
(
ptr
);
return
me
.
v
==
*
reinterpret_cast
<
const
atom_value
*>
(
ptr
);
}
}
bool
try_match
(
const
type_erased_tuple
&
xs
,
bool
try_match
(
const
type_erased_tuple
&
xs
,
pattern_iterator
iter
,
size_t
ps
)
{
pattern_iterator
iter
,
size_t
ps
)
{
if
(
xs
.
size
()
!=
ps
)
if
(
xs
.
size
()
!=
ps
)
return
false
;
return
false
;
for
(
size_t
i
=
0
;
i
<
ps
;
++
i
,
++
iter
)
for
(
size_t
i
=
0
;
i
<
ps
;
++
i
,
++
iter
)
...
...
libcaf_core/src/policy/downstream_messages.cpp
View file @
f4c5842b
...
@@ -57,8 +57,9 @@ auto downstream_messages::id_of(mailbox_element& x) noexcept -> key_type {
...
@@ -57,8 +57,9 @@ auto downstream_messages::id_of(mailbox_element& x) noexcept -> key_type {
bool
downstream_messages
::
enabled
(
const
nested_queue_type
&
q
)
noexcept
{
bool
downstream_messages
::
enabled
(
const
nested_queue_type
&
q
)
noexcept
{
auto
congested
=
q
.
policy
().
handler
->
mgr
->
congested
();
auto
congested
=
q
.
policy
().
handler
->
mgr
->
congested
();
CAF_LOG_DEBUG_IF
(
congested
,
"path is congested:"
CAF_LOG_DEBUG_IF
(
congested
,
<<
CAF_ARG2
(
"slot"
,
q
.
policy
().
handler
->
slots
.
receiver
));
"path is congested:"
<<
CAF_ARG2
(
"slot"
,
q
.
policy
().
handler
->
slots
.
receiver
));
return
!
congested
;
return
!
congested
;
}
}
...
@@ -70,4 +71,3 @@ auto downstream_messages::quantum(const nested_queue_type& q,
...
@@ -70,4 +71,3 @@ auto downstream_messages::quantum(const nested_queue_type& q,
}
// namespace policy
}
// namespace policy
}
// namespace caf
}
// namespace caf
libcaf_core/src/policy/work_stealing.cpp
View file @
f4c5842b
...
@@ -39,8 +39,8 @@ work_stealing::worker_data::worker_data(scheduler::abstract_coordinator* p)
...
@@ -39,8 +39,8 @@ work_stealing::worker_data::worker_data(scheduler::abstract_coordinator* p)
// no need to worry about wrap-around; if `p->num_workers() < 2`,
// no need to worry about wrap-around; if `p->num_workers() < 2`,
// `uniform` will not be used anyway
// `uniform` will not be used anyway
uniform
(
0
,
p
->
num_workers
()
-
2
),
uniform
(
0
,
p
->
num_workers
()
-
2
),
strategies
{
{
strategies
{
{
CONFIG
(
"aggressive-poll-attempts"
,
aggressive_poll_attempts
),
1
,
{
{
CONFIG
(
"aggressive-poll-attempts"
,
aggressive_poll_attempts
),
1
,
CONFIG
(
"aggressive-steal-interval"
,
aggressive_steal_interval
),
CONFIG
(
"aggressive-steal-interval"
,
aggressive_steal_interval
),
timespan
{
0
}},
timespan
{
0
}},
{
CONFIG
(
"moderate-poll-attempts"
,
moderate_poll_attempts
),
1
,
{
CONFIG
(
"moderate-poll-attempts"
,
moderate_poll_attempts
),
1
,
...
...
libcaf_core/src/scheduler/abstract_coordinator.cpp
View file @
f4c5842b
...
@@ -18,14 +18,14 @@
...
@@ -18,14 +18,14 @@
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include <ios>
#include <thread>
#include <atomic>
#include <atomic>
#include <chrono>
#include <chrono>
#include <condition_variable>
#include <fstream>
#include <fstream>
#include <ios>
#include <iostream>
#include <iostream>
#include <thread>
#include <unordered_map>
#include <unordered_map>
#include <condition_variable>
#include "caf/actor_ostream.hpp"
#include "caf/actor_ostream.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system.hpp"
...
@@ -51,7 +51,7 @@ namespace scheduler {
...
@@ -51,7 +51,7 @@ namespace scheduler {
namespace
{
namespace
{
using
string_sink
=
std
::
function
<
void
(
std
::
string
&&
)
>
;
using
string_sink
=
std
::
function
<
void
(
std
::
string
&&
)
>
;
// the first value is the use count, the last ostream_handle that
// the first value is the use count, the last ostream_handle that
// decrements it to 0 removes the ostream pointer from the map
// decrements it to 0 removes the ostream pointer from the map
...
@@ -127,7 +127,7 @@ string_sink make_sink(actor_system& sys, const std::string& fn, int flags) {
...
@@ -127,7 +127,7 @@ string_sink make_sink(actor_system& sys, const std::string& fn, int flags) {
:
std
::
ios_base
::
out
);
:
std
::
ios_base
::
out
);
if
(
fs
->
is_open
())
if
(
fs
->
is_open
())
return
[
fs
](
std
::
string
&&
out
)
{
*
fs
<<
out
;
};
return
[
fs
](
std
::
string
&&
out
)
{
*
fs
<<
out
;
};
std
::
cerr
<<
"cannot open file: "
<<
fn
<<
std
::
endl
;
std
::
cerr
<<
"cannot open file: "
<<
fn
<<
std
::
endl
;
return
nullptr
;
return
nullptr
;
}
}
...
@@ -197,9 +197,7 @@ public:
...
@@ -197,9 +197,7 @@ public:
flush
(
d
,
false
);
flush
(
d
,
false
);
}
}
},
},
[
&
](
flush_atom
,
actor_id
aid
)
{
[
&
](
flush_atom
,
actor_id
aid
)
{
flush
(
get_data
(
aid
,
false
),
true
);
},
flush
(
get_data
(
aid
,
false
),
true
);
},
[
&
](
delete_atom
,
actor_id
aid
)
{
[
&
](
delete_atom
,
actor_id
aid
)
{
auto
data_ptr
=
get_data
(
aid
,
false
);
auto
data_ptr
=
get_data
(
aid
,
false
);
if
(
data_ptr
!=
nullptr
)
{
if
(
data_ptr
!=
nullptr
)
{
...
@@ -218,8 +216,8 @@ public:
...
@@ -218,8 +216,8 @@ public:
[
&
](
exit_msg
&
em
)
{
[
&
](
exit_msg
&
em
)
{
fail_state
(
std
::
move
(
em
.
reason
));
fail_state
(
std
::
move
(
em
.
reason
));
done
=
true
;
done
=
true
;
}
}
)
)
.
until
([
&
]
{
return
done
;
});
.
until
([
&
]
{
return
done
;
});
}
}
const
char
*
name
()
const
override
{
const
char
*
name
()
const
override
{
...
@@ -271,10 +269,7 @@ void abstract_coordinator::stop_actors() {
...
@@ -271,10 +269,7 @@ void abstract_coordinator::stop_actors() {
}
}
abstract_coordinator
::
abstract_coordinator
(
actor_system
&
sys
)
abstract_coordinator
::
abstract_coordinator
(
actor_system
&
sys
)
:
next_worker_
(
0
),
:
next_worker_
(
0
),
max_throughput_
(
0
),
num_workers_
(
0
),
system_
(
sys
)
{
max_throughput_
(
0
),
num_workers_
(
0
),
system_
(
sys
)
{
// nop
// nop
}
}
...
...
libcaf_core/src/scheduler/test_coordinator.cpp
View file @
f4c5842b
...
@@ -33,8 +33,7 @@ namespace {
...
@@ -33,8 +33,7 @@ namespace {
class
dummy_worker
:
public
execution_unit
{
class
dummy_worker
:
public
execution_unit
{
public:
public:
dummy_worker
(
test_coordinator
*
parent
)
dummy_worker
(
test_coordinator
*
parent
)
:
execution_unit
(
&
parent
->
system
()),
:
execution_unit
(
&
parent
->
system
()),
parent_
(
parent
)
{
parent_
(
parent
)
{
// nop
// nop
}
}
...
@@ -50,10 +49,7 @@ class dummy_printer : public monitorable_actor {
...
@@ -50,10 +49,7 @@ class dummy_printer : public monitorable_actor {
public:
public:
dummy_printer
(
actor_config
&
cfg
)
:
monitorable_actor
(
cfg
)
{
dummy_printer
(
actor_config
&
cfg
)
:
monitorable_actor
(
cfg
)
{
mh_
.
assign
(
mh_
.
assign
(
[
&
](
add_atom
,
actor_id
,
const
std
::
string
&
str
)
{
[
&
](
add_atom
,
actor_id
,
const
std
::
string
&
str
)
{
std
::
cout
<<
str
;
});
std
::
cout
<<
str
;
}
);
}
}
void
enqueue
(
mailbox_element_ptr
what
,
execution_unit
*
)
override
{
void
enqueue
(
mailbox_element_ptr
what
,
execution_unit
*
)
override
{
...
@@ -82,8 +78,9 @@ void test_coordinator::start() {
...
@@ -82,8 +78,9 @@ void test_coordinator::start() {
dummy_worker
worker
{
this
};
dummy_worker
worker
{
this
};
actor_config
cfg
{
&
worker
};
actor_config
cfg
{
&
worker
};
auto
&
sys
=
system
();
auto
&
sys
=
system
();
utility_actors_
[
printer_id
]
=
make_actor
<
dummy_printer
,
actor
>
(
utility_actors_
[
printer_id
]
=
make_actor
<
dummy_printer
,
sys
.
next_actor_id
(),
sys
.
node
(),
&
sys
,
cfg
);
actor
>
(
sys
.
next_actor_id
(),
sys
.
node
(),
&
sys
,
cfg
);
}
}
void
test_coordinator
::
stop
()
{
void
test_coordinator
::
stop
()
{
...
@@ -161,6 +158,5 @@ void test_coordinator::inline_all_enqueues_helper() {
...
@@ -161,6 +158,5 @@ void test_coordinator::inline_all_enqueues_helper() {
after_next_enqueue
([
=
]
{
inline_all_enqueues_helper
();
});
after_next_enqueue
([
=
]
{
inline_all_enqueues_helper
();
});
}
}
}
// namespace caf
}
// namespace scheduler
}
// namespace scheduler
}
// namespace caf
libcaf_core/test/decorator/sequencer.cpp
View file @
f4c5842b
...
@@ -24,8 +24,7 @@
...
@@ -24,8 +24,7 @@
#include "caf/all.hpp"
#include "caf/all.hpp"
#define ERROR_HANDLER \
#define ERROR_HANDLER [&](error& err) { CAF_FAIL(system.render(err)); }
[&](error& err) { CAF_FAIL(system.render(err)); }
using
namespace
caf
;
using
namespace
caf
;
...
@@ -33,12 +32,8 @@ namespace {
...
@@ -33,12 +32,8 @@ namespace {
behavior
testee
(
event_based_actor
*
self
)
{
behavior
testee
(
event_based_actor
*
self
)
{
return
{
return
{
[](
int
v
)
{
[](
int
v
)
{
return
2
*
v
;
},
return
2
*
v
;
[
=
]
{
self
->
quit
();
},
},
[
=
]
{
self
->
quit
();
}
};
};
}
}
...
@@ -46,14 +41,14 @@ using first_stage = typed_actor<replies_to<int>::with<double, double>>;
...
@@ -46,14 +41,14 @@ using first_stage = typed_actor<replies_to<int>::with<double, double>>;
using
second_stage
=
typed_actor
<
replies_to
<
double
,
double
>::
with
<
double
>>
;
using
second_stage
=
typed_actor
<
replies_to
<
double
,
double
>::
with
<
double
>>
;
first_stage
::
behavior_type
typed_first_stage
()
{
first_stage
::
behavior_type
typed_first_stage
()
{
return
[](
int
i
)
{
return
{
return
std
::
make_tuple
(
i
*
2.0
,
i
*
4.0
);
[](
int
i
)
{
return
std
::
make_tuple
(
i
*
2.0
,
i
*
4.0
);
},
};
};
}
}
second_stage
::
behavior_type
typed_second_stage
()
{
second_stage
::
behavior_type
typed_second_stage
()
{
return
[](
double
x
,
double
y
)
{
return
{
return
x
*
y
;
[](
double
x
,
double
y
)
{
return
x
*
y
;
},
};
};
}
}
...
@@ -140,14 +135,12 @@ CAF_TEST(request_response_promise) {
...
@@ -140,14 +135,12 @@ CAF_TEST(request_response_promise) {
auto
h
=
f
*
g
;
auto
h
=
f
*
g
;
anon_send_exit
(
h
,
exit_reason
::
kill
);
anon_send_exit
(
h
,
exit_reason
::
kill
);
CAF_CHECK
(
exited
(
h
));
CAF_CHECK
(
exited
(
h
));
self
->
request
(
h
,
infinite
,
1
).
receive
(
self
->
request
(
h
,
infinite
,
1
)
[](
int
)
{
.
receive
([](
int
)
{
CAF_CHECK
(
false
);
},
CAF_CHECK
(
false
);
},
[](
error
err
)
{
[](
error
err
)
{
CAF_CHECK_EQUAL
(
err
.
code
(),
static_cast
<
uint8_t
>
(
sec
::
request_receiver_down
));
CAF_CHECK_EQUAL
(
err
.
code
(),
static_cast
<
uint8_t
>
(
}
sec
::
request_receiver_down
));
);
}
);
}
}
// single composition of distinct actors
// single composition of distinct actors
...
@@ -155,25 +148,17 @@ CAF_TEST(dot_composition_1) {
...
@@ -155,25 +148,17 @@ CAF_TEST(dot_composition_1) {
auto
first
=
system
.
spawn
(
typed_first_stage
);
auto
first
=
system
.
spawn
(
typed_first_stage
);
auto
second
=
system
.
spawn
(
typed_second_stage
);
auto
second
=
system
.
spawn
(
typed_second_stage
);
auto
first_then_second
=
second
*
first
;
auto
first_then_second
=
second
*
first
;
self
->
request
(
first_then_second
,
infinite
,
42
).
receive
(
self
->
request
(
first_then_second
,
infinite
,
42
)
[](
double
res
)
{
.
receive
([](
double
res
)
{
CAF_CHECK_EQUAL
(
res
,
(
42
*
2.0
)
*
(
42
*
4.0
));
},
CAF_CHECK_EQUAL
(
res
,
(
42
*
2.0
)
*
(
42
*
4.0
));
ERROR_HANDLER
);
},
ERROR_HANDLER
);
}
}
// multiple self composition
// multiple self composition
CAF_TEST
(
dot_composition_2
)
{
CAF_TEST
(
dot_composition_2
)
{
auto
dbl_actor
=
system
.
spawn
(
testee
);
auto
dbl_actor
=
system
.
spawn
(
testee
);
auto
dbl_x4_actor
=
dbl_actor
*
dbl_actor
auto
dbl_x4_actor
=
dbl_actor
*
dbl_actor
*
dbl_actor
*
dbl_actor
;
*
dbl_actor
*
dbl_actor
;
self
->
request
(
dbl_x4_actor
,
infinite
,
1
)
self
->
request
(
dbl_x4_actor
,
infinite
,
1
).
receive
(
.
receive
([](
int
v
)
{
CAF_CHECK_EQUAL
(
v
,
16
);
},
ERROR_HANDLER
);
[](
int
v
)
{
CAF_CHECK_EQUAL
(
v
,
16
);
},
ERROR_HANDLER
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/decorator/splitter.cpp
View file @
f4c5842b
...
@@ -24,8 +24,7 @@
...
@@ -24,8 +24,7 @@
#include "caf/all.hpp"
#include "caf/all.hpp"
#define ERROR_HANDLER \
#define ERROR_HANDLER [&](error& err) { CAF_FAIL(system.render(err)); }
[&](error& err) { CAF_FAIL(system.render(err)); }
using
namespace
caf
;
using
namespace
caf
;
...
@@ -36,19 +35,15 @@ using second_stage = typed_actor<replies_to<double, double>::with<double>,
...
@@ -36,19 +35,15 @@ using second_stage = typed_actor<replies_to<double, double>::with<double>,
replies_to
<
double
>::
with
<
double
>>
;
replies_to
<
double
>::
with
<
double
>>
;
first_stage
::
behavior_type
typed_first_stage
()
{
first_stage
::
behavior_type
typed_first_stage
()
{
return
[](
double
x
)
{
return
{
return
std
::
make_tuple
(
x
*
2.0
,
x
*
4.0
);
[](
double
x
)
{
return
std
::
make_tuple
(
x
*
2.0
,
x
*
4.0
);
},
};
};
}
}
second_stage
::
behavior_type
typed_second_stage
()
{
second_stage
::
behavior_type
typed_second_stage
()
{
return
{
return
{
[](
double
x
,
double
y
)
{
[](
double
x
,
double
y
)
{
return
x
*
y
;
},
return
x
*
y
;
[](
double
x
)
{
return
23.0
*
x
;
},
},
[](
double
x
)
{
return
23.0
*
x
;
}
};
};
}
}
...
@@ -105,14 +100,14 @@ CAF_TEST(kill_second) {
...
@@ -105,14 +100,14 @@ CAF_TEST(kill_second) {
CAF_TEST
(
untyped_splicing
)
{
CAF_TEST
(
untyped_splicing
)
{
init_untyped
();
init_untyped
();
self
->
request
(
first_and_second
,
infinite
,
42.0
).
receive
(
self
->
request
(
first_and_second
,
infinite
,
42.0
)
.
receive
(
[](
double
x
,
double
y
,
double
z
)
{
[](
double
x
,
double
y
,
double
z
)
{
CAF_CHECK_EQUAL
(
x
,
(
42.0
*
2.0
));
CAF_CHECK_EQUAL
(
x
,
(
42.0
*
2.0
));
CAF_CHECK_EQUAL
(
y
,
(
42.0
*
4.0
));
CAF_CHECK_EQUAL
(
y
,
(
42.0
*
4.0
));
CAF_CHECK_EQUAL
(
z
,
(
23.0
*
42.0
));
CAF_CHECK_EQUAL
(
z
,
(
23.0
*
42.0
));
},
},
ERROR_HANDLER
ERROR_HANDLER
);
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/detail/limited_vector.cpp
View file @
f4c5842b
...
@@ -28,13 +28,14 @@ using caf::detail::limited_vector;
...
@@ -28,13 +28,14 @@ using caf::detail::limited_vector;
CAF_TEST
(
basics
)
{
CAF_TEST
(
basics
)
{
using
std
::
equal
;
using
std
::
equal
;
int
arr1
[]
{
1
,
2
,
3
,
4
};
int
arr1
[]{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
4
>
vec1
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
4
>
vec1
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
5
>
vec2
{
4
,
3
,
2
,
1
};
limited_vector
<
int
,
5
>
vec2
{
4
,
3
,
2
,
1
};
limited_vector
<
int
,
4
>
vec3
;
limited_vector
<
int
,
4
>
vec3
;
for
(
int
i
=
1
;
i
<=
4
;
++
i
)
vec3
.
push_back
(
i
);
for
(
int
i
=
1
;
i
<=
4
;
++
i
)
limited_vector
<
int
,
4
>
vec4
{
1
,
2
};
vec3
.
push_back
(
i
);
limited_vector
<
int
,
2
>
vec5
{
3
,
4
};
limited_vector
<
int
,
4
>
vec4
{
1
,
2
};
limited_vector
<
int
,
2
>
vec5
{
3
,
4
};
vec4
.
insert
(
vec4
.
end
(),
vec5
.
begin
(),
vec5
.
end
());
vec4
.
insert
(
vec4
.
end
(),
vec5
.
begin
(),
vec5
.
end
());
auto
vec6
=
vec4
;
auto
vec6
=
vec4
;
CAF_CHECK_EQUAL
(
vec1
.
size
(),
4u
);
CAF_CHECK_EQUAL
(
vec1
.
size
(),
4u
);
...
@@ -54,22 +55,22 @@ CAF_TEST(basics) {
...
@@ -54,22 +55,22 @@ CAF_TEST(basics) {
CAF_CHECK
(
std
::
equal
(
vec4
.
begin
(),
vec4
.
end
(),
arr1
));
CAF_CHECK
(
std
::
equal
(
vec4
.
begin
(),
vec4
.
end
(),
arr1
));
CAF_CHECK
(
std
::
equal
(
vec6
.
begin
(),
vec6
.
end
(),
arr1
));
CAF_CHECK
(
std
::
equal
(
vec6
.
begin
(),
vec6
.
end
(),
arr1
));
CAF_CHECK
(
std
::
equal
(
vec6
.
begin
(),
vec6
.
end
(),
vec2
.
rbegin
()));
CAF_CHECK
(
std
::
equal
(
vec6
.
begin
(),
vec6
.
end
(),
vec2
.
rbegin
()));
limited_vector
<
int
,
10
>
vec7
{
5
,
9
};
limited_vector
<
int
,
10
>
vec7
{
5
,
9
};
limited_vector
<
int
,
10
>
vec8
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
10
>
vec8
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
10
>
vec9
{
6
,
7
,
8
};
limited_vector
<
int
,
10
>
vec9
{
6
,
7
,
8
};
vec7
.
insert
(
vec7
.
begin
()
+
1
,
vec9
.
begin
(),
vec9
.
end
());
vec7
.
insert
(
vec7
.
begin
()
+
1
,
vec9
.
begin
(),
vec9
.
end
());
vec7
.
insert
(
vec7
.
begin
(),
vec8
.
begin
(),
vec8
.
end
());
vec7
.
insert
(
vec7
.
begin
(),
vec8
.
begin
(),
vec8
.
end
());
CAF_CHECK_EQUAL
(
vec7
.
full
(),
false
);
CAF_CHECK_EQUAL
(
vec7
.
full
(),
false
);
limited_vector
<
int
,
1
>
vec10
{
10
};
limited_vector
<
int
,
1
>
vec10
{
10
};
vec7
.
insert
(
vec7
.
end
(),
vec10
.
begin
(),
vec10
.
end
());
vec7
.
insert
(
vec7
.
end
(),
vec10
.
begin
(),
vec10
.
end
());
CAF_CHECK_EQUAL
(
vec7
.
full
(),
true
);
CAF_CHECK_EQUAL
(
vec7
.
full
(),
true
);
CAF_CHECK
((
std
::
is_sorted
(
vec7
.
begin
(),
vec7
.
end
())));
CAF_CHECK
((
std
::
is_sorted
(
vec7
.
begin
(),
vec7
.
end
())));
int
arr2
[]
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
int
arr2
[]{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
CAF_CHECK
((
std
::
equal
(
vec7
.
begin
(),
vec7
.
end
(),
std
::
begin
(
arr2
))));
CAF_CHECK
((
std
::
equal
(
vec7
.
begin
(),
vec7
.
end
(),
std
::
begin
(
arr2
))));
vec7
.
assign
(
std
::
begin
(
arr2
),
std
::
end
(
arr2
));
vec7
.
assign
(
std
::
begin
(
arr2
),
std
::
end
(
arr2
));
CAF_CHECK
((
std
::
equal
(
vec7
.
begin
(),
vec7
.
end
(),
std
::
begin
(
arr2
))));
CAF_CHECK
((
std
::
equal
(
vec7
.
begin
(),
vec7
.
end
(),
std
::
begin
(
arr2
))));
vec7
.
assign
(
5
,
0
);
vec7
.
assign
(
5
,
0
);
CAF_CHECK_EQUAL
(
vec7
.
size
(),
5u
);
CAF_CHECK_EQUAL
(
vec7
.
size
(),
5u
);
CAF_CHECK
(
(
std
::
all_of
(
vec7
.
begin
(),
vec7
.
end
(),
CAF_CHECK
(
[](
int
i
)
{
return
i
==
0
;
})));
(
std
::
all_of
(
vec7
.
begin
(),
vec7
.
end
(),
[](
int
i
)
{
return
i
==
0
;
})));
}
}
libcaf_core/test/detail/parser/read_atom.cpp
View file @
f4c5842b
...
@@ -32,7 +32,7 @@ namespace {
...
@@ -32,7 +32,7 @@ namespace {
struct
atom_parser_consumer
{
struct
atom_parser_consumer
{
atom_value
x
;
atom_value
x
;
inline
void
value
(
atom_value
y
)
{
void
value
(
atom_value
y
)
{
x
=
y
;
x
=
y
;
}
}
};
};
...
@@ -70,7 +70,7 @@ CAF_TEST(empty atom) {
...
@@ -70,7 +70,7 @@ CAF_TEST(empty atom) {
CAF_CHECK_EQUAL
(
p
(
"
\t
''
\t\t\t
"
),
atom
(
""
));
CAF_CHECK_EQUAL
(
p
(
"
\t
''
\t\t\t
"
),
atom
(
""
));
}
}
CAF_TEST
(
non
-
empty
atom
)
{
CAF_TEST
(
valid
atom
)
{
CAF_CHECK_EQUAL
(
p
(
"'abc'"
),
atom
(
"abc"
));
CAF_CHECK_EQUAL
(
p
(
"'abc'"
),
atom
(
"abc"
));
CAF_CHECK_EQUAL
(
p
(
"'a b c'"
),
atom
(
"a b c"
));
CAF_CHECK_EQUAL
(
p
(
"'a b c'"
),
atom
(
"a b c"
));
CAF_CHECK_EQUAL
(
p
(
" 'abcdef' "
),
atom
(
"abcdef"
));
CAF_CHECK_EQUAL
(
p
(
" 'abcdef' "
),
atom
(
"abcdef"
));
...
...
libcaf_core/test/detail/parser/read_ini.cpp
View file @
f4c5842b
...
@@ -261,7 +261,7 @@ CAF_TEST(empty inis) {
...
@@ -261,7 +261,7 @@ CAF_TEST(empty inis) {
CAF_CHECK_EQUAL
(
parse
(
";hello
\n
;world"
),
make_log
());
CAF_CHECK_EQUAL
(
parse
(
";hello
\n
;world"
),
make_log
());
}
}
CAF_TEST
(
section
with
valid
key
-
value
pairs
)
{
CAF_TEST
(
section
with
valid
key
-
value
pairs
)
{
CAF_CHECK_EQUAL
(
parse
(
"[foo]"
),
make_log
(
"key: foo"
,
"{"
,
"}"
));
CAF_CHECK_EQUAL
(
parse
(
"[foo]"
),
make_log
(
"key: foo"
,
"{"
,
"}"
));
CAF_CHECK_EQUAL
(
parse
(
" [foo]"
),
make_log
(
"key: foo"
,
"{"
,
"}"
));
CAF_CHECK_EQUAL
(
parse
(
" [foo]"
),
make_log
(
"key: foo"
,
"{"
,
"}"
));
CAF_CHECK_EQUAL
(
parse
(
" [ foo] "
),
make_log
(
"key: foo"
,
"{"
,
"}"
));
CAF_CHECK_EQUAL
(
parse
(
" [ foo] "
),
make_log
(
"key: foo"
,
"{"
,
"}"
));
...
...
libcaf_core/test/detail/parser/read_number_or_timespan.cpp
View file @
f4c5842b
...
@@ -132,4 +132,3 @@ CAF_TEST(invalid timespans) {
...
@@ -132,4 +132,3 @@ CAF_TEST(invalid timespans) {
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/detail/parser/read_string.cpp
View file @
f4c5842b
...
@@ -57,7 +57,7 @@ struct fixture {
...
@@ -57,7 +57,7 @@ struct fixture {
};
};
// TODO: remove and use "..."s from the STL when switching to C++14
// TODO: remove and use "..."s from the STL when switching to C++14
std
::
string
operator
""
_s
(
const
char
*
str
,
size_t
str_len
)
{
std
::
string
operator
""
_s
(
const
char
*
str
,
size_t
str_len
)
{
std
::
string
result
;
std
::
string
result
;
result
.
assign
(
str
,
str_len
);
result
.
assign
(
str
,
str_len
);
return
result
;
return
result
;
...
@@ -77,7 +77,7 @@ CAF_TEST(empty string) {
...
@@ -77,7 +77,7 @@ CAF_TEST(empty string) {
CAF_CHECK_EQUAL
(
p
(
"
\t
\"\"
\t\t\t
"
),
""
_s
);
CAF_CHECK_EQUAL
(
p
(
"
\t
\"\"
\t\t\t
"
),
""
_s
);
}
}
CAF_TEST
(
non
-
empty
quoted
string
)
{
CAF_TEST
(
non
-
empty
quoted
string
)
{
CAF_CHECK_EQUAL
(
p
(
R"("abc")"
),
"abc"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("abc")"
),
"abc"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a b c")"
),
"a b c"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a b c")"
),
"a b c"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"( "abcdefABCDEF" )"
),
"abcdefABCDEF"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"( "abcdefABCDEF" )"
),
"abcdefABCDEF"
_s
);
...
...
libcaf_core/test/detail/tick_emitter.cpp
View file @
f4c5842b
...
@@ -72,8 +72,8 @@ CAF_TEST(ticks) {
...
@@ -72,8 +72,8 @@ CAF_TEST(ticks) {
auto
cycle
=
detail
::
gcd
(
credit_interval
.
count
(),
auto
cycle
=
detail
::
gcd
(
credit_interval
.
count
(),
force_batch_interval
.
count
());
force_batch_interval
.
count
());
CAF_CHECK_EQUAL
(
cycle
,
50
);
CAF_CHECK_EQUAL
(
cycle
,
50
);
auto
force_batch_frequency
=
auto
force_batch_frequency
=
static_cast
<
size_t
>
(
force_batch_interval
.
count
()
static_cast
<
size_t
>
(
force_batch_interval
.
count
()
/
cycle
);
/
cycle
);
auto
credit_frequency
=
static_cast
<
size_t
>
(
credit_interval
.
count
()
/
cycle
);
auto
credit_frequency
=
static_cast
<
size_t
>
(
credit_interval
.
count
()
/
cycle
);
detail
::
tick_emitter
tctrl
{
time_point
{
timespan
{
100
}}};
detail
::
tick_emitter
tctrl
{
time_point
{
timespan
{
100
}}};
tctrl
.
interval
(
timespan
{
cycle
});
tctrl
.
interval
(
timespan
{
cycle
});
...
@@ -149,4 +149,3 @@ CAF_TEST(next_timeout) {
...
@@ -149,4 +149,3 @@ CAF_TEST(next_timeout) {
next
=
tctrl
.
next_timeout
(
now
,
{
5
,
7
});
next
=
tctrl
.
next_timeout
(
now
,
{
5
,
7
});
CAF_CHECK_EQUAL
(
next
,
start
+
timespan
((
2
*
7
)
*
interval
));
CAF_CHECK_EQUAL
(
next
,
start
+
timespan
((
2
*
7
)
*
interval
));
}
}
libcaf_core/test/detail/unique_function.cpp
View file @
f4c5842b
...
@@ -30,7 +30,7 @@ int fourty_two() {
...
@@ -30,7 +30,7 @@ int fourty_two() {
return
42
;
return
42
;
}
}
class
instance_counting_wrapper
final
:
public
int_fun
::
wrapper
{
class
instance_counting_wrapper
final
:
public
int_fun
::
wrapper
{
public:
public:
instance_counting_wrapper
(
size_t
*
instance_counter
)
instance_counting_wrapper
(
size_t
*
instance_counter
)
:
instance_counter_
(
instance_counter
)
{
:
instance_counter_
(
instance_counter
)
{
...
...
libcaf_core/test/detail/unordered_flat_map.cpp
View file @
f4c5842b
...
@@ -171,11 +171,9 @@ CAF_TEST(exceptions) {
...
@@ -171,11 +171,9 @@ CAF_TEST(exceptions) {
try
{
try
{
auto
x
=
xs
.
at
(
10
);
auto
x
=
xs
.
at
(
10
);
CAF_FAIL
(
"got an unexpected value: "
<<
x
);
CAF_FAIL
(
"got an unexpected value: "
<<
x
);
}
}
catch
(
std
::
out_of_range
&
)
{
catch
(
std
::
out_of_range
&
)
{
CAF_MESSAGE
(
"got expected out_of_range exception"
);
CAF_MESSAGE
(
"got expected out_of_range exception"
);
}
}
catch
(...)
{
catch
(...)
{
CAF_FAIL
(
"got an expected exception"
);
CAF_FAIL
(
"got an expected exception"
);
}
}
}
}
...
...
libcaf_core/test/intrusive/drr_cached_queue.cpp
View file @
f4c5842b
...
@@ -169,7 +169,7 @@ CAF_TEST(take_front) {
...
@@ -169,7 +169,7 @@ CAF_TEST(take_front) {
}
}
CAF_TEST
(
alternating_consumer
)
{
CAF_TEST
(
alternating_consumer
)
{
using
fun_type
=
std
::
function
<
task_result
(
inode
&
)
>
;
using
fun_type
=
std
::
function
<
task_result
(
inode
&
)
>
;
fun_type
f
;
fun_type
f
;
fun_type
g
;
fun_type
g
;
fun_type
*
selected
=
&
f
;
fun_type
*
selected
=
&
f
;
...
@@ -191,9 +191,7 @@ CAF_TEST(alternating_consumer) {
...
@@ -191,9 +191,7 @@ CAF_TEST(alternating_consumer) {
return
task_result
::
resume
;
return
task_result
::
resume
;
};
};
/// Define a function object that alternates between f and g.
/// Define a function object that alternates between f and g.
auto
h
=
[
&
](
inode
&
x
)
{
auto
h
=
[
&
](
inode
&
x
)
{
return
(
*
selected
)(
x
);
};
return
(
*
selected
)(
x
);
};
// Fill and consume queue, h leaves 9 in the cache since it reads (odd, even)
// Fill and consume queue, h leaves 9 in the cache since it reads (odd, even)
// sequences and no odd value to read after 7 is available.
// sequences and no odd value to read after 7 is available.
fill
(
queue
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
fill
(
queue
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
...
@@ -236,5 +234,4 @@ CAF_TEST(to_string) {
...
@@ -236,5 +234,4 @@ CAF_TEST(to_string) {
CAF_CHECK_EQUAL
(
deep_to_string
(
queue
),
"[1, 2, 3, 4]"
);
CAF_CHECK_EQUAL
(
deep_to_string
(
queue
),
"[1, 2, 3, 4]"
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/intrusive/fifo_inbox.cpp
View file @
f4c5842b
...
@@ -132,9 +132,7 @@ CAF_TEST(unblock) {
...
@@ -132,9 +132,7 @@ CAF_TEST(unblock) {
CAF_TEST
(
await
)
{
CAF_TEST
(
await
)
{
std
::
mutex
mx
;
std
::
mutex
mx
;
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
thread
t
{[
&
]
{
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_back
(
mx
,
cv
,
1
);
}};
inbox
.
synchronized_emplace_back
(
mx
,
cv
,
1
);
}};
inbox
.
synchronized_await
(
mx
,
cv
);
inbox
.
synchronized_await
(
mx
,
cv
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"1"
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"1"
);
t
.
join
();
t
.
join
();
...
@@ -152,9 +150,7 @@ CAF_TEST(timed_await) {
...
@@ -152,9 +150,7 @@ CAF_TEST(timed_await) {
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_CHECK_EQUAL
(
fetch
(),
"1"
);
CAF_CHECK_EQUAL
(
fetch
(),
"1"
);
tout
+=
std
::
chrono
::
hours
(
1000
);
tout
+=
std
::
chrono
::
hours
(
1000
);
std
::
thread
t
{[
&
]
{
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_back
(
mx
,
cv
,
2
);
}};
inbox
.
synchronized_emplace_back
(
mx
,
cv
,
2
);
}};
res
=
inbox
.
synchronized_await
(
mx
,
cv
,
tout
);
res
=
inbox
.
synchronized_await
(
mx
,
cv
,
tout
);
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"2"
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"2"
);
...
...
libcaf_core/test/intrusive/lifo_inbox.cpp
View file @
f4c5842b
...
@@ -125,9 +125,7 @@ CAF_TEST(unblock) {
...
@@ -125,9 +125,7 @@ CAF_TEST(unblock) {
CAF_TEST
(
await
)
{
CAF_TEST
(
await
)
{
std
::
mutex
mx
;
std
::
mutex
mx
;
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
thread
t
{[
&
]
{
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_front
(
mx
,
cv
,
1
);
}};
inbox
.
synchronized_emplace_front
(
mx
,
cv
,
1
);
}};
inbox
.
synchronized_await
(
mx
,
cv
);
inbox
.
synchronized_await
(
mx
,
cv
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"1"
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"1"
);
t
.
join
();
t
.
join
();
...
@@ -145,9 +143,7 @@ CAF_TEST(timed_await) {
...
@@ -145,9 +143,7 @@ CAF_TEST(timed_await) {
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_CHECK_EQUAL
(
fetch
(),
"1"
);
CAF_CHECK_EQUAL
(
fetch
(),
"1"
);
tout
+=
std
::
chrono
::
hours
(
1000
);
tout
+=
std
::
chrono
::
hours
(
1000
);
std
::
thread
t
{[
&
]
{
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_front
(
mx
,
cv
,
2
);
}};
inbox
.
synchronized_emplace_front
(
mx
,
cv
,
2
);
}};
res
=
inbox
.
synchronized_await
(
mx
,
cv
,
tout
);
res
=
inbox
.
synchronized_await
(
mx
,
cv
,
tout
);
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"2"
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"2"
);
...
...
libcaf_core/test/intrusive/wdrr_dynamic_multiplexed_queue.cpp
View file @
f4c5842b
...
@@ -35,7 +35,7 @@ namespace {
...
@@ -35,7 +35,7 @@ namespace {
struct
inode
:
singly_linked
<
inode
>
{
struct
inode
:
singly_linked
<
inode
>
{
int
value
;
int
value
;
inode
(
int
x
=
0
)
:
value
(
x
)
{
inode
(
int
x
=
0
)
noexcept
:
value
(
x
)
{
// nop
// nop
}
}
};
};
...
@@ -55,7 +55,7 @@ struct nested_inode_policy {
...
@@ -55,7 +55,7 @@ struct nested_inode_policy {
using
unique_pointer
=
std
::
unique_ptr
<
mapped_type
,
deleter_type
>
;
using
unique_pointer
=
std
::
unique_ptr
<
mapped_type
,
deleter_type
>
;
static
inline
task_size_type
task_size
(
const
mapped_type
&
)
{
static
task_size_type
task_size
(
const
mapped_type
&
)
noexcept
{
return
1
;
return
1
;
}
}
...
@@ -65,8 +65,8 @@ struct nested_inode_policy {
...
@@ -65,8 +65,8 @@ struct nested_inode_policy {
// nop
// nop
}
}
nested_inode_policy
(
nested_inode_policy
&&
)
=
default
;
nested_inode_policy
(
nested_inode_policy
&&
)
noexcept
=
default
;
nested_inode_policy
&
operator
=
(
nested_inode_policy
&&
)
=
default
;
nested_inode_policy
&
operator
=
(
nested_inode_policy
&&
)
noexcept
=
default
;
};
};
struct
inode_policy
{
struct
inode_policy
{
...
@@ -86,15 +86,15 @@ struct inode_policy {
...
@@ -86,15 +86,15 @@ struct inode_policy {
using
queue_map_type
=
std
::
map
<
key_type
,
queue_type
>
;
using
queue_map_type
=
std
::
map
<
key_type
,
queue_type
>
;
static
inline
key_type
id_of
(
const
inode
&
x
)
{
static
key_type
id_of
(
const
inode
&
x
)
noexcept
{
return
x
.
value
%
3
;
return
x
.
value
%
3
;
}
}
static
inline
bool
enabled
(
const
queue_type
&
)
{
static
bool
enabled
(
const
queue_type
&
)
noexcept
{
return
true
;
return
true
;
}
}
deficit_type
quantum
(
const
queue_type
&
q
,
deficit_type
x
)
{
deficit_type
quantum
(
const
queue_type
&
q
,
deficit_type
x
)
noexcept
{
return
enable_priorities
&&
*
q
.
policy
().
queue_id
==
0
?
2
*
x
:
x
;
return
enable_priorities
&&
*
q
.
policy
().
queue_id
==
0
?
2
*
x
:
x
;
}
}
...
@@ -210,5 +210,4 @@ CAF_TEST(to_string) {
...
@@ -210,5 +210,4 @@ CAF_TEST(to_string) {
CAF_CHECK_EQUAL
(
deep_to_string
(
queue
),
"[3, 1, 4, 2]"
);
CAF_CHECK_EQUAL
(
deep_to_string
(
queue
),
"[3, 1, 4, 2]"
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/intrusive/wdrr_fixed_multiplexed_queue.cpp
View file @
f4c5842b
...
@@ -86,10 +86,8 @@ public:
...
@@ -86,10 +86,8 @@ public:
using
nested_queue_type
=
drr_queue
<
inode_policy
>
;
using
nested_queue_type
=
drr_queue
<
inode_policy
>
;
using
queue_type
=
wdrr_fixed_multiplexed_queue
<
inode_policy
,
using
queue_type
=
wdrr_fixed_multiplexed_queue
<
high_prio_queue
,
inode_policy
,
high_prio_queue
,
nested_queue_type
,
nested_queue_type
>
;
nested_queue_type
,
nested_queue_type
>
;
struct
fetch_helper
{
struct
fetch_helper
{
std
::
string
result
;
std
::
string
result
;
...
...
libcaf_core/test/policy/categorized.cpp
View file @
f4c5842b
...
@@ -59,7 +59,7 @@ struct mailbox_policy {
...
@@ -59,7 +59,7 @@ struct mailbox_policy {
using
mailbox_type
=
intrusive
::
fifo_inbox
<
mailbox_policy
>
;
using
mailbox_type
=
intrusive
::
fifo_inbox
<
mailbox_policy
>
;
struct
fixture
{};
struct
fixture
{};
struct
consumer
{
struct
consumer
{
std
::
vector
<
int
>
ints
;
std
::
vector
<
int
>
ints
;
...
@@ -75,7 +75,7 @@ struct consumer {
...
@@ -75,7 +75,7 @@ struct consumer {
template
<
class
Key
,
class
Queue
,
class
...
Ts
>
template
<
class
Key
,
class
Queue
,
class
...
Ts
>
intrusive
::
task_result
operator
()(
const
Key
&
,
const
Queue
&
,
const
Ts
&
...)
{
intrusive
::
task_result
operator
()(
const
Key
&
,
const
Queue
&
,
const
Ts
&
...)
{
CAF_FAIL
(
"unexepected message type"
);
// << typeid(Ts).name());
CAF_FAIL
(
"unexepected message type"
);
// << typeid(Ts).name());
return
intrusive
::
task_result
::
resume
;
return
intrusive
::
task_result
::
resume
;
}
}
};
};
...
...
libcaf_io/src/detail/socket_guard.cpp
View file @
f4c5842b
...
@@ -52,4 +52,4 @@ void socket_guard::close() {
...
@@ -52,4 +52,4 @@ void socket_guard::close() {
}
}
}
// namespace detail
}
// namespace detail
}
// namespace
detail
}
// namespace
caf
libcaf_io/src/io/abstract_broker.cpp
View file @
f4c5842b
...
@@ -16,11 +16,11 @@
...
@@ -16,11 +16,11 @@
* http://www.boost.org/LICENSE_1_0.txt. *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
******************************************************************************/
#include "caf/
none
.hpp"
#include "caf/
actor_system
.hpp"
#include "caf/config.hpp"
#include "caf/config.hpp"
#include "caf/logger.hpp"
#include "caf/logger.hpp"
#include "caf/actor_system.hpp"
#include "caf/make_counted.hpp"
#include "caf/make_counted.hpp"
#include "caf/none.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/io/broker.hpp"
#include "caf/io/broker.hpp"
...
@@ -34,8 +34,8 @@
...
@@ -34,8 +34,8 @@
namespace
caf
{
namespace
caf
{
namespace
io
{
namespace
io
{
void
abstract_broker
::
enqueue
(
strong_actor_ptr
src
,
message_id
mid
,
void
abstract_broker
::
enqueue
(
strong_actor_ptr
src
,
message_id
mid
,
message
msg
,
message
msg
,
execution_unit
*
)
{
execution_unit
*
)
{
enqueue
(
make_mailbox_element
(
std
::
move
(
src
),
mid
,
{},
std
::
move
(
msg
)),
enqueue
(
make_mailbox_element
(
std
::
move
(
src
),
mid
,
{},
std
::
move
(
msg
)),
&
backend
());
&
backend
());
}
}
...
@@ -137,8 +137,7 @@ void abstract_broker::enqueue_datagram(datagram_handle hdl,
...
@@ -137,8 +137,7 @@ void abstract_broker::enqueue_datagram(datagram_handle hdl,
x
->
enqueue_datagram
(
hdl
,
std
::
move
(
buf
));
x
->
enqueue_datagram
(
hdl
,
std
::
move
(
buf
));
}
}
void
abstract_broker
::
write
(
datagram_handle
hdl
,
size_t
bs
,
void
abstract_broker
::
write
(
datagram_handle
hdl
,
size_t
bs
,
const
void
*
buf
)
{
const
void
*
buf
)
{
auto
&
out
=
wr_buf
(
hdl
);
auto
&
out
=
wr_buf
(
hdl
);
auto
first
=
reinterpret_cast
<
const
char
*>
(
buf
);
auto
first
=
reinterpret_cast
<
const
char
*>
(
buf
);
auto
last
=
first
+
bs
;
auto
last
=
first
+
bs
;
...
@@ -225,7 +224,8 @@ void abstract_broker::add_hdl_for_datagram_servant(datagram_servant_ptr ptr,
...
@@ -225,7 +224,8 @@ void abstract_broker::add_hdl_for_datagram_servant(datagram_servant_ptr ptr,
get_map
(
hdl
).
emplace
(
hdl
,
std
::
move
(
ptr
));
get_map
(
hdl
).
emplace
(
hdl
,
std
::
move
(
ptr
));
}
}
datagram_handle
abstract_broker
::
add_datagram_servant
(
network
::
native_socket
fd
)
{
datagram_handle
abstract_broker
::
add_datagram_servant
(
network
::
native_socket
fd
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
));
CAF_LOG_TRACE
(
CAF_ARG
(
fd
));
auto
ptr
=
backend
().
new_datagram_servant
(
fd
);
auto
ptr
=
backend
().
new_datagram_servant
(
fd
);
auto
hdl
=
ptr
->
hdl
();
auto
hdl
=
ptr
->
hdl
();
...
@@ -233,9 +233,8 @@ datagram_handle abstract_broker::add_datagram_servant(network::native_socket fd)
...
@@ -233,9 +233,8 @@ datagram_handle abstract_broker::add_datagram_servant(network::native_socket fd)
return
hdl
;
return
hdl
;
}
}
datagram_handle
datagram_handle
abstract_broker
::
add_datagram_servant_for_endpoint
(
abstract_broker
::
add_datagram_servant_for_endpoint
(
network
::
native_socket
fd
,
network
::
native_socket
fd
,
const
network
::
ip_endpoint
&
ep
)
{
const
network
::
ip_endpoint
&
ep
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
));
CAF_LOG_TRACE
(
CAF_ARG
(
fd
));
auto
ptr
=
backend
().
new_datagram_servant_for_endpoint
(
fd
,
ep
);
auto
ptr
=
backend
().
new_datagram_servant_for_endpoint
(
fd
,
ep
);
auto
hdl
=
ptr
->
hdl
();
auto
hdl
=
ptr
->
hdl
();
...
@@ -356,8 +355,8 @@ resumable::subtype_t abstract_broker::subtype() const {
...
@@ -356,8 +355,8 @@ resumable::subtype_t abstract_broker::subtype() const {
return
io_actor
;
return
io_actor
;
}
}
resumable
::
resume_result
resumable
::
resume_result
abstract_broker
::
resume
(
execution_unit
*
ctx
,
abstract_broker
::
resume
(
execution_unit
*
ctx
,
size_t
mt
)
{
size_t
mt
)
{
CAF_ASSERT
(
ctx
!=
nullptr
);
CAF_ASSERT
(
ctx
!=
nullptr
);
CAF_ASSERT
(
ctx
==
&
backend
());
CAF_ASSERT
(
ctx
==
&
backend
());
return
scheduled_actor
::
resume
(
ctx
,
mt
);
return
scheduled_actor
::
resume
(
ctx
,
mt
);
...
...
libcaf_io/src/io/basp/header.cpp
View file @
f4c5842b
...
@@ -33,22 +33,16 @@ std::string to_bin(uint8_t x) {
...
@@ -33,22 +33,16 @@ std::string to_bin(uint8_t x) {
return
res
;
return
res
;
}
}
std
::
string
to_string
(
const
header
&
hdr
)
{
std
::
string
to_string
(
const
header
&
hdr
)
{
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
oss
<<
"{"
oss
<<
"{"
<<
to_string
(
hdr
.
operation
)
<<
", "
<<
to_bin
(
hdr
.
flags
)
<<
", "
<<
to_string
(
hdr
.
operation
)
<<
", "
<<
hdr
.
payload_len
<<
", "
<<
hdr
.
operation_data
<<
", "
<<
to_bin
(
hdr
.
flags
)
<<
", "
<<
hdr
.
source_actor
<<
", "
<<
hdr
.
dest_actor
<<
"}"
;
<<
hdr
.
payload_len
<<
", "
<<
hdr
.
operation_data
<<
", "
<<
hdr
.
source_actor
<<
", "
<<
hdr
.
dest_actor
<<
"}"
;
return
oss
.
str
();
return
oss
.
str
();
}
}
bool
operator
==
(
const
header
&
lhs
,
const
header
&
rhs
)
{
bool
operator
==
(
const
header
&
lhs
,
const
header
&
rhs
)
{
return
lhs
.
operation
==
rhs
.
operation
return
lhs
.
operation
==
rhs
.
operation
&&
lhs
.
flags
==
rhs
.
flags
&&
lhs
.
flags
==
rhs
.
flags
&&
lhs
.
payload_len
==
rhs
.
payload_len
&&
lhs
.
payload_len
==
rhs
.
payload_len
&&
lhs
.
operation_data
==
rhs
.
operation_data
&&
lhs
.
operation_data
==
rhs
.
operation_data
&&
lhs
.
source_actor
==
rhs
.
source_actor
&&
lhs
.
source_actor
==
rhs
.
source_actor
...
...
libcaf_io/src/io/basp/instance.cpp
View file @
f4c5842b
...
@@ -42,9 +42,7 @@ instance::callee::~callee() {
...
@@ -42,9 +42,7 @@ instance::callee::~callee() {
}
}
instance
::
instance
(
abstract_broker
*
parent
,
callee
&
lstnr
)
instance
::
instance
(
abstract_broker
*
parent
,
callee
&
lstnr
)
:
tbl_
(
parent
),
:
tbl_
(
parent
),
this_node_
(
parent
->
system
().
node
()),
callee_
(
lstnr
)
{
this_node_
(
parent
->
system
().
node
()),
callee_
(
lstnr
)
{
CAF_ASSERT
(
this_node_
!=
none
);
CAF_ASSERT
(
this_node_
!=
none
);
auto
workers
=
get_or
(
config
(),
"middleman.workers"
,
auto
workers
=
get_or
(
config
(),
"middleman.workers"
,
defaults
::
middleman
::
workers
);
defaults
::
middleman
::
workers
);
...
@@ -52,9 +50,8 @@ instance::instance(abstract_broker* parent, callee& lstnr)
...
@@ -52,9 +50,8 @@ instance::instance(abstract_broker* parent, callee& lstnr)
hub_
.
add_new_worker
(
queue_
,
proxies
());
hub_
.
add_new_worker
(
queue_
,
proxies
());
}
}
connection_state
instance
::
handle
(
execution_unit
*
ctx
,
connection_state
instance
::
handle
(
execution_unit
*
ctx
,
new_data_msg
&
dm
,
new_data_msg
&
dm
,
header
&
hdr
,
header
&
hdr
,
bool
is_payload
)
{
bool
is_payload
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
dm
)
<<
CAF_ARG
(
is_payload
));
CAF_LOG_TRACE
(
CAF_ARG
(
dm
)
<<
CAF_ARG
(
is_payload
));
// function object providing cleanup code on errors
// function object providing cleanup code on errors
auto
err
=
[
&
]()
->
connection_state
{
auto
err
=
[
&
]()
->
connection_state
{
...
@@ -90,7 +87,7 @@ connection_state instance::handle(execution_unit* ctx,
...
@@ -90,7 +87,7 @@ connection_state instance::handle(execution_unit* ctx,
void
instance
::
handle_heartbeat
(
execution_unit
*
ctx
)
{
void
instance
::
handle_heartbeat
(
execution_unit
*
ctx
)
{
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
for
(
auto
&
kvp
:
tbl_
.
direct_by_hdl_
)
{
for
(
auto
&
kvp
:
tbl_
.
direct_by_hdl_
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
kvp
.
first
)
<<
CAF_ARG
(
kvp
.
second
));
CAF_LOG_TRACE
(
CAF_ARG
(
kvp
.
first
)
<<
CAF_ARG
(
kvp
.
second
));
write_heartbeat
(
ctx
,
callee_
.
get_buffer
(
kvp
.
first
));
write_heartbeat
(
ctx
,
callee_
.
get_buffer
(
kvp
.
first
));
callee_
.
flush
(
kvp
.
first
);
callee_
.
flush
(
kvp
.
first
);
...
@@ -116,8 +113,8 @@ void instance::write(execution_unit* ctx, const routing_table::route& r,
...
@@ -116,8 +113,8 @@ void instance::write(execution_unit* ctx, const routing_table::route& r,
void
instance
::
add_published_actor
(
uint16_t
port
,
void
instance
::
add_published_actor
(
uint16_t
port
,
strong_actor_ptr
published_actor
,
strong_actor_ptr
published_actor
,
std
::
set
<
std
::
string
>
published_interface
)
{
std
::
set
<
std
::
string
>
published_interface
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
published_actor
)
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
published_interface
));
<<
CAF_ARG
(
published_
actor
)
<<
CAF_ARG
(
published_
interface
));
using
std
::
swap
;
using
std
::
swap
;
auto
&
entry
=
published_actors_
[
port
];
auto
&
entry
=
published_actors_
[
port
];
swap
(
entry
.
first
,
published_actor
);
swap
(
entry
.
first
,
published_actor
);
...
@@ -136,8 +133,7 @@ size_t instance::remove_published_actor(uint16_t port,
...
@@ -136,8 +133,7 @@ size_t instance::remove_published_actor(uint16_t port,
return
1
;
return
1
;
}
}
size_t
instance
::
remove_published_actor
(
const
actor_addr
&
whom
,
size_t
instance
::
remove_published_actor
(
const
actor_addr
&
whom
,
uint16_t
port
,
uint16_t
port
,
removed_published_actor
*
cb
)
{
removed_published_actor
*
cb
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
whom
)
<<
CAF_ARG
(
port
));
CAF_LOG_TRACE
(
CAF_ARG
(
whom
)
<<
CAF_ARG
(
port
));
size_t
result
=
0
;
size_t
result
=
0
;
...
@@ -169,23 +165,30 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
...
@@ -169,23 +165,30 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
const
std
::
vector
<
strong_actor_ptr
>&
forwarding_stack
,
const
std
::
vector
<
strong_actor_ptr
>&
forwarding_stack
,
const
node_id
&
dest_node
,
uint64_t
dest_actor
,
const
node_id
&
dest_node
,
uint64_t
dest_actor
,
uint8_t
flags
,
message_id
mid
,
const
message
&
msg
)
{
uint8_t
flags
,
message_id
mid
,
const
message
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
sender
)
<<
CAF_ARG
(
dest_node
)
<<
CAF_ARG
(
mid
)
CAF_LOG_TRACE
(
CAF_ARG
(
sender
)
<<
CAF_ARG
(
msg
));
<<
CAF_ARG
(
dest_node
)
<<
CAF_ARG
(
mid
)
<<
CAF_ARG
(
msg
));
CAF_ASSERT
(
dest_node
&&
this_node_
!=
dest_node
);
CAF_ASSERT
(
dest_node
&&
this_node_
!=
dest_node
);
auto
path
=
lookup
(
dest_node
);
auto
path
=
lookup
(
dest_node
);
if
(
!
path
)
if
(
!
path
)
return
false
;
return
false
;
auto
&
source_node
=
sender
?
sender
->
node
()
:
this_node_
;
auto
&
source_node
=
sender
?
sender
->
node
()
:
this_node_
;
if
(
dest_node
==
path
->
next_hop
&&
source_node
==
this_node_
)
{
if
(
dest_node
==
path
->
next_hop
&&
source_node
==
this_node_
)
{
header
hdr
{
message_type
::
direct_message
,
flags
,
0
,
mid
.
integer_value
(),
header
hdr
{
message_type
::
direct_message
,
sender
?
sender
->
id
()
:
invalid_actor_id
,
dest_actor
};
flags
,
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
0
,
return
sink
(
forwarding_stack
,
msg
);
mid
.
integer_value
(),
});
sender
?
sender
->
id
()
:
invalid_actor_id
,
dest_actor
};
auto
writer
=
make_callback
(
[
&
](
serializer
&
sink
)
->
error
{
return
sink
(
forwarding_stack
,
msg
);
});
write
(
ctx
,
callee_
.
get_buffer
(
path
->
hdl
),
hdr
,
&
writer
);
write
(
ctx
,
callee_
.
get_buffer
(
path
->
hdl
),
hdr
,
&
writer
);
}
else
{
}
else
{
header
hdr
{
message_type
::
routed_message
,
flags
,
0
,
mid
.
integer_value
(),
header
hdr
{
message_type
::
routed_message
,
sender
?
sender
->
id
()
:
invalid_actor_id
,
dest_actor
};
flags
,
0
,
mid
.
integer_value
(),
sender
?
sender
->
id
()
:
invalid_actor_id
,
dest_actor
};
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
return
sink
(
source_node
,
dest_node
,
forwarding_stack
,
msg
);
return
sink
(
source_node
,
dest_node
,
forwarding_stack
,
msg
);
});
});
...
@@ -195,8 +198,8 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
...
@@ -195,8 +198,8 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
return
true
;
return
true
;
}
}
void
instance
::
write
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
void
instance
::
write
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
header
&
hdr
,
header
&
hdr
,
payload_writer
*
pw
)
{
payload_writer
*
pw
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdr
));
CAF_LOG_TRACE
(
CAF_ARG
(
hdr
));
binary_serializer
sink
{
ctx
,
buf
};
binary_serializer
sink
{
ctx
,
buf
};
if
(
pw
!=
nullptr
)
{
if
(
pw
!=
nullptr
)
{
...
@@ -235,26 +238,32 @@ void instance::write_server_handshake(execution_unit* ctx, buffer_type& out_buf,
...
@@ -235,26 +238,32 @@ void instance::write_server_handshake(execution_unit* ctx, buffer_type& out_buf,
}
}
return
sink
(
this_node_
,
app_ids
,
aid
,
iface
);
return
sink
(
this_node_
,
app_ids
,
aid
,
iface
);
});
});
header
hdr
{
message_type
::
server_handshake
,
0
,
0
,
version
,
header
hdr
{
message_type
::
server_handshake
,
invalid_actor_id
,
invalid_actor_id
};
0
,
0
,
version
,
invalid_actor_id
,
invalid_actor_id
};
write
(
ctx
,
out_buf
,
hdr
,
&
writer
);
write
(
ctx
,
out_buf
,
hdr
,
&
writer
);
}
}
void
instance
::
write_client_handshake
(
execution_unit
*
ctx
,
buffer_type
&
buf
)
{
void
instance
::
write_client_handshake
(
execution_unit
*
ctx
,
buffer_type
&
buf
)
{
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
auto
writer
=
make_callback
(
return
sink
(
this_node_
);
[
&
](
serializer
&
sink
)
->
error
{
return
sink
(
this_node_
);
});
});
header
hdr
{
message_type
::
client_handshake
,
header
hdr
{
message_type
::
client_handshake
,
0
,
0
,
0
,
0
,
invalid_actor_id
,
invalid_actor_id
};
0
,
0
,
invalid_actor_id
,
invalid_actor_id
};
write
(
ctx
,
buf
,
hdr
,
&
writer
);
write
(
ctx
,
buf
,
hdr
,
&
writer
);
}
}
void
instance
::
write_monitor_message
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
void
instance
::
write_monitor_message
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
const
node_id
&
dest_node
,
actor_id
aid
)
{
const
node_id
&
dest_node
,
actor_id
aid
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
dest_node
)
<<
CAF_ARG
(
aid
));
CAF_LOG_TRACE
(
CAF_ARG
(
dest_node
)
<<
CAF_ARG
(
aid
));
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
auto
writer
=
make_callback
(
return
sink
(
this_node_
,
dest_node
);
[
&
](
serializer
&
sink
)
->
error
{
return
sink
(
this_node_
,
dest_node
);
});
});
header
hdr
{
message_type
::
monitor_message
,
0
,
0
,
0
,
invalid_actor_id
,
aid
};
header
hdr
{
message_type
::
monitor_message
,
0
,
0
,
0
,
invalid_actor_id
,
aid
};
write
(
ctx
,
buf
,
hdr
,
&
writer
);
write
(
ctx
,
buf
,
hdr
,
&
writer
);
}
}
...
@@ -322,8 +331,8 @@ bool instance::handle(execution_unit* ctx, connection_handle hdl, header& hdr,
...
@@ -322,8 +331,8 @@ bool instance::handle(execution_unit* ctx, connection_handle hdl, header& hdr,
}
}
// Close this connection if we already have a direct connection.
// Close this connection if we already have a direct connection.
if
(
tbl_
.
lookup_direct
(
source_node
))
{
if
(
tbl_
.
lookup_direct
(
source_node
))
{
CAF_LOG_DEBUG
(
"close redundant direct connection:"
CAF_LOG_DEBUG
(
<<
CAF_ARG
(
source_node
));
"close redundant direct connection:"
<<
CAF_ARG
(
source_node
));
callee_
.
finalize_handshake
(
source_node
,
aid
,
sigs
);
callee_
.
finalize_handshake
(
source_node
,
aid
,
sigs
);
return
false
;
return
false
;
}
}
...
@@ -354,8 +363,8 @@ bool instance::handle(execution_unit* ctx, connection_handle hdl, header& hdr,
...
@@ -354,8 +363,8 @@ bool instance::handle(execution_unit* ctx, connection_handle hdl, header& hdr,
}
}
// Drop repeated handshakes.
// Drop repeated handshakes.
if
(
tbl_
.
lookup_direct
(
source_node
))
{
if
(
tbl_
.
lookup_direct
(
source_node
))
{
CAF_LOG_DEBUG
(
"received repeated client handshake:"
CAF_LOG_DEBUG
(
<<
CAF_ARG
(
source_node
));
"received repeated client handshake:"
<<
CAF_ARG
(
source_node
));
break
;
break
;
}
}
// Add direct route to this node and remove any indirect entry.
// Add direct route to this node and remove any indirect entry.
...
...
libcaf_io/src/io/basp/message_type.cpp
View file @
f4c5842b
...
@@ -27,13 +27,8 @@ namespace basp {
...
@@ -27,13 +27,8 @@ namespace basp {
namespace
{
namespace
{
const
char
*
message_type_strings
[]
=
{
const
char
*
message_type_strings
[]
=
{
"server_handshake"
,
"server_handshake"
,
"client_handshake"
,
"direct_message"
,
"routed_message"
,
"client_handshake"
,
"proxy_creation"
,
"proxy_destruction"
,
"heartbeat"
,
"direct_message"
,
"routed_message"
,
"proxy_creation"
,
"proxy_destruction"
,
"heartbeat"
};
};
}
// namespace
}
// namespace
...
...
libcaf_io/src/io/basp/routing_table.cpp
View file @
f4c5842b
...
@@ -24,8 +24,7 @@ namespace caf {
...
@@ -24,8 +24,7 @@ namespace caf {
namespace
io
{
namespace
io
{
namespace
basp
{
namespace
basp
{
routing_table
::
routing_table
(
abstract_broker
*
parent
)
routing_table
::
routing_table
(
abstract_broker
*
parent
)
:
parent_
(
parent
)
{
:
parent_
(
parent
)
{
// nop
// nop
}
}
...
...
libcaf_io/src/io/broker.cpp
View file @
f4c5842b
...
@@ -16,12 +16,12 @@
...
@@ -16,12 +16,12 @@
* http://www.boost.org/LICENSE_1_0.txt. *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
******************************************************************************/
#include "caf/none.hpp"
#include "caf/config.hpp"
#include "caf/config.hpp"
#include "caf/make_counted.hpp"
#include "caf/make_counted.hpp"
#include "caf/none.hpp"
#include "caf/logger.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/logger.hpp"
#include "caf/io/broker.hpp"
#include "caf/io/broker.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/middleman.hpp"
...
@@ -49,7 +49,6 @@ broker::broker(actor_config& cfg) : super(cfg) {
...
@@ -49,7 +49,6 @@ broker::broker(actor_config& cfg) : super(cfg) {
// nop
// nop
}
}
behavior
broker
::
make_behavior
()
{
behavior
broker
::
make_behavior
()
{
behavior
res
;
behavior
res
;
if
(
initial_behavior_fac_
)
{
if
(
initial_behavior_fac_
)
{
...
...
libcaf_io/src/io/connection_helper.cpp
View file @
f4c5842b
...
@@ -49,8 +49,7 @@ behavior connection_helper(stateful_actor<connection_helper_state>* self,
...
@@ -49,8 +49,7 @@ behavior connection_helper(stateful_actor<connection_helper_state>* self,
CAF_LOG_DEBUG
(
"received requested config:"
<<
CAF_ARG
(
msg
));
CAF_LOG_DEBUG
(
"received requested config:"
<<
CAF_ARG
(
msg
));
// whatever happens, we are done afterwards
// whatever happens, we are done afterwards
self
->
quit
();
self
->
quit
();
msg
.
apply
({
msg
.
apply
({[
&
](
uint16_t
port
,
network
::
address_listing
&
addresses
)
{
[
&
](
uint16_t
port
,
network
::
address_listing
&
addresses
)
{
if
(
item
==
"basp.default-connectivity-tcp"
)
{
if
(
item
==
"basp.default-connectivity-tcp"
)
{
auto
&
mx
=
self
->
system
().
middleman
().
backend
();
auto
&
mx
=
self
->
system
().
middleman
().
backend
();
for
(
auto
&
kvp
:
addresses
)
{
for
(
auto
&
kvp
:
addresses
)
{
...
@@ -70,18 +69,17 @@ behavior connection_helper(stateful_actor<connection_helper_state>* self,
...
@@ -70,18 +69,17 @@ behavior connection_helper(stateful_actor<connection_helper_state>* self,
CAF_LOG_INFO
(
"aborted direct connection attempt, unknown item: "
CAF_LOG_INFO
(
"aborted direct connection attempt, unknown item: "
<<
CAF_ARG
(
item
));
<<
CAF_ARG
(
item
));
}
}
}
}});
});
},
},
after
(
autoconnect_timeout
)
>>
[
=
]
{
after
(
autoconnect_timeout
)
>>
[
=
]
{
CAF_LOG_TRACE
(
CAF_ARG
(
""
));
CAF_LOG_TRACE
(
CAF_ARG
(
""
));
// nothing heard in about 10 minutes... just a call it a day, then
// nothing heard in about 10 minutes... just a call it a day, then
CAF_LOG_INFO
(
"aborted direct connection attempt after 10min"
);
CAF_LOG_INFO
(
"aborted direct connection attempt after 10min"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
self
->
quit
(
exit_reason
::
user_shutdown
);
}
},
};
};
}
}
}
// namespace io
}
// namespace io
}
// namespace caf
}
// namespace caf
libcaf_io/src/io/datagram_servant.cpp
View file @
f4c5842b
...
@@ -75,4 +75,3 @@ void datagram_servant::datagram_sent(execution_unit* ctx, datagram_handle hdl,
...
@@ -75,4 +75,3 @@ void datagram_servant::datagram_sent(execution_unit* ctx, datagram_handle hdl,
}
// namespace io
}
// namespace io
}
// namespace caf
}
// namespace caf
libcaf_io/src/io/middleman.cpp
View file @
f4c5842b
...
@@ -18,49 +18,49 @@
...
@@ -18,49 +18,49 @@
#include "caf/io/middleman.hpp"
#include "caf/io/middleman.hpp"
#include <tuple>
#include <cerrno>
#include <cerrno>
#include <memory>
#include <cstring>
#include <cstring>
#include <memory>
#include <sstream>
#include <sstream>
#include <stdexcept>
#include <stdexcept>
#include <tuple>
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/actor.hpp"
#include "caf/actor.hpp"
#include "caf/actor_proxy.hpp"
#include "caf/actor_registry.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/after.hpp"
#include "caf/after.hpp"
#include "caf/config.hpp"
#include "caf/config.hpp"
#include "caf/logger.hpp"
#include "caf/node_id.hpp"
#include "caf/defaults.hpp"
#include "caf/defaults.hpp"
#include "caf/actor_proxy.hpp"
#include "caf/make_counted.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/function_view.hpp"
#include "caf/actor_registry.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/function_view.hpp"
#include "caf/logger.hpp"
#include "caf/make_counted.hpp"
#include "caf/node_id.hpp"
#include "caf/raw_event_based_actor.hpp"
#include "caf/raw_event_based_actor.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/typed_event_based_actor.hpp"
#include "caf/typed_event_based_actor.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/test_multiplexer.hpp"
#include "caf/io/network/test_multiplexer.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/detail/get_mac_addresses.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/detail/ripemd_160.hpp"
#include "caf/detail/ripemd_160.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/detail/get_mac_addresses.hpp"
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
#
include <io
.h>
#
include <fcntl
.h>
#
include <fcntl
.h>
#
include <io
.h>
#endif // CAF_WINDOWS
#endif // CAF_WINDOWS
namespace
caf
{
namespace
caf
{
...
@@ -106,8 +106,8 @@ expected<strong_actor_ptr> middleman::remote_spawn_impl(const node_id& nid,
...
@@ -106,8 +106,8 @@ expected<strong_actor_ptr> middleman::remote_spawn_impl(const node_id& nid,
std
::
set
<
std
::
string
>
s
,
std
::
set
<
std
::
string
>
s
,
duration
timeout
)
{
duration
timeout
)
{
auto
f
=
make_function_view
(
actor_handle
(),
timeout
);
auto
f
=
make_function_view
(
actor_handle
(),
timeout
);
return
f
(
spawn_atom
::
value
,
nid
,
std
::
move
(
name
),
return
f
(
spawn_atom
::
value
,
nid
,
std
::
move
(
name
),
std
::
move
(
args
),
std
::
move
(
args
),
std
::
move
(
s
));
std
::
move
(
s
));
}
}
expected
<
uint16_t
>
middleman
::
open
(
uint16_t
port
,
const
char
*
in
,
bool
reuse
)
{
expected
<
uint16_t
>
middleman
::
open
(
uint16_t
port
,
const
char
*
in
,
bool
reuse
)
{
...
@@ -151,7 +151,7 @@ expected<uint16_t> middleman::publish_local_groups(uint16_t port,
...
@@ -151,7 +151,7 @@ expected<uint16_t> middleman::publish_local_groups(uint16_t port,
return
{
return
{
[
self
](
get_atom
,
const
std
::
string
&
name
)
{
[
self
](
get_atom
,
const
std
::
string
&
name
)
{
return
self
->
system
().
groups
().
get_local
(
name
);
return
self
->
system
().
groups
().
get_local
(
name
);
}
}
,
};
};
};
};
auto
gn
=
system
().
spawn
<
hidden
+
lazy_init
>
(
group_nameserver
);
auto
gn
=
system
().
spawn
<
hidden
+
lazy_init
>
(
group_nameserver
);
...
@@ -217,34 +217,25 @@ expected<group> middleman::remote_group(const std::string& group_identifier,
...
@@ -217,34 +217,25 @@ expected<group> middleman::remote_group(const std::string& group_identifier,
/// terminate the actor after both requests finish.
/// terminate the actor after both requests finish.
self
->
unbecome
();
self
->
unbecome
();
auto
rp
=
self
->
make_response_promise
();
auto
rp
=
self
->
make_response_promise
();
self
->
request
(
mm
,
infinite
,
connect_atom
::
value
,
host
,
port
)
.
then
(
self
->
request
(
mm
,
infinite
,
connect_atom
::
value
,
host
,
port
)
[
=
](
const
node_id
&
,
strong_actor_ptr
&
ptr
,
.
then
(
[
=
](
const
node_id
&
,
strong_actor_ptr
&
ptr
,
const
std
::
set
<
std
::
string
>&
)
mutable
{
const
std
::
set
<
std
::
string
>&
)
mutable
{
auto
hdl
=
actor_cast
<
actor
>
(
ptr
);
auto
hdl
=
actor_cast
<
actor
>
(
ptr
);
self
->
request
(
hdl
,
infinite
,
get_atom
::
value
,
group_identifier
)
self
->
request
(
hdl
,
infinite
,
get_atom
::
value
,
group_identifier
)
.
then
(
.
then
(
[
=
](
group
&
result
)
mutable
{
[
=
](
group
&
result
)
mutable
{
rp
.
deliver
(
std
::
move
(
result
));
});
rp
.
deliver
(
std
::
move
(
result
));
});
}
},
);
}
);
}
};
};
};
};
// Spawn the helper actor and wait for the result.
// Spawn the helper actor and wait for the result.
expected
<
group
>
result
{
sec
::
cannot_connect_to_node
};
expected
<
group
>
result
{
sec
::
cannot_connect_to_node
};
scoped_actor
self
{
system
(),
true
};
scoped_actor
self
{
system
(),
true
};
self
->
request
(
self
->
spawn
<
lazy_init
>
(
two_step_lookup
,
actor_handle
()),
self
infinite
,
get_atom
::
value
)
->
request
(
self
->
spawn
<
lazy_init
>
(
two_step_lookup
,
actor_handle
()),
infinite
,
.
receive
(
get_atom
::
value
)
[
&
](
group
&
grp
)
{
.
receive
([
&
](
group
&
grp
)
{
result
=
std
::
move
(
grp
);
},
result
=
std
::
move
(
grp
);
[
&
](
error
&
err
)
{
result
=
std
::
move
(
err
);
});
},
[
&
](
error
&
err
)
{
result
=
std
::
move
(
err
);
}
);
return
result
;
return
result
;
}
}
...
@@ -257,14 +248,11 @@ strong_actor_ptr middleman::remote_lookup(atom_value name, const node_id& nid) {
...
@@ -257,14 +248,11 @@ strong_actor_ptr middleman::remote_lookup(atom_value name, const node_id& nid) {
scoped_actor
self
{
system
(),
true
};
scoped_actor
self
{
system
(),
true
};
self
->
send
(
basp
,
forward_atom
::
value
,
nid
,
atom
(
"ConfigServ"
),
self
->
send
(
basp
,
forward_atom
::
value
,
nid
,
atom
(
"ConfigServ"
),
make_message
(
get_atom
::
value
,
name
));
make_message
(
get_atom
::
value
,
name
));
self
->
receive
(
self
->
receive
([
&
](
strong_actor_ptr
&
addr
)
{
result
=
std
::
move
(
addr
);
},
[
&
](
strong_actor_ptr
&
addr
)
{
after
(
std
::
chrono
::
minutes
(
5
))
>>
result
=
std
::
move
(
addr
);
[]
{
},
after
(
std
::
chrono
::
minutes
(
5
))
>>
[]
{
// nop
// nop
}
});
);
return
result
;
return
result
;
}
}
...
@@ -281,7 +269,7 @@ void middleman::start() {
...
@@ -281,7 +269,7 @@ void middleman::start() {
std
::
atomic
<
bool
>
init_done
{
false
};
std
::
atomic
<
bool
>
init_done
{
false
};
std
::
mutex
mtx
;
std
::
mutex
mtx
;
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
thread_
=
std
::
thread
{[
&
,
this
]
{
thread_
=
std
::
thread
{[
&
,
this
]
{
CAF_SET_LOGGER_SYS
(
&
system
());
CAF_SET_LOGGER_SYS
(
&
system
());
detail
::
set_thread_name
(
"caf.multiplexer"
);
detail
::
set_thread_name
(
"caf.multiplexer"
);
system
().
thread_started
();
system
().
thread_started
();
...
@@ -348,8 +336,7 @@ void middleman::init(actor_system_config& cfg) {
...
@@ -348,8 +336,7 @@ void middleman::init(actor_system_config& cfg) {
struct
remote_groups
:
group_module
{
struct
remote_groups
:
group_module
{
public:
public:
remote_groups
(
middleman
&
parent
)
remote_groups
(
middleman
&
parent
)
:
group_module
(
parent
.
system
(),
"remote"
),
:
group_module
(
parent
.
system
(),
"remote"
),
parent_
(
parent
)
{
parent_
(
parent
)
{
// nop
// nop
}
}
...
...
libcaf_io/src/io/middleman_actor.cpp
View file @
f4c5842b
...
@@ -18,13 +18,13 @@
...
@@ -18,13 +18,13 @@
#include "caf/io/middleman_actor.hpp"
#include "caf/io/middleman_actor.hpp"
#include <tuple>
#include <stdexcept>
#include <stdexcept>
#include <tuple>
#include <utility>
#include <utility>
#include "caf/actor_system.hpp"
#include "caf/actor_system.hpp"
#include "caf/spawn_options.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/spawn_options.hpp"
#include "caf/io/middleman_actor_impl.hpp"
#include "caf/io/middleman_actor_impl.hpp"
...
...
libcaf_io/src/io/middleman_actor_impl.cpp
View file @
f4c5842b
...
@@ -18,32 +18,31 @@
...
@@ -18,32 +18,31 @@
#include "caf/io/middleman_actor_impl.hpp"
#include "caf/io/middleman_actor_impl.hpp"
#include <tuple>
#include <stdexcept>
#include <stdexcept>
#include <tuple>
#include <utility>
#include <utility>
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/actor.hpp"
#include "caf/actor.hpp"
#include "caf/logger.hpp"
#include "caf/node_id.hpp"
#include "caf/actor_proxy.hpp"
#include "caf/actor_proxy.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/logger.hpp"
#include "caf/node_id.hpp"
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/typed_event_based_actor.hpp"
#include "caf/typed_event_based_actor.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/interfaces.hpp"
namespace
caf
{
namespace
caf
{
namespace
io
{
namespace
io
{
middleman_actor_impl
::
middleman_actor_impl
(
actor_config
&
cfg
,
middleman_actor_impl
::
middleman_actor_impl
(
actor_config
&
cfg
,
actor
default_broker
)
actor
default_broker
)
:
middleman_actor
::
base
(
cfg
),
:
middleman_actor
::
base
(
cfg
),
broker_
(
std
::
move
(
default_broker
))
{
broker_
(
std
::
move
(
default_broker
))
{
set_down_handler
([
=
](
down_msg
&
dm
)
{
set_down_handler
([
=
](
down_msg
&
dm
)
{
auto
i
=
cached_tcp_
.
begin
();
auto
i
=
cached_tcp_
.
begin
();
auto
e
=
cached_tcp_
.
end
();
auto
e
=
cached_tcp_
.
end
();
...
@@ -154,9 +153,9 @@ auto middleman_actor_impl::make_behavior() -> behavior_type {
...
@@ -154,9 +153,9 @@ auto middleman_actor_impl::make_behavior() -> behavior_type {
[
=
](
spawn_atom
atm
,
node_id
&
nid
,
std
::
string
&
str
,
message
&
msg
,
[
=
](
spawn_atom
atm
,
node_id
&
nid
,
std
::
string
&
str
,
message
&
msg
,
std
::
set
<
std
::
string
>&
ifs
)
->
delegated
<
strong_actor_ptr
>
{
std
::
set
<
std
::
string
>&
ifs
)
->
delegated
<
strong_actor_ptr
>
{
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
delegate
(
delegate
(
broker_
,
forward_atom
::
value
,
nid
,
atom
(
"SpawnServ"
),
broker_
,
forward_atom
::
value
,
nid
,
atom
(
"SpawnServ"
),
make_message
(
atm
,
std
::
move
(
str
),
std
::
move
(
msg
),
make_message
(
atm
,
std
::
move
(
str
),
std
::
move
(
msg
),
std
::
move
(
ifs
)));
std
::
move
(
ifs
)));
return
{};
return
{};
},
},
[
=
](
get_atom
atm
,
[
=
](
get_atom
atm
,
...
@@ -164,15 +163,15 @@ auto middleman_actor_impl::make_behavior() -> behavior_type {
...
@@ -164,15 +163,15 @@ auto middleman_actor_impl::make_behavior() -> behavior_type {
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
delegate
(
broker_
,
atm
,
std
::
move
(
nid
));
delegate
(
broker_
,
atm
,
std
::
move
(
nid
));
return
{};
return
{};
}
}
,
};
};
}
}
middleman_actor_impl
::
put_res
middleman_actor_impl
::
put_res
middleman_actor_impl
::
put
(
uint16_t
port
,
strong_actor_ptr
&
whom
,
mpi_set
&
sigs
,
middleman_actor_impl
::
put
(
uint16_t
port
,
strong_actor_ptr
&
whom
,
mpi_set
&
sigs
,
const
char
*
in
,
bool
reuse_addr
)
{
const
char
*
in
,
bool
reuse_addr
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
)
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
)
<<
CAF_ARG
(
in
)
<<
CAF_ARG
(
in
)
<<
CAF_ARG
(
reuse_addr
));
<<
CAF_ARG
(
reuse_addr
));
uint16_t
actual_port
;
uint16_t
actual_port
;
// treat empty strings like nullptr
// treat empty strings like nullptr
if
(
in
!=
nullptr
&&
in
[
0
]
==
'\0'
)
if
(
in
!=
nullptr
&&
in
[
0
]
==
'\0'
)
...
@@ -190,8 +189,8 @@ middleman_actor_impl::put(uint16_t port, strong_actor_ptr& whom, mpi_set& sigs,
...
@@ -190,8 +189,8 @@ middleman_actor_impl::put(uint16_t port, strong_actor_ptr& whom, mpi_set& sigs,
middleman_actor_impl
::
put_res
middleman_actor_impl
::
put_res
middleman_actor_impl
::
put_udp
(
uint16_t
port
,
strong_actor_ptr
&
whom
,
middleman_actor_impl
::
put_udp
(
uint16_t
port
,
strong_actor_ptr
&
whom
,
mpi_set
&
sigs
,
const
char
*
in
,
bool
reuse_addr
)
{
mpi_set
&
sigs
,
const
char
*
in
,
bool
reuse_addr
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
)
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
)
<<
CAF_ARG
(
in
)
<<
CAF_ARG
(
in
)
<<
CAF_ARG
(
reuse_addr
));
<<
CAF_ARG
(
reuse_addr
));
uint16_t
actual_port
;
uint16_t
actual_port
;
// treat empty strings like nullptr
// treat empty strings like nullptr
if
(
in
!=
nullptr
&&
in
[
0
]
==
'\0'
)
if
(
in
!=
nullptr
&&
in
[
0
]
==
'\0'
)
...
@@ -240,8 +239,8 @@ middleman_actor_impl::contact(const std::string& host, uint16_t port) {
...
@@ -240,8 +239,8 @@ middleman_actor_impl::contact(const std::string& host, uint16_t port) {
return
system
().
middleman
().
backend
().
new_remote_udp_endpoint
(
host
,
port
);
return
system
().
middleman
().
backend
().
new_remote_udp_endpoint
(
host
,
port
);
}
}
expected
<
doorman_ptr
>
expected
<
doorman_ptr
>
middleman_actor_impl
::
open
(
uint16_t
port
,
middleman_actor_impl
::
open
(
uint16_t
port
,
const
char
*
addr
,
bool
reuse
)
{
const
char
*
addr
,
bool
reuse
)
{
return
system
().
middleman
().
backend
().
new_tcp_doorman
(
port
,
addr
,
reuse
);
return
system
().
middleman
().
backend
().
new_tcp_doorman
(
port
,
addr
,
reuse
);
}
}
...
...
libcaf_io/src/io/network/acceptor.cpp
View file @
f4c5842b
...
@@ -25,8 +25,7 @@ namespace io {
...
@@ -25,8 +25,7 @@ namespace io {
namespace
network
{
namespace
network
{
acceptor
::
acceptor
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
acceptor
::
acceptor
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
:
event_handler
(
backend_ref
,
sockfd
),
:
event_handler
(
backend_ref
,
sockfd
),
sock_
(
invalid_native_socket
)
{
sock_
(
invalid_native_socket
)
{
// nop
// nop
}
}
...
...
libcaf_io/src/io/network/datagram_handler.cpp
View file @
f4c5842b
...
@@ -40,8 +40,8 @@ namespace network {
...
@@ -40,8 +40,8 @@ namespace network {
datagram_handler
::
datagram_handler
(
default_multiplexer
&
backend_ref
,
datagram_handler
::
datagram_handler
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
native_socket
sockfd
)
:
event_handler
(
backend_ref
,
sockfd
),
:
event_handler
(
backend_ref
,
sockfd
),
max_consecutive_reads_
(
max_consecutive_reads_
(
get_or
(
backend
().
system
().
config
(),
get_or
(
backend
().
system
().
config
(),
"middleman.max-consecutive-reads"
,
"middleman.max-consecutive-reads"
,
defaults
::
middleman
::
max_consecutive_reads
)),
defaults
::
middleman
::
max_consecutive_reads
)),
max_datagram_size_
(
receive_buffer_size
),
max_datagram_size_
(
receive_buffer_size
),
rd_buf_
(
receive_buffer_size
),
rd_buf_
(
receive_buffer_size
),
...
@@ -74,7 +74,8 @@ void datagram_handler::write(datagram_handle hdl, const void* buf,
...
@@ -74,7 +74,8 @@ void datagram_handler::write(datagram_handle hdl, const void* buf,
wr_offline_buf_
.
back
().
first
=
hdl
;
wr_offline_buf_
.
back
().
first
=
hdl
;
auto
cbuf
=
reinterpret_cast
<
const
char
*>
(
buf
);
auto
cbuf
=
reinterpret_cast
<
const
char
*>
(
buf
);
wr_offline_buf_
.
back
().
second
.
assign
(
cbuf
,
wr_offline_buf_
.
back
().
second
.
assign
(
cbuf
,
cbuf
+
static_cast
<
ptrdiff_t
>
(
num_bytes
));
cbuf
+
static_cast
<
ptrdiff_t
>
(
num_bytes
));
}
}
void
datagram_handler
::
flush
(
const
manager_ptr
&
mgr
)
{
void
datagram_handler
::
flush
(
const
manager_ptr
&
mgr
)
{
...
@@ -88,7 +89,8 @@ void datagram_handler::flush(const manager_ptr& mgr) {
...
@@ -88,7 +89,8 @@ void datagram_handler::flush(const manager_ptr& mgr) {
}
}
}
}
std
::
unordered_map
<
datagram_handle
,
ip_endpoint
>&
datagram_handler
::
endpoints
()
{
std
::
unordered_map
<
datagram_handle
,
ip_endpoint
>&
datagram_handler
::
endpoints
()
{
return
ep_by_hdl_
;
return
ep_by_hdl_
;
}
}
...
@@ -124,9 +126,13 @@ void datagram_handler::remove_endpoint(datagram_handle hdl) {
...
@@ -124,9 +126,13 @@ void datagram_handler::remove_endpoint(datagram_handle hdl) {
void
datagram_handler
::
removed_from_loop
(
operation
op
)
{
void
datagram_handler
::
removed_from_loop
(
operation
op
)
{
switch
(
op
)
{
switch
(
op
)
{
case
operation
:
:
read
:
reader_
.
reset
();
break
;
case
operation
:
:
read
:
case
operation
:
:
write
:
writer_
.
reset
();
break
;
reader_
.
reset
();
case
operation
:
:
propagate_error
:
;
// nop
break
;
case
operation
:
:
write
:
writer_
.
reset
();
break
;
case
operation
:
:
propagate_error
:
;
// nop
};
};
}
}
...
@@ -184,7 +190,8 @@ bool datagram_handler::handle_read_result(bool read_result) {
...
@@ -184,7 +190,8 @@ bool datagram_handler::handle_read_result(bool read_result) {
return
true
;
return
true
;
}
}
void
datagram_handler
::
handle_write_result
(
bool
write_result
,
datagram_handle
id
,
void
datagram_handler
::
handle_write_result
(
bool
write_result
,
datagram_handle
id
,
std
::
vector
<
char
>&
buf
,
size_t
wb
)
{
std
::
vector
<
char
>&
buf
,
size_t
wb
)
{
if
(
!
write_result
)
{
if
(
!
write_result
)
{
writer_
->
io_failure
(
&
backend
(),
operation
::
write
);
writer_
->
io_failure
(
&
backend
(),
operation
::
write
);
...
...
libcaf_io/src/io/network/datagram_manager.cpp
View file @
f4c5842b
...
@@ -29,4 +29,3 @@ datagram_manager::~datagram_manager() {
...
@@ -29,4 +29,3 @@ datagram_manager::~datagram_manager() {
}
// namespace network
}
// namespace network
}
// namespace io
}
// namespace io
}
// namespace caf
}
// namespace caf
libcaf_io/src/io/network/datagram_servant_impl.cpp
View file @
f4c5842b
...
@@ -141,7 +141,6 @@ void datagram_servant_impl::remove_from_loop() {
...
@@ -141,7 +141,6 @@ void datagram_servant_impl::remove_from_loop() {
handler_
.
passivate
();
handler_
.
passivate
();
}
}
void
datagram_servant_impl
::
detach_handles
()
{
void
datagram_servant_impl
::
detach_handles
()
{
for
(
auto
&
p
:
handler_
.
endpoints
())
{
for
(
auto
&
p
:
handler_
.
endpoints
())
{
if
(
p
.
first
!=
hdl
())
if
(
p
.
first
!=
hdl
())
...
...
libcaf_io/src/io/network/default_multiplexer.cpp
View file @
f4c5842b
...
@@ -20,19 +20,19 @@
...
@@ -20,19 +20,19 @@
#include <utility>
#include <utility>
#include "caf/actor_system_config.hpp"
#include "caf/config.hpp"
#include "caf/config.hpp"
#include "caf/defaults.hpp"
#include "caf/defaults.hpp"
#include "caf/optional.hpp"
#include "caf/make_counted.hpp"
#include "caf/make_counted.hpp"
#include "caf/
actor_system_config
.hpp"
#include "caf/
optional
.hpp"
#include "caf/io/broker.hpp"
#include "caf/io/broker.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/network/protocol.hpp"
#include "caf/io/network/datagram_servant_impl.hpp"
#include "caf/io/network/doorman_impl.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/protocol.hpp"
#include "caf/io/network/scribe_impl.hpp"
#include "caf/io/network/scribe_impl.hpp"
#include "caf/io/network/doorman_impl.hpp"
#include "caf/io/network/datagram_servant_impl.hpp"
#include "caf/detail/call_cfun.hpp"
#include "caf/detail/call_cfun.hpp"
#include "caf/detail/socket_guard.hpp"
#include "caf/detail/socket_guard.hpp"
...
@@ -59,7 +59,6 @@
...
@@ -59,7 +59,6 @@
# include <ws2ipdef.h>
# include <ws2ipdef.h>
# include <ws2tcpip.h>
# include <ws2tcpip.h>
#else
#else
# include <unistd.h>
# include <arpa/inet.h>
# include <arpa/inet.h>
# include <cerrno>
# include <cerrno>
# include <fcntl.h>
# include <fcntl.h>
...
@@ -69,13 +68,14 @@
...
@@ -69,13 +68,14 @@
# include <netinet/tcp.h>
# include <netinet/tcp.h>
# include <sys/socket.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <sys/types.h>
#ifdef CAF_POLL_MULTIPLEXER
# include <unistd.h>
# ifdef CAF_POLL_MULTIPLEXER
# include <poll.h>
# include <poll.h>
#elif defined(CAF_EPOLL_MULTIPLEXER)
#
elif defined(CAF_EPOLL_MULTIPLEXER)
# include <sys/epoll.h>
# include <sys/epoll.h>
#else
#
else
# error "neither CAF_POLL_MULTIPLEXER nor CAF_EPOLL_MULTIPLEXER defined"
# error "neither CAF_POLL_MULTIPLEXER nor CAF_EPOLL_MULTIPLEXER defined"
#endif
#
endif
#endif
#endif
...
@@ -126,34 +126,34 @@ namespace network {
...
@@ -126,34 +126,34 @@ namespace network {
# define POLLPRI POLLIN
# define POLLPRI POLLIN
# endif
# endif
# ifdef CAF_WINDOWS
# ifdef CAF_WINDOWS
// From the MSDN: If the POLLPRI flag is set on a socket for the Microsoft
// From the MSDN: If the POLLPRI flag is set on a socket for the Microsoft
// Winsock provider, the WSAPoll function will fail.
// Winsock provider, the WSAPoll function will fail.
const
event_mask_type
input_mask
=
POLLIN
;
const
event_mask_type
input_mask
=
POLLIN
;
# else
# else
const
event_mask_type
input_mask
=
POLLIN
|
POLLPRI
;
const
event_mask_type
input_mask
=
POLLIN
|
POLLPRI
;
# endif
# endif
const
event_mask_type
error_mask
=
POLLRDHUP
|
POLLERR
|
POLLHUP
|
POLLNVAL
;
const
event_mask_type
error_mask
=
POLLRDHUP
|
POLLERR
|
POLLHUP
|
POLLNVAL
;
const
event_mask_type
output_mask
=
POLLOUT
;
const
event_mask_type
output_mask
=
POLLOUT
;
#else
#else
const
event_mask_type
input_mask
=
EPOLLIN
;
const
event_mask_type
input_mask
=
EPOLLIN
;
const
event_mask_type
error_mask
=
EPOLLRDHUP
|
EPOLLERR
|
EPOLLHUP
;
const
event_mask_type
error_mask
=
EPOLLRDHUP
|
EPOLLERR
|
EPOLLHUP
;
const
event_mask_type
output_mask
=
EPOLLOUT
;
const
event_mask_type
output_mask
=
EPOLLOUT
;
#endif
#endif
// -- Platform-dependent abstraction over epoll() or poll() --------------------
// -- Platform-dependent abstraction over epoll() or poll() --------------------
#ifdef CAF_EPOLL_MULTIPLEXER
#ifdef CAF_EPOLL_MULTIPLEXER
// In this implementation, shadow_ is the number of sockets we have
// In this implementation, shadow_ is the number of sockets we have
// registered to epoll.
// registered to epoll.
default_multiplexer
::
default_multiplexer
(
actor_system
*
sys
)
default_multiplexer
::
default_multiplexer
(
actor_system
*
sys
)
:
multiplexer
(
sys
),
:
multiplexer
(
sys
),
epollfd_
(
invalid_native_socket
),
epollfd_
(
invalid_native_socket
),
shadow_
(
1
),
shadow_
(
1
),
pipe_reader_
(
*
this
),
pipe_reader_
(
*
this
),
servant_ids_
(
0
),
servant_ids_
(
0
),
max_throughput_
(
0
)
{
max_throughput_
(
0
)
{
init
();
init
();
epollfd_
=
epoll_create1
(
EPOLL_CLOEXEC
);
epollfd_
=
epoll_create1
(
EPOLL_CLOEXEC
);
if
(
epollfd_
==
-
1
)
{
if
(
epollfd_
==
-
1
)
{
...
@@ -171,18 +171,17 @@ namespace network {
...
@@ -171,18 +171,17 @@ namespace network {
CAF_LOG_ERROR
(
"epoll_ctl: "
<<
strerror
(
errno
));
CAF_LOG_ERROR
(
"epoll_ctl: "
<<
strerror
(
errno
));
exit
(
errno
);
exit
(
errno
);
}
}
}
}
bool
default_multiplexer
::
poll_once_impl
(
bool
block
)
{
bool
default_multiplexer
::
poll_once_impl
(
bool
block
)
{
CAF_LOG_TRACE
(
"epoll()-based multiplexer"
);
CAF_LOG_TRACE
(
"epoll()-based multiplexer"
);
CAF_ASSERT
(
block
==
false
||
internally_posted_
.
empty
());
CAF_ASSERT
(
block
==
false
||
internally_posted_
.
empty
());
// Keep running in case of `EINTR`.
// Keep running in case of `EINTR`.
for
(;;)
{
for
(;;)
{
int
presult
=
epoll_wait
(
epollfd_
,
pollset_
.
data
(),
int
presult
=
epoll_wait
(
epollfd_
,
pollset_
.
data
(),
static_cast
<
int
>
(
pollset_
.
size
()),
static_cast
<
int
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
block
?
-
1
:
0
);
CAF_LOG_DEBUG
(
"epoll_wait() on"
<<
shadow_
<<
"sockets reported"
<<
presult
CAF_LOG_DEBUG
(
"epoll_wait() on"
<<
shadow_
<<
"event(s)"
);
<<
"sockets reported"
<<
presult
<<
"event(s)"
);
if
(
presult
<
0
)
{
if
(
presult
<
0
)
{
switch
(
errno
)
{
switch
(
errno
)
{
case
EINTR
:
{
case
EINTR
:
{
...
@@ -208,17 +207,16 @@ namespace network {
...
@@ -208,17 +207,16 @@ namespace network {
handle_internal_events
();
handle_internal_events
();
return
true
;
return
true
;
}
}
}
}
void
default_multiplexer
::
run
()
{
void
default_multiplexer
::
run
()
{
CAF_LOG_TRACE
(
"epoll()-based multiplexer"
);
CAF_LOG_TRACE
(
"epoll()-based multiplexer"
);
while
(
shadow_
>
0
)
while
(
shadow_
>
0
)
poll_once
(
true
);
poll_once
(
true
);
}
}
void
default_multiplexer
::
handle
(
const
default_multiplexer
::
event
&
e
)
{
void
default_multiplexer
::
handle
(
const
default_multiplexer
::
event
&
e
)
{
CAF_LOG_TRACE
(
"e.fd = "
<<
CAF_ARG
(
e
.
fd
)
<<
", mask = "
CAF_LOG_TRACE
(
"e.fd = "
<<
CAF_ARG
(
e
.
fd
)
<<
", mask = "
<<
CAF_ARG
(
e
.
mask
));
<<
CAF_ARG
(
e
.
mask
));
// ptr is only allowed to nullptr if fd is our pipe
// ptr is only allowed to nullptr if fd is our pipe
// read handle which is only registered for input
// read handle which is only registered for input
CAF_ASSERT
(
e
.
ptr
!=
nullptr
||
e
.
fd
==
pipe_
.
first
);
CAF_ASSERT
(
e
.
ptr
!=
nullptr
||
e
.
fd
==
pipe_
.
first
);
...
@@ -227,7 +225,7 @@ namespace network {
...
@@ -227,7 +225,7 @@ namespace network {
return
;
return
;
}
}
auto
old
=
e
.
ptr
?
e
.
ptr
->
eventbf
()
:
input_mask
;
auto
old
=
e
.
ptr
?
e
.
ptr
->
eventbf
()
:
input_mask
;
if
(
e
.
ptr
)
{
if
(
e
.
ptr
)
{
e
.
ptr
->
eventbf
(
e
.
mask
);
e
.
ptr
->
eventbf
(
e
.
mask
);
}
}
epoll_event
ee
;
epoll_event
ee
;
...
@@ -244,8 +242,9 @@ namespace network {
...
@@ -244,8 +242,9 @@ namespace network {
op
=
EPOLL_CTL_ADD
;
op
=
EPOLL_CTL_ADD
;
++
shadow_
;
++
shadow_
;
}
else
{
}
else
{
CAF_LOG_DEBUG
(
"modify epoll event mask for socket "
<<
CAF_ARG
(
e
.
fd
)
CAF_LOG_DEBUG
(
"modify epoll event mask for socket "
<<
": "
<<
CAF_ARG
(
old
)
<<
" -> "
<<
CAF_ARG
(
e
.
mask
));
<<
CAF_ARG
(
e
.
fd
)
<<
": "
<<
CAF_ARG
(
old
)
<<
" -> "
<<
CAF_ARG
(
e
.
mask
));
op
=
EPOLL_CTL_MOD
;
op
=
EPOLL_CTL_MOD
;
}
}
if
(
epoll_ctl
(
epollfd_
,
op
,
e
.
fd
,
&
ee
)
<
0
)
{
if
(
epoll_ctl
(
epollfd_
,
op
,
e
.
fd
,
&
ee
)
<
0
)
{
...
@@ -258,8 +257,7 @@ namespace network {
...
@@ -258,8 +257,7 @@ namespace network {
// op was EPOLL_CTL_MOD or EPOLL_CTL_DEL,
// op was EPOLL_CTL_MOD or EPOLL_CTL_DEL,
// and fd is not registered with this epoll instance.
// and fd is not registered with this epoll instance.
case
ENOENT
:
case
ENOENT
:
CAF_LOG_ERROR
(
CAF_LOG_ERROR
(
"cannot delete file descriptor "
"cannot delete file descriptor "
"because it isn't registered"
);
"because it isn't registered"
);
if
(
e
.
mask
==
0
)
{
if
(
e
.
mask
==
0
)
{
++
shadow_
;
++
shadow_
;
...
@@ -280,31 +278,28 @@ namespace network {
...
@@ -280,31 +278,28 @@ namespace network {
remove_from_loop_if_needed
(
input_mask
,
operation
::
read
);
remove_from_loop_if_needed
(
input_mask
,
operation
::
read
);
remove_from_loop_if_needed
(
output_mask
,
operation
::
write
);
remove_from_loop_if_needed
(
output_mask
,
operation
::
write
);
}
}
}
}
size_t
default_multiplexer
::
num_socket_handlers
()
const
noexcept
{
size_t
default_multiplexer
::
num_socket_handlers
()
const
noexcept
{
return
shadow_
;
return
shadow_
;
}
}
#else // CAF_EPOLL_MULTIPLEXER
#else // CAF_EPOLL_MULTIPLEXER
// Let's be honest: the API of poll() sucks. When dealing with 1000 sockets
// Let's be honest: the API of poll() sucks. When dealing with 1000 sockets
// and the very last socket in your pollset triggers, you have to traverse
// and the very last socket in your pollset triggers, you have to traverse
// all elements only to find a single event. Even worse, poll() does
// all elements only to find a single event. Even worse, poll() does
// not give you a way of storing a user-defined pointer in the pollset.
// not give you a way of storing a user-defined pointer in the pollset.
// Hence, you need to find a pointer to the actual object managing the
// Hence, you need to find a pointer to the actual object managing the
// socket. When using a map, your already dreadful O(n) turns into
// socket. When using a map, your already dreadful O(n) turns into
// a worst case of O(n * log n). To deal with this nonsense, we have two
// a worst case of O(n * log n). To deal with this nonsense, we have two
// vectors in this implementation: pollset_ and shadow_. The former
// vectors in this implementation: pollset_ and shadow_. The former
// stores our pollset, the latter stores our pointers. Both vectors
// stores our pollset, the latter stores our pointers. Both vectors
// are sorted by the file descriptor. This allows us to quickly,
// are sorted by the file descriptor. This allows us to quickly,
// i.e., O(1), access the actual object when handling socket events.
// i.e., O(1), access the actual object when handling socket events.
default_multiplexer
::
default_multiplexer
(
actor_system
*
sys
)
default_multiplexer
::
default_multiplexer
(
actor_system
*
sys
)
:
multiplexer
(
sys
),
:
multiplexer
(
sys
),
epollfd_
(
-
1
),
pipe_reader_
(
*
this
),
servant_ids_
(
0
)
{
epollfd_
(
-
1
),
pipe_reader_
(
*
this
),
servant_ids_
(
0
)
{
init
();
init
();
// initial setup
// initial setup
pipe_
=
create_pipe
();
pipe_
=
create_pipe
();
...
@@ -315,9 +310,9 @@ namespace network {
...
@@ -315,9 +310,9 @@ namespace network {
pipefd
.
revents
=
0
;
pipefd
.
revents
=
0
;
pollset_
.
push_back
(
pipefd
);
pollset_
.
push_back
(
pipefd
);
shadow_
.
push_back
(
&
pipe_reader_
);
shadow_
.
push_back
(
&
pipe_reader_
);
}
}
bool
default_multiplexer
::
poll_once_impl
(
bool
block
)
{
bool
default_multiplexer
::
poll_once_impl
(
bool
block
)
{
CAF_LOG_TRACE
(
"poll()-based multiplexer"
);
CAF_LOG_TRACE
(
"poll()-based multiplexer"
);
CAF_ASSERT
(
block
==
false
||
internally_posted_
.
empty
());
CAF_ASSERT
(
block
==
false
||
internally_posted_
.
empty
());
// we store the results of poll() in a separate vector , because
// we store the results of poll() in a separate vector , because
...
@@ -329,15 +324,14 @@ namespace network {
...
@@ -329,15 +324,14 @@ namespace network {
event_handler
*
ptr
;
// nullptr in case of a pipe event
event_handler
*
ptr
;
// nullptr in case of a pipe event
};
};
std
::
vector
<
fd_event
>
poll_res
;
std
::
vector
<
fd_event
>
poll_res
;
for
(;;)
{
for
(;;)
{
int
presult
;
int
presult
;
# ifdef CAF_WINDOWS
# ifdef CAF_WINDOWS
presult
=
::
WSAPoll
(
pollset_
.
data
(),
presult
=
::
WSAPoll
(
pollset_
.
data
(),
static_cast
<
ULONG
>
(
pollset_
.
size
()),
static_cast
<
ULONG
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
block
?
-
1
:
0
);
# else
# else
presult
=
::
poll
(
pollset_
.
data
(
),
presult
=
::
poll
(
pollset_
.
data
(),
static_cast
<
nfds_t
>
(
pollset_
.
size
()
),
static_cast
<
nfds_t
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
block
?
-
1
:
0
);
# endif
# endif
if
(
presult
<
0
)
{
if
(
presult
<
0
)
{
switch
(
last_socket_error
())
{
switch
(
last_socket_error
())
{
...
@@ -360,8 +354,8 @@ namespace network {
...
@@ -360,8 +354,8 @@ namespace network {
}
}
continue
;
// rinse and repeat
continue
;
// rinse and repeat
}
}
CAF_LOG_DEBUG
(
"poll() on"
<<
pollset_
.
size
()
CAF_LOG_DEBUG
(
"poll() on"
<<
pollset_
.
size
()
<<
"sockets reported"
<<
"sockets reported"
<<
presult
<<
"event(s)"
);
<<
presult
<<
"event(s)"
);
if
(
presult
==
0
)
if
(
presult
==
0
)
return
false
;
return
false
;
// scan pollset for events first, because we might alter pollset_
// scan pollset for events first, because we might alter pollset_
...
@@ -388,16 +382,17 @@ namespace network {
...
@@ -388,16 +382,17 @@ namespace network {
handle_internal_events
();
handle_internal_events
();
return
true
;
return
true
;
}
}
}
}
void
default_multiplexer
::
run
()
{
void
default_multiplexer
::
run
()
{
CAF_LOG_TRACE
(
"poll()-based multiplexer:"
<<
CAF_ARG
(
input_mask
)
CAF_LOG_TRACE
(
"poll()-based multiplexer:"
<<
CAF_ARG
(
input_mask
)
<<
CAF_ARG
(
output_mask
)
<<
CAF_ARG
(
error_mask
));
<<
CAF_ARG
(
output_mask
)
<<
CAF_ARG
(
error_mask
));
while
(
!
pollset_
.
empty
())
while
(
!
pollset_
.
empty
())
poll_once
(
true
);
poll_once
(
true
);
}
}
void
default_multiplexer
::
handle
(
const
default_multiplexer
::
event
&
e
)
{
void
default_multiplexer
::
handle
(
const
default_multiplexer
::
event
&
e
)
{
CAF_ASSERT
(
e
.
fd
!=
invalid_native_socket
);
CAF_ASSERT
(
e
.
fd
!=
invalid_native_socket
);
CAF_ASSERT
(
pollset_
.
size
()
==
shadow_
.
size
());
CAF_ASSERT
(
pollset_
.
size
()
==
shadow_
.
size
());
CAF_LOG_TRACE
(
CAF_ARG
(
e
.
fd
)
<<
CAF_ARG
(
e
.
mask
));
CAF_LOG_TRACE
(
CAF_ARG
(
e
.
fd
)
<<
CAF_ARG
(
e
.
mask
));
...
@@ -452,11 +447,11 @@ namespace network {
...
@@ -452,11 +447,11 @@ namespace network {
pollset_
.
insert
(
i
,
new_element
);
pollset_
.
insert
(
i
,
new_element
);
shadow_
.
insert
(
j
,
e
.
ptr
);
shadow_
.
insert
(
j
,
e
.
ptr
);
}
}
}
}
size_t
default_multiplexer
::
num_socket_handlers
()
const
noexcept
{
size_t
default_multiplexer
::
num_socket_handlers
()
const
noexcept
{
return
pollset_
.
size
();
return
pollset_
.
size
();
}
}
#endif // CAF_EPOLL_MULTIPLEXER
#endif // CAF_EPOLL_MULTIPLEXER
...
@@ -515,19 +510,19 @@ void default_multiplexer::del(operation op, native_socket fd,
...
@@ -515,19 +510,19 @@ void default_multiplexer::del(operation op, native_socket fd,
CAF_ASSERT
(
fd
!=
invalid_native_socket
);
CAF_ASSERT
(
fd
!=
invalid_native_socket
);
// ptr == nullptr is only allowed when removing our pipe read handle
// ptr == nullptr is only allowed when removing our pipe read handle
CAF_ASSERT
(
ptr
!=
nullptr
||
fd
==
pipe_
.
first
);
CAF_ASSERT
(
ptr
!=
nullptr
||
fd
==
pipe_
.
first
);
CAF_LOG_TRACE
(
CAF_ARG
(
op
)
<<
CAF_ARG
(
fd
));
CAF_LOG_TRACE
(
CAF_ARG
(
op
)
<<
CAF_ARG
(
fd
));
new_event
(
del_flag
,
op
,
fd
,
ptr
);
new_event
(
del_flag
,
op
,
fd
,
ptr
);
}
}
void
default_multiplexer
::
wr_dispatch_request
(
resumable
*
ptr
)
{
void
default_multiplexer
::
wr_dispatch_request
(
resumable
*
ptr
)
{
intptr_t
ptrval
=
reinterpret_cast
<
intptr_t
>
(
ptr
);
intptr_t
ptrval
=
reinterpret_cast
<
intptr_t
>
(
ptr
);
// on windows, we actually have sockets, otherwise we have file handles
// on windows, we actually have sockets, otherwise we have file handles
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
auto
res
=
::
send
(
pipe_
.
second
,
reinterpret_cast
<
socket_send_ptr
>
(
&
ptrval
),
auto
res
=
::
send
(
pipe_
.
second
,
reinterpret_cast
<
socket_send_ptr
>
(
&
ptrval
),
sizeof
(
ptrval
),
no_sigpipe_io_flag
);
sizeof
(
ptrval
),
no_sigpipe_io_flag
);
#
else
#else
auto
res
=
::
write
(
pipe_
.
second
,
&
ptrval
,
sizeof
(
ptrval
));
auto
res
=
::
write
(
pipe_
.
second
,
&
ptrval
,
sizeof
(
ptrval
));
#
endif
#endif
if
(
res
<=
0
)
{
if
(
res
<=
0
)
{
// pipe closed, discard resumable
// pipe closed, discard resumable
intrusive_ptr_release
(
ptr
);
intrusive_ptr_release
(
ptr
);
...
@@ -548,6 +543,7 @@ multiplexer::supervisor_ptr default_multiplexer::make_supervisor() {
...
@@ -548,6 +543,7 @@ multiplexer::supervisor_ptr default_multiplexer::make_supervisor() {
auto
ptr
=
this_
;
auto
ptr
=
this_
;
ptr
->
dispatch
([
=
]
{
ptr
->
close_pipe
();
});
ptr
->
dispatch
([
=
]
{
ptr
->
close_pipe
();
});
}
}
private:
private:
default_multiplexer
*
this_
;
default_multiplexer
*
this_
;
};
};
...
@@ -586,12 +582,12 @@ void default_multiplexer::handle_socket_event(native_socket fd, int mask,
...
@@ -586,12 +582,12 @@ void default_multiplexer::handle_socket_event(native_socket fd, int mask,
}
}
void
default_multiplexer
::
init
()
{
void
default_multiplexer
::
init
()
{
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
WSADATA
WinsockData
;
WSADATA
WinsockData
;
if
(
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
WinsockData
)
!=
0
)
{
if
(
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
WinsockData
)
!=
0
)
{
CAF_CRITICAL
(
"WSAStartup failed"
);
CAF_CRITICAL
(
"WSAStartup failed"
);
}
}
#
endif
#endif
namespace
sr
=
defaults
::
scheduler
;
namespace
sr
=
defaults
::
scheduler
;
max_throughput_
=
get_or
(
system
().
config
(),
"scheduler.max-throughput"
,
max_throughput_
=
get_or
(
system
().
config
(),
"scheduler.max-throughput"
,
sr
::
max_throughput
);
sr
::
max_throughput
);
...
@@ -629,8 +625,7 @@ void default_multiplexer::resume(intrusive_ptr<resumable> ptr) {
...
@@ -629,8 +625,7 @@ void default_multiplexer::resume(intrusive_ptr<resumable> ptr) {
// Don't touch reference count of shutdown helpers.
// Don't touch reference count of shutdown helpers.
ptr
.
release
();
ptr
.
release
();
break
;
break
;
default:
default:
;
// Done. Release reference to resumable.
;
// Done. Release reference to resumable.
}
}
}
}
...
@@ -649,9 +644,9 @@ default_multiplexer::~default_multiplexer() {
...
@@ -649,9 +644,9 @@ default_multiplexer::~default_multiplexer() {
// do cleanup for pipe reader manually, since WSACleanup needs to happen last
// do cleanup for pipe reader manually, since WSACleanup needs to happen last
close_socket
(
pipe_reader_
.
fd
());
close_socket
(
pipe_reader_
.
fd
());
pipe_reader_
.
init
(
invalid_native_socket
);
pipe_reader_
.
init
(
invalid_native_socket
);
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
WSACleanup
();
WSACleanup
();
#
endif
#endif
}
}
void
default_multiplexer
::
exec_later
(
resumable
*
ptr
)
{
void
default_multiplexer
::
exec_later
(
resumable
*
ptr
)
{
...
@@ -751,12 +746,8 @@ bool ip_connect(native_socket fd, const std::string& host, uint16_t port) {
...
@@ -751,12 +746,8 @@ bool ip_connect(native_socket fd, const std::string& host, uint16_t port) {
CAF_LOG_TRACE
(
"Family ="
<<
(
Family
==
AF_INET
?
"AF_INET"
:
"AF_INET6"
)
CAF_LOG_TRACE
(
"Family ="
<<
(
Family
==
AF_INET
?
"AF_INET"
:
"AF_INET6"
)
<<
CAF_ARG
(
fd
)
<<
CAF_ARG
(
host
));
<<
CAF_ARG
(
fd
)
<<
CAF_ARG
(
host
));
static_assert
(
Family
==
AF_INET
||
Family
==
AF_INET6
,
"invalid family"
);
static_assert
(
Family
==
AF_INET
||
Family
==
AF_INET6
,
"invalid family"
);
using
sockaddr_type
=
using
sockaddr_type
=
typename
std
::
conditional
<
typename
std
::
conditional
<
Family
==
AF_INET
,
sockaddr_in
,
sockaddr_in6
>::
type
;
Family
==
AF_INET
,
sockaddr_in
,
sockaddr_in6
>::
type
;
sockaddr_type
sa
;
sockaddr_type
sa
;
memset
(
&
sa
,
0
,
sizeof
(
sockaddr_type
));
memset
(
&
sa
,
0
,
sizeof
(
sockaddr_type
));
inet_pton
(
Family
,
host
.
c_str
(),
&
addr_of
(
sa
));
inet_pton
(
Family
,
host
.
c_str
(),
&
addr_of
(
sa
));
...
@@ -787,8 +778,8 @@ new_tcp_connection(const std::string& host, uint16_t port,
...
@@ -787,8 +778,8 @@ new_tcp_connection(const std::string& host, uint16_t port,
detail
::
socket_guard
sguard
(
fd
);
detail
::
socket_guard
sguard
(
fd
);
if
(
proto
==
ipv6
)
{
if
(
proto
==
ipv6
)
{
if
(
ip_connect
<
AF_INET6
>
(
fd
,
res
->
first
,
port
))
{
if
(
ip_connect
<
AF_INET6
>
(
fd
,
res
->
first
,
port
))
{
CAF_LOG_INFO
(
"successfully connected to (IPv6):"
CAF_LOG_INFO
(
"successfully connected to (IPv6):"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
<<
CAF_ARG
(
port
));
return
sguard
.
release
();
return
sguard
.
release
();
}
}
sguard
.
close
();
sguard
.
close
();
...
@@ -797,11 +788,11 @@ new_tcp_connection(const std::string& host, uint16_t port,
...
@@ -797,11 +788,11 @@ new_tcp_connection(const std::string& host, uint16_t port,
}
}
if
(
!
ip_connect
<
AF_INET
>
(
fd
,
res
->
first
,
port
))
{
if
(
!
ip_connect
<
AF_INET
>
(
fd
,
res
->
first
,
port
))
{
CAF_LOG_WARNING
(
"could not connect to:"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
CAF_LOG_WARNING
(
"could not connect to:"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
return
make_error
(
sec
::
cannot_connect_to_node
,
return
make_error
(
sec
::
cannot_connect_to_node
,
"ip_connect failed"
,
host
,
"ip_connect failed"
,
host
,
port
);
port
);
}
}
CAF_LOG_INFO
(
"successfully connected to (IPv4):"
CAF_LOG_INFO
(
"successfully connected to (IPv4):"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
<<
CAF_ARG
(
port
));
return
sguard
.
release
();
return
sguard
.
release
();
}
}
...
@@ -849,12 +840,8 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr,
...
@@ -849,12 +840,8 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr,
reinterpret_cast
<
setsockopt_ptr
>
(
&
on
),
reinterpret_cast
<
setsockopt_ptr
>
(
&
on
),
static_cast
<
socket_size_type
>
(
sizeof
(
on
))));
static_cast
<
socket_size_type
>
(
sizeof
(
on
))));
}
}
using
sockaddr_type
=
using
sockaddr_type
=
typename
std
::
conditional
<
typename
std
::
conditional
<
Family
==
AF_INET
,
sockaddr_in
,
sockaddr_in6
>::
type
;
Family
==
AF_INET
,
sockaddr_in
,
sockaddr_in6
>::
type
;
sockaddr_type
sa
;
sockaddr_type
sa
;
memset
(
&
sa
,
0
,
sizeof
(
sockaddr_type
));
memset
(
&
sa
,
0
,
sizeof
(
sockaddr_type
));
family_of
(
sa
)
=
Family
;
family_of
(
sa
)
=
Family
;
...
@@ -883,7 +870,8 @@ expected<native_socket> new_tcp_acceptor_impl(uint16_t port, const char* addr,
...
@@ -883,7 +870,8 @@ expected<native_socket> new_tcp_acceptor_impl(uint16_t port, const char* addr,
auto
hostname
=
elem
.
first
.
c_str
();
auto
hostname
=
elem
.
first
.
c_str
();
auto
p
=
elem
.
second
==
ipv4
auto
p
=
elem
.
second
==
ipv4
?
new_ip_acceptor_impl
<
AF_INET
>
(
port
,
hostname
,
reuse_addr
,
any
)
?
new_ip_acceptor_impl
<
AF_INET
>
(
port
,
hostname
,
reuse_addr
,
any
)
:
new_ip_acceptor_impl
<
AF_INET6
>
(
port
,
hostname
,
reuse_addr
,
any
);
:
new_ip_acceptor_impl
<
AF_INET6
>
(
port
,
hostname
,
reuse_addr
,
any
);
if
(
!
p
)
{
if
(
!
p
)
{
CAF_LOG_DEBUG
(
p
.
error
());
CAF_LOG_DEBUG
(
p
.
error
());
continue
;
continue
;
...
@@ -894,8 +882,8 @@ expected<native_socket> new_tcp_acceptor_impl(uint16_t port, const char* addr,
...
@@ -894,8 +882,8 @@ expected<native_socket> new_tcp_acceptor_impl(uint16_t port, const char* addr,
if
(
fd
==
invalid_native_socket
)
{
if
(
fd
==
invalid_native_socket
)
{
CAF_LOG_WARNING
(
"could not open tcp socket on:"
<<
CAF_ARG
(
port
)
CAF_LOG_WARNING
(
"could not open tcp socket on:"
<<
CAF_ARG
(
port
)
<<
CAF_ARG
(
addr_str
));
<<
CAF_ARG
(
addr_str
));
return
make_error
(
sec
::
cannot_open_port
,
"tcp socket creation failed"
,
return
make_error
(
sec
::
cannot_open_port
,
"tcp socket creation failed"
,
port
,
port
,
addr_str
);
addr_str
);
}
}
detail
::
socket_guard
sguard
{
fd
};
detail
::
socket_guard
sguard
{
fd
};
CALL_CFUN
(
tmp2
,
detail
::
cc_zero
,
"listen"
,
listen
(
fd
,
SOMAXCONN
));
CALL_CFUN
(
tmp2
,
detail
::
cc_zero
,
"listen"
,
listen
(
fd
,
SOMAXCONN
));
...
@@ -935,8 +923,10 @@ new_local_udp_endpoint_impl(uint16_t port, const char* addr, bool reuse,
...
@@ -935,8 +923,10 @@ new_local_udp_endpoint_impl(uint16_t port, const char* addr, bool reuse,
for
(
auto
&
elem
:
addrs
)
{
for
(
auto
&
elem
:
addrs
)
{
auto
host
=
elem
.
first
.
c_str
();
auto
host
=
elem
.
first
.
c_str
();
auto
p
=
elem
.
second
==
ipv4
auto
p
=
elem
.
second
==
ipv4
?
new_ip_acceptor_impl
<
AF_INET
,
SOCK_DGRAM
>
(
port
,
host
,
reuse
,
any
)
?
new_ip_acceptor_impl
<
AF_INET
,
SOCK_DGRAM
>
(
port
,
host
,
reuse
,
:
new_ip_acceptor_impl
<
AF_INET6
,
SOCK_DGRAM
>
(
port
,
host
,
reuse
,
any
);
any
)
:
new_ip_acceptor_impl
<
AF_INET6
,
SOCK_DGRAM
>
(
port
,
host
,
reuse
,
any
);
if
(
!
p
)
{
if
(
!
p
)
{
CAF_LOG_DEBUG
(
p
.
error
());
CAF_LOG_DEBUG
(
p
.
error
());
continue
;
continue
;
...
@@ -948,8 +938,8 @@ new_local_udp_endpoint_impl(uint16_t port, const char* addr, bool reuse,
...
@@ -948,8 +938,8 @@ new_local_udp_endpoint_impl(uint16_t port, const char* addr, bool reuse,
if
(
fd
==
invalid_native_socket
)
{
if
(
fd
==
invalid_native_socket
)
{
CAF_LOG_WARNING
(
"could not open udp socket on:"
<<
CAF_ARG
(
port
)
CAF_LOG_WARNING
(
"could not open udp socket on:"
<<
CAF_ARG
(
port
)
<<
CAF_ARG
(
addr_str
));
<<
CAF_ARG
(
addr_str
));
return
make_error
(
sec
::
cannot_open_port
,
"udp socket creation failed"
,
return
make_error
(
sec
::
cannot_open_port
,
"udp socket creation failed"
,
port
,
port
,
addr_str
);
addr_str
);
}
}
CAF_LOG_DEBUG
(
CAF_ARG
(
fd
));
CAF_LOG_DEBUG
(
CAF_ARG
(
fd
));
return
std
::
make_pair
(
fd
,
proto
);
return
std
::
make_pair
(
fd
,
proto
);
...
...
libcaf_io/src/io/network/doorman_impl.cpp
View file @
f4c5842b
...
@@ -29,8 +29,7 @@ namespace io {
...
@@ -29,8 +29,7 @@ namespace io {
namespace
network
{
namespace
network
{
doorman_impl
::
doorman_impl
(
default_multiplexer
&
mx
,
native_socket
sockfd
)
doorman_impl
::
doorman_impl
(
default_multiplexer
&
mx
,
native_socket
sockfd
)
:
doorman
(
network
::
accept_hdl_from_socket
(
sockfd
)),
:
doorman
(
network
::
accept_hdl_from_socket
(
sockfd
)),
acceptor_
(
mx
,
sockfd
)
{
acceptor_
(
mx
,
sockfd
)
{
// nop
// nop
}
}
...
...
libcaf_io/src/io/network/event_handler.cpp
View file @
f4c5842b
libcaf_io/src/io/network/interfaces.cpp
View file @
f4c5842b
...
@@ -20,28 +20,28 @@
...
@@ -20,28 +20,28 @@
#include "caf/config.hpp"
#include "caf/config.hpp"
#include <algorithm>
#include <cerrno>
#include <cerrno>
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <cstring>
#include <algorithm>
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
# ifndef _WIN32_WINNT
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# define _WIN32_WINNT 0x0600
# endif
# endif
# include <iostream>
# include <iostream>
# include <iphlpapi.h>
# include <winsock2.h>
# include <winsock2.h>
# include <ws2tcpip.h>
# include <ws2tcpip.h>
# include <iphlpapi.h>
#else
#else
#
include <sys/sock
et.h>
#
include <arpa/in
et.h>
#
include <netinet/in
.h>
#
include <ifaddrs
.h>
# include <net/if.h>
# include <net/if.h>
# include <unistd.h>
# include <netdb.h>
# include <netdb.h>
#
include <ifaddrs
.h>
#
include <netinet/in
.h>
# include <sys/ioctl.h>
# include <sys/ioctl.h>
# include <arpa/inet.h>
# include <sys/socket.h>
# include <unistd.h>
#endif
#endif
#include <memory>
#include <memory>
...
@@ -56,9 +56,8 @@ namespace io {
...
@@ -56,9 +56,8 @@ namespace io {
namespace
network
{
namespace
network
{
// {interface_name => {protocol => address}}
// {interface_name => {protocol => address}}
using
interfaces_map
=
std
::
map
<
std
::
string
,
using
interfaces_map
=
std
::
map
<
std
::
map
<
protocol
::
network
,
std
::
string
,
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>>
;
std
::
vector
<
std
::
string
>>>
;
template
<
class
T
>
template
<
class
T
>
void
*
vptr
(
T
*
ptr
)
{
void
*
vptr
(
T
*
ptr
)
{
...
@@ -71,8 +70,7 @@ void* fetch_in_addr(int family, sockaddr* addr) {
...
@@ -71,8 +70,7 @@ void* fetch_in_addr(int family, sockaddr* addr) {
return
vptr
(
&
reinterpret_cast
<
sockaddr_in6
*>
(
addr
)
->
sin6_addr
);
return
vptr
(
&
reinterpret_cast
<
sockaddr_in6
*>
(
addr
)
->
sin6_addr
);
}
}
int
fetch_addr_str
(
bool
get_ipv4
,
bool
get_ipv6
,
int
fetch_addr_str
(
bool
get_ipv4
,
bool
get_ipv6
,
char
(
&
buf
)[
INET6_ADDRSTRLEN
],
char
(
&
buf
)[
INET6_ADDRSTRLEN
],
sockaddr
*
addr
)
{
sockaddr
*
addr
)
{
if
(
addr
==
nullptr
)
if
(
addr
==
nullptr
)
return
AF_UNSPEC
;
return
AF_UNSPEC
;
...
@@ -100,13 +98,13 @@ void for_each_address(bool get_ipv4, bool get_ipv6, F fun) {
...
@@ -100,13 +98,13 @@ void for_each_address(bool get_ipv4, bool get_ipv6, F fun) {
tmp
=
reinterpret_cast
<
IP_ADAPTER_ADDRESSES
*>
(
malloc
(
tmp_size
));
tmp
=
reinterpret_cast
<
IP_ADAPTER_ADDRESSES
*>
(
malloc
(
tmp_size
));
if
(
!
tmp
)
if
(
!
tmp
)
CAF_RAISE_ERROR
(
"malloc() failed"
);
CAF_RAISE_ERROR
(
"malloc() failed"
);
retval
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
retval
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
nullptr
,
nullptr
,
tmp
,
&
tmp_size
);
tmp
,
&
tmp_size
);
}
while
(
retval
==
ERROR_BUFFER_OVERFLOW
&&
++
try_nr
<
max_tries
);
}
while
(
retval
==
ERROR_BUFFER_OVERFLOW
&&
++
try_nr
<
max_tries
);
std
::
unique_ptr
<
IP_ADAPTER_ADDRESSES
,
decltype
(
free
)
*>
ifs
{
tmp
,
free
};
std
::
unique_ptr
<
IP_ADAPTER_ADDRESSES
,
decltype
(
free
)
*>
ifs
{
tmp
,
free
};
if
(
retval
!=
NO_ERROR
)
{
if
(
retval
!=
NO_ERROR
)
{
std
::
cerr
<<
"Call to GetAdaptersAddresses failed with error: "
std
::
cerr
<<
"Call to GetAdaptersAddresses failed with error: "
<<
retval
<<
retval
<<
std
::
endl
;
<<
std
::
endl
;
if
(
retval
==
ERROR_NO_DATA
)
{
if
(
retval
==
ERROR_NO_DATA
)
{
std
::
cerr
<<
"No addresses were found for the requested parameters"
std
::
cerr
<<
"No addresses were found for the requested parameters"
<<
std
::
endl
;
<<
std
::
endl
;
...
@@ -152,8 +150,7 @@ void for_each_address(bool get_ipv4, bool get_ipv6, F fun) {
...
@@ -152,8 +150,7 @@ void for_each_address(bool get_ipv4, bool get_ipv6, F fun) {
auto
family
=
fetch_addr_str
(
get_ipv4
,
get_ipv6
,
buffer
,
i
->
ifa_addr
);
auto
family
=
fetch_addr_str
(
get_ipv4
,
get_ipv6
,
buffer
,
i
->
ifa_addr
);
if
(
family
!=
AF_UNSPEC
)
if
(
family
!=
AF_UNSPEC
)
fun
(
i
->
ifa_name
,
family
==
AF_INET
?
protocol
::
ipv4
:
protocol
::
ipv6
,
fun
(
i
->
ifa_name
,
family
==
AF_INET
?
protocol
::
ipv4
:
protocol
::
ipv6
,
(
i
->
ifa_flags
&
IFF_LOOPBACK
)
!=
0
,
(
i
->
ifa_flags
&
IFF_LOOPBACK
)
!=
0
,
buffer
);
buffer
);
}
}
}
}
...
@@ -181,9 +178,9 @@ void interfaces::traverse(consumer f) {
...
@@ -181,9 +178,9 @@ void interfaces::traverse(consumer f) {
interfaces_map
interfaces
::
list_all
(
bool
include_localhost
)
{
interfaces_map
interfaces
::
list_all
(
bool
include_localhost
)
{
interfaces_map
result
;
interfaces_map
result
;
traverse_impl
(
traverse_impl
(
{
protocol
::
ipv4
,
protocol
::
ipv6
},
{
protocol
::
ipv4
,
protocol
::
ipv6
}
,
[
&
](
const
char
*
name
,
protocol
::
network
p
,
bool
lo
,
[
&
](
const
char
*
name
,
protocol
::
network
p
,
bool
lo
,
const
char
*
addr
)
{
const
char
*
addr
)
{
if
(
include_localhost
||
!
lo
)
if
(
include_localhost
||
!
lo
)
result
[
name
][
p
].
emplace_back
(
addr
);
result
[
name
][
p
].
emplace_back
(
addr
);
});
});
...
@@ -193,9 +190,9 @@ interfaces_map interfaces::list_all(bool include_localhost) {
...
@@ -193,9 +190,9 @@ interfaces_map interfaces::list_all(bool include_localhost) {
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>
interfaces
::
list_addresses
(
bool
include_localhost
)
{
interfaces
::
list_addresses
(
bool
include_localhost
)
{
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>
result
;
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>
result
;
traverse_impl
(
traverse_impl
(
{
protocol
::
ipv4
,
protocol
::
ipv6
},
{
protocol
::
ipv4
,
protocol
::
ipv6
}
,
[
&
](
const
char
*
,
protocol
::
network
p
,
bool
lo
,
[
&
](
const
char
*
,
protocol
::
network
p
,
bool
lo
,
const
char
*
addr
)
{
const
char
*
addr
)
{
if
(
include_localhost
||
!
lo
)
if
(
include_localhost
||
!
lo
)
result
[
p
].
emplace_back
(
addr
);
result
[
p
].
emplace_back
(
addr
);
});
});
...
@@ -266,8 +263,7 @@ interfaces::server_address(uint16_t port, const char* host,
...
@@ -266,8 +263,7 @@ interfaces::server_address(uint16_t port, const char* host,
auto
family
=
fetch_addr_str
(
true
,
true
,
buffer
,
i
->
ai_addr
);
auto
family
=
fetch_addr_str
(
true
,
true
,
buffer
,
i
->
ai_addr
);
if
(
family
!=
AF_UNSPEC
)
{
if
(
family
!=
AF_UNSPEC
)
{
results
.
emplace_back
(
std
::
string
{
buffer
},
results
.
emplace_back
(
std
::
string
{
buffer
},
family
==
AF_INET
?
protocol
::
ipv4
family
==
AF_INET
?
protocol
::
ipv4
:
protocol
::
ipv6
);
:
protocol
::
ipv6
);
}
}
}
}
std
::
stable_sort
(
std
::
begin
(
results
),
std
::
end
(
results
),
std
::
stable_sort
(
std
::
begin
(
results
),
std
::
end
(
results
),
...
...
libcaf_io/src/io/network/ip_endpoint.cpp
View file @
f4c5842b
...
@@ -24,17 +24,17 @@
...
@@ -24,17 +24,17 @@
#include "caf/sec.hpp"
#include "caf/sec.hpp"
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
# include <winsock2.h>
# include <windows.h>
# include <windows.h>
#
include <ws2tcpip
.h>
#
include <winsock2
.h>
# include <ws2ipdef.h>
# include <ws2ipdef.h>
# include <ws2tcpip.h>
#else
#else
# include <unistd.h>
# include <cerrno>
# include <arpa/inet.h>
# include <arpa/inet.h>
#
include <sys/socket.h
>
#
include <cerrno
>
# include <netinet/in.h>
# include <netinet/in.h>
# include <netinet/ip.h>
# include <netinet/ip.h>
# include <sys/socket.h>
# include <unistd.h>
#endif
#endif
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
...
@@ -91,7 +91,7 @@ void ip_endpoint::clear() {
...
@@ -91,7 +91,7 @@ void ip_endpoint::clear() {
ptr_
->
len
=
0
;
ptr_
->
len
=
0
;
}
}
void
ip_endpoint
::
impl_deleter
::
operator
()(
ip_endpoint
::
impl
*
ptr
)
const
{
void
ip_endpoint
::
impl_deleter
::
operator
()(
ip_endpoint
::
impl
*
ptr
)
const
{
delete
ptr
;
delete
ptr
;
}
}
...
@@ -126,8 +126,8 @@ size_t ep_hash::hash(const sockaddr_in6* sa) const noexcept {
...
@@ -126,8 +126,8 @@ size_t ep_hash::hash(const sockaddr_in6* sa) const noexcept {
bool
operator
==
(
const
ip_endpoint
&
lhs
,
const
ip_endpoint
&
rhs
)
{
bool
operator
==
(
const
ip_endpoint
&
lhs
,
const
ip_endpoint
&
rhs
)
{
auto
same
=
false
;
auto
same
=
false
;
if
(
*
lhs
.
clength
()
==
*
rhs
.
clength
()
&&
if
(
*
lhs
.
clength
()
==
*
rhs
.
clength
()
lhs
.
caddress
()
->
sa_family
==
rhs
.
caddress
()
->
sa_family
)
{
&&
lhs
.
caddress
()
->
sa_family
==
rhs
.
caddress
()
->
sa_family
)
{
switch
(
lhs
.
caddress
()
->
sa_family
)
{
switch
(
lhs
.
caddress
()
->
sa_family
)
{
case
AF_INET
:
{
case
AF_INET
:
{
auto
*
la
=
reinterpret_cast
<
const
sockaddr_in
*>
(
lhs
.
caddress
());
auto
*
la
=
reinterpret_cast
<
const
sockaddr_in
*>
(
lhs
.
caddress
());
...
@@ -158,15 +158,19 @@ std::string host(const ip_endpoint& ep) {
...
@@ -158,15 +158,19 @@ std::string host(const ip_endpoint& ep) {
char
addr
[
INET6_ADDRSTRLEN
];
char
addr
[
INET6_ADDRSTRLEN
];
if
(
*
ep
.
clength
()
==
0
)
if
(
*
ep
.
clength
()
==
0
)
return
""
;
return
""
;
switch
(
ep
.
caddress
()
->
sa_family
)
{
switch
(
ep
.
caddress
()
->
sa_family
)
{
case
AF_INET
:
case
AF_INET
:
inet_ntop
(
AF_INET
,
inet_ntop
(
AF_INET
,
&
const_cast
<
sockaddr_in
*>
(
reinterpret_cast
<
const
sockaddr_in
*>
(
ep
.
caddress
()))
->
sin_addr
,
&
const_cast
<
sockaddr_in
*>
(
reinterpret_cast
<
const
sockaddr_in
*>
(
ep
.
caddress
()))
->
sin_addr
,
addr
,
static_cast
<
socket_size_type
>
(
*
ep
.
clength
()));
addr
,
static_cast
<
socket_size_type
>
(
*
ep
.
clength
()));
break
;
break
;
case
AF_INET6
:
case
AF_INET6
:
inet_ntop
(
AF_INET6
,
inet_ntop
(
AF_INET6
,
&
const_cast
<
sockaddr_in6
*>
(
reinterpret_cast
<
const
sockaddr_in6
*>
(
ep
.
caddress
()))
->
sin6_addr
,
&
const_cast
<
sockaddr_in6
*>
(
reinterpret_cast
<
const
sockaddr_in6
*>
(
ep
.
caddress
()))
->
sin6_addr
,
addr
,
static_cast
<
socket_size_type
>
(
*
ep
.
clength
()));
addr
,
static_cast
<
socket_size_type
>
(
*
ep
.
clength
()));
break
;
break
;
default:
default:
...
@@ -180,12 +184,14 @@ uint16_t port(const ip_endpoint& ep) {
...
@@ -180,12 +184,14 @@ uint16_t port(const ip_endpoint& ep) {
uint16_t
port
=
0
;
uint16_t
port
=
0
;
if
(
*
ep
.
clength
()
==
0
)
if
(
*
ep
.
clength
()
==
0
)
return
0
;
return
0
;
switch
(
ep
.
caddress
()
->
sa_family
)
{
switch
(
ep
.
caddress
()
->
sa_family
)
{
case
AF_INET
:
case
AF_INET
:
port
=
ntohs
(
reinterpret_cast
<
const
sockaddr_in
*>
(
ep
.
caddress
())
->
sin_port
);
port
=
ntohs
(
reinterpret_cast
<
const
sockaddr_in
*>
(
ep
.
caddress
())
->
sin_port
);
break
;
break
;
case
AF_INET6
:
case
AF_INET6
:
port
=
ntohs
(
reinterpret_cast
<
const
sockaddr_in6
*>
(
ep
.
caddress
())
->
sin6_port
);
port
=
ntohs
(
reinterpret_cast
<
const
sockaddr_in6
*>
(
ep
.
caddress
())
->
sin6_port
);
break
;
break
;
default:
default:
// nop
// nop
...
@@ -200,12 +206,12 @@ uint32_t family(const ip_endpoint& ep) {
...
@@ -200,12 +206,12 @@ uint32_t family(const ip_endpoint& ep) {
return
ep
.
caddress
()
->
sa_family
;
return
ep
.
caddress
()
->
sa_family
;
}
}
error
load_endpoint
(
ip_endpoint
&
ep
,
uint32_t
&
f
,
std
::
string
&
h
,
error
load_endpoint
(
ip_endpoint
&
ep
,
uint32_t
&
f
,
std
::
string
&
h
,
uint16_t
&
p
,
uint16_t
&
p
,
size_t
&
l
)
{
size_t
&
l
)
{
ep
.
clear
();
ep
.
clear
();
if
(
l
>
0
)
{
if
(
l
>
0
)
{
*
ep
.
length
()
=
l
;
*
ep
.
length
()
=
l
;
switch
(
f
)
{
switch
(
f
)
{
case
AF_INET
:
{
case
AF_INET
:
{
auto
*
addr
=
reinterpret_cast
<
sockaddr_in
*>
(
ep
.
address
());
auto
*
addr
=
reinterpret_cast
<
sockaddr_in
*>
(
ep
.
address
());
inet_pton
(
AF_INET
,
h
.
c_str
(),
&
addr
->
sin_addr
);
inet_pton
(
AF_INET
,
h
.
c_str
(),
&
addr
->
sin_addr
);
...
@@ -227,8 +233,8 @@ error load_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h,
...
@@ -227,8 +233,8 @@ error load_endpoint(ip_endpoint& ep, uint32_t& f, std::string& h,
return
none
;
return
none
;
}
}
error
save_endpoint
(
ip_endpoint
&
ep
,
uint32_t
&
f
,
std
::
string
&
h
,
error
save_endpoint
(
ip_endpoint
&
ep
,
uint32_t
&
f
,
std
::
string
&
h
,
uint16_t
&
p
,
uint16_t
&
p
,
size_t
&
l
)
{
size_t
&
l
)
{
if
(
*
ep
.
length
()
>
0
)
{
if
(
*
ep
.
length
()
>
0
)
{
f
=
family
(
ep
);
f
=
family
(
ep
);
h
=
host
(
ep
);
h
=
host
(
ep
);
...
...
libcaf_io/src/io/network/manager.cpp
View file @
f4c5842b
...
@@ -57,8 +57,8 @@ void manager::detach(execution_unit*, bool invoke_disconnect_message) {
...
@@ -57,8 +57,8 @@ void manager::detach(execution_unit*, bool invoke_disconnect_message) {
ptr
.
swap
(
parent_
);
ptr
.
swap
(
parent_
);
detach_from
(
raw_ptr
);
detach_from
(
raw_ptr
);
if
(
invoke_disconnect_message
)
{
if
(
invoke_disconnect_message
)
{
auto
mptr
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
auto
mptr
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
{},
{},
detach_message
());
detach_message
());
switch
(
raw_ptr
->
consume
(
*
mptr
))
{
switch
(
raw_ptr
->
consume
(
*
mptr
))
{
case
im_success
:
case
im_success
:
raw_ptr
->
finalize
();
raw_ptr
->
finalize
();
...
...
libcaf_io/src/io/network/multiplexer.cpp
View file @
f4c5842b
...
@@ -24,8 +24,7 @@ namespace io {
...
@@ -24,8 +24,7 @@ namespace io {
namespace
network
{
namespace
network
{
multiplexer
::
multiplexer
(
actor_system
*
sys
)
multiplexer
::
multiplexer
(
actor_system
*
sys
)
:
execution_unit
(
sys
),
:
execution_unit
(
sys
),
tid_
(
std
::
this_thread
::
get_id
())
{
tid_
(
std
::
this_thread
::
get_id
())
{
// nop
// nop
}
}
...
...
libcaf_io/src/io/network/native_socket.cpp
View file @
f4c5842b
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
#include "caf/io/network/native_socket.hpp"
#include "caf/io/network/native_socket.hpp"
#include "caf/sec.hpp"
#include "caf/logger.hpp"
#include "caf/logger.hpp"
#include "caf/sec.hpp"
#include "caf/detail/call_cfun.hpp"
#include "caf/detail/call_cfun.hpp"
...
@@ -39,19 +39,19 @@
...
@@ -39,19 +39,19 @@
# define WINVER WindowsVista
# define WINVER WindowsVista
# include <w32api.h>
# include <w32api.h>
# endif
# endif
# include <winsock2.h>
# include <windows.h>
# include <windows.h>
#
include <ws2tcpip
.h>
#
include <winsock2
.h>
# include <ws2ipdef.h>
# include <ws2ipdef.h>
# include <ws2tcpip.h>
#else
#else
# include <arpa/inet.h>
# include <cerrno>
# include <cerrno>
# include <fcntl.h>
# include <fcntl.h>
# include <unistd.h>
# include <arpa/inet.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <netinet/in.h>
# include <netinet/ip.h>
# include <netinet/ip.h>
# include <netinet/tcp.h>
# include <netinet/tcp.h>
# include <sys/socket.h>
# include <unistd.h>
#endif
#endif
using
std
::
string
;
using
std
::
string
;
...
@@ -66,7 +66,8 @@ auto port_of(sockaddr_in6& what) -> decltype(what.sin6_port)& {
...
@@ -66,7 +66,8 @@ auto port_of(sockaddr_in6& what) -> decltype(what.sin6_port)& {
return
what
.
sin6_port
;
return
what
.
sin6_port
;
}
}
auto
port_of
(
sockaddr
&
what
)
->
decltype
(
port_of
(
std
::
declval
<
sockaddr_in
&>
()))
{
auto
port_of
(
sockaddr
&
what
)
->
decltype
(
port_of
(
std
::
declval
<
sockaddr_in
&>
()))
{
switch
(
what
.
sa_family
)
{
switch
(
what
.
sa_family
)
{
case
AF_INET
:
case
AF_INET
:
return
port_of
(
reinterpret_cast
<
sockaddr_in
&>
(
what
));
return
port_of
(
reinterpret_cast
<
sockaddr_in
&>
(
what
));
...
@@ -85,71 +86,70 @@ namespace io {
...
@@ -85,71 +86,70 @@ namespace io {
namespace
network
{
namespace
network
{
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
const
int
ec_out_of_memory
=
WSAENOBUFS
;
const
int
ec_out_of_memory
=
WSAENOBUFS
;
const
int
ec_interrupted_syscall
=
WSAEINTR
;
const
int
ec_interrupted_syscall
=
WSAEINTR
;
#else
#else
const
int
ec_out_of_memory
=
ENOMEM
;
const
int
ec_out_of_memory
=
ENOMEM
;
const
int
ec_interrupted_syscall
=
EINTR
;
const
int
ec_interrupted_syscall
=
EINTR
;
#endif
#endif
// platform-dependent SIGPIPE setup
// platform-dependent SIGPIPE setup
#if defined(CAF_MACOS) || defined(CAF_IOS) || defined(CAF_BSD)
#if defined(CAF_MACOS) || defined(CAF_IOS) || defined(CAF_BSD)
// Use the socket option but no flags to recv/send on macOS/iOS/BSD.
// Use the socket option but no flags to recv/send on macOS/iOS/BSD.
const
int
no_sigpipe_socket_flag
=
SO_NOSIGPIPE
;
const
int
no_sigpipe_socket_flag
=
SO_NOSIGPIPE
;
const
int
no_sigpipe_io_flag
=
0
;
const
int
no_sigpipe_io_flag
=
0
;
#elif defined(CAF_WINDOWS)
#elif defined(CAF_WINDOWS)
// Do nothing on Windows (SIGPIPE does not exist).
// Do nothing on Windows (SIGPIPE does not exist).
const
int
no_sigpipe_socket_flag
=
0
;
const
int
no_sigpipe_socket_flag
=
0
;
const
int
no_sigpipe_io_flag
=
0
;
const
int
no_sigpipe_io_flag
=
0
;
#else
#else
// Use flags to recv/send on Linux/Android but no socket option.
// Use flags to recv/send on Linux/Android but no socket option.
const
int
no_sigpipe_socket_flag
=
0
;
const
int
no_sigpipe_socket_flag
=
0
;
const
int
no_sigpipe_io_flag
=
MSG_NOSIGNAL
;
const
int
no_sigpipe_io_flag
=
MSG_NOSIGNAL
;
#endif
#endif
#ifndef CAF_WINDOWS
#ifndef CAF_WINDOWS
int
last_socket_error
()
{
int
last_socket_error
()
{
return
errno
;
return
errno
;
}
}
void
close_socket
(
native_socket
fd
)
{
void
close_socket
(
native_socket
fd
)
{
close
(
fd
);
close
(
fd
);
}
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
EAGAIN
||
errcode
==
EWOULDBLOCK
;
return
errcode
==
EAGAIN
||
errcode
==
EWOULDBLOCK
;
}
}
string
last_socket_error_as_string
()
{
string
last_socket_error_as_string
()
{
return
strerror
(
errno
);
return
strerror
(
errno
);
}
}
string
socket_error_as_string
(
int
errcode
)
{
string
socket_error_as_string
(
int
errcode
)
{
return
strerror
(
errcode
);
return
strerror
(
errcode
);
}
}
expected
<
void
>
child_process_inherit
(
native_socket
fd
,
bool
new_value
)
{
expected
<
void
>
child_process_inherit
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
// read flags for fd
// read flags for fd
CALL_CFUN
(
rf
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_GETFD
));
CALL_CFUN
(
rf
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_GETFD
));
// calculate and set new flags
// calculate and set new flags
auto
wf
=
(
!
new_value
)
?
(
rf
|
FD_CLOEXEC
)
:
(
rf
&
(
~
(
FD_CLOEXEC
)));
auto
wf
=
(
!
new_value
)
?
(
rf
|
FD_CLOEXEC
)
:
(
rf
&
(
~
(
FD_CLOEXEC
)));
CALL_CFUN
(
set_res
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_SETFD
,
wf
));
CALL_CFUN
(
set_res
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_SETFD
,
wf
));
return
unit
;
return
unit
;
}
}
expected
<
void
>
keepalive
(
native_socket
fd
,
bool
new_value
)
{
expected
<
void
>
keepalive
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
int
value
=
new_value
?
1
:
0
;
int
value
=
new_value
?
1
:
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_KEEPALIVE
,
&
value
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_KEEPALIVE
,
&
value
,
static_cast
<
unsigned
>
(
sizeof
(
value
))));
static_cast
<
unsigned
>
(
sizeof
(
value
))));
return
unit
;
return
unit
;
}
}
expected
<
void
>
nonblocking
(
native_socket
fd
,
bool
new_value
)
{
expected
<
void
>
nonblocking
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
// read flags for fd
// read flags for fd
CALL_CFUN
(
rf
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_GETFL
,
0
));
CALL_CFUN
(
rf
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_GETFL
,
0
));
...
@@ -157,9 +157,9 @@ namespace network {
...
@@ -157,9 +157,9 @@ namespace network {
auto
wf
=
new_value
?
(
rf
|
O_NONBLOCK
)
:
(
rf
&
(
~
(
O_NONBLOCK
)));
auto
wf
=
new_value
?
(
rf
|
O_NONBLOCK
)
:
(
rf
&
(
~
(
O_NONBLOCK
)));
CALL_CFUN
(
set_res
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_SETFL
,
wf
));
CALL_CFUN
(
set_res
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_SETFL
,
wf
));
return
unit
;
return
unit
;
}
}
expected
<
void
>
allow_sigpipe
(
native_socket
fd
,
bool
new_value
)
{
expected
<
void
>
allow_sigpipe
(
native_socket
fd
,
bool
new_value
)
{
if
(
no_sigpipe_socket_flag
!=
0
)
{
if
(
no_sigpipe_socket_flag
!=
0
)
{
int
value
=
new_value
?
0
:
1
;
int
value
=
new_value
?
0
:
1
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
...
@@ -167,14 +167,14 @@ namespace network {
...
@@ -167,14 +167,14 @@ namespace network {
static_cast
<
unsigned
>
(
sizeof
(
value
))));
static_cast
<
unsigned
>
(
sizeof
(
value
))));
}
}
return
unit
;
return
unit
;
}
}
expected
<
void
>
allow_udp_connreset
(
native_socket
,
bool
)
{
expected
<
void
>
allow_udp_connreset
(
native_socket
,
bool
)
{
// nop; SIO_UDP_CONNRESET only exists on Windows
// nop; SIO_UDP_CONNRESET only exists on Windows
return
unit
;
return
unit
;
}
}
std
::
pair
<
native_socket
,
native_socket
>
create_pipe
()
{
std
::
pair
<
native_socket
,
native_socket
>
create_pipe
()
{
int
pipefds
[
2
];
int
pipefds
[
2
];
if
(
pipe
(
pipefds
)
!=
0
)
{
if
(
pipe
(
pipefds
)
!=
0
)
{
perror
(
"pipe"
);
perror
(
"pipe"
);
...
@@ -184,29 +184,29 @@ namespace network {
...
@@ -184,29 +184,29 @@ namespace network {
child_process_inherit
(
pipefds
[
0
],
false
);
child_process_inherit
(
pipefds
[
0
],
false
);
child_process_inherit
(
pipefds
[
1
],
false
);
child_process_inherit
(
pipefds
[
1
],
false
);
return
{
pipefds
[
0
],
pipefds
[
1
]};
return
{
pipefds
[
0
],
pipefds
[
1
]};
}
}
#else // CAF_WINDOWS
#else // CAF_WINDOWS
int
last_socket_error
()
{
int
last_socket_error
()
{
return
WSAGetLastError
();
return
WSAGetLastError
();
}
}
void
close_socket
(
native_socket
fd
)
{
void
close_socket
(
native_socket
fd
)
{
closesocket
(
fd
);
closesocket
(
fd
);
}
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
WSAEWOULDBLOCK
||
errcode
==
WSATRY_AGAIN
;
return
errcode
==
WSAEWOULDBLOCK
||
errcode
==
WSATRY_AGAIN
;
}
}
string
last_socket_error_as_string
()
{
string
last_socket_error_as_string
()
{
return
socket_error_as_string
(
last_socket_error
());
return
socket_error_as_string
(
last_socket_error
());
}
}
string
socket_error_as_string
(
int
errcode
)
{
string
socket_error_as_string
(
int
errcode
)
{
LPTSTR
errorText
=
NULL
;
LPTSTR
errorText
=
NULL
;
FormatMessage
(
// use system message tables to retrieve error text
FormatMessage
(
// use system message tables to retrieve error text
FORMAT_MESSAGE_FROM_SYSTEM
FORMAT_MESSAGE_FROM_SYSTEM
// allocate buffer on local heap for error text
// allocate buffer on local heap for error text
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
...
@@ -215,7 +215,7 @@ namespace network {
...
@@ -215,7 +215,7 @@ namespace network {
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
nullptr
,
// unused with FORMAT_MESSAGE_FROM_SYSTEM
nullptr
,
// unused with FORMAT_MESSAGE_FROM_SYSTEM
errcode
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
errcode
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
(
LPTSTR
)
&
errorText
,
// output
(
LPTSTR
)
&
errorText
,
// output
0
,
// minimum size for output buffer
0
,
// minimum size for output buffer
nullptr
);
// arguments - see note
nullptr
);
// arguments - see note
string
result
;
string
result
;
...
@@ -225,43 +225,43 @@ namespace network {
...
@@ -225,43 +225,43 @@ namespace network {
LocalFree
(
errorText
);
LocalFree
(
errorText
);
}
}
return
result
;
return
result
;
}
}
expected
<
void
>
child_process_inherit
(
native_socket
fd
,
bool
new_value
)
{
expected
<
void
>
child_process_inherit
(
native_socket
fd
,
bool
new_value
)
{
// nop; FIXME: possible to implement via SetHandleInformation ?
// nop; FIXME: possible to implement via SetHandleInformation ?
return
unit
;
return
unit
;
}
}
expected
<
void
>
keepalive
(
native_socket
fd
,
bool
new_value
)
{
expected
<
void
>
keepalive
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
char
value
=
new_value
?
1
:
0
;
char
value
=
new_value
?
1
:
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_KEEPALIVE
,
&
value
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_KEEPALIVE
,
&
value
,
static_cast
<
int
>
(
sizeof
(
value
))));
static_cast
<
int
>
(
sizeof
(
value
))));
return
unit
;
return
unit
;
}
}
expected
<
void
>
nonblocking
(
native_socket
fd
,
bool
new_value
)
{
expected
<
void
>
nonblocking
(
native_socket
fd
,
bool
new_value
)
{
u_long
mode
=
new_value
?
1
:
0
;
u_long
mode
=
new_value
?
1
:
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"ioctlsocket"
,
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"ioctlsocket"
,
ioctlsocket
(
fd
,
FIONBIO
,
&
mode
));
ioctlsocket
(
fd
,
FIONBIO
,
&
mode
));
return
unit
;
return
unit
;
}
}
expected
<
void
>
allow_sigpipe
(
native_socket
,
bool
)
{
expected
<
void
>
allow_sigpipe
(
native_socket
,
bool
)
{
// nop; SIGPIPE does not exist on Windows
// nop; SIGPIPE does not exist on Windows
return
unit
;
return
unit
;
}
}
expected
<
void
>
allow_udp_connreset
(
native_socket
fd
,
bool
new_value
)
{
expected
<
void
>
allow_udp_connreset
(
native_socket
fd
,
bool
new_value
)
{
DWORD
bytes_returned
=
0
;
DWORD
bytes_returned
=
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"WSAIoctl"
,
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"WSAIoctl"
,
WSAIoctl
(
fd
,
_WSAIOW
(
IOC_VENDOR
,
12
),
&
new_value
,
sizeof
(
new_value
),
WSAIoctl
(
fd
,
_WSAIOW
(
IOC_VENDOR
,
12
),
&
new_value
,
sizeof
(
new_value
),
NULL
,
0
,
&
bytes_returned
,
NULL
,
NULL
));
NULL
,
0
,
&
bytes_returned
,
NULL
,
NULL
));
return
unit
;
return
unit
;
}
}
/**************************************************************************\
/**************************************************************************\
* Based on work of others; *
* Based on work of others; *
* original header: *
* original header: *
* *
* *
...
@@ -292,7 +292,7 @@ namespace network {
...
@@ -292,7 +292,7 @@ namespace network {
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
\**************************************************************************/
\**************************************************************************/
std
::
pair
<
native_socket
,
native_socket
>
create_pipe
()
{
std
::
pair
<
native_socket
,
native_socket
>
create_pipe
()
{
socket_size_type
addrlen
=
sizeof
(
sockaddr_in
);
socket_size_type
addrlen
=
sizeof
(
sockaddr_in
);
native_socket
socks
[
2
]
=
{
invalid_native_socket
,
invalid_native_socket
};
native_socket
socks
[
2
]
=
{
invalid_native_socket
,
invalid_native_socket
};
CALL_CRITICAL_CFUN
(
listener
,
detail
::
cc_valid_socket
,
"socket"
,
CALL_CRITICAL_CFUN
(
listener
,
detail
::
cc_valid_socket
,
"socket"
,
...
@@ -344,7 +344,7 @@ namespace network {
...
@@ -344,7 +344,7 @@ namespace network {
close_socket
(
listener
);
close_socket
(
listener
);
guard
.
disable
();
guard
.
disable
();
return
std
::
make_pair
(
read_fd
,
write_fd
);
return
std
::
make_pair
(
read_fd
,
write_fd
);
}
}
#endif
#endif
...
@@ -392,20 +392,20 @@ expected<string> local_addr_of_fd(native_socket fd) {
...
@@ -392,20 +392,20 @@ expected<string> local_addr_of_fd(native_socket fd) {
socket_size_type
st_len
=
sizeof
(
st
);
socket_size_type
st_len
=
sizeof
(
st
);
sockaddr
*
sa
=
reinterpret_cast
<
sockaddr
*>
(
&
st
);
sockaddr
*
sa
=
reinterpret_cast
<
sockaddr
*>
(
&
st
);
CALL_CFUN
(
tmp1
,
detail
::
cc_zero
,
"getsockname"
,
getsockname
(
fd
,
sa
,
&
st_len
));
CALL_CFUN
(
tmp1
,
detail
::
cc_zero
,
"getsockname"
,
getsockname
(
fd
,
sa
,
&
st_len
));
char
addr
[
INET6_ADDRSTRLEN
]
{
0
};
char
addr
[
INET6_ADDRSTRLEN
]{
0
};
switch
(
sa
->
sa_family
)
{
switch
(
sa
->
sa_family
)
{
case
AF_INET
:
case
AF_INET
:
return
inet_ntop
(
AF_INET
,
&
reinterpret_cast
<
sockaddr_in
*>
(
sa
)
->
sin_addr
,
return
inet_ntop
(
AF_INET
,
&
reinterpret_cast
<
sockaddr_in
*>
(
sa
)
->
sin_addr
,
addr
,
sizeof
(
addr
));
addr
,
sizeof
(
addr
));
case
AF_INET6
:
case
AF_INET6
:
return
inet_ntop
(
AF_INET6
,
return
inet_ntop
(
AF_INET6
,
&
reinterpret_cast
<
sockaddr_in6
*>
(
sa
)
->
sin6_addr
,
&
reinterpret_cast
<
sockaddr_in6
*>
(
sa
)
->
sin6_addr
,
addr
,
addr
,
sizeof
(
addr
));
sizeof
(
addr
));
default:
default:
break
;
break
;
}
}
return
make_error
(
sec
::
invalid_protocol_family
,
return
make_error
(
sec
::
invalid_protocol_family
,
"local_addr_of_fd"
,
"local_addr_of_fd"
,
sa
->
sa_family
);
sa
->
sa_family
);
}
}
expected
<
uint16_t
>
local_port_of_fd
(
native_socket
fd
)
{
expected
<
uint16_t
>
local_port_of_fd
(
native_socket
fd
)
{
...
@@ -421,20 +421,20 @@ expected<string> remote_addr_of_fd(native_socket fd) {
...
@@ -421,20 +421,20 @@ expected<string> remote_addr_of_fd(native_socket fd) {
socket_size_type
st_len
=
sizeof
(
st
);
socket_size_type
st_len
=
sizeof
(
st
);
sockaddr
*
sa
=
reinterpret_cast
<
sockaddr
*>
(
&
st
);
sockaddr
*
sa
=
reinterpret_cast
<
sockaddr
*>
(
&
st
);
CALL_CFUN
(
tmp
,
detail
::
cc_zero
,
"getpeername"
,
getpeername
(
fd
,
sa
,
&
st_len
));
CALL_CFUN
(
tmp
,
detail
::
cc_zero
,
"getpeername"
,
getpeername
(
fd
,
sa
,
&
st_len
));
char
addr
[
INET6_ADDRSTRLEN
]
{
0
};
char
addr
[
INET6_ADDRSTRLEN
]{
0
};
switch
(
sa
->
sa_family
)
{
switch
(
sa
->
sa_family
)
{
case
AF_INET
:
case
AF_INET
:
return
inet_ntop
(
AF_INET
,
&
reinterpret_cast
<
sockaddr_in
*>
(
sa
)
->
sin_addr
,
return
inet_ntop
(
AF_INET
,
&
reinterpret_cast
<
sockaddr_in
*>
(
sa
)
->
sin_addr
,
addr
,
sizeof
(
addr
));
addr
,
sizeof
(
addr
));
case
AF_INET6
:
case
AF_INET6
:
return
inet_ntop
(
AF_INET6
,
return
inet_ntop
(
AF_INET6
,
&
reinterpret_cast
<
sockaddr_in6
*>
(
sa
)
->
sin6_addr
,
&
reinterpret_cast
<
sockaddr_in6
*>
(
sa
)
->
sin6_addr
,
addr
,
addr
,
sizeof
(
addr
));
sizeof
(
addr
));
default:
default:
break
;
break
;
}
}
return
make_error
(
sec
::
invalid_protocol_family
,
return
make_error
(
sec
::
invalid_protocol_family
,
"remote_addr_of_fd"
,
"remote_addr_of_fd"
,
sa
->
sa_family
);
sa
->
sa_family
);
}
}
expected
<
uint16_t
>
remote_port_of_fd
(
native_socket
fd
)
{
expected
<
uint16_t
>
remote_port_of_fd
(
native_socket
fd
)
{
...
...
libcaf_io/src/io/network/pipe_reader.cpp
View file @
f4c5842b
...
@@ -20,14 +20,14 @@
...
@@ -20,14 +20,14 @@
#include <cstdint>
#include <cstdint>
#include "caf/io/network/pipe_reader.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/pipe_reader.hpp"
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
# include <winsock2.h>
# include <winsock2.h>
#else
#else
# include <unistd.h>
# include <sys/socket.h>
# include <sys/socket.h>
# include <unistd.h>
#endif
#endif
namespace
caf
{
namespace
caf
{
...
@@ -50,12 +50,12 @@ void pipe_reader::graceful_shutdown() {
...
@@ -50,12 +50,12 @@ void pipe_reader::graceful_shutdown() {
resumable
*
pipe_reader
::
try_read_next
()
{
resumable
*
pipe_reader
::
try_read_next
()
{
std
::
intptr_t
ptrval
;
std
::
intptr_t
ptrval
;
// on windows, we actually have sockets, otherwise we have file handles
// on windows, we actually have sockets, otherwise we have file handles
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
auto
res
=
recv
(
fd
(),
reinterpret_cast
<
socket_recv_ptr
>
(
&
ptrval
),
auto
res
=
recv
(
fd
(),
reinterpret_cast
<
socket_recv_ptr
>
(
&
ptrval
),
sizeof
(
ptrval
),
0
);
sizeof
(
ptrval
),
0
);
#
else
#else
auto
res
=
read
(
fd
(),
&
ptrval
,
sizeof
(
ptrval
));
auto
res
=
read
(
fd
(),
&
ptrval
,
sizeof
(
ptrval
));
#
endif
#endif
if
(
res
!=
sizeof
(
ptrval
))
if
(
res
!=
sizeof
(
ptrval
))
return
nullptr
;
return
nullptr
;
return
reinterpret_cast
<
resumable
*>
(
ptrval
);
return
reinterpret_cast
<
resumable
*>
(
ptrval
);
...
...
libcaf_io/src/io/network/protocol.cpp
View file @
f4c5842b
...
@@ -33,4 +33,3 @@ std::string to_string(const protocol& x) {
...
@@ -33,4 +33,3 @@ std::string to_string(const protocol& x) {
}
// namespace network
}
// namespace network
}
// namespace io
}
// namespace io
}
// namespace caf
}
// namespace caf
libcaf_io/src/io/network/receive_buffer.cpp
View file @
f4c5842b
...
@@ -33,9 +33,7 @@ namespace io {
...
@@ -33,9 +33,7 @@ namespace io {
namespace
network
{
namespace
network
{
receive_buffer
::
receive_buffer
()
noexcept
receive_buffer
::
receive_buffer
()
noexcept
:
buffer_
(
nullptr
),
:
buffer_
(
nullptr
),
capacity_
(
0
),
size_
(
0
)
{
capacity_
(
0
),
size_
(
0
)
{
// nop
// nop
}
}
...
@@ -126,7 +124,8 @@ void receive_buffer::shrink_by(size_t bytes) {
...
@@ -126,7 +124,8 @@ void receive_buffer::shrink_by(size_t bytes) {
capacity_
=
new_size
;
capacity_
=
new_size
;
}
}
receive_buffer
::
iterator
receive_buffer
::
insert
(
iterator
pos
,
value_type
value
)
{
receive_buffer
::
iterator
receive_buffer
::
insert
(
iterator
pos
,
value_type
value
)
{
if
(
size_
==
capacity_
)
{
if
(
size_
==
capacity_
)
{
auto
dist
=
(
pos
==
nullptr
)
?
0
:
std
::
distance
(
begin
(),
pos
);
auto
dist
=
(
pos
==
nullptr
)
?
0
:
std
::
distance
(
begin
(),
pos
);
increase_by
(
std
::
max
(
capacity_
,
min_size
));
increase_by
(
std
::
max
(
capacity_
,
min_size
));
...
@@ -138,6 +137,6 @@ receive_buffer::iterator receive_buffer::insert(iterator pos, value_type value)
...
@@ -138,6 +137,6 @@ receive_buffer::iterator receive_buffer::insert(iterator pos, value_type value)
return
pos
;
return
pos
;
}
}
}
// name
ps
ace network
}
// name
sp
ace network
}
// namespace io
}
// namespace io
}
// namespace caf
}
// namespace caf
libcaf_io/src/io/network/scribe_impl.cpp
View file @
f4c5842b
libcaf_io/src/io/network/stream.cpp
View file @
f4c5842b
...
@@ -32,8 +32,8 @@ namespace network {
...
@@ -32,8 +32,8 @@ namespace network {
stream
::
stream
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
stream
::
stream
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
:
event_handler
(
backend_ref
,
sockfd
),
:
event_handler
(
backend_ref
,
sockfd
),
max_consecutive_reads_
(
max_consecutive_reads_
(
get_or
(
backend
().
system
().
config
(),
get_or
(
backend
().
system
().
config
(),
"middleman.max-consecutive-reads"
,
"middleman.max-consecutive-reads"
,
defaults
::
middleman
::
max_consecutive_reads
)),
defaults
::
middleman
::
max_consecutive_reads
)),
read_threshold_
(
1
),
read_threshold_
(
1
),
collected_
(
0
),
collected_
(
0
),
...
@@ -80,9 +80,13 @@ void stream::flush(const manager_ptr& mgr) {
...
@@ -80,9 +80,13 @@ void stream::flush(const manager_ptr& mgr) {
void
stream
::
removed_from_loop
(
operation
op
)
{
void
stream
::
removed_from_loop
(
operation
op
)
{
CAF_LOG_TRACE
(
CAF_ARG2
(
"fd"
,
fd_
)
<<
CAF_ARG
(
op
));
CAF_LOG_TRACE
(
CAF_ARG2
(
"fd"
,
fd_
)
<<
CAF_ARG
(
op
));
switch
(
op
)
{
switch
(
op
)
{
case
operation
:
:
read
:
reader_
.
reset
();
break
;
case
operation
:
:
read
:
case
operation
:
:
write
:
writer_
.
reset
();
break
;
reader_
.
reset
();
case
operation
:
:
propagate_error
:
;
// nop
break
;
case
operation
:
:
write
:
writer_
.
reset
();
break
;
case
operation
:
:
propagate_error
:
;
// nop
}
}
}
}
...
@@ -159,8 +163,7 @@ bool stream::handle_read_result(rw_state read_result, size_t rb) {
...
@@ -159,8 +163,7 @@ bool stream::handle_read_result(rw_state read_result, size_t rb) {
return
false
;
return
false
;
collected_
+=
rb
;
collected_
+=
rb
;
if
(
collected_
>=
read_threshold_
)
{
if
(
collected_
>=
read_threshold_
)
{
auto
res
=
reader_
->
consume
(
&
backend
(),
rd_buf_
.
data
(),
auto
res
=
reader_
->
consume
(
&
backend
(),
rd_buf_
.
data
(),
collected_
);
collected_
);
prepare_next_read
();
prepare_next_read
();
if
(
!
res
)
{
if
(
!
res
)
{
passivate
();
passivate
();
...
...
libcaf_io/src/io/network/test_multiplexer.cpp
View file @
f4c5842b
...
@@ -47,14 +47,11 @@ test_multiplexer::scribe_data::scribe_data(shared_buffer_type input,
...
@@ -47,14 +47,11 @@ test_multiplexer::scribe_data::scribe_data(shared_buffer_type input,
}
}
test_multiplexer
::
doorman_data
::
doorman_data
()
test_multiplexer
::
doorman_data
::
doorman_data
()
:
port
(
0
),
:
port
(
0
),
stopped_reading
(
false
),
passive_mode
(
false
)
{
stopped_reading
(
false
),
passive_mode
(
false
)
{
// nop
// nop
}
}
test_multiplexer
::
datagram_data
::
test_multiplexer
::
datagram_data
::
datagram_data
(
shared_job_queue_type
input
,
datagram_data
(
shared_job_queue_type
input
,
shared_job_queue_type
output
)
shared_job_queue_type
output
)
:
vn_buf_ptr
(
std
::
move
(
input
)),
:
vn_buf_ptr
(
std
::
move
(
input
)),
wr_buf_ptr
(
std
::
move
(
output
)),
wr_buf_ptr
(
std
::
move
(
output
)),
...
@@ -71,9 +68,7 @@ test_multiplexer::datagram_data::
...
@@ -71,9 +68,7 @@ test_multiplexer::datagram_data::
}
}
test_multiplexer
::
test_multiplexer
(
actor_system
*
sys
)
test_multiplexer
::
test_multiplexer
(
actor_system
*
sys
)
:
multiplexer
(
sys
),
:
multiplexer
(
sys
),
inline_runnables_
(
0
),
servant_ids_
(
0
)
{
inline_runnables_
(
0
),
servant_ids_
(
0
)
{
CAF_ASSERT
(
sys
!=
nullptr
);
CAF_ASSERT
(
sys
!=
nullptr
);
}
}
...
@@ -126,6 +121,7 @@ scribe_ptr test_multiplexer::new_scribe(connection_handle hdl) {
...
@@ -126,6 +121,7 @@ scribe_ptr test_multiplexer::new_scribe(connection_handle hdl) {
void
remove_from_loop
()
override
{
void
remove_from_loop
()
override
{
mpx_
->
passive_mode
(
hdl
())
=
true
;
mpx_
->
passive_mode
(
hdl
())
=
true
;
}
}
private:
private:
test_multiplexer
*
mpx_
;
test_multiplexer
*
mpx_
;
};
};
...
@@ -203,6 +199,7 @@ doorman_ptr test_multiplexer::new_doorman(accept_handle hdl, uint16_t port) {
...
@@ -203,6 +199,7 @@ doorman_ptr test_multiplexer::new_doorman(accept_handle hdl, uint16_t port) {
void
remove_from_loop
()
override
{
void
remove_from_loop
()
override
{
mpx_
->
passive_mode
(
hdl
())
=
true
;
mpx_
->
passive_mode
(
hdl
())
=
true
;
}
}
private:
private:
test_multiplexer
*
mpx_
;
test_multiplexer
*
mpx_
;
};
};
...
@@ -251,14 +248,16 @@ expected<doorman_ptr> test_multiplexer::new_tcp_doorman(uint16_t desired_port,
...
@@ -251,14 +248,16 @@ expected<doorman_ptr> test_multiplexer::new_tcp_doorman(uint16_t desired_port,
datagram_servant_ptr
test_multiplexer
::
new_datagram_servant
(
native_socket
)
{
datagram_servant_ptr
test_multiplexer
::
new_datagram_servant
(
native_socket
)
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_CRITICAL
(
"test_multiplexer::new_datagram_servant called with native socket"
);
CAF_CRITICAL
(
"test_multiplexer::new_datagram_servant called with native socket"
);
}
}
datagram_servant_ptr
datagram_servant_ptr
test_multiplexer
::
new_datagram_servant_for_endpoint
(
native_socket
,
test_multiplexer
::
new_datagram_servant_for_endpoint
(
native_socket
,
const
ip_endpoint
&
)
{
const
ip_endpoint
&
)
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_CRITICAL
(
"test_multiplexer::new_datagram_servant_for_endpoint called with "
CAF_CRITICAL
(
"test_multiplexer::new_datagram_servant_for_endpoint called with "
"native socket"
);
"native socket"
);
}
}
...
@@ -289,8 +288,8 @@ test_multiplexer::new_remote_udp_endpoint(const std::string& host,
...
@@ -289,8 +288,8 @@ test_multiplexer::new_remote_udp_endpoint(const std::string& host,
}
}
expected
<
datagram_servant_ptr
>
expected
<
datagram_servant_ptr
>
test_multiplexer
::
new_local_udp_endpoint
(
uint16_t
desired_port
,
test_multiplexer
::
new_local_udp_endpoint
(
uint16_t
desired_port
,
const
char
*
,
const
char
*
,
bool
)
{
bool
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
desired_port
));
CAF_LOG_TRACE
(
CAF_ARG
(
desired_port
));
datagram_handle
hdl
;
datagram_handle
hdl
;
uint16_t
port
=
0
;
uint16_t
port
=
0
;
...
@@ -355,8 +354,7 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
...
@@ -355,8 +354,7 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
buf
.
first
=
dh
;
buf
.
first
=
dh
;
return
buf
.
second
;
return
buf
.
second
;
}
}
void
enqueue_datagram
(
datagram_handle
dh
,
void
enqueue_datagram
(
datagram_handle
dh
,
std
::
vector
<
char
>
buf
)
override
{
std
::
vector
<
char
>
buf
)
override
{
auto
&
q
=
mpx_
->
output_queue
(
dh
);
auto
&
q
=
mpx_
->
output_queue
(
dh
);
q
.
emplace_back
(
dh
,
std
::
move
(
buf
));
q
.
emplace_back
(
dh
,
std
::
move
(
buf
));
}
}
...
@@ -398,7 +396,8 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
...
@@ -398,7 +396,8 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
mpx_
->
passive_mode
(
hdl
())
=
true
;
mpx_
->
passive_mode
(
hdl
())
=
true
;
}
}
void
add_endpoint
(
const
ip_endpoint
&
,
datagram_handle
)
override
{
void
add_endpoint
(
const
ip_endpoint
&
,
datagram_handle
)
override
{
CAF_CRITICAL
(
"datagram_servant impl::add_endpoint called with ip_endpoint"
);
CAF_CRITICAL
(
"datagram_servant impl::add_endpoint called with ip_endpoint"
);
}
}
void
remove_endpoint
(
datagram_handle
dh
)
override
{
void
remove_endpoint
(
datagram_handle
dh
)
override
{
auto
data
=
mpx_
->
data_for_hdl
(
hdl
());
auto
data
=
mpx_
->
data_for_hdl
(
hdl
());
...
@@ -417,6 +416,7 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
...
@@ -417,6 +416,7 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
data
->
servants
.
clear
();
data
->
servants
.
clear
();
data
->
servants
.
emplace
(
hdl
());
data
->
servants
.
emplace
(
hdl
());
}
}
private:
private:
test_multiplexer
*
mpx_
;
test_multiplexer
*
mpx_
;
};
};
...
@@ -442,7 +442,6 @@ int64_t test_multiplexer::next_endpoint_id() {
...
@@ -442,7 +442,6 @@ int64_t test_multiplexer::next_endpoint_id() {
return
servant_ids_
++
;
return
servant_ids_
++
;
}
}
bool
test_multiplexer
::
is_known_port
(
uint16_t
x
)
const
{
bool
test_multiplexer
::
is_known_port
(
uint16_t
x
)
const
{
auto
pred1
=
[
&
](
const
doorman_data_map
::
value_type
&
y
)
{
auto
pred1
=
[
&
](
const
doorman_data_map
::
value_type
&
y
)
{
return
x
==
y
.
second
.
port
;
return
x
==
y
.
second
.
port
;
...
@@ -472,7 +471,8 @@ bool test_multiplexer::is_known_handle(datagram_handle x) const {
...
@@ -472,7 +471,8 @@ bool test_multiplexer::is_known_handle(datagram_handle x) const {
};
};
return
datagram_data_
.
count
(
x
)
>
0
return
datagram_data_
.
count
(
x
)
>
0
||
std
::
any_of
(
local_endpoints_
.
begin
(),
local_endpoints_
.
end
(),
pred1
)
||
std
::
any_of
(
local_endpoints_
.
begin
(),
local_endpoints_
.
end
(),
pred1
)
||
std
::
any_of
(
remote_endpoints_
.
begin
(),
remote_endpoints_
.
end
(),
pred2
);
||
std
::
any_of
(
remote_endpoints_
.
begin
(),
remote_endpoints_
.
end
(),
pred2
);
}
}
auto
test_multiplexer
::
make_supervisor
()
->
supervisor_ptr
{
auto
test_multiplexer
::
make_supervisor
()
->
supervisor_ptr
{
...
@@ -682,7 +682,8 @@ void test_multiplexer::prepare_connection(accept_handle src,
...
@@ -682,7 +682,8 @@ void test_multiplexer::prepare_connection(accept_handle src,
CAF_RAISE_ERROR
(
"prepare_connection: peer handle already in use"
);
CAF_RAISE_ERROR
(
"prepare_connection: peer handle already in use"
);
CAF_LOG_INFO
(
"acceptor"
<<
src
<<
"has connection"
<<
hdl
CAF_LOG_INFO
(
"acceptor"
<<
src
<<
"has connection"
<<
hdl
<<
"ready for incoming connect from"
<<
host
<<
":"
<<
"ready for incoming connect from"
<<
host
<<
":"
<<
port
<<
"from peer with connection handle"
<<
peer_hdl
);
<<
port
<<
"from peer with connection handle"
<<
peer_hdl
);
if
(
doormen_
.
count
(
port
)
==
0
)
if
(
doormen_
.
count
(
port
)
==
0
)
provide_acceptor
(
port
,
src
);
provide_acceptor
(
port
,
src
);
add_pending_connect
(
src
,
hdl
);
add_pending_connect
(
src
,
hdl
);
...
@@ -711,8 +712,7 @@ bool test_multiplexer::has_pending_scribe(std::string x, uint16_t y) {
...
@@ -711,8 +712,7 @@ bool test_multiplexer::has_pending_scribe(std::string x, uint16_t y) {
return
scribes_
.
count
(
std
::
make_pair
(
std
::
move
(
x
),
y
))
>
0
;
return
scribes_
.
count
(
std
::
make_pair
(
std
::
move
(
x
),
y
))
>
0
;
}
}
bool
test_multiplexer
::
has_pending_remote_endpoint
(
std
::
string
x
,
bool
test_multiplexer
::
has_pending_remote_endpoint
(
std
::
string
x
,
uint16_t
y
)
{
uint16_t
y
)
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
guard_type
guard
{
mx_
};
guard_type
guard
{
mx_
};
return
remote_endpoints_
.
count
(
std
::
make_pair
(
std
::
move
(
x
),
y
))
>
0
;
return
remote_endpoints_
.
count
(
std
::
make_pair
(
std
::
move
(
x
),
y
))
>
0
;
...
@@ -894,7 +894,8 @@ bool test_multiplexer::read_data(datagram_handle hdl) {
...
@@ -894,7 +894,8 @@ bool test_multiplexer::read_data(datagram_handle hdl) {
return
false
;
return
false
;
auto
ditr
=
datagram_data_
.
find
(
hdl
);
auto
ditr
=
datagram_data_
.
find
(
hdl
);
if
(
ditr
==
datagram_data_
.
end
()
||
ditr
->
second
->
ptr
->
parent
()
==
nullptr
if
(
ditr
==
datagram_data_
.
end
()
||
ditr
->
second
->
ptr
->
parent
()
==
nullptr
||
!
ditr
->
second
->
ptr
->
parent
()
->
getf
(
abstract_actor
::
is_initialized_flag
))
||
!
ditr
->
second
->
ptr
->
parent
()
->
getf
(
abstract_actor
::
is_initialized_flag
))
return
false
;
return
false
;
auto
&
data
=
ditr
->
second
;
auto
&
data
=
ditr
->
second
;
if
(
data
->
vn_buf
.
back
().
second
.
empty
())
if
(
data
->
vn_buf
.
back
().
second
.
empty
())
...
@@ -1032,8 +1033,7 @@ void test_multiplexer::exec(resumable_ptr& ptr) {
...
@@ -1032,8 +1033,7 @@ void test_multiplexer::exec(resumable_ptr& ptr) {
case
resumable
:
:
awaiting_message
:
case
resumable
:
:
awaiting_message
:
intrusive_ptr_release
(
ptr
.
get
());
intrusive_ptr_release
(
ptr
.
get
());
break
;
break
;
default:
default:
;
// ignored
;
// ignored
}
}
}
}
...
...
libcaf_io/src/io/scribe.cpp
View file @
f4c5842b
...
@@ -71,10 +71,10 @@ void scribe::data_transferred(execution_unit* ctx, size_t written,
...
@@ -71,10 +71,10 @@ void scribe::data_transferred(execution_unit* ctx, size_t written,
mailbox_element
::
forwarding_stack
{},
mailbox_element
::
forwarding_stack
{},
transferred_t
{
hdl
(),
written
,
remaining
}};
transferred_t
{
hdl
(),
written
,
remaining
}};
invoke_mailbox_element_impl
(
ctx
,
tmp
);
invoke_mailbox_element_impl
(
ctx
,
tmp
);
//data_transferred_msg tmp{hdl(), written, remaining};
//
data_transferred_msg tmp{hdl(), written, remaining};
//auto ptr = make_mailbox_element(nullptr, invalid_message_id, {}, tmp);
//
auto ptr = make_mailbox_element(nullptr, invalid_message_id, {}, tmp);
//parent()->context(ctx);
//
parent()->context(ctx);
//parent()->consume(std::move(ptr));
//
parent()->consume(std::move(ptr));
}
}
}
// namespace io
}
// namespace io
...
...
libcaf_io/src/policy/tcp.cpp
View file @
f4c5842b
...
@@ -26,17 +26,17 @@
...
@@ -26,17 +26,17 @@
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
# include <winsock2.h>
# include <winsock2.h>
#else
#else
# include <sys/types.h>
# include <sys/socket.h>
# include <sys/socket.h>
# include <sys/types.h>
#endif
#endif
using
caf
::
io
::
network
::
is_error
;
using
caf
::
io
::
network
::
is_error
;
using
caf
::
io
::
network
::
rw_state
;
using
caf
::
io
::
network
::
native_socket
;
using
caf
::
io
::
network
::
socket_size_type
;
using
caf
::
io
::
network
::
last_socket_error
;
using
caf
::
io
::
network
::
last_socket_error
;
using
caf
::
io
::
network
::
native_socket
;
using
caf
::
io
::
network
::
no_sigpipe_io_flag
;
using
caf
::
io
::
network
::
no_sigpipe_io_flag
;
using
caf
::
io
::
network
::
rw_state
;
using
caf
::
io
::
network
::
socket_error_as_string
;
using
caf
::
io
::
network
::
socket_error_as_string
;
using
caf
::
io
::
network
::
socket_size_type
;
namespace
caf
{
namespace
caf
{
namespace
policy
{
namespace
policy
{
...
...
libcaf_io/test/io/basp_broker.cpp
View file @
f4c5842b
...
@@ -37,7 +37,7 @@ namespace {
...
@@ -37,7 +37,7 @@ namespace {
using
caf
::
make_message_id
;
using
caf
::
make_message_id
;
struct
anything
{
};
struct
anything
{};
anything
any_vals
;
anything
any_vals
;
...
@@ -92,7 +92,9 @@ struct node {
...
@@ -92,7 +92,9 @@ struct node {
std
::
string
name
;
std
::
string
name
;
node_id
id
;
node_id
id
;
connection_handle
connection
;
connection_handle
connection
;
union
{
scoped_actor
dummy_actor
;
};
union
{
scoped_actor
dummy_actor
;
};
node
()
{
node
()
{
// nop
// nop
...
@@ -257,13 +259,13 @@ public:
...
@@ -257,13 +259,13 @@ public:
return
{
hdr
,
std
::
move
(
payload
)};
return
{
hdr
,
std
::
move
(
payload
)};
}
}
void
connect_node
(
node
&
n
,
void
connect_node
(
optional
<
accept_handle
>
ax
=
none
,
node
&
n
,
optional
<
accept_handle
>
ax
=
none
,
actor_id
published_actor_id
=
invalid_actor_id
,
actor_id
published_actor_id
=
invalid_actor_id
,
const
set
<
string
>&
published_actor_ifs
=
std
::
set
<
std
::
string
>
{})
{
const
set
<
string
>&
published_actor_ifs
=
std
::
set
<
std
::
string
>
{})
{
auto
src
=
ax
?
*
ax
:
ahdl_
;
auto
src
=
ax
?
*
ax
:
ahdl_
;
CAF_MESSAGE
(
"connect remote node "
<<
n
.
name
CAF_MESSAGE
(
"connect remote node "
<<
", connection ID = "
<<
n
.
connection
.
id
()
<<
n
.
name
<<
", connection ID = "
<<
n
.
connection
.
id
()
<<
", acceptor ID = "
<<
src
.
id
());
<<
", acceptor ID = "
<<
src
.
id
());
auto
hdl
=
n
.
connection
;
auto
hdl
=
n
.
connection
;
mpx_
->
add_pending_connect
(
src
,
hdl
);
mpx_
->
add_pending_connect
(
src
,
hdl
);
...
@@ -339,13 +341,10 @@ public:
...
@@ -339,13 +341,10 @@ public:
}
}
template
<
class
...
Ts
>
template
<
class
...
Ts
>
mock_t
&
receive
(
connection_handle
hdl
,
mock_t
&
receive
(
connection_handle
hdl
,
maybe
<
basp
::
message_type
>
operation
,
maybe
<
basp
::
message_type
>
operation
,
maybe
<
uint8_t
>
flags
,
maybe
<
uint32_t
>
payload_len
,
maybe
<
uint8_t
>
flags
,
maybe
<
uint32_t
>
payload_len
,
maybe
<
uint64_t
>
operation_data
,
maybe
<
uint64_t
>
operation_data
,
maybe
<
actor_id
>
source_actor
,
maybe
<
actor_id
>
source_actor
,
maybe
<
actor_id
>
dest_actor
,
maybe
<
actor_id
>
dest_actor
,
const
Ts
&
...
xs
)
{
const
Ts
&
...
xs
)
{
CAF_MESSAGE
(
"expect #"
<<
num
);
CAF_MESSAGE
(
"expect #"
<<
num
);
buffer
buf
;
buffer
buf
;
...
@@ -394,8 +393,8 @@ public:
...
@@ -394,8 +393,8 @@ public:
mock_t
mock
(
connection_handle
hdl
,
basp
::
header
hdr
,
const
Ts
&
...
xs
)
{
mock_t
mock
(
connection_handle
hdl
,
basp
::
header
hdr
,
const
Ts
&
...
xs
)
{
buffer
buf
;
buffer
buf
;
to_buf
(
buf
,
hdr
,
nullptr
,
xs
...);
to_buf
(
buf
,
hdr
,
nullptr
,
xs
...);
CAF_MESSAGE
(
"virtually send "
<<
to_string
(
hdr
.
operation
)
CAF_MESSAGE
(
"virtually send "
<<
to_string
(
hdr
.
operation
)
<<
" with "
<<
" with "
<<
(
buf
.
size
()
-
basp
::
header_size
)
<<
(
buf
.
size
()
-
basp
::
header_size
)
<<
" bytes payload"
);
<<
" bytes payload"
);
mpx
()
->
virtual_send
(
hdl
,
buf
);
mpx
()
->
virtual_send
(
hdl
,
buf
);
return
{
this
};
return
{
this
};
...
@@ -430,7 +429,6 @@ public:
...
@@ -430,7 +429,6 @@ public:
scheduler_type
&
sched
;
scheduler_type
&
sched
;
middleman_actor
mma
;
middleman_actor
mma
;
autoconn_enabled_fixture
()
autoconn_enabled_fixture
()
:
fixture
(
true
),
:
fixture
(
true
),
sched
(
dynamic_cast
<
scheduler_type
&>
(
sys
.
scheduler
())),
sched
(
dynamic_cast
<
scheduler_type
&>
(
sys
.
scheduler
())),
...
@@ -462,9 +460,12 @@ CAF_TEST(empty_server_handshake) {
...
@@ -462,9 +460,12 @@ CAF_TEST(empty_server_handshake) {
basp
::
header
hdr
;
basp
::
header
hdr
;
buffer
payload
;
buffer
payload
;
std
::
tie
(
hdr
,
payload
)
=
from_buf
(
buf
);
std
::
tie
(
hdr
,
payload
)
=
from_buf
(
buf
);
basp
::
header
expected
{
basp
::
message_type
::
server_handshake
,
0
,
basp
::
header
expected
{
basp
::
message_type
::
server_handshake
,
0
,
static_cast
<
uint32_t
>
(
payload
.
size
()),
static_cast
<
uint32_t
>
(
payload
.
size
()),
basp
::
version
,
invalid_actor_id
,
invalid_actor_id
};
basp
::
version
,
invalid_actor_id
,
invalid_actor_id
};
CAF_CHECK
(
basp
::
valid
(
hdr
));
CAF_CHECK
(
basp
::
valid
(
hdr
));
CAF_CHECK
(
basp
::
is_handshake
(
hdr
));
CAF_CHECK
(
basp
::
is_handshake
(
hdr
));
CAF_CHECK_EQUAL
(
to_string
(
hdr
),
to_string
(
expected
));
CAF_CHECK_EQUAL
(
to_string
(
hdr
),
to_string
(
expected
));
...
@@ -480,9 +481,12 @@ CAF_TEST(non_empty_server_handshake) {
...
@@ -480,9 +481,12 @@ CAF_TEST(non_empty_server_handshake) {
basp
::
header
hdr
;
basp
::
header
hdr
;
buffer
payload
;
buffer
payload
;
std
::
tie
(
hdr
,
payload
)
=
from_buf
(
buf
);
std
::
tie
(
hdr
,
payload
)
=
from_buf
(
buf
);
basp
::
header
expected
{
basp
::
message_type
::
server_handshake
,
0
,
basp
::
header
expected
{
basp
::
message_type
::
server_handshake
,
0
,
static_cast
<
uint32_t
>
(
payload
.
size
()),
static_cast
<
uint32_t
>
(
payload
.
size
()),
basp
::
version
,
invalid_actor_id
,
invalid_actor_id
};
basp
::
version
,
invalid_actor_id
,
invalid_actor_id
};
CAF_CHECK
(
basp
::
valid
(
hdr
));
CAF_CHECK
(
basp
::
valid
(
hdr
));
CAF_CHECK
(
basp
::
is_handshake
(
hdr
));
CAF_CHECK
(
basp
::
is_handshake
(
hdr
));
CAF_CHECK_EQUAL
(
to_string
(
hdr
),
to_string
(
expected
));
CAF_CHECK_EQUAL
(
to_string
(
hdr
),
to_string
(
expected
));
...
@@ -509,8 +513,7 @@ CAF_TEST(remote_address_and_port) {
...
@@ -509,8 +513,7 @@ CAF_TEST(remote_address_and_port) {
// all test nodes have address "test" and connection handle ID as port
// all test nodes have address "test" and connection handle ID as port
CAF_CHECK_EQUAL
(
addr
,
"test"
);
CAF_CHECK_EQUAL
(
addr
,
"test"
);
CAF_CHECK_EQUAL
(
port
,
mars
().
connection
.
id
());
CAF_CHECK_EQUAL
(
port
,
mars
().
connection
.
id
());
}
});
);
}
}
CAF_TEST
(
client_handshake_and_dispatch
)
{
CAF_TEST
(
client_handshake_and_dispatch
)
{
...
@@ -528,23 +531,17 @@ CAF_TEST(client_handshake_and_dispatch) {
...
@@ -528,23 +531,17 @@ CAF_TEST(client_handshake_and_dispatch) {
CAF_REQUIRE
(
proxies
().
count_proxies
(
jupiter
().
id
)
==
1
);
CAF_REQUIRE
(
proxies
().
count_proxies
(
jupiter
().
id
)
==
1
);
// must've send remote node a message that this proxy is monitored now
// must've send remote node a message that this proxy is monitored now
// receive the message
// receive the message
self
()
->
receive
(
self
()
->
receive
([](
int
a
,
int
b
,
int
c
)
{
[](
int
a
,
int
b
,
int
c
)
{
CAF_CHECK_EQUAL
(
a
,
1
);
CAF_CHECK_EQUAL
(
a
,
1
);
CAF_CHECK_EQUAL
(
b
,
2
);
CAF_CHECK_EQUAL
(
b
,
2
);
CAF_CHECK_EQUAL
(
c
,
3
);
CAF_CHECK_EQUAL
(
c
,
3
);
return
a
+
b
+
c
;
return
a
+
b
+
c
;
}
});
);
CAF_MESSAGE
(
"exec message of forwarding proxy"
);
CAF_MESSAGE
(
"exec message of forwarding proxy"
);
mpx
()
->
exec_runnable
();
mpx
()
->
exec_runnable
();
// deserialize and send message from out buf
// deserialize and send message from out buf
dispatch_out_buf
(
jupiter
().
connection
);
dispatch_out_buf
(
jupiter
().
connection
);
jupiter
().
dummy_actor
->
receive
(
jupiter
().
dummy_actor
->
receive
([](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
6
);
});
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
6
);
}
);
}
}
CAF_TEST
(
message_forwarding
)
{
CAF_TEST
(
message_forwarding
)
{
...
@@ -579,8 +576,8 @@ CAF_TEST(remote_actor_and_send) {
...
@@ -579,8 +576,8 @@ CAF_TEST(remote_actor_and_send) {
CAF_REQUIRE
(
mpx
()
->
has_pending_scribe
(
lo
,
4242
));
CAF_REQUIRE
(
mpx
()
->
has_pending_scribe
(
lo
,
4242
));
auto
mm1
=
sys
.
middleman
().
actor_handle
();
auto
mm1
=
sys
.
middleman
().
actor_handle
();
actor
result
;
actor
result
;
auto
f
=
self
()
->
request
(
mm1
,
infinite
,
auto
f
=
self
()
->
request
(
mm1
,
infinite
,
connect_atom
::
value
,
lo
,
connect_atom
::
value
,
lo
,
uint16_t
{
4242
});
uint16_t
{
4242
});
// wait until BASP broker has received and processed the connect message
// wait until BASP broker has received and processed the connect message
while
(
!
aut
()
->
valid
(
jupiter
().
connection
))
while
(
!
aut
()
->
valid
(
jupiter
().
connection
))
mpx
()
->
exec_runnable
();
mpx
()
->
exec_runnable
();
...
@@ -621,14 +618,11 @@ CAF_TEST(remote_actor_and_send) {
...
@@ -621,14 +618,11 @@ CAF_TEST(remote_actor_and_send) {
CAF_REQUIRE
(
proxy
==
res
);
CAF_REQUIRE
(
proxy
==
res
);
result
=
actor_cast
<
actor
>
(
res
);
result
=
actor_cast
<
actor
>
(
res
);
},
},
[
&
](
error
&
err
)
{
[
&
](
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
sys
.
render
(
err
));
});
CAF_FAIL
(
"error: "
<<
sys
.
render
(
err
));
}
);
CAF_MESSAGE
(
"send message to proxy"
);
CAF_MESSAGE
(
"send message to proxy"
);
anon_send
(
actor_cast
<
actor
>
(
result
),
42
);
anon_send
(
actor_cast
<
actor
>
(
result
),
42
);
mpx
()
->
flush_runnables
();
mpx
()
->
flush_runnables
();
// mpx()->exec_runnable(); // process forwarded message in basp_broker
// mpx()->exec_runnable(); // process forwarded message in basp_broker
mock
().
receive
(
jupiter
().
connection
,
basp
::
message_type
::
direct_message
,
mock
().
receive
(
jupiter
().
connection
,
basp
::
message_type
::
direct_message
,
no_flags
,
any_vals
,
default_operation_data
,
invalid_actor_id
,
no_flags
,
any_vals
,
default_operation_data
,
invalid_actor_id
,
jupiter
().
dummy_actor
->
id
(),
std
::
vector
<
strong_actor_ptr
>
{},
jupiter
().
dummy_actor
->
id
(),
std
::
vector
<
strong_actor_ptr
>
{},
...
@@ -639,23 +633,19 @@ CAF_TEST(remote_actor_and_send) {
...
@@ -639,23 +633,19 @@ CAF_TEST(remote_actor_and_send) {
{
basp
::
message_type
::
direct_message
,
0
,
0
,
0
,
{
basp
::
message_type
::
direct_message
,
0
,
0
,
0
,
jupiter
().
dummy_actor
->
id
(),
self
()
->
id
()},
jupiter
().
dummy_actor
->
id
(),
self
()
->
id
()},
std
::
vector
<
strong_actor_ptr
>
{},
make_message
(
"hi there!"
));
std
::
vector
<
strong_actor_ptr
>
{},
make_message
(
"hi there!"
));
self
()
->
receive
(
self
()
->
receive
([
&
](
const
string
&
str
)
{
[
&
](
const
string
&
str
)
{
CAF_CHECK_EQUAL
(
to_string
(
self
()
->
current_sender
()),
to_string
(
result
));
CAF_CHECK_EQUAL
(
to_string
(
self
()
->
current_sender
()),
to_string
(
result
));
CAF_CHECK_EQUAL
(
self
()
->
current_sender
(),
result
.
address
());
CAF_CHECK_EQUAL
(
self
()
->
current_sender
(),
result
.
address
());
CAF_CHECK_EQUAL
(
str
,
"hi there!"
);
CAF_CHECK_EQUAL
(
str
,
"hi there!"
);
}
});
);
}
}
CAF_TEST
(
actor_serialize_and_deserialize
)
{
CAF_TEST
(
actor_serialize_and_deserialize
)
{
auto
testee_impl
=
[](
event_based_actor
*
testee_self
)
->
behavior
{
auto
testee_impl
=
[](
event_based_actor
*
testee_self
)
->
behavior
{
testee_self
->
set_default_handler
(
reflect_and_quit
);
testee_self
->
set_default_handler
(
reflect_and_quit
);
return
{
return
{[]
{
[]
{
// nop
// nop
}
}};
};
};
};
connect_node
(
jupiter
());
connect_node
(
jupiter
());
auto
prx
=
proxies
().
get_or_put
(
jupiter
().
id
,
jupiter
().
dummy_actor
->
id
());
auto
prx
=
proxies
().
get_or_put
(
jupiter
().
id
,
jupiter
().
dummy_actor
->
id
());
...
@@ -711,12 +701,10 @@ CAF_TEST(indirect_connections) {
...
@@ -711,12 +701,10 @@ CAF_TEST(indirect_connections) {
any_vals
,
no_operation_data
,
invalid_actor_id
,
any_vals
,
no_operation_data
,
invalid_actor_id
,
jupiter
().
dummy_actor
->
id
(),
this_node
(),
jupiter
().
id
);
jupiter
().
dummy_actor
->
id
(),
this_node
(),
jupiter
().
id
);
CAF_MESSAGE
(
"receive message from jupiter"
);
CAF_MESSAGE
(
"receive message from jupiter"
);
self
()
->
receive
(
self
()
->
receive
([](
const
std
::
string
&
str
)
->
std
::
string
{
[](
const
std
::
string
&
str
)
->
std
::
string
{
CAF_CHECK_EQUAL
(
str
,
"hello from jupiter!"
);
CAF_CHECK_EQUAL
(
str
,
"hello from jupiter!"
);
return
"hello from earth!"
;
return
"hello from earth!"
;
}
});
);
mpx
()
->
exec_runnable
();
// process forwarded message in basp_broker
mpx
()
->
exec_runnable
();
// process forwarded message in basp_broker
mock
().
receive
(
mars
().
connection
,
basp
::
message_type
::
routed_message
,
mock
().
receive
(
mars
().
connection
,
basp
::
message_type
::
routed_message
,
no_flags
,
any_vals
,
default_operation_data
,
self
()
->
id
(),
no_flags
,
any_vals
,
default_operation_data
,
self
()
->
id
(),
...
@@ -807,12 +795,10 @@ CAF_TEST(automatic_connection) {
...
@@ -807,12 +795,10 @@ CAF_TEST(automatic_connection) {
check_node_in_tbl
(
jupiter
());
check_node_in_tbl
(
jupiter
());
check_node_in_tbl
(
mars
());
check_node_in_tbl
(
mars
());
CAF_MESSAGE
(
"receive message from jupiter"
);
CAF_MESSAGE
(
"receive message from jupiter"
);
self
()
->
receive
(
self
()
->
receive
([](
const
std
::
string
&
str
)
->
std
::
string
{
[](
const
std
::
string
&
str
)
->
std
::
string
{
CAF_CHECK_EQUAL
(
str
,
"hello from jupiter!"
);
CAF_CHECK_EQUAL
(
str
,
"hello from jupiter!"
);
return
"hello from earth!"
;
return
"hello from earth!"
;
}
});
);
mpx
()
->
exec_runnable
();
// process forwarded message in basp_broker
mpx
()
->
exec_runnable
();
// process forwarded message in basp_broker
CAF_MESSAGE
(
"response message must take direct route now"
);
CAF_MESSAGE
(
"response message must take direct route now"
);
mock
().
receive
(
jupiter
().
connection
,
basp
::
message_type
::
direct_message
,
mock
().
receive
(
jupiter
().
connection
,
basp
::
message_type
::
direct_message
,
...
...
libcaf_io/test/io/broker.cpp
View file @
f4c5842b
...
@@ -22,8 +22,8 @@
...
@@ -22,8 +22,8 @@
#include "caf/test/dsl.hpp"
#include "caf/test/dsl.hpp"
#include <memory>
#include <iostream>
#include <iostream>
#include <memory>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
...
@@ -39,58 +39,53 @@ using pong_atom = caf::atom_constant<caf::atom("pong")>;
...
@@ -39,58 +39,53 @@ using pong_atom = caf::atom_constant<caf::atom("pong")>;
using
publish_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"publish"
)
>
;
using
publish_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"publish"
)
>
;
using
kickoff_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"kickoff"
)
>
;
using
kickoff_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"kickoff"
)
>
;
void
ping
(
event_based_actor
*
self
,
size_t
num_pings
)
{
behavior
ping
(
event_based_actor
*
self
,
size_t
num_pings
)
{
CAF_MESSAGE
(
"num_pings: "
<<
num_pings
);
CAF_MESSAGE
(
"num_pings: "
<<
num_pings
);
auto
count
=
std
::
make_shared
<
size_t
>
(
0
);
auto
count
=
std
::
make_shared
<
size_t
>
(
0
);
self
->
become
(
return
{
[
=
](
kickoff_atom
,
const
actor
&
pong
)
{
[
=
](
kickoff_atom
,
const
actor
&
pong
)
{
CAF_MESSAGE
(
"received `kickoff_atom`"
);
CAF_MESSAGE
(
"received `kickoff_atom`"
);
self
->
send
(
pong
,
ping_atom
::
value
,
1
);
self
->
send
(
pong
,
ping_atom
::
value
,
1
);
self
->
become
(
self
->
become
([
=
](
pong_atom
,
int
value
)
->
std
::
tuple
<
atom_value
,
int
>
{
[
=
](
pong_atom
,
int
value
)
->
std
::
tuple
<
atom_value
,
int
>
{
if
(
++*
count
>=
num_pings
)
{
if
(
++*
count
>=
num_pings
)
{
CAF_MESSAGE
(
"received "
<<
num_pings
CAF_MESSAGE
(
"received "
<<
num_pings
<<
" pings, call self->quit"
);
<<
" pings, call self->quit"
);
self
->
quit
();
self
->
quit
();
}
}
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
}
});
);
},
}
};
);
}
}
void
pong
(
event_based_actor
*
self
)
{
behavior
pong
(
event_based_actor
*
self
)
{
CAF_MESSAGE
(
"pong actor started"
);
CAF_MESSAGE
(
"pong actor started"
);
self
->
set_down_handler
([
=
](
down_msg
&
dm
)
{
self
->
set_down_handler
([
=
](
down_msg
&
dm
)
{
CAF_MESSAGE
(
"received down_msg{"
<<
to_string
(
dm
.
reason
)
<<
"}"
);
CAF_MESSAGE
(
"received down_msg{"
<<
to_string
(
dm
.
reason
)
<<
"}"
);
self
->
quit
(
dm
.
reason
);
self
->
quit
(
dm
.
reason
);
});
});
self
->
become
(
return
{
[
=
](
ping_atom
,
int
value
)
->
std
::
tuple
<
atom_value
,
int
>
{
[
=
](
ping_atom
,
int
value
)
->
std
::
tuple
<
atom_value
,
int
>
{
CAF_MESSAGE
(
"received `ping_atom`"
);
CAF_MESSAGE
(
"received `ping_atom`"
);
self
->
monitor
(
self
->
current_sender
());
self
->
monitor
(
self
->
current_sender
());
// set next behavior
// set next behavior
self
->
become
(
self
->
become
([](
ping_atom
,
int
val
)
{
[](
ping_atom
,
int
val
)
{
return
std
::
make_tuple
(
pong_atom
::
value
,
val
);
return
std
::
make_tuple
(
pong_atom
::
value
,
val
);
}
});
);
// reply to 'ping'
// reply to 'ping'
return
std
::
make_tuple
(
pong_atom
::
value
,
value
);
return
std
::
make_tuple
(
pong_atom
::
value
,
value
);
}
}
,
)
;
}
;
}
}
void
peer_fun
(
broker
*
self
,
connection_handle
hdl
,
const
actor
&
buddy
)
{
behavior
peer_fun
(
broker
*
self
,
connection_handle
hdl
,
const
actor
&
buddy
)
{
CAF_MESSAGE
(
"peer_fun called"
);
CAF_MESSAGE
(
"peer_fun called"
);
CAF_REQUIRE
(
self
->
subtype
()
==
resumable
::
io_actor
);
CAF_REQUIRE
(
self
->
subtype
()
==
resumable
::
io_actor
);
CAF_CHECK
(
self
!=
nullptr
);
CAF_CHECK
(
self
!=
nullptr
);
self
->
monitor
(
buddy
);
self
->
monitor
(
buddy
);
// assume exactly one connection
// assume exactly one connection
CAF_REQUIRE
(
self
->
connections
().
size
()
==
1
);
CAF_REQUIRE
(
self
->
connections
().
size
()
==
1
);
self
->
configure_read
(
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
atom_value
)
hdl
,
receive_policy
::
exactly
(
sizeof
(
atom_value
)
+
sizeof
(
int
)));
+
sizeof
(
int
)));
auto
write
=
[
=
](
atom_value
type
,
int
value
)
{
auto
write
=
[
=
](
atom_value
type
,
int
value
)
{
auto
&
buf
=
self
->
wr_buf
(
hdl
);
auto
&
buf
=
self
->
wr_buf
(
hdl
);
auto
first
=
reinterpret_cast
<
char
*>
(
&
type
);
auto
first
=
reinterpret_cast
<
char
*>
(
&
type
);
...
@@ -104,7 +99,7 @@ void peer_fun(broker* self, connection_handle hdl, const actor& buddy) {
...
@@ -104,7 +99,7 @@ void peer_fun(broker* self, connection_handle hdl, const actor& buddy) {
if
(
dm
.
source
==
buddy
)
if
(
dm
.
source
==
buddy
)
self
->
quit
(
dm
.
reason
);
self
->
quit
(
dm
.
reason
);
});
});
self
->
become
(
return
{
[
=
](
const
connection_closed_msg
&
)
{
[
=
](
const
connection_closed_msg
&
)
{
CAF_MESSAGE
(
"received connection_closed_msg"
);
CAF_MESSAGE
(
"received connection_closed_msg"
);
self
->
quit
();
self
->
quit
();
...
@@ -124,8 +119,8 @@ void peer_fun(broker* self, connection_handle hdl, const actor& buddy) {
...
@@ -124,8 +119,8 @@ void peer_fun(broker* self, connection_handle hdl, const actor& buddy) {
[
=
](
pong_atom
,
int
value
)
{
[
=
](
pong_atom
,
int
value
)
{
CAF_MESSAGE
(
"received: pong "
<<
value
);
CAF_MESSAGE
(
"received: pong "
<<
value
);
write
(
pong_atom
::
value
,
value
);
write
(
pong_atom
::
value
,
value
);
}
}
,
)
;
}
;
}
}
behavior
peer_acceptor_fun
(
broker
*
self
,
const
actor
&
buddy
)
{
behavior
peer_acceptor_fun
(
broker
*
self
,
const
actor
&
buddy
)
{
...
@@ -141,7 +136,7 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) {
...
@@ -141,7 +136,7 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) {
if
(
!
res
)
if
(
!
res
)
return
std
::
move
(
res
.
error
());
return
std
::
move
(
res
.
error
());
return
res
->
second
;
return
res
->
second
;
}
}
,
};
};
}
}
...
@@ -153,8 +148,8 @@ void run_client(int argc, char** argv, uint16_t port) {
...
@@ -153,8 +148,8 @@ void run_client(int argc, char** argv, uint16_t port) {
actor_system
system
{
cfg
};
actor_system
system
{
cfg
};
auto
p
=
system
.
spawn
(
ping
,
size_t
{
10
});
auto
p
=
system
.
spawn
(
ping
,
size_t
{
10
});
CAF_MESSAGE
(
"spawn_client..."
);
CAF_MESSAGE
(
"spawn_client..."
);
auto
cl
=
unbox
(
system
.
middleman
().
spawn_client
(
peer_fun
,
auto
cl
=
unbox
(
"127.0.0.1"
,
port
,
p
));
system
.
middleman
().
spawn_client
(
peer_fun
,
"127.0.0.1"
,
port
,
p
));
CAF_MESSAGE
(
"spawn_client finished"
);
CAF_MESSAGE
(
"spawn_client finished"
);
anon_send
(
p
,
kickoff_atom
::
value
,
cl
);
anon_send
(
p
,
kickoff_atom
::
value
,
cl
);
CAF_MESSAGE
(
"`kickoff_atom` has been send"
);
CAF_MESSAGE
(
"`kickoff_atom` has been send"
);
...
@@ -171,17 +166,15 @@ void run_server(int argc, char** argv) {
...
@@ -171,17 +166,15 @@ void run_server(int argc, char** argv) {
auto
serv
=
system
.
middleman
().
spawn_broker
(
peer_acceptor_fun
,
auto
serv
=
system
.
middleman
().
spawn_broker
(
peer_acceptor_fun
,
system
.
spawn
(
pong
));
system
.
spawn
(
pong
));
std
::
thread
child
;
std
::
thread
child
;
self
->
request
(
serv
,
infinite
,
publish_atom
::
value
).
receive
(
self
->
request
(
serv
,
infinite
,
publish_atom
::
value
)
.
receive
(
[
&
](
uint16_t
port
)
{
[
&
](
uint16_t
port
)
{
CAF_MESSAGE
(
"server is running on port "
<<
port
);
CAF_MESSAGE
(
"server is running on port "
<<
port
);
child
=
std
::
thread
([
=
]
{
child
=
std
::
thread
([
=
]
{
run_client
(
argc
,
argv
,
port
);
});
run_client
(
argc
,
argv
,
port
);
});
},
},
[
&
](
const
error
&
err
)
{
[
&
](
const
error
&
err
)
{
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
}
});
);
self
->
await_all_other_actors_done
();
self
->
await_all_other_actors_done
();
child
.
join
();
child
.
join
();
}
}
...
...
libcaf_io/test/io/http_broker.cpp
View file @
f4c5842b
...
@@ -21,14 +21,14 @@
...
@@ -21,14 +21,14 @@
#define CAF_SUITE io_http_broker
#define CAF_SUITE io_http_broker
#include "caf/test/unit_test.hpp"
#include "caf/test/unit_test.hpp"
#include <cassert>
#include <algorithm>
#include <algorithm>
#include <cassert>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
using
std
::
cout
;
using
std
::
cerr
;
using
std
::
cerr
;
using
std
::
cout
;
using
std
::
endl
;
using
std
::
endl
;
using
namespace
caf
;
using
namespace
caf
;
...
@@ -131,17 +131,19 @@ behavior http_worker(http_broker* self, connection_handle hdl) {
...
@@ -131,17 +131,19 @@ behavior http_worker(http_broker* self, connection_handle hdl) {
}
else
if
(
msg
.
buf
.
back
()
==
'\n'
)
{
}
else
if
(
msg
.
buf
.
back
()
==
'\n'
)
{
self
->
state
.
ps
=
receive_new_line
;
// we've got a clean cut
self
->
state
.
ps
=
receive_new_line
;
// we've got a clean cut
}
else
{
}
else
{
self
->
state
.
ps
=
receive_continued_line
;
// interrupted in the middle
self
->
state
.
ps
=
receive_continued_line
;
// interrupted in the
// middle
}
}
// we don't need to check for completion in any intermediate state
// we don't need to check for completion in any intermediate state
if
(
self
->
state
.
ps
!=
receive_new_line
)
if
(
self
->
state
.
ps
!=
receive_new_line
)
return
;
return
;
// we have received the HTTP header if we have an empty line at the end
// we have received the HTTP header if we have an empty line at the
// end
if
(
lines
.
size
()
>
1
&&
lines
.
back
().
empty
())
{
if
(
lines
.
size
()
>
1
&&
lines
.
back
().
empty
())
{
auto
&
out
=
self
->
wr_buf
(
hdl
);
auto
&
out
=
self
->
wr_buf
(
hdl
);
// we only look at the first line in our example and reply with
our
// we only look at the first line in our example and reply with
//
OK message if we receive exactly "GET / HTTP/1.1", otherwise
//
our OK message if we receive exactly "GET / HTTP/1.1",
// we send a 404 HTTP response
//
otherwise
we send a 404 HTTP response
if
(
lines
.
front
()
==
http_valid_get
)
if
(
lines
.
front
()
==
http_valid_get
)
out
.
insert
(
out
.
end
(),
std
::
begin
(
http_ok
),
std
::
end
(
http_ok
));
out
.
insert
(
out
.
end
(),
std
::
begin
(
http_ok
),
std
::
end
(
http_ok
));
else
else
...
@@ -151,9 +153,7 @@ behavior http_worker(http_broker* self, connection_handle hdl) {
...
@@ -151,9 +153,7 @@ behavior http_worker(http_broker* self, connection_handle hdl) {
self
->
quit
();
self
->
quit
();
}
}
},
},
[
=
](
const
connection_closed_msg
&
)
{
[
=
](
const
connection_closed_msg
&
)
{
self
->
quit
();
},
self
->
quit
();
}
};
};
}
}
...
@@ -163,15 +163,16 @@ behavior server(broker* self) {
...
@@ -163,15 +163,16 @@ behavior server(broker* self) {
[
=
](
const
new_connection_msg
&
ncm
)
{
[
=
](
const
new_connection_msg
&
ncm
)
{
CAF_MESSAGE
(
"fork on new connection"
);
CAF_MESSAGE
(
"fork on new connection"
);
self
->
fork
(
http_worker
,
ncm
.
handle
);
self
->
fork
(
http_worker
,
ncm
.
handle
);
}
}
,
};
};
}
}
class
fixture
{
class
fixture
{
public:
public:
using
multiplexer_type
=
network
::
test_multiplexer
;
fixture
()
:
system
(
cfg
.
load
<
io
::
middleman
,
network
::
test_multiplexer
>
())
{
fixture
()
:
system
(
cfg
.
load
<
io
::
middleman
,
network
::
test_multiplexer
>
())
{
mpx_
=
dynamic_cast
<
network
::
test_multiplexer
*>
(
&
system
.
middleman
().
backend
());
mpx_
=
dynamic_cast
<
multiplexer_type
*>
(
&
system
.
middleman
().
backend
());
CAF_REQUIRE
(
mpx_
!=
nullptr
);
CAF_REQUIRE
(
mpx_
!=
nullptr
);
// spawn the actor-under-test
// spawn the actor-under-test
aut_
=
system
.
middleman
().
spawn_broker
(
server
);
aut_
=
system
.
middleman
().
spawn_broker
(
server
);
...
@@ -202,10 +203,10 @@ public:
...
@@ -202,10 +203,10 @@ public:
mock_t
&
expect
(
const
std
::
string
&
x
)
{
mock_t
&
expect
(
const
std
::
string
&
x
)
{
auto
&
buf
=
this_
->
mpx_
->
output_buffer
(
this_
->
connection_
);
auto
&
buf
=
this_
->
mpx_
->
output_buffer
(
this_
->
connection_
);
CAF_REQUIRE
(
(
buf
.
size
()
>=
x
.
size
()
));
CAF_REQUIRE
(
buf
.
size
()
>=
x
.
size
(
));
CAF_REQUIRE
(
(
std
::
equal
(
buf
.
begin
(),
CAF_REQUIRE
(
std
::
equal
(
buf
.
begin
(),
buf
.
begin
()
+
static_cast
<
ptrdiff_t
>
(
x
.
size
()),
buf
.
begin
()
+
static_cast
<
ptrdiff_t
>
(
x
.
size
()),
x
.
begin
()
)));
x
.
begin
(
)));
buf
.
erase
(
buf
.
begin
(),
buf
.
begin
()
+
static_cast
<
ptrdiff_t
>
(
x
.
size
()));
buf
.
erase
(
buf
.
begin
(),
buf
.
begin
()
+
static_cast
<
ptrdiff_t
>
(
x
.
size
()));
return
*
this
;
return
*
this
;
}
}
...
...
libcaf_io/test/io/network/ip_endpoint.cpp
View file @
f4c5842b
...
@@ -45,29 +45,26 @@ public:
...
@@ -45,29 +45,26 @@ public:
};
};
struct
fixture
{
struct
fixture
{
template
<
class
T
,
class
...
Ts
>
template
<
class
T
,
class
...
Ts
>
std
::
vector
<
char
>
serialize
(
T
&
x
,
Ts
&
...
xs
)
{
std
::
vector
<
char
>
serialize
(
T
&
x
,
Ts
&
...
xs
)
{
std
::
vector
<
char
>
buf
;
std
::
vector
<
char
>
buf
;
binary_serializer
bs
{
&
context
,
buf
};
binary_serializer
bs
{
&
context
,
buf
};
bs
(
x
,
xs
...);
bs
(
x
,
xs
...);
return
buf
;
return
buf
;
}
}
template
<
class
T
,
class
...
Ts
>
template
<
class
T
,
class
...
Ts
>
void
deserialize
(
const
std
::
vector
<
char
>&
buf
,
T
&
x
,
Ts
&
...
xs
)
{
void
deserialize
(
const
std
::
vector
<
char
>&
buf
,
T
&
x
,
Ts
&
...
xs
)
{
binary_deserializer
bd
{
&
context
,
buf
};
binary_deserializer
bd
{
&
context
,
buf
};
bd
(
x
,
xs
...);
bd
(
x
,
xs
...);
}
}
fixture
()
:
cfg
(),
system
(
cfg
),
context
(
&
system
)
{
}
config
cfg
;
fixture
()
:
cfg
(),
system
(
cfg
),
context
(
&
system
)
{
actor_system
system
;
}
scoped_execution_unit
context
;
config
cfg
;
actor_system
system
;
scoped_execution_unit
context
;
};
};
}
// namespace
}
// namespace
...
...
libcaf_io/test/io/receive_buffer.cpp
View file @
f4c5842b
...
@@ -101,24 +101,21 @@ CAF_TEST(resize) {
...
@@ -101,24 +101,21 @@ CAF_TEST(resize) {
a
.
resize
(
1024
);
a
.
resize
(
1024
);
std
::
fill
(
a
.
begin
(),
a
.
end
(),
'a'
);
std
::
fill
(
a
.
begin
(),
a
.
end
(),
'a'
);
auto
cnt
=
0
;
auto
cnt
=
0
;
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
[
&
](
char
c
)
{
++
cnt
;
++
cnt
;
return
c
==
'a'
;
return
c
==
'a'
;
}));
}));
CAF_CHECK_EQUAL
(
cnt
,
1024
);
CAF_CHECK_EQUAL
(
cnt
,
1024
);
a
.
resize
(
10
);
a
.
resize
(
10
);
cnt
=
0
;
cnt
=
0
;
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
[
&
](
char
c
)
{
++
cnt
;
++
cnt
;
return
c
==
'a'
;
return
c
==
'a'
;
}));
}));
CAF_CHECK_EQUAL
(
cnt
,
10
);
CAF_CHECK_EQUAL
(
cnt
,
10
);
a
.
resize
(
1024
);
a
.
resize
(
1024
);
cnt
=
0
;
cnt
=
0
;
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
[
&
](
char
c
)
{
++
cnt
;
++
cnt
;
return
c
==
'a'
;
return
c
==
'a'
;
}));
}));
...
@@ -136,7 +133,7 @@ CAF_TEST(push_back) {
...
@@ -136,7 +133,7 @@ CAF_TEST(push_back) {
}
}
CAF_TEST
(
insert
)
{
CAF_TEST
(
insert
)
{
for
(
auto
c
:
vec
)
for
(
auto
c
:
vec
)
a
.
insert
(
a
.
end
(),
c
);
a
.
insert
(
a
.
end
(),
c
);
CAF_CHECK_EQUAL
(
as_string
(
a
),
"hallo"
);
CAF_CHECK_EQUAL
(
as_string
(
a
),
"hallo"
);
a
.
insert
(
a
.
begin
(),
'!'
);
a
.
insert
(
a
.
begin
(),
'!'
);
...
...
libcaf_io/test/io/remote_actor.cpp
View file @
f4c5842b
...
@@ -21,10 +21,10 @@
...
@@ -21,10 +21,10 @@
#define CAF_SUITE io_dynamic_remote_actor
#define CAF_SUITE io_dynamic_remote_actor
#include "caf/test/dsl.hpp"
#include "caf/test/dsl.hpp"
#include <
vector
>
#include <
algorithm
>
#include <sstream>
#include <sstream>
#include <utility>
#include <utility>
#include <
algorithm
>
#include <
vector
>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
...
@@ -71,26 +71,23 @@ behavior make_pong_behavior() {
...
@@ -71,26 +71,23 @@ behavior make_pong_behavior() {
++
val
;
++
val
;
CAF_MESSAGE
(
"pong with "
<<
val
);
CAF_MESSAGE
(
"pong with "
<<
val
);
return
val
;
return
val
;
}
}
,
};
};
}
}
behavior
make_ping_behavior
(
event_based_actor
*
self
,
const
actor
&
pong
)
{
behavior
make_ping_behavior
(
event_based_actor
*
self
,
const
actor
&
pong
)
{
CAF_MESSAGE
(
"ping with "
<<
0
);
CAF_MESSAGE
(
"ping with "
<<
0
);
self
->
send
(
pong
,
0
);
self
->
send
(
pong
,
0
);
return
{
return
{[
=
](
int
val
)
->
int
{
[
=
](
int
val
)
->
int
{
if
(
val
==
3
)
{
if
(
val
==
3
)
{
CAF_MESSAGE
(
"ping with exit"
);
CAF_MESSAGE
(
"ping with exit"
);
self
->
send_exit
(
self
->
current_sender
(),
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
exit_reason
::
user_shutdown
);
CAF_MESSAGE
(
"ping quits"
);
CAF_MESSAGE
(
"ping quits"
);
self
->
quit
();
self
->
quit
();
}
}
CAF_MESSAGE
(
"ping with "
<<
val
);
CAF_MESSAGE
(
"ping with "
<<
val
);
return
val
;
return
val
;
}
}};
};
}
}
behavior
make_sort_behavior
()
{
behavior
make_sort_behavior
()
{
...
@@ -100,7 +97,7 @@ behavior make_sort_behavior() {
...
@@ -100,7 +97,7 @@ behavior make_sort_behavior() {
std
::
sort
(
vec
.
begin
(),
vec
.
end
());
std
::
sort
(
vec
.
begin
(),
vec
.
end
());
CAF_MESSAGE
(
"sorter sent: "
<<
deep_to_string
(
vec
));
CAF_MESSAGE
(
"sorter sent: "
<<
deep_to_string
(
vec
));
return
std
::
move
(
vec
);
return
std
::
move
(
vec
);
}
}
,
};
};
}
}
...
@@ -114,7 +111,7 @@ behavior make_sort_requester_behavior(event_based_actor* self,
...
@@ -114,7 +111,7 @@ behavior make_sort_requester_behavior(event_based_actor* self,
CAF_CHECK_EQUAL
(
vec
,
expected_vec
);
CAF_CHECK_EQUAL
(
vec
,
expected_vec
);
self
->
send_exit
(
sorter
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
sorter
,
exit_reason
::
user_shutdown
);
self
->
quit
();
self
->
quit
();
}
}
,
};
};
}
}
...
@@ -123,7 +120,7 @@ behavior fragile_mirror(event_based_actor* self) {
...
@@ -123,7 +120,7 @@ behavior fragile_mirror(event_based_actor* self) {
[
=
](
int
i
)
{
[
=
](
int
i
)
{
self
->
quit
(
exit_reason
::
user_shutdown
);
self
->
quit
(
exit_reason
::
user_shutdown
);
return
i
;
return
i
;
}
}
,
};
};
}
}
...
@@ -132,9 +129,7 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
...
@@ -132,9 +129,7 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
self
->
link_to
(
buddy
);
self
->
link_to
(
buddy
);
self
->
send
(
buddy
,
42
);
self
->
send
(
buddy
,
42
);
return
{
return
{
[](
int
i
)
{
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
42
);
},
CAF_CHECK_EQUAL
(
i
,
42
);
}
};
};
}
}
...
@@ -160,8 +155,9 @@ CAF_TEST(identity_semantics) {
...
@@ -160,8 +155,9 @@ CAF_TEST(identity_semantics) {
CAF_TEST
(
ping_pong
)
{
CAF_TEST
(
ping_pong
)
{
// server side
// server side
auto
port
=
unbox
(
server_side_mm
.
publish
(
auto
port
=
unbox
(
server_side
.
spawn
(
make_pong_behavior
),
0
,
local_host
));
server_side_mm
.
publish
(
server_side
.
spawn
(
make_pong_behavior
),
0
,
local_host
));
// client side
// client side
auto
pong
=
unbox
(
client_side_mm
.
remote_actor
(
local_host
,
port
));
auto
pong
=
unbox
(
client_side_mm
.
remote_actor
(
local_host
,
port
));
client_side
.
spawn
(
make_ping_behavior
,
pong
);
client_side
.
spawn
(
make_ping_behavior
,
pong
);
...
@@ -169,8 +165,9 @@ CAF_TEST(ping_pong) {
...
@@ -169,8 +165,9 @@ CAF_TEST(ping_pong) {
CAF_TEST
(
custom_message_type
)
{
CAF_TEST
(
custom_message_type
)
{
// server side
// server side
auto
port
=
unbox
(
server_side_mm
.
publish
(
auto
port
=
unbox
(
server_side
.
spawn
(
make_sort_behavior
),
0
,
local_host
));
server_side_mm
.
publish
(
server_side
.
spawn
(
make_sort_behavior
),
0
,
local_host
));
// client side
// client side
auto
sorter
=
unbox
(
client_side_mm
.
remote_actor
(
local_host
,
port
));
auto
sorter
=
unbox
(
client_side_mm
.
remote_actor
(
local_host
,
port
));
client_side
.
spawn
(
make_sort_requester_behavior
,
sorter
);
client_side
.
spawn
(
make_sort_requester_behavior
,
sorter
);
...
...
libcaf_io/test/io/remote_group.cpp
View file @
f4c5842b
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
#define CAF_SUITE io_dynamic_remote_group
#define CAF_SUITE io_dynamic_remote_group
#include "caf/test/io_dsl.hpp"
#include "caf/test/io_dsl.hpp"
#include <vector>
#include <algorithm>
#include <algorithm>
#include <vector>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
...
@@ -49,11 +49,7 @@ size_t received_messages = 0u;
...
@@ -49,11 +49,7 @@ size_t received_messages = 0u;
behavior
group_receiver
(
event_based_actor
*
self
)
{
behavior
group_receiver
(
event_based_actor
*
self
)
{
self
->
set_default_handler
(
reflect_and_quit
);
self
->
set_default_handler
(
reflect_and_quit
);
return
{
return
{[](
ok_atom
)
{
++
received_messages
;
}};
[](
ok_atom
)
{
++
received_messages
;
}
};
}
}
// Our server is `mars` and our client is `earth`.
// Our server is `mars` and our client is `earth`.
...
...
libcaf_io/test/io/remote_spawn.cpp
View file @
f4c5842b
...
@@ -21,12 +21,12 @@
...
@@ -21,12 +21,12 @@
#define CAF_SUITE io_remote_spawn
#define CAF_SUITE io_remote_spawn
#include "caf/test/dsl.hpp"
#include "caf/test/dsl.hpp"
#include <thread>
#include <string>
#include <cstring>
#include <cstring>
#include <sstream>
#include <iostream>
#include <functional>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <thread>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
...
@@ -43,13 +43,9 @@ using calculator = typed_actor<replies_to<add_atom, int, int>::with<int>,
...
@@ -43,13 +43,9 @@ using calculator = typed_actor<replies_to<add_atom, int, int>::with<int>,
// function-based, dynamically typed, event-based API
// function-based, dynamically typed, event-based API
behavior
calculator_fun
(
event_based_actor
*
)
{
behavior
calculator_fun
(
event_based_actor
*
)
{
return
behavior
{
return
{
[](
add_atom
,
int
a
,
int
b
)
{
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
},
return
a
+
b
;
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
},
},
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
}
};
};
}
}
...
@@ -61,12 +57,8 @@ public:
...
@@ -61,12 +57,8 @@ public:
behavior
make_behavior
()
override
{
behavior
make_behavior
()
override
{
return
{
return
{
[](
add_atom
,
int
a
,
int
b
)
{
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
},
return
a
+
b
;
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
},
},
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
}
};
};
}
}
};
};
...
@@ -74,12 +66,8 @@ public:
...
@@ -74,12 +66,8 @@ public:
// function-based, statically typed, event-based API
// function-based, statically typed, event-based API
calculator
::
behavior_type
typed_calculator_fun
()
{
calculator
::
behavior_type
typed_calculator_fun
()
{
return
{
return
{
[](
add_atom
,
int
a
,
int
b
)
{
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
},
return
a
+
b
;
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
},
},
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
}
};
};
}
}
...
@@ -113,15 +101,12 @@ void run_client(int argc, char** argv, uint16_t port) {
...
@@ -113,15 +101,12 @@ void run_client(int argc, char** argv, uint16_t port) {
CAF_REQUIRE_EQUAL
(
f1
(
sub_atom
::
value
,
10
,
20
),
-
10
);
CAF_REQUIRE_EQUAL
(
f1
(
sub_atom
::
value
,
10
,
20
),
-
10
);
f1
.
reset
();
f1
.
reset
();
anon_send_exit
(
*
calc
,
exit_reason
::
kill
);
anon_send_exit
(
*
calc
,
exit_reason
::
kill
);
auto
dyn_calc
=
unbox
(
mm
.
remote_spawn
<
actor
>
(
*
nid
,
"calculator-class"
,
make_message
()));
auto
dyn_calc
=
unbox
(
mm
.
remote_spawn
<
actor
>
(
*
nid
,
"calculator-class"
,
make_message
()));
CAF_REQUIRE
(
dyn_calc
);
CAF_REQUIRE
(
dyn_calc
);
self
->
request
(
dyn_calc
,
infinite
,
add_atom
::
value
,
10
,
20
).
receive
(
self
->
request
(
dyn_calc
,
infinite
,
add_atom
::
value
,
10
,
20
)
[](
int
result
)
{
.
receive
([](
int
result
)
{
CAF_CHECK_EQUAL
(
result
,
30
);
},
CAF_CHECK_EQUAL
(
result
,
30
);
[
&
](
const
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
sys
.
render
(
err
));
});
},
[
&
](
const
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
sys
.
render
(
err
));
});
anon_send_exit
(
dyn_calc
,
exit_reason
::
kill
);
anon_send_exit
(
dyn_calc
,
exit_reason
::
kill
);
mm
.
close
(
port
);
mm
.
close
(
port
);
}
}
...
...
libcaf_io/test/io/triggering.cpp
View file @
f4c5842b
...
@@ -16,16 +16,16 @@
...
@@ -16,16 +16,16 @@
* http://www.boost.org/LICENSE_1_0.txt. *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
******************************************************************************/
#include "caf/config.hpp"
#define CAF_SUITE io.triggering
#include "caf/io/all.hpp"
#define CAF_SUITE io_triggering
#include "caf/test/unit_test.hpp"
#include "caf/test/unit_test.hpp"
#include <memory>
#include <iostream>
#include <iostream>
#include <memory>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
using
namespace
std
;
using
namespace
std
;
using
namespace
caf
;
using
namespace
caf
;
...
@@ -44,12 +44,8 @@ behavior client(broker* self, connection_handle hdl) {
...
@@ -44,12 +44,8 @@ behavior client(broker* self, connection_handle hdl) {
self
->
configure_read
(
hdl
,
receive_policy
::
at_least
(
1
));
self
->
configure_read
(
hdl
,
receive_policy
::
at_least
(
1
));
self
->
flush
(
hdl
);
self
->
flush
(
hdl
);
return
{
return
{
[
=
](
const
new_data_msg
&
)
{
[
=
](
const
new_data_msg
&
)
{
CAF_FAIL
(
"server unexpectedly sent data"
);
},
CAF_FAIL
(
"server unexpectedly sent data"
);
[
=
](
const
connection_closed_msg
&
)
{
self
->
quit
();
},
},
[
=
](
const
connection_closed_msg
&
)
{
self
->
quit
();
}
};
};
}
}
...
@@ -76,7 +72,7 @@ behavior server1_stage4(stateful_actor<server1_state, broker>* self) {
...
@@ -76,7 +72,7 @@ behavior server1_stage4(stateful_actor<server1_state, broker>* self) {
// delay new tokens to force MM to remove this broker from its loop
// delay new tokens to force MM to remove this broker from its loop
CAF_MESSAGE
(
"server is done"
);
CAF_MESSAGE
(
"server is done"
);
self
->
quit
();
self
->
quit
();
}
}
,
};
};
}
}
...
@@ -98,9 +94,7 @@ behavior server1_stage3(stateful_actor<server1_state, broker>* self) {
...
@@ -98,9 +94,7 @@ behavior server1_stage3(stateful_actor<server1_state, broker>* self) {
// delay new tokens to force MM to remove this broker from its loop
// delay new tokens to force MM to remove this broker from its loop
self
->
send
(
self
,
ok_atom
::
value
);
self
->
send
(
self
,
ok_atom
::
value
);
},
},
[
=
](
ok_atom
)
{
[
=
](
ok_atom
)
{
self
->
become
(
server1_stage4
(
self
));
},
self
->
become
(
server1_stage4
(
self
));
}
};
};
}
}
...
@@ -118,7 +112,7 @@ behavior server1_stage2(stateful_actor<server1_state, broker>* self) {
...
@@ -118,7 +112,7 @@ behavior server1_stage2(stateful_actor<server1_state, broker>* self) {
CAF_REQUIRE_EQUAL
(
self
->
state
.
received
,
5u
);
CAF_REQUIRE_EQUAL
(
self
->
state
.
received
,
5u
);
CAF_REQUIRE_NOT_EQUAL
(
self
->
state
.
peer
,
invalid_connection_handle
);
CAF_REQUIRE_NOT_EQUAL
(
self
->
state
.
peer
,
invalid_connection_handle
);
self
->
become
(
server1_stage3
(
self
));
self
->
become
(
server1_stage3
(
self
));
}
}
,
};
};
}
}
...
@@ -130,7 +124,7 @@ behavior server1(stateful_actor<server1_state, broker>* self) {
...
@@ -130,7 +124,7 @@ behavior server1(stateful_actor<server1_state, broker>* self) {
self
->
state
.
peer
=
nc
.
handle
;
self
->
state
.
peer
=
nc
.
handle
;
self
->
configure_read
(
nc
.
handle
,
receive_policy
::
exactly
(
10
));
self
->
configure_read
(
nc
.
handle
,
receive_policy
::
exactly
(
10
));
self
->
become
(
server1_stage2
(
self
));
self
->
become
(
server1_stage2
(
self
));
}
}
,
};
};
}
}
...
@@ -144,14 +138,12 @@ struct server2_state {
...
@@ -144,14 +138,12 @@ struct server2_state {
behavior
server2_stage4
(
stateful_actor
<
server2_state
,
broker
>*
self
)
{
behavior
server2_stage4
(
stateful_actor
<
server2_state
,
broker
>*
self
)
{
CAF_MESSAGE
(
"enter server stage 4"
);
CAF_MESSAGE
(
"enter server stage 4"
);
return
{
return
{
[
=
](
const
new_connection_msg
&
)
{
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
acceptor_passivated_msg
&
)
{
[
=
](
const
acceptor_passivated_msg
&
)
{
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
16u
);
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
16u
);
CAF_MESSAGE
(
"server is done"
);
CAF_MESSAGE
(
"server is done"
);
self
->
quit
();
self
->
quit
();
}
}
,
};
};
}
}
...
@@ -161,9 +153,7 @@ behavior server2_stage4(stateful_actor<server2_state, broker>* self) {
...
@@ -161,9 +153,7 @@ behavior server2_stage4(stateful_actor<server2_state, broker>* self) {
behavior
server2_stage3
(
stateful_actor
<
server2_state
,
broker
>*
self
)
{
behavior
server2_stage3
(
stateful_actor
<
server2_state
,
broker
>*
self
)
{
CAF_MESSAGE
(
"enter server stage 3"
);
CAF_MESSAGE
(
"enter server stage 3"
);
return
{
return
{
[
=
](
const
new_connection_msg
&
)
{
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
acceptor_passivated_msg
&
cp
)
{
[
=
](
const
acceptor_passivated_msg
&
cp
)
{
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
11u
);
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
11u
);
// delay new tokens to force MM to remove this broker from its loop
// delay new tokens to force MM to remove this broker from its loop
...
@@ -172,7 +162,7 @@ behavior server2_stage3(stateful_actor<server2_state, broker>* self) {
...
@@ -172,7 +162,7 @@ behavior server2_stage3(stateful_actor<server2_state, broker>* self) {
[
=
](
ok_atom
,
accept_handle
hdl
)
{
[
=
](
ok_atom
,
accept_handle
hdl
)
{
self
->
trigger
(
hdl
,
5
);
self
->
trigger
(
hdl
,
5
);
self
->
become
(
server2_stage4
(
self
));
self
->
become
(
server2_stage4
(
self
));
}
}
,
};
};
}
}
...
@@ -181,14 +171,12 @@ behavior server2_stage2(stateful_actor<server2_state, broker>* self) {
...
@@ -181,14 +171,12 @@ behavior server2_stage2(stateful_actor<server2_state, broker>* self) {
CAF_MESSAGE
(
"enter server stage 2"
);
CAF_MESSAGE
(
"enter server stage 2"
);
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
1u
);
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
1u
);
return
{
return
{
[
=
](
const
new_connection_msg
&
)
{
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
acceptor_passivated_msg
&
cp
)
{
[
=
](
const
acceptor_passivated_msg
&
cp
)
{
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
6u
);
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
6u
);
self
->
trigger
(
cp
.
handle
,
5
);
self
->
trigger
(
cp
.
handle
,
5
);
self
->
become
(
server2_stage3
(
self
));
self
->
become
(
server2_stage3
(
self
));
}
}
,
};
};
}
}
...
@@ -199,7 +187,7 @@ behavior server2(stateful_actor<server2_state, broker>* self) {
...
@@ -199,7 +187,7 @@ behavior server2(stateful_actor<server2_state, broker>* self) {
self
->
state
.
accepted
+=
1
;
self
->
state
.
accepted
+=
1
;
self
->
trigger
(
nc
.
source
,
5
);
self
->
trigger
(
nc
.
source
,
5
);
self
->
become
(
server2_stage2
(
self
));
self
->
become
(
server2_stage2
(
self
));
}
}
,
};
};
}
}
...
@@ -253,8 +241,8 @@ CAF_TEST(trigger_acceptor) {
...
@@ -253,8 +241,8 @@ CAF_TEST(trigger_acceptor) {
std
::
thread
child
{[
&
]
{
std
::
thread
child
{[
&
]
{
// 16 clients will succeed to connect
// 16 clients will succeed to connect
for
(
int
i
=
0
;
i
<
16
;
++
i
)
{
for
(
int
i
=
0
;
i
<
16
;
++
i
)
{
auto
cl
=
client_system
.
middleman
().
spawn_client
(
client
,
auto
cl
=
client_system
.
middleman
().
spawn_client
(
client
,
"localhost"
,
"localhost"
,
port
);
port
);
CAF_REQUIRE
(
cl
);
CAF_REQUIRE
(
cl
);
}
}
}};
}};
...
...
libcaf_io/test/io/typed_broker.cpp
View file @
f4c5842b
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
#define CAF_SUITE io_typed_broker
#define CAF_SUITE io_typed_broker
#include "caf/test/dsl.hpp"
#include "caf/test/dsl.hpp"
#include <memory>
#include <iostream>
#include <iostream>
#include <memory>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
...
@@ -43,11 +43,14 @@ using kickoff_atom = caf::atom_constant<atom("kickoff")>;
...
@@ -43,11 +43,14 @@ using kickoff_atom = caf::atom_constant<atom("kickoff")>;
using
peer
=
connection_handler
::
extend
<
reacts_to
<
ping_atom
,
int
>
,
using
peer
=
connection_handler
::
extend
<
reacts_to
<
ping_atom
,
int
>
,
reacts_to
<
pong_atom
,
int
>>
;
reacts_to
<
pong_atom
,
int
>>
;
using
acceptor
=
accept_handler
::
extend
<
replies_to
<
publish_atom
>::
with
<
uint16_t
>>
;
using
acceptor
=
accept_handler
::
extend
<
replies_to
<
publish_atom
>::
with
<
uint16_t
>>
;
using
ping_actor
=
typed_actor
<
replies_to
<
pong_atom
,
int
>::
with
<
ping_atom
,
int
>>
;
using
ping_actor
=
typed_actor
<
replies_to
<
pong_atom
,
int
>::
with
<
ping_atom
,
int
>>
;
using
pong_actor
=
typed_actor
<
replies_to
<
ping_atom
,
int
>::
with
<
pong_atom
,
int
>>
;
using
pong_actor
=
typed_actor
<
replies_to
<
ping_atom
,
int
>::
with
<
pong_atom
,
int
>>
;
behavior
ping
(
event_based_actor
*
self
,
size_t
num_pings
)
{
behavior
ping
(
event_based_actor
*
self
,
size_t
num_pings
)
{
CAF_MESSAGE
(
"num_pings: "
<<
num_pings
);
CAF_MESSAGE
(
"num_pings: "
<<
num_pings
);
...
@@ -56,17 +59,14 @@ behavior ping(event_based_actor* self, size_t num_pings) {
...
@@ -56,17 +59,14 @@ behavior ping(event_based_actor* self, size_t num_pings) {
[
=
](
kickoff_atom
,
const
peer
&
pong
)
{
[
=
](
kickoff_atom
,
const
peer
&
pong
)
{
CAF_MESSAGE
(
"received `kickoff_atom`"
);
CAF_MESSAGE
(
"received `kickoff_atom`"
);
self
->
send
(
pong
,
ping_atom
::
value
,
1
);
self
->
send
(
pong
,
ping_atom
::
value
,
1
);
self
->
become
(
self
->
become
([
=
](
pong_atom
,
int
value
)
->
std
::
tuple
<
ping_atom
,
int
>
{
[
=
](
pong_atom
,
int
value
)
->
std
::
tuple
<
ping_atom
,
int
>
{
if
(
++*
count
>=
num_pings
)
{
if
(
++*
count
>=
num_pings
)
{
CAF_MESSAGE
(
"received "
<<
num_pings
CAF_MESSAGE
(
"received "
<<
num_pings
<<
" pings, call self->quit"
);
<<
" pings, call self->quit"
);
self
->
quit
();
self
->
quit
();
}
}
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
}
});
);
},
}
};
};
}
}
...
@@ -81,15 +81,13 @@ behavior pong(event_based_actor* self) {
...
@@ -81,15 +81,13 @@ behavior pong(event_based_actor* self) {
CAF_MESSAGE
(
"received: 'ping', "
<<
value
);
CAF_MESSAGE
(
"received: 'ping', "
<<
value
);
self
->
monitor
(
self
->
current_sender
());
self
->
monitor
(
self
->
current_sender
());
// set next behavior
// set next behavior
self
->
become
(
self
->
become
([](
ping_atom
,
int
val
)
{
[](
ping_atom
,
int
val
)
{
// CAF_MESSAGE("received: 'ping', " << val);
//CAF_MESSAGE("received: 'ping', " << val);
return
std
::
make_tuple
(
pong_atom
::
value
,
val
);
return
std
::
make_tuple
(
pong_atom
::
value
,
val
);
}
});
);
// reply to 'ping'
// reply to 'ping'
return
std
::
make_tuple
(
pong_atom
::
value
,
value
);
return
std
::
make_tuple
(
pong_atom
::
value
,
value
);
}
}
,
};
};
}
}
...
@@ -99,8 +97,8 @@ peer::behavior_type peer_fun(peer::broker_pointer self, connection_handle hdl,
...
@@ -99,8 +97,8 @@ peer::behavior_type peer_fun(peer::broker_pointer self, connection_handle hdl,
self
->
monitor
(
buddy
);
self
->
monitor
(
buddy
);
// assume exactly one connection
// assume exactly one connection
CAF_REQUIRE_EQUAL
(
self
->
connections
().
size
(),
1u
);
CAF_REQUIRE_EQUAL
(
self
->
connections
().
size
(),
1u
);
self
->
configure_read
(
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
atom_value
)
hdl
,
receive_policy
::
exactly
(
sizeof
(
atom_value
)
+
sizeof
(
int
)));
+
sizeof
(
int
)));
auto
write
=
[
=
](
atom_value
x
,
int
y
)
{
auto
write
=
[
=
](
atom_value
x
,
int
y
)
{
auto
&
buf
=
self
->
wr_buf
(
hdl
);
auto
&
buf
=
self
->
wr_buf
(
hdl
);
binary_serializer
sink
{
self
->
system
(),
buf
};
binary_serializer
sink
{
self
->
system
(),
buf
};
...
@@ -137,7 +135,7 @@ peer::behavior_type peer_fun(peer::broker_pointer self, connection_handle hdl,
...
@@ -137,7 +135,7 @@ peer::behavior_type peer_fun(peer::broker_pointer self, connection_handle hdl,
[
=
](
pong_atom
,
int
value
)
{
[
=
](
pong_atom
,
int
value
)
{
CAF_MESSAGE
(
"received: 'pong', "
<<
value
);
CAF_MESSAGE
(
"received: 'pong', "
<<
value
);
write
(
pong_atom
::
value
,
value
);
write
(
pong_atom
::
value
,
value
);
}
}
,
};
};
}
}
...
@@ -158,7 +156,7 @@ acceptor::behavior_type acceptor_fun(acceptor::broker_pointer self,
...
@@ -158,7 +156,7 @@ acceptor::behavior_type acceptor_fun(acceptor::broker_pointer self,
if
(
dm
)
if
(
dm
)
return
get
<
1
>
(
*
dm
);
return
get
<
1
>
(
*
dm
);
return
std
::
move
(
dm
.
error
());
return
std
::
move
(
dm
.
error
());
}
}
,
};
};
}
}
...
@@ -170,8 +168,8 @@ void run_client(int argc, char** argv, uint16_t port) {
...
@@ -170,8 +168,8 @@ void run_client(int argc, char** argv, uint16_t port) {
actor_system
system
{
cfg
};
actor_system
system
{
cfg
};
auto
p
=
system
.
spawn
(
ping
,
size_t
{
10
});
auto
p
=
system
.
spawn
(
ping
,
size_t
{
10
});
CAF_MESSAGE
(
"spawn_client_typed..."
);
CAF_MESSAGE
(
"spawn_client_typed..."
);
auto
cl
=
unbox
(
system
.
middleman
().
spawn_client
(
peer_fun
,
auto
cl
=
unbox
(
"localhost"
,
port
,
p
));
system
.
middleman
().
spawn_client
(
peer_fun
,
"localhost"
,
port
,
p
));
CAF_MESSAGE
(
"spawn_client_typed finished"
);
CAF_MESSAGE
(
"spawn_client_typed finished"
);
anon_send
(
p
,
kickoff_atom
::
value
,
cl
);
anon_send
(
p
,
kickoff_atom
::
value
,
cl
);
CAF_MESSAGE
(
"`kickoff_atom` has been send"
);
CAF_MESSAGE
(
"`kickoff_atom` has been send"
);
...
@@ -186,17 +184,13 @@ void run_server(int argc, char** argv) {
...
@@ -186,17 +184,13 @@ void run_server(int argc, char** argv) {
scoped_actor
self
{
system
};
scoped_actor
self
{
system
};
auto
serv
=
system
.
middleman
().
spawn_broker
(
acceptor_fun
,
system
.
spawn
(
pong
));
auto
serv
=
system
.
middleman
().
spawn_broker
(
acceptor_fun
,
system
.
spawn
(
pong
));
std
::
thread
child
;
std
::
thread
child
;
self
->
request
(
serv
,
infinite
,
publish_atom
::
value
).
receive
(
self
->
request
(
serv
,
infinite
,
publish_atom
::
value
)
.
receive
(
[
&
](
uint16_t
port
)
{
[
&
](
uint16_t
port
)
{
CAF_MESSAGE
(
"server is running on port "
<<
port
);
CAF_MESSAGE
(
"server is running on port "
<<
port
);
child
=
std
::
thread
([
=
]
{
child
=
std
::
thread
([
=
]
{
run_client
(
argc
,
argv
,
port
);
});
run_client
(
argc
,
argv
,
port
);
});
},
},
[
&
](
error
&
err
)
{
[
&
](
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
system
.
render
(
err
));
});
CAF_FAIL
(
"error: "
<<
system
.
render
(
err
));
}
);
self
->
await_all_other_actors_done
();
self
->
await_all_other_actors_done
();
CAF_MESSAGE
(
"wait for client system"
);
CAF_MESSAGE
(
"wait for client system"
);
child
.
join
();
child
.
join
();
...
...
libcaf_io/test/io/typed_remote_actor.cpp
View file @
f4c5842b
...
@@ -21,12 +21,12 @@
...
@@ -21,12 +21,12 @@
#define CAF_SUITE io_typed_remote_actor
#define CAF_SUITE io_typed_remote_actor
#include "caf/test/dsl.hpp"
#include "caf/test/dsl.hpp"
#include <thread>
#include <string>
#include <cstring>
#include <cstring>
#include <sstream>
#include <iostream>
#include <functional>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <thread>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
...
@@ -65,12 +65,10 @@ using server_type = typed_actor<replies_to<ping>::with<pong>>;
...
@@ -65,12 +65,10 @@ using server_type = typed_actor<replies_to<ping>::with<pong>>;
using
client_type
=
typed_actor
<>
;
using
client_type
=
typed_actor
<>
;
server_type
::
behavior_type
server
()
{
server_type
::
behavior_type
server
()
{
return
{
return
{[](
const
ping
&
p
)
->
pong
{
[](
const
ping
&
p
)
->
pong
{
CAF_CHECK_EQUAL
(
p
.
value
,
42
);
CAF_CHECK_EQUAL
(
p
.
value
,
42
);
return
pong
{
p
.
value
};
return
pong
{
p
.
value
};
}
}};
};
}
}
void
run_client
(
int
argc
,
char
**
argv
,
uint16_t
port
)
{
void
run_client
(
int
argc
,
char
**
argv
,
uint16_t
port
)
{
...
@@ -88,8 +86,8 @@ void run_client(int argc, char** argv, uint16_t port) {
...
@@ -88,8 +86,8 @@ void run_client(int argc, char** argv, uint16_t port) {
CAF_REQUIRE
(
!
res
);
CAF_REQUIRE
(
!
res
);
CAF_MESSAGE
(
sys
.
render
(
res
.
error
()));
CAF_MESSAGE
(
sys
.
render
(
res
.
error
()));
CAF_MESSAGE
(
"connect to typed_remote_actor"
);
CAF_MESSAGE
(
"connect to typed_remote_actor"
);
auto
serv
=
unbox
(
sys
.
middleman
().
remote_actor
<
server_type
>
(
"127.0.0.1"
,
auto
serv
=
unbox
(
port
));
sys
.
middleman
().
remote_actor
<
server_type
>
(
"127.0.0.1"
,
port
));
auto
f
=
make_function_view
(
serv
);
auto
f
=
make_function_view
(
serv
);
CAF_CHECK_EQUAL
(
f
(
ping
{
42
}),
pong
{
42
});
CAF_CHECK_EQUAL
(
f
(
ping
{
42
}),
pong
{
42
});
anon_send_exit
(
serv
,
exit_reason
::
user_shutdown
);
anon_send_exit
(
serv
,
exit_reason
::
user_shutdown
);
...
@@ -114,4 +112,3 @@ CAF_TEST(test_typed_remote_actor) {
...
@@ -114,4 +112,3 @@ CAF_TEST(test_typed_remote_actor) {
auto
argv
=
test
::
engine
::
argv
();
auto
argv
=
test
::
engine
::
argv
();
run_server
(
argc
,
argv
);
run_server
(
argc
,
argv
);
}
}
libcaf_io/test/io/unpublish.cpp
View file @
f4c5842b
...
@@ -21,9 +21,9 @@
...
@@ -21,9 +21,9 @@
#define CAF_SUITE io_unpublish
#define CAF_SUITE io_unpublish
#include "caf/test/dsl.hpp"
#include "caf/test/dsl.hpp"
#include <atomic>
#include <new>
#include <new>
#include <thread>
#include <thread>
#include <atomic>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
...
@@ -45,11 +45,9 @@ public:
...
@@ -45,11 +45,9 @@ public:
}
}
behavior
make_behavior
()
override
{
behavior
make_behavior
()
override
{
return
{
return
{[]
{
[]
{
// nop
// nop
}
}};
};
}
}
};
};
...
@@ -78,8 +76,10 @@ struct fixture {
...
@@ -78,8 +76,10 @@ struct fixture {
bool
expect_fail
=
false
)
{
bool
expect_fail
=
false
)
{
actor
result
;
actor
result
;
scoped_actor
self
{
system
,
true
};
scoped_actor
self
{
system
,
true
};
self
->
request
(
system
.
middleman
().
actor_handle
(),
infinite
,
self
connect_atom
::
value
,
hostname
,
port
).
receive
(
->
request
(
system
.
middleman
().
actor_handle
(),
infinite
,
connect_atom
::
value
,
hostname
,
port
)
.
receive
(
[
&
](
node_id
&
,
strong_actor_ptr
&
res
,
std
::
set
<
std
::
string
>&
xs
)
{
[
&
](
node_id
&
,
strong_actor_ptr
&
res
,
std
::
set
<
std
::
string
>&
xs
)
{
CAF_REQUIRE
(
xs
.
empty
());
CAF_REQUIRE
(
xs
.
empty
());
if
(
res
)
if
(
res
)
...
@@ -87,8 +87,7 @@ struct fixture {
...
@@ -87,8 +87,7 @@ struct fixture {
},
},
[
&
](
error
&
)
{
[
&
](
error
&
)
{
// nop
// nop
}
});
);
if
(
expect_fail
)
if
(
expect_fail
)
CAF_REQUIRE
(
!
result
);
CAF_REQUIRE
(
!
result
);
else
else
...
@@ -97,7 +96,9 @@ struct fixture {
...
@@ -97,7 +96,9 @@ struct fixture {
}
}
config
cfg
;
config
cfg
;
union
{
actor_system
system
;
};
// manually control ctor/dtor
union
{
actor_system
system
;
};
// manually control ctor/dtor
actor
testee
;
actor
testee
;
};
};
...
...
libcaf_openssl/src/openssl/manager.cpp
View file @
f4c5842b
...
@@ -23,8 +23,8 @@ CAF_PUSH_WARNINGS
...
@@ -23,8 +23,8 @@ CAF_PUSH_WARNINGS
#include <openssl/ssl.h>
#include <openssl/ssl.h>
CAF_POP_WARNINGS
CAF_POP_WARNINGS
#include <vector>
#include <mutex>
#include <mutex>
#include <vector>
#include "caf/actor_control_block.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system.hpp"
...
@@ -33,8 +33,8 @@ CAF_POP_WARNINGS
...
@@ -33,8 +33,8 @@ CAF_POP_WARNINGS
#include "caf/raise_error.hpp"
#include "caf/raise_error.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/openssl/middleman_actor.hpp"
#include "caf/openssl/middleman_actor.hpp"
...
@@ -97,8 +97,10 @@ manager::~manager() {
...
@@ -97,8 +97,10 @@ manager::~manager() {
void
manager
::
start
()
{
void
manager
::
start
()
{
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
manager_
=
make_middleman_actor
(
manager_
=
make_middleman_actor
(
system
(),
system
()
system
(),
system
().
middleman
().
named_broker
<
io
::
basp_broker
>
(
atom
(
"BASP"
)));
.
middleman
()
.
named_broker
<
io
::
basp_broker
>
(
atom
(
"BASP"
)));
}
}
void
manager
::
stop
()
{
void
manager
::
stop
()
{
...
...
libcaf_openssl/src/openssl/middleman_actor.cpp
View file @
f4c5842b
...
@@ -18,27 +18,27 @@
...
@@ -18,27 +18,27 @@
#include "caf/io/middleman_actor.hpp"
#include "caf/io/middleman_actor.hpp"
#include <tuple>
#include <stdexcept>
#include <stdexcept>
#include <tuple>
#include <utility>
#include <utility>
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/actor.hpp"
#include "caf/actor.hpp"
#include "caf/logger.hpp"
#include "caf/node_id.hpp"
#include "caf/actor_proxy.hpp"
#include "caf/actor_proxy.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/logger.hpp"
#include "caf/node_id.hpp"
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/typed_event_based_actor.hpp"
#include "caf/typed_event_based_actor.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/middleman_actor_impl.hpp"
#include "caf/io/middleman_actor_impl.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/doorman_impl.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/stream_impl.hpp"
#include "caf/io/network/stream_impl.hpp"
#include "caf/io/network/doorman_impl.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/openssl/session.hpp"
#include "caf/openssl/session.hpp"
...
@@ -46,8 +46,8 @@
...
@@ -46,8 +46,8 @@
# include <winsock2.h>
# include <winsock2.h>
# include <ws2tcpip.h> // socket_size_type, etc. (MSVC20xx)
# include <ws2tcpip.h> // socket_size_type, etc. (MSVC20xx)
#else
#else
# include <sys/types.h>
# include <sys/socket.h>
# include <sys/socket.h>
# include <sys/types.h>
#endif
#endif
namespace
caf
{
namespace
caf
{
...
@@ -84,8 +84,8 @@ struct ssl_policy {
...
@@ -84,8 +84,8 @@ struct ssl_policy {
if
(
result
==
io
::
network
::
invalid_native_socket
)
{
if
(
result
==
io
::
network
::
invalid_native_socket
)
{
auto
err
=
io
::
network
::
last_socket_error
();
auto
err
=
io
::
network
::
last_socket_error
();
if
(
!
io
::
network
::
would_block_or_temporarily_unavailable
(
err
))
if
(
!
io
::
network
::
would_block_or_temporarily_unavailable
(
err
))
CAF_LOG_ERROR
(
"accept failed:"
CAF_LOG_ERROR
(
<<
io
::
network
::
socket_error_as_string
(
err
));
"accept failed:"
<<
io
::
network
::
socket_error_as_string
(
err
));
return
false
;
return
false
;
}
}
io
::
network
::
child_process_inherit
(
result
,
false
);
io
::
network
::
child_process_inherit
(
result
,
false
);
...
@@ -102,9 +102,8 @@ private:
...
@@ -102,9 +102,8 @@ private:
};
};
class
scribe_impl
:
public
io
::
scribe
{
class
scribe_impl
:
public
io
::
scribe
{
public:
public:
scribe_impl
(
default_mpx
&
mpx
,
native_socket
sockfd
,
scribe_impl
(
default_mpx
&
mpx
,
native_socket
sockfd
,
session_ptr
sptr
)
session_ptr
sptr
)
:
scribe
(
io
::
network
::
conn_hdl_from_socket
(
sockfd
)),
:
scribe
(
io
::
network
::
conn_hdl_from_socket
(
sockfd
)),
launched_
(
false
),
launched_
(
false
),
stream_
(
mpx
,
sockfd
,
std
::
move
(
sptr
))
{
stream_
(
mpx
,
sockfd
,
std
::
move
(
sptr
))
{
...
@@ -181,7 +180,7 @@ class scribe_impl : public io::scribe {
...
@@ -181,7 +180,7 @@ class scribe_impl : public io::scribe {
stream_
.
passivate
();
stream_
.
passivate
();
}
}
private:
private:
bool
launched_
;
bool
launched_
;
io
::
network
::
stream_impl
<
ssl_policy
>
stream_
;
io
::
network
::
stream_impl
<
ssl_policy
>
stream_
;
};
};
...
@@ -240,8 +239,8 @@ protected:
...
@@ -240,8 +239,8 @@ protected:
CAF_LOG_ERROR
(
"Unable to create SSL session for connection"
);
CAF_LOG_ERROR
(
"Unable to create SSL session for connection"
);
return
sec
::
cannot_connect_to_node
;
return
sec
::
cannot_connect_to_node
;
}
}
CAF_LOG_DEBUG
(
"successfully created an SSL session for:"
CAF_LOG_DEBUG
(
"successfully created an SSL session for:"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
<<
CAF_ARG
(
port
));
return
make_counted
<
scribe_impl
>
(
mpx
(),
*
fd
,
std
::
move
(
sssn
));
return
make_counted
<
scribe_impl
>
(
mpx
(),
*
fd
,
std
::
move
(
sssn
));
}
}
...
...
libcaf_openssl/src/openssl/publish.cpp
View file @
f4c5842b
...
@@ -20,11 +20,11 @@
...
@@ -20,11 +20,11 @@
#include <set>
#include <set>
#include "caf/actor_control_block.hpp"
#include "caf/actor_system.hpp"
#include "caf/atom.hpp"
#include "caf/atom.hpp"
#include "caf/expected.hpp"
#include "caf/expected.hpp"
#include "caf/actor_system.hpp"
#include "caf/function_view.hpp"
#include "caf/function_view.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/openssl/manager.hpp"
#include "caf/openssl/manager.hpp"
...
@@ -46,4 +46,3 @@ expected<uint16_t> publish(actor_system& sys, const strong_actor_ptr& whom,
...
@@ -46,4 +46,3 @@ expected<uint16_t> publish(actor_system& sys, const strong_actor_ptr& whom,
}
// namespace openssl
}
// namespace openssl
}
// namespace caf
}
// namespace caf
libcaf_openssl/src/openssl/remote_actor.cpp
View file @
f4c5842b
...
@@ -18,10 +18,10 @@
...
@@ -18,10 +18,10 @@
#include "caf/openssl/remote_actor.hpp"
#include "caf/openssl/remote_actor.hpp"
#include "caf/sec.hpp"
#include "caf/atom.hpp"
#include "caf/atom.hpp"
#include "caf/expected.hpp"
#include "caf/expected.hpp"
#include "caf/function_view.hpp"
#include "caf/function_view.hpp"
#include "caf/sec.hpp"
#include "caf/openssl/manager.hpp"
#include "caf/openssl/manager.hpp"
...
@@ -54,4 +54,3 @@ expected<strong_actor_ptr> remote_actor(actor_system& sys,
...
@@ -54,4 +54,3 @@ expected<strong_actor_ptr> remote_actor(actor_system& sys,
}
// namespace openssl
}
// namespace openssl
}
// namespace caf
}
// namespace caf
libcaf_openssl/src/openssl/session.cpp
View file @
f4c5842b
...
@@ -32,8 +32,8 @@ CAF_POP_WARNINGS
...
@@ -32,8 +32,8 @@ CAF_POP_WARNINGS
// Unfortunately there's no sane way to configure OpenSSL properly.
// Unfortunately there's no sane way to configure OpenSSL properly.
#ifdef CAF_LINUX
#ifdef CAF_LINUX
#include "caf/detail/scope_guard.hpp"
#
include "caf/detail/scope_guard.hpp"
#include <signal.h>
#
include <signal.h>
# define CAF_BLOCK_SIGPIPE() \
# define CAF_BLOCK_SIGPIPE() \
sigset_t sigpipe_mask; \
sigset_t sigpipe_mask; \
...
@@ -55,7 +55,7 @@ CAF_POP_WARNINGS
...
@@ -55,7 +55,7 @@ CAF_POP_WARNINGS
#else
#else
#define CAF_BLOCK_SIGPIPE() static_cast<void>(0)
#
define CAF_BLOCK_SIGPIPE() static_cast<void>(0)
#endif // CAF_LINUX
#endif // CAF_LINUX
...
@@ -231,10 +231,10 @@ SSL_CTX* session::create_ssl_context() {
...
@@ -231,10 +231,10 @@ SSL_CTX* session::create_ssl_context() {
SSL_FILETYPE_PEM
)
SSL_FILETYPE_PEM
)
!=
1
)
!=
1
)
CAF_RAISE_ERROR
(
"cannot load private key"
);
CAF_RAISE_ERROR
(
"cannot load private key"
);
auto
cafile
=
auto
cafile
=
(
cfg
.
openssl_cafile
.
size
()
>
0
?
cfg
.
openssl_cafile
.
c_str
()
(
cfg
.
openssl_cafile
.
size
()
>
0
?
cfg
.
openssl_cafile
.
c_str
()
:
nullptr
);
:
nullptr
);
auto
capath
=
auto
capath
=
(
cfg
.
openssl_capath
.
size
()
>
0
?
cfg
.
openssl_capath
.
c_str
()
(
cfg
.
openssl_capath
.
size
()
>
0
?
cfg
.
openssl_capath
.
c_str
()
:
nullptr
);
:
nullptr
);
if
(
cafile
||
capath
)
{
if
(
cafile
||
capath
)
{
if
(
SSL_CTX_load_verify_locations
(
ctx
,
cafile
,
capath
)
!=
1
)
if
(
SSL_CTX_load_verify_locations
(
ctx
,
cafile
,
capath
)
!=
1
)
CAF_RAISE_ERROR
(
"cannot load trusted CA certificates"
);
CAF_RAISE_ERROR
(
"cannot load trusted CA certificates"
);
...
...
libcaf_openssl/test/openssl/authentication.cpp
View file @
f4c5842b
...
@@ -80,28 +80,24 @@ public:
...
@@ -80,28 +80,24 @@ public:
};
};
behavior
make_pong_behavior
()
{
behavior
make_pong_behavior
()
{
return
{
return
{[](
int
val
)
->
int
{
[](
int
val
)
->
int
{
++
val
;
++
val
;
CAF_MESSAGE
(
"pong "
<<
val
);
CAF_MESSAGE
(
"pong "
<<
val
);
return
val
;
return
val
;
}
}};
};
}
}
behavior
make_ping_behavior
(
event_based_actor
*
self
,
const
actor
&
pong
)
{
behavior
make_ping_behavior
(
event_based_actor
*
self
,
const
actor
&
pong
)
{
CAF_MESSAGE
(
"ping "
<<
0
);
CAF_MESSAGE
(
"ping "
<<
0
);
self
->
send
(
pong
,
0
);
self
->
send
(
pong
,
0
);
return
{
return
{[
=
](
int
val
)
->
int
{
[
=
](
int
val
)
->
int
{
CAF_MESSAGE
(
"ping "
<<
val
);
CAF_MESSAGE
(
"ping "
<<
val
);
if
(
val
>=
3
)
{
if
(
val
>=
3
)
{
CAF_MESSAGE
(
"terminate ping"
);
CAF_MESSAGE
(
"terminate ping"
);
self
->
quit
();
self
->
quit
();
}
}
return
val
;
return
val
;
}
}};
};
}
}
struct
fixture
{
struct
fixture
{
...
@@ -110,8 +106,12 @@ struct fixture {
...
@@ -110,8 +106,12 @@ struct fixture {
config
server_side_config
;
config
server_side_config
;
config
client_side_config
;
config
client_side_config
;
bool
initialized
;
bool
initialized
;
union
{
actor_system
server_side
;
};
union
{
union
{
actor_system
client_side
;
};
actor_system
server_side
;
};
union
{
actor_system
client_side
;
};
sched_t
*
ssched
;
sched_t
*
ssched
;
sched_t
*
csched
;
sched_t
*
csched
;
...
@@ -132,15 +132,14 @@ struct fixture {
...
@@ -132,15 +132,14 @@ struct fixture {
server_side_config
.
openssl_passphrase
=
"12345"
;
server_side_config
.
openssl_passphrase
=
"12345"
;
// check whether all files exist before setting config parameters
// check whether all files exist before setting config parameters
std
::
string
dummy
;
std
::
string
dummy
;
std
::
pair
<
const
char
*
,
std
::
string
*>
cfg
[]
{
std
::
pair
<
const
char
*
,
std
::
string
*>
{
"ca.pem"
,
&
server_side_config
.
openssl_cafile
},
cfg
[]{
{
"ca.pem"
,
&
server_side_config
.
openssl_cafile
},
{
"cert.1.pem"
,
&
server_side_config
.
openssl_certificate
},
{
"cert.1.pem"
,
&
server_side_config
.
openssl_certificate
},
{
"key.1.enc.pem"
,
&
server_side_config
.
openssl_key
},
{
"key.1.enc.pem"
,
&
server_side_config
.
openssl_key
},
{
"ca.pem"
,
skip_client_side_ca
?
&
dummy
{
"ca.pem"
,
:
&
client_side_config
.
openssl_cafile
},
skip_client_side_ca
?
&
dummy
:
&
client_side_config
.
openssl_cafile
},
{
"cert.2.pem"
,
&
client_side_config
.
openssl_certificate
},
{
"cert.2.pem"
,
&
client_side_config
.
openssl_certificate
},
{
"key.2.pem"
,
&
client_side_config
.
openssl_key
}
{
"key.2.pem"
,
&
client_side_config
.
openssl_key
}};
};
// return if any file is unreadable or non-existend
// return if any file is unreadable or non-existend
for
(
auto
&
x
:
cfg
)
{
for
(
auto
&
x
:
cfg
)
{
auto
path
=
cd
+
x
.
first
;
auto
path
=
cd
+
x
.
first
;
...
@@ -195,8 +194,8 @@ struct fixture {
...
@@ -195,8 +194,8 @@ struct fixture {
CAF_TEST_FIXTURE_SCOPE
(
authentication
,
fixture
)
CAF_TEST_FIXTURE_SCOPE
(
authentication
,
fixture
)
using
openssl
::
remote_actor
;
using
openssl
::
publish
;
using
openssl
::
publish
;
using
openssl
::
remote_actor
;
CAF_TEST
(
authentication_success
)
{
CAF_TEST
(
authentication_success
)
{
if
(
!
init
(
false
))
if
(
!
init
(
false
))
...
...
libcaf_openssl/test/openssl/remote_actor.cpp
View file @
f4c5842b
...
@@ -23,10 +23,10 @@
...
@@ -23,10 +23,10 @@
#define CAF_SUITE openssl_dynamic_remote_actor
#define CAF_SUITE openssl_dynamic_remote_actor
#include "caf/test/dsl.hpp"
#include "caf/test/dsl.hpp"
#include <
vector
>
#include <
algorithm
>
#include <sstream>
#include <sstream>
#include <utility>
#include <utility>
#include <
algorithm
>
#include <
vector
>
#include "caf/all.hpp"
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/io/all.hpp"
...
@@ -44,8 +44,7 @@ public:
...
@@ -44,8 +44,7 @@ public:
load
<
io
::
middleman
>
();
load
<
io
::
middleman
>
();
load
<
openssl
::
manager
>
();
load
<
openssl
::
manager
>
();
add_message_type
<
std
::
vector
<
int
>>
(
"std::vector<int>"
);
add_message_type
<
std
::
vector
<
int
>>
(
"std::vector<int>"
);
actor_system_config
::
parse
(
test
::
engine
::
argc
(),
actor_system_config
::
parse
(
test
::
engine
::
argc
(),
test
::
engine
::
argv
());
test
::
engine
::
argv
());
// Setting the "max consecutive reads" to 1 is highly likely to cause
// Setting the "max consecutive reads" to 1 is highly likely to cause
// OpenSSL to buffer data internally and report "pending" data after a read
// OpenSSL to buffer data internally and report "pending" data after a read
// operation. This will trigger `must_read_more` in the SSL read policy
// operation. This will trigger `must_read_more` in the SSL read policy
...
@@ -72,7 +71,7 @@ behavior make_pong_behavior() {
...
@@ -72,7 +71,7 @@ behavior make_pong_behavior() {
++
val
;
++
val
;
CAF_MESSAGE
(
"pong with "
<<
val
);
CAF_MESSAGE
(
"pong with "
<<
val
);
return
val
;
return
val
;
}
}
,
};
};
}
}
...
@@ -83,14 +82,13 @@ behavior make_ping_behavior(event_based_actor* self, const actor& pong) {
...
@@ -83,14 +82,13 @@ behavior make_ping_behavior(event_based_actor* self, const actor& pong) {
[
=
](
int
val
)
->
int
{
[
=
](
int
val
)
->
int
{
if
(
val
==
3
)
{
if
(
val
==
3
)
{
CAF_MESSAGE
(
"ping with exit"
);
CAF_MESSAGE
(
"ping with exit"
);
self
->
send_exit
(
self
->
current_sender
(),
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
exit_reason
::
user_shutdown
);
CAF_MESSAGE
(
"ping quits"
);
CAF_MESSAGE
(
"ping quits"
);
self
->
quit
();
self
->
quit
();
}
}
CAF_MESSAGE
(
"ping with "
<<
val
);
CAF_MESSAGE
(
"ping with "
<<
val
);
return
val
;
return
val
;
}
}
,
};
};
}
}
...
@@ -109,11 +107,12 @@ behavior make_sort_behavior() {
...
@@ -109,11 +107,12 @@ behavior make_sort_behavior() {
std
::
sort
(
vec
.
begin
(),
vec
.
end
());
std
::
sort
(
vec
.
begin
(),
vec
.
end
());
CAF_MESSAGE
(
"sorter sent: "
<<
to_string
(
vec
));
CAF_MESSAGE
(
"sorter sent: "
<<
to_string
(
vec
));
return
std
::
move
(
vec
);
return
std
::
move
(
vec
);
}
}
,
};
};
}
}
behavior
make_sort_requester_behavior
(
event_based_actor
*
self
,
const
actor
&
sorter
)
{
behavior
make_sort_requester_behavior
(
event_based_actor
*
self
,
const
actor
&
sorter
)
{
self
->
send
(
sorter
,
std
::
vector
<
int
>
{
5
,
4
,
3
,
2
,
1
});
self
->
send
(
sorter
,
std
::
vector
<
int
>
{
5
,
4
,
3
,
2
,
1
});
return
{
return
{
[
=
](
const
std
::
vector
<
int
>&
vec
)
{
[
=
](
const
std
::
vector
<
int
>&
vec
)
{
...
@@ -122,7 +121,7 @@ behavior make_sort_requester_behavior(event_based_actor* self, const actor& sort
...
@@ -122,7 +121,7 @@ behavior make_sort_requester_behavior(event_based_actor* self, const actor& sort
CAF_CHECK_EQUAL
(
static_cast
<
int
>
(
i
),
vec
[
i
-
1
]);
CAF_CHECK_EQUAL
(
static_cast
<
int
>
(
i
),
vec
[
i
-
1
]);
self
->
send_exit
(
sorter
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
sorter
,
exit_reason
::
user_shutdown
);
self
->
quit
();
self
->
quit
();
}
}
,
};
};
}
}
...
@@ -131,7 +130,7 @@ behavior fragile_mirror(event_based_actor* self) {
...
@@ -131,7 +130,7 @@ behavior fragile_mirror(event_based_actor* self) {
[
=
](
int
i
)
{
[
=
](
int
i
)
{
self
->
quit
(
exit_reason
::
user_shutdown
);
self
->
quit
(
exit_reason
::
user_shutdown
);
return
i
;
return
i
;
}
}
,
};
};
}
}
...
@@ -140,9 +139,7 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
...
@@ -140,9 +139,7 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
self
->
link_to
(
buddy
);
self
->
link_to
(
buddy
);
self
->
send
(
buddy
,
42
);
self
->
send
(
buddy
,
42
);
return
{
return
{
[](
int
i
)
{
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
42
);
},
CAF_CHECK_EQUAL
(
i
,
42
);
}
};
};
}
}
...
@@ -150,8 +147,8 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
...
@@ -150,8 +147,8 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
CAF_TEST_FIXTURE_SCOPE
(
dynamic_remote_actor_tests
,
fixture
)
CAF_TEST_FIXTURE_SCOPE
(
dynamic_remote_actor_tests
,
fixture
)
using
openssl
::
remote_actor
;
using
openssl
::
publish
;
using
openssl
::
publish
;
using
openssl
::
remote_actor
;
CAF_TEST_DISABLED
(
identity_semantics
)
{
CAF_TEST_DISABLED
(
identity_semantics
)
{
// server side
// server side
...
@@ -171,8 +168,8 @@ CAF_TEST_DISABLED(identity_semantics) {
...
@@ -171,8 +168,8 @@ CAF_TEST_DISABLED(identity_semantics) {
CAF_TEST_DISABLED
(
ping_pong
)
{
CAF_TEST_DISABLED
(
ping_pong
)
{
// server side
// server side
auto
port
=
unbox
(
publish
(
server_side
.
spawn
(
make_pong_behavior
),
auto
port
=
unbox
(
0
,
local_host
));
publish
(
server_side
.
spawn
(
make_pong_behavior
),
0
,
local_host
));
// client side
// client side
auto
pong
=
unbox
(
remote_actor
(
client_side
,
local_host
,
port
));
auto
pong
=
unbox
(
remote_actor
(
client_side
,
local_host
,
port
));
client_side
.
spawn
(
make_ping_behavior
,
pong
);
client_side
.
spawn
(
make_ping_behavior
,
pong
);
...
@@ -180,8 +177,8 @@ CAF_TEST_DISABLED(ping_pong) {
...
@@ -180,8 +177,8 @@ CAF_TEST_DISABLED(ping_pong) {
CAF_TEST_DISABLED
(
custom_message_type
)
{
CAF_TEST_DISABLED
(
custom_message_type
)
{
// server side
// server side
auto
port
=
unbox
(
publish
(
server_side
.
spawn
(
make_sort_behavior
),
auto
port
=
unbox
(
0
,
local_host
));
publish
(
server_side
.
spawn
(
make_sort_behavior
),
0
,
local_host
));
// client side
// client side
auto
sorter
=
unbox
(
remote_actor
(
client_side
,
local_host
,
port
));
auto
sorter
=
unbox
(
remote_actor
(
client_side
,
local_host
,
port
));
client_side
.
spawn
(
make_sort_requester_behavior
,
sorter
);
client_side
.
spawn
(
make_sort_requester_behavior
,
sorter
);
...
...
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