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
Hide 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
...
...
@@ -29,20 +29,23 @@ namespace decorator {
sequencer
::
sequencer
(
strong_actor_ptr
f
,
strong_actor_ptr
g
,
message_types_set
msg_types
)
:
monitorable_actor
(
actor_config
{}.
add_flag
(
is_actor_dot_decorator_flag
)),
f_
(
std
::
move
(
f
)),
g_
(
std
::
move
(
g
)),
msg_types_
(
std
::
move
(
msg_types
))
{
:
monitorable_actor
(
actor_config
{}.
add_flag
(
is_actor_dot_decorator_flag
)),
f_
(
std
::
move
(
f
)),
g_
(
std
::
move
(
g
)),
msg_types_
(
std
::
move
(
msg_types
))
{
CAF_ASSERT
(
f_
);
CAF_ASSERT
(
g_
);
// composed actor has dependency on constituent actors by default;
// if either constituent actor is already dead upon establishing
// the dependency, the actor is spawned dead
f_
->
get
()
->
attach
(
default_attachable
::
make_monitor
(
actor_cast
<
actor_addr
>
(
f_
),
address
()));
if
(
g_
!=
f_
)
g_
->
get
()
->
attach
(
default_attachable
::
make_monitor
(
actor_cast
<
actor_addr
>
(
g_
),
address
()));
auto
monitor1
=
default_attachable
::
make_monitor
(
actor_cast
<
actor_addr
>
(
f_
),
address
());
f_
->
get
()
->
attach
(
std
::
move
(
monitor1
));
if
(
g_
!=
f_
)
{
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
)
{
...
...
libcaf_core/src/decorator/splitter.cpp
View file @
f4c5842b
...
...
@@ -19,10 +19,10 @@
#include "caf/decorator/splitter.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/event_based_actor.hpp"
#include "caf/response_promise.hpp"
#include "caf/stateful_actor.hpp"
#include "caf/detail/disposer.hpp"
#include "caf/detail/sync_request_bouncer.hpp"
...
...
@@ -47,21 +47,21 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
// request().await() has LIFO ordering
for
(
auto
i
=
workers
.
rbegin
();
i
!=
workers
.
rend
();
++
i
)
// TODO: maybe infer some useful timeout or use config parameter?
self
->
request
(
actor_cast
<
actor
>
(
*
i
),
infinite
,
msg
)
.
await
(
[
=
]()
{
// nop
},
[
=
](
error
&
err
)
mutable
{
if
(
err
==
sec
::
unexpected_response
)
{
self
->
state
.
result
+=
std
::
move
(
err
.
context
());
if
(
--
self
->
state
.
pending
==
0
)
self
->
state
.
rp
.
deliver
(
std
::
move
(
self
->
state
.
result
));
}
else
{
self
->
state
.
rp
.
deliver
(
err
);
self
->
quit
(
);
}
}
);
self
->
request
(
actor_cast
<
actor
>
(
*
i
),
infinite
,
msg
)
.
await
(
[
=
]()
{
// nop
},
[
=
](
error
&
err
)
mutable
{
if
(
err
==
sec
::
unexpected_response
)
{
self
->
state
.
result
+=
std
::
move
(
err
.
context
());
if
(
--
self
->
state
.
pending
==
0
)
self
->
state
.
rp
.
deliver
(
std
::
move
(
self
->
state
.
result
));
}
else
{
self
->
state
.
rp
.
deliver
(
err
);
self
->
quit
();
}
}
);
return
delegated
<
message
>
{};
};
self
->
set_default_handler
(
f
);
...
...
@@ -74,10 +74,10 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
splitter
::
splitter
(
std
::
vector
<
strong_actor_ptr
>
workers
,
message_types_set
msg_types
)
:
monitorable_actor
(
actor_config
{}.
add_flag
(
is_actor_dot_decorator_flag
)),
num_workers
(
workers
.
size
()),
workers_
(
std
::
move
(
workers
)),
msg_types_
(
std
::
move
(
msg_types
))
{
:
monitorable_actor
(
actor_config
{}.
add_flag
(
is_actor_dot_decorator_flag
)),
num_workers
(
workers
.
size
()),
workers_
(
std
::
move
(
workers
)),
msg_types_
(
std
::
move
(
msg_types
))
{
// composed actor has dependency on constituent actors by default;
// if either constituent actor is already dead upon establishing
// the dependency, the actor is spawned dead
...
...
libcaf_core/src/detail/behavior_impl.cpp
View file @
f4c5842b
...
...
@@ -20,8 +20,8 @@
#include "caf/detail/behavior_impl.hpp"
#include "caf/message_handler.hpp"
#include "caf/make_type_erased_tuple_view.hpp"
#include "caf/message_handler.hpp"
namespace
caf
{
namespace
detail
{
...
...
@@ -43,9 +43,7 @@ public:
}
combinator
(
pointer
p0
,
const
pointer
&
p1
)
:
behavior_impl
(
p1
->
timeout
()),
first
(
std
::
move
(
p0
)),
second
(
p1
)
{
:
behavior_impl
(
p1
->
timeout
()),
first
(
std
::
move
(
p0
)),
second
(
p1
)
{
// nop
}
...
...
@@ -82,9 +80,7 @@ behavior_impl::~behavior_impl() {
}
behavior_impl
::
behavior_impl
(
duration
tout
)
:
timeout_
(
tout
),
begin_
(
nullptr
),
end_
(
nullptr
)
{
:
timeout_
(
tout
),
begin_
(
nullptr
),
end_
(
nullptr
)
{
// nop
}
...
...
libcaf_core/src/detail/behavior_stack.cpp
View file @
f4c5842b
...
...
@@ -18,9 +18,9 @@
#include <iterator>
#include "caf/none.hpp"
#include "caf/local_actor.hpp"
#include "caf/detail/behavior_stack.hpp"
#include "caf/local_actor.hpp"
#include "caf/none.hpp"
namespace
caf
{
namespace
detail
{
...
...
libcaf_core/src/detail/decorated_tuple.cpp
View file @
f4c5842b
...
...
@@ -24,12 +24,10 @@ namespace caf {
namespace
detail
{
decorated_tuple
::
decorated_tuple
(
cow_ptr
&&
d
,
vector_type
&&
v
)
:
decorated_
(
std
::
move
(
d
)),
mapping_
(
std
::
move
(
v
)),
type_token_
(
0xFFFFFFFF
)
{
:
decorated_
(
std
::
move
(
d
)),
mapping_
(
std
::
move
(
v
)),
type_token_
(
0xFFFFFFFF
)
{
CAF_ASSERT
(
mapping_
.
empty
()
||
*
(
std
::
max_element
(
mapping_
.
begin
(),
mapping_
.
end
()))
<
static_cast
<
const
cow_ptr
&>
(
decorated_
)
->
size
());
||
*
(
std
::
max_element
(
mapping_
.
begin
(),
mapping_
.
end
()))
<
static_cast
<
const
cow_ptr
&>
(
decorated_
)
->
size
());
// calculate type token
for
(
unsigned
long
i
:
mapping_
)
{
type_token_
<<=
6
;
...
...
libcaf_core/src/detail/dynamic_message_data.cpp
View file @
f4c5842b
...
...
@@ -30,15 +30,13 @@ dynamic_message_data::dynamic_message_data() : type_token_(0xFFFFFFFF) {
}
dynamic_message_data
::
dynamic_message_data
(
elements
&&
data
)
:
elements_
(
std
::
move
(
data
)),
type_token_
(
0xFFFFFFFF
)
{
:
elements_
(
std
::
move
(
data
)),
type_token_
(
0xFFFFFFFF
)
{
for
(
auto
&
e
:
elements_
)
add_to_type_token
(
e
->
type
().
first
);
}
dynamic_message_data
::
dynamic_message_data
(
const
dynamic_message_data
&
other
)
:
detail
::
message_data
(
other
),
type_token_
(
0xFFFFFFFF
)
{
:
detail
::
message_data
(
other
),
type_token_
(
0xFFFFFFFF
)
{
for
(
auto
&
e
:
other
.
elements_
)
{
add_to_type_token
(
e
->
type
().
first
);
elements_
.
emplace_back
(
e
->
copy
());
...
...
libcaf_core/src/detail/get_mac_addresses.cpp
View file @
f4c5842b
...
...
@@ -23,21 +23,21 @@
#if defined(CAF_MACOS) || defined(CAF_BSD) || defined(CAF_IOS)
#
include <sys/types
.h>
#
include <sys/socket.h
>
#
include <sys/ioctl.h
>
#
include <sys/sysctl.h
>
#
include <net/if.h
>
#
include <net/if_dl
.h>
#
include <netinet/in
.h>
#
include <arpa/inet
.h>
#
include <cerrno
>
#
include <cstdio
>
#
include <cstdlib
>
#
include <memory
>
#
include <sstream
>
#
include <arpa/inet
.h>
#
include <cerrno
>
#
include <cstdio
>
#
include <cstdlib
>
#
include <memory
>
#
include <net/if
.h>
#
include <net/if_dl
.h>
#
include <netinet/in
.h>
#
include <sstream
>
#
include <sys/ioctl.h
>
#
include <sys/socket.h
>
#
include <sys/sysctl.h
>
#
include <sys/types.h
>
#include <iostream>
#
include <iostream>
namespace
caf
{
namespace
detail
{
...
...
@@ -99,22 +99,21 @@ std::vector<iface_info> get_mac_addresses() {
#elif defined(CAF_LINUX) || defined(CAF_ANDROID) || defined(CAF_CYGWIN)
#include <vector>
#include <string>
#include <cctype>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <cstring>
#include <unistd.h>
#include <iostream>
# include <algorithm>
# include <cctype>
# include <cstring>
# include <fstream>
# include <iostream>
# include <iterator>
# include <net/if.h>
# include <sstream>
# include <stdio.h>
# include <string>
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <unistd.h>
# include <vector>
namespace
caf
{
namespace
detail
{
...
...
@@ -122,17 +121,15 @@ namespace detail {
std
::
vector
<
iface_info
>
get_mac_addresses
()
{
// get a socket handle
int
socktype
=
SOCK_DGRAM
;
#ifdef SOCK_CLOEXEC
#
ifdef SOCK_CLOEXEC
socktype
|=
SOCK_CLOEXEC
;
#endif
#
endif
int
sck
=
socket
(
AF_INET
,
socktype
,
0
);
if
(
sck
<
0
)
{
perror
(
"socket"
);
return
{};
}
auto
g
=
make_scope_guard
([
&
]
{
close
(
sck
);
});
auto
g
=
make_scope_guard
([
&
]
{
close
(
sck
);
});
// query available interfaces
char
buf
[
1024
]
=
{
0
};
ifconf
ifc
;
...
...
@@ -143,9 +140,7 @@ std::vector<iface_info> get_mac_addresses() {
return
{};
}
std
::
vector
<
iface_info
>
result
;
auto
ctoi
=
[](
char
c
)
->
unsigned
{
return
static_cast
<
unsigned
char
>
(
c
);
};
auto
ctoi
=
[](
char
c
)
->
unsigned
{
return
static_cast
<
unsigned
char
>
(
c
);
};
// iterate through interfaces
auto
ifr
=
ifc
.
ifc_req
;
auto
num_ifaces
=
static_cast
<
size_t
>
(
ifc
.
ifc_len
)
/
sizeof
(
ifreq
);
...
...
@@ -180,22 +175,22 @@ std::vector<iface_info> get_mac_addresses() {
// windows
#
include <ws2tcpip
.h>
#include <winsock2.h>
#
include <iphlpapi
.h>
#
include <iphlpapi
.h>
#
include <winsock2.h>
#
include <ws2tcpip
.h>
#
include <memory
>
#
include <vector
>
#
include <string
>
#
include <cctype
>
#
include <cstdio
>
#
include <cstdlib
>
#
include <cstring
>
#
include <fstream
>
#
include <sstream
>
#
include <io
stream>
#
include <iterator
>
#
include <algorithm
>
#
include <algorithm
>
#
include <cctype
>
#
include <cstdio
>
#
include <cstdlib
>
#
include <cstring
>
#
include <fstream
>
#
include <iostream
>
#
include <iterator
>
#
include <memory
>
#
include <s
stream>
#
include <string
>
#
include <vector
>
namespace
{
...
...
@@ -230,7 +225,7 @@ std::vector<iface_info> get_mac_addresses() {
// break condition
size_t
iterations
=
0
;
do
{
addresses
.
reset
((
IP_ADAPTER_ADDRESSES
*
)
malloc
(
addresses_len
));
addresses
.
reset
((
IP_ADAPTER_ADDRESSES
*
)
malloc
(
addresses_len
));
if
(
!
addresses
)
{
perror
(
"Memory allocation failed for IP_ADAPTER_ADDRESSES struct"
);
exit
(
1
);
...
...
libcaf_core/src/detail/get_process_id.cpp
View file @
f4c5842b
...
...
@@ -20,7 +20,7 @@
#include "caf/config.hpp"
#ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
# include <windows.h>
#else
# include <sys/types.h>
...
...
@@ -31,11 +31,11 @@ namespace caf {
namespace
detail
{
unsigned
get_process_id
()
{
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
return
GetCurrentProcessId
();
#
else
#else
return
static_cast
<
unsigned
>
(
getpid
());
#
endif
#endif
}
}
// namespace detail
...
...
libcaf_core/src/detail/get_root_uuid.cpp
View file @
f4c5842b
...
...
@@ -16,13 +16,13 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/config.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/config.hpp"
#ifndef CAF_MACOS // not needed on Mac OS X
namespace
{
constexpr
char
uuid_format
[]
=
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
;
}
// namespace
<anonmyous>
}
// namespace
#endif // CAF_MACOS
#if defined(CAF_MACOS)
...
...
@@ -35,9 +35,8 @@ inline void erase_trailing_newline(std::string& str) {
}
}
constexpr
const
char
*
s_get_uuid
=
"/usr/sbin/diskutil info / | "
"/usr/bin/awk '$0 ~ /UUID/ { print $3 }'"
;
constexpr
const
char
*
s_get_uuid
=
"/usr/sbin/diskutil info / | "
"/usr/bin/awk '$0 ~ /UUID/ { print $3 }'"
;
}
// namespace
...
...
@@ -62,28 +61,27 @@ std::string get_root_uuid() {
#elif defined(CAF_LINUX) || defined(CAF_BSD) || defined(CAF_CYGWIN)
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <iostream>
# include <algorithm>
# include <fstream>
# include <iostream>
# include <iterator>
# include <sstream>
# include <string>
# include <vector>
#include "caf/string_algorithms.hpp"
#
include "caf/string_algorithms.hpp"
using
std
::
vector
;
using
std
::
string
;
using
std
::
ifstream
;
using
std
::
string
;
using
std
::
vector
;
namespace
caf
{
namespace
detail
{
namespace
{
struct
columns_iterator
:
std
::
iterator
<
std
::
forward_iterator_tag
,
vector
<
string
>>
{
struct
columns_iterator
:
std
::
iterator
<
std
::
forward_iterator_tag
,
vector
<
string
>>
{
columns_iterator
(
ifstream
*
s
=
nullptr
)
:
fs
(
s
)
{
// nop
}
...
...
@@ -145,12 +143,12 @@ std::string get_root_uuid() {
#elif defined(CAF_WINDOWS)
#
include <string
>
#include <iostream>
#
include <algorithm
>
#
include <algorithm
>
#
include <iostream>
#
include <string
>
#
include <windows
.h>
#
include <tchar
.h>
#
include <tchar
.h>
#
include <windows
.h>
namespace
caf
{
namespace
detail
{
...
...
@@ -167,8 +165,8 @@ void mv(std::string& lhs, std::string&& rhs) {
// if TCHAR is defined as WCHAR, we have to do unicode conversion
void
mv
(
std
::
string
&
lhs
,
const
std
::
basic_string
<
WCHAR
>&
rhs
)
{
auto
size_needed
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
rhs
.
c_str
(),
static_cast
<
int
>
(
rhs
.
size
()),
nullptr
,
0
,
nullptr
,
nullptr
);
static_cast
<
int
>
(
rhs
.
size
()),
nullptr
,
0
,
nullptr
,
nullptr
);
lhs
.
resize
(
size_needed
);
WideCharToMultiByte
(
CP_UTF8
,
0
,
rhs
.
c_str
(),
static_cast
<
int
>
(
rhs
.
size
()),
&
lhs
[
0
],
size_needed
,
nullptr
,
nullptr
);
...
...
@@ -210,12 +208,11 @@ std::string get_root_uuid() {
}
// namespace detail
}
// namespace caf
#elif defined(CAF_IOS) || defined(CAF_ANDROID)
// return a randomly-generated UUID on mobile devices
#include <random>
#
include <random>
namespace
caf
{
namespace
detail
{
...
...
libcaf_core/src/detail/ini_consumer.cpp
View file @
f4c5842b
...
...
@@ -26,7 +26,7 @@ namespace detail {
// -- abstract_ini_consumer ----------------------------------------------------
abstract_ini_consumer
::
abstract_ini_consumer
(
abstract_ini_consumer
*
parent
)
:
parent_
(
parent
)
{
:
parent_
(
parent
)
{
// nop
}
...
...
@@ -45,13 +45,12 @@ ini_list_consumer abstract_ini_consumer::begin_list() {
// -- map_consumer -------------------------------------------------------------
ini_map_consumer
::
ini_map_consumer
(
abstract_ini_consumer
*
parent
)
:
super
(
parent
),
i_
(
xs_
.
end
())
{
:
super
(
parent
),
i_
(
xs_
.
end
())
{
CAF_ASSERT
(
parent
!=
nullptr
);
}
ini_map_consumer
::
ini_map_consumer
(
ini_map_consumer
&&
other
)
:
super
(
other
.
parent
())
{
:
super
(
other
.
parent
())
{
}
ini_map_consumer
::~
ini_map_consumer
()
{
...
...
@@ -74,13 +73,12 @@ void ini_map_consumer::value_impl(config_value&& x) {
// -- ini_list_consumer --------------------------------------------------------
ini_list_consumer
::
ini_list_consumer
(
abstract_ini_consumer
*
parent
)
:
super
(
parent
)
{
:
super
(
parent
)
{
CAF_ASSERT
(
parent
!=
nullptr
);
}
ini_list_consumer
::
ini_list_consumer
(
ini_list_consumer
&&
other
)
:
super
(
other
.
parent
()),
xs_
(
std
::
move
(
other
.
xs_
))
{
:
super
(
other
.
parent
()),
xs_
(
std
::
move
(
other
.
xs_
))
{
// nop
}
...
...
@@ -95,7 +93,7 @@ void ini_list_consumer::value_impl(config_value&& x) {
// -- ini_value_consumer -------------------------------------------------------
ini_value_consumer
::
ini_value_consumer
(
abstract_ini_consumer
*
parent
)
:
super
(
parent
)
{
:
super
(
parent
)
{
// nop
}
...
...
@@ -107,16 +105,15 @@ void ini_value_consumer::value_impl(config_value&& x) {
ini_category_consumer
::
ini_category_consumer
(
ini_consumer
*
parent
,
std
::
string
category
)
:
super
(
parent
),
category_
(
std
::
move
(
category
))
{
:
super
(
parent
),
category_
(
std
::
move
(
category
))
{
CAF_ASSERT
(
parent_
!=
nullptr
);
}
ini_category_consumer
::
ini_category_consumer
(
ini_category_consumer
&&
other
)
:
super
(
other
.
parent
()),
category_
(
std
::
move
(
other
.
category_
)),
xs_
(
std
::
move
(
other
.
xs_
)),
current_key
(
std
::
move
(
other
.
current_key
))
{
:
super
(
other
.
parent
()),
category_
(
std
::
move
(
other
.
category_
)),
xs_
(
std
::
move
(
other
.
xs_
)),
current_key
(
std
::
move
(
other
.
current_key
))
{
CAF_ASSERT
(
parent_
!=
nullptr
);
}
...
...
@@ -169,13 +166,14 @@ void ini_consumer::value_impl(config_value&& x) {
using
dict_type
=
config_value
::
dictionary
;
auto
dict
=
get_if
<
dict_type
>
(
&
x
);
if
(
dict
==
nullptr
)
{
warnings_
.
emplace_back
(
make_error
(
pec
::
type_mismatch
,
"expected a dictionary at top level"
));
warnings_
.
emplace_back
(
make_error
(
pec
::
type_mismatch
,
"expected a dictionary at top level"
));
return
;
}
if
(
current_key_
!=
"global"
)
{
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
);
// We need to "merge" values into the destination, because it can already
// 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) {
else
mapping
.
emplace_back
(
0
,
i
);
}
return
cow_ptr
{
make_counted
<
merged_tuple
>
(
std
::
move
(
data
),
std
::
move
(
mapping
))};
return
cow_ptr
{
make_counted
<
merged_tuple
>
(
std
::
move
(
data
),
std
::
move
(
mapping
))};
}
merged_tuple
::
merged_tuple
(
data_type
xs
,
mapping_type
ys
)
:
data_
(
std
::
move
(
xs
)),
type_token_
(
0xFFFFFFFF
),
mapping_
(
std
::
move
(
ys
))
{
:
data_
(
std
::
move
(
xs
)),
type_token_
(
0xFFFFFFFF
),
mapping_
(
std
::
move
(
ys
))
{
CAF_ASSERT
(
!
data_
.
empty
());
CAF_ASSERT
(
!
mapping_
.
empty
());
// calculate type token
...
...
libcaf_core/src/detail/parser/chars.cpp
View file @
f4c5842b
...
...
@@ -38,4 +38,3 @@ const char octal_chars[9] = "01234567";
}
// namespace parser
}
// namespace detail
}
// namespace caf
libcaf_core/src/detail/pretty_type_name.cpp
View file @
f4c5842b
...
...
@@ -21,9 +21,9 @@
#include "caf/config.hpp"
#if defined(CAF_LINUX) || defined(CAF_MACOS)
#
include <unistd
.h>
#
include <cxxabi
.h>
#
include <sys/types
.h>
#
include <cxxabi
.h>
#
include <sys/types
.h>
#
include <unistd
.h>
#endif
#include "caf/string_algorithms.hpp"
...
...
@@ -32,7 +32,7 @@ namespace caf {
namespace
detail
{
void
prettify_type_name
(
std
::
string
&
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
,
".__1."
,
"."
);
// gets rid of weird Clang-lib names
...
...
@@ -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
)
{
#
if defined(CAF_LINUX) || defined(CAF_MACOS)
#if defined(CAF_LINUX) || defined(CAF_MACOS)
int
stat
=
0
;
std
::
unique_ptr
<
char
,
decltype
(
free
)
*>
real_class_name
{
nullptr
,
free
};
auto
tmp
=
abi
::
__cxa_demangle
(
c_class_name
,
nullptr
,
nullptr
,
&
stat
);
real_class_name
.
reset
(
tmp
);
class_name
=
stat
==
0
?
real_class_name
.
get
()
:
c_class_name
;
#
else
#else
class_name
=
c_class_name
;
#
endif
#endif
prettify_type_name
(
class_name
);
}
...
...
libcaf_core/src/detail/private_thread.cpp
View file @
f4c5842b
...
...
@@ -27,10 +27,10 @@ namespace caf {
namespace
detail
{
private_thread
::
private_thread
(
scheduled_actor
*
self
)
:
self_destroyed_
(
false
),
self_
(
self
),
state_
(
active
),
system_
(
self
->
system
())
{
:
self_destroyed_
(
false
),
self_
(
self
),
state_
(
active
),
system_
(
self
->
system
())
{
intrusive_ptr_add_ref
(
self
->
ctrl
());
system_
.
inc_detached_threads
();
}
...
...
libcaf_core/src/detail/ripemd_160.cpp
View file @
f4c5842b
...
...
@@ -54,8 +54,8 @@
* *
\******************************************************************************/
#include <cstring>
#include "caf/detail/ripemd_160.hpp"
#include <cstring>
namespace
{
...
...
@@ -378,7 +378,7 @@ void MDfinish(dword* MDbuf, const byte* strptr, dword lswlen, dword mswlen) {
compress
(
MDbuf
,
X
);
}
}
// namespace
<anonmyous>
}
// namespace
namespace
caf
{
namespace
detail
{
...
...
libcaf_core/src/detail/set_thread_name.cpp
View file @
f4c5842b
...
...
@@ -21,13 +21,13 @@
#include "caf/config.hpp"
#ifndef CAF_WINDOWS
#include <pthread.h>
#
include <pthread.h>
#endif // CAF_WINDOWS
#if defined(CAF_LINUX)
#include <sys/prctl.h>
#
include <sys/prctl.h>
#elif defined(CAF_BSD)
#include <pthread_np.h>
#
include <pthread_np.h>
#endif // defined(...)
#include <thread>
...
...
@@ -43,14 +43,14 @@ void set_thread_name(const char* name) {
#else // CAF_WINDOWS
static_assert
(
std
::
is_same
<
std
::
thread
::
native_handle_type
,
pthread_t
>::
value
,
"std::thread not based on pthread_t"
);
#if defined(CAF_MACOS)
#
if defined(CAF_MACOS)
pthread_setname_np
(
name
);
#elif defined(CAF_LINUX)
#
elif defined(CAF_LINUX)
prctl
(
PR_SET_NAME
,
name
,
0
,
0
,
0
);
#elif defined(CAF_BSD)
#
elif defined(CAF_BSD)
pthread_set_name_np
(
pthread_self
(),
name
);
#endif // defined(...)
#endif // CAF_WINDOWS
#
endif // defined(...)
#endif
// CAF_WINDOWS
}
}
// namespace detail
...
...
libcaf_core/src/detail/simple_actor_clock.cpp
View file @
f4c5842b
...
...
@@ -177,9 +177,8 @@ size_t simple_actor_clock::trigger_expired_timeouts() {
return
result
;
}
void
simple_actor_clock
::
add_schedule_entry
(
time_point
t
,
std
::
unique_ptr
<
ordinary_timeout
>
x
)
{
void
simple_actor_clock
::
add_schedule_entry
(
time_point
t
,
std
::
unique_ptr
<
ordinary_timeout
>
x
)
{
auto
aid
=
x
->
self
->
id
();
auto
type
=
x
->
type
;
auto
pred
=
[
&
](
const
actor_lookup_map
::
value_type
&
kvp
)
{
...
...
libcaf_core/src/detail/sync_request_bouncer.cpp
View file @
f4c5842b
...
...
@@ -16,14 +16,14 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/sec.hpp"
#include "caf/atom.hpp"
#include "caf/actor.hpp"
#include "caf/config.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/mailbox_element.hpp"
#include "caf/message_id.hpp"
#include "caf/sec.hpp"
#include "caf/system_messages.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,
void
thread_safe_actor_clock
::
schedule_message
(
time_point
t
,
group
target
,
strong_actor_ptr
sender
,
message
content
)
{
push
(
new
group_msg
(
t
,
std
::
move
(
target
),
std
::
move
(
sender
),
std
::
move
(
content
)));
auto
ptr
=
new
group_msg
(
t
,
std
::
move
(
target
),
std
::
move
(
sender
),
std
::
move
(
content
));
push
(
ptr
);
}
void
thread_safe_actor_clock
::
cancel_all
()
{
...
...
libcaf_core/src/detail/tick_emitter.cpp
View file @
f4c5842b
...
...
@@ -25,9 +25,7 @@ namespace caf {
namespace
detail
{
tick_emitter
::
tick_emitter
()
:
start_
(
duration_type
{
0
}),
interval_
(
0
),
last_tick_id_
(
0
)
{
:
start_
(
duration_type
{
0
}),
interval_
(
0
),
last_tick_id_
(
0
)
{
// nop
}
...
...
@@ -56,8 +54,8 @@ void tick_emitter::interval(duration_type x) {
size_t
tick_emitter
::
timeouts
(
time_point
now
,
std
::
initializer_list
<
size_t
>
periods
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
now
)
<<
CAF_ARG
(
periods
)
<<
CAF_ARG
(
interval_
)
<<
CAF_ARG
(
start_
));
CAF_LOG_TRACE
(
CAF_ARG
(
now
)
<<
CAF_ARG
(
periods
)
<<
CAF_ARG
(
interval_
)
<<
CAF_ARG
(
start_
));
CAF_ASSERT
(
now
>=
start_
);
size_t
result
=
0
;
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,
return
me
.
v
==
*
reinterpret_cast
<
const
atom_value
*>
(
ptr
);
}
bool
try_match
(
const
type_erased_tuple
&
xs
,
pattern_iterator
iter
,
size_t
ps
)
{
bool
try_match
(
const
type_erased_tuple
&
xs
,
pattern_iterator
iter
,
size_t
ps
)
{
if
(
xs
.
size
()
!=
ps
)
return
false
;
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 {
bool
downstream_messages
::
enabled
(
const
nested_queue_type
&
q
)
noexcept
{
auto
congested
=
q
.
policy
().
handler
->
mgr
->
congested
();
CAF_LOG_DEBUG_IF
(
congested
,
"path is congested:"
<<
CAF_ARG2
(
"slot"
,
q
.
policy
().
handler
->
slots
.
receiver
));
CAF_LOG_DEBUG_IF
(
congested
,
"path is congested:"
<<
CAF_ARG2
(
"slot"
,
q
.
policy
().
handler
->
slots
.
receiver
));
return
!
congested
;
}
...
...
@@ -70,4 +71,3 @@ auto downstream_messages::quantum(const nested_queue_type& q,
}
// namespace policy
}
// namespace caf
libcaf_core/src/policy/work_stealing.cpp
View file @
f4c5842b
...
...
@@ -35,26 +35,26 @@ work_stealing::~work_stealing() {
}
work_stealing
::
worker_data
::
worker_data
(
scheduler
::
abstract_coordinator
*
p
)
:
rengine
(
std
::
random_device
{}()),
// no need to worry about wrap-around; if `p->num_workers() < 2`,
// `uniform` will not be used anyway
uniform
(
0
,
p
->
num_workers
()
-
2
),
strategies
{
{
{
CONFIG
(
"aggressive-poll-attempts"
,
aggressive_poll_attempts
),
1
,
CONFIG
(
"aggressive-steal-interval"
,
aggressive_steal_interval
),
timespan
{
0
}},
{
CONFIG
(
"moderate-poll-attempts"
,
moderate_poll_attempts
),
1
,
CONFIG
(
"moderate-steal-interval"
,
moderate_steal_interval
),
CONFIG
(
"moderate-sleep-duration"
,
moderate_sleep_duration
)},
{
1
,
0
,
CONFIG
(
"relaxed-steal-interval"
,
relaxed_steal_interval
),
CONFIG
(
"relaxed-sleep-duration"
,
relaxed_sleep_duration
)}}}
{
:
rengine
(
std
::
random_device
{}()),
// no need to worry about wrap-around; if `p->num_workers() < 2`,
// `uniform` will not be used anyway
uniform
(
0
,
p
->
num_workers
()
-
2
),
strategies
{
{
{
CONFIG
(
"aggressive-poll-attempts"
,
aggressive_poll_attempts
),
1
,
CONFIG
(
"aggressive-steal-interval"
,
aggressive_steal_interval
),
timespan
{
0
}},
{
CONFIG
(
"moderate-poll-attempts"
,
moderate_poll_attempts
),
1
,
CONFIG
(
"moderate-steal-interval"
,
moderate_steal_interval
),
CONFIG
(
"moderate-sleep-duration"
,
moderate_sleep_duration
)},
{
1
,
0
,
CONFIG
(
"relaxed-steal-interval"
,
relaxed_steal_interval
),
CONFIG
(
"relaxed-sleep-duration"
,
relaxed_sleep_duration
)}}}
{
// nop
}
work_stealing
::
worker_data
::
worker_data
(
const
worker_data
&
other
)
:
rengine
(
std
::
random_device
{}()),
uniform
(
other
.
uniform
),
strategies
(
other
.
strategies
)
{
:
rengine
(
std
::
random_device
{}()),
uniform
(
other
.
uniform
),
strategies
(
other
.
strategies
)
{
// nop
}
...
...
libcaf_core/src/scheduler/abstract_coordinator.cpp
View file @
f4c5842b
...
...
@@ -18,14 +18,14 @@
#include "caf/scheduler/abstract_coordinator.hpp"
#include <ios>
#include <thread>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <fstream>
#include <ios>
#include <iostream>
#include <thread>
#include <unordered_map>
#include <condition_variable>
#include "caf/actor_ostream.hpp"
#include "caf/actor_system.hpp"
...
...
@@ -51,7 +51,7 @@ namespace scheduler {
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
// 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) {
:
std
::
ios_base
::
out
);
if
(
fs
->
is_open
())
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
;
}
...
...
@@ -197,9 +197,7 @@ public:
flush
(
d
,
false
);
}
},
[
&
](
flush_atom
,
actor_id
aid
)
{
flush
(
get_data
(
aid
,
false
),
true
);
},
[
&
](
flush_atom
,
actor_id
aid
)
{
flush
(
get_data
(
aid
,
false
),
true
);
},
[
&
](
delete_atom
,
actor_id
aid
)
{
auto
data_ptr
=
get_data
(
aid
,
false
);
if
(
data_ptr
!=
nullptr
)
{
...
...
@@ -218,8 +216,8 @@ public:
[
&
](
exit_msg
&
em
)
{
fail_state
(
std
::
move
(
em
.
reason
));
done
=
true
;
}
)
.
until
([
&
]
{
return
done
;
});
}
)
.
until
([
&
]
{
return
done
;
});
}
const
char
*
name
()
const
override
{
...
...
@@ -271,10 +269,7 @@ void abstract_coordinator::stop_actors() {
}
abstract_coordinator
::
abstract_coordinator
(
actor_system
&
sys
)
:
next_worker_
(
0
),
max_throughput_
(
0
),
num_workers_
(
0
),
system_
(
sys
)
{
:
next_worker_
(
0
),
max_throughput_
(
0
),
num_workers_
(
0
),
system_
(
sys
)
{
// nop
}
...
...
libcaf_core/src/scheduler/test_coordinator.cpp
View file @
f4c5842b
...
...
@@ -33,8 +33,7 @@ namespace {
class
dummy_worker
:
public
execution_unit
{
public:
dummy_worker
(
test_coordinator
*
parent
)
:
execution_unit
(
&
parent
->
system
()),
parent_
(
parent
)
{
:
execution_unit
(
&
parent
->
system
()),
parent_
(
parent
)
{
// nop
}
...
...
@@ -50,10 +49,7 @@ class dummy_printer : public monitorable_actor {
public:
dummy_printer
(
actor_config
&
cfg
)
:
monitorable_actor
(
cfg
)
{
mh_
.
assign
(
[
&
](
add_atom
,
actor_id
,
const
std
::
string
&
str
)
{
std
::
cout
<<
str
;
}
);
[
&
](
add_atom
,
actor_id
,
const
std
::
string
&
str
)
{
std
::
cout
<<
str
;
});
}
void
enqueue
(
mailbox_element_ptr
what
,
execution_unit
*
)
override
{
...
...
@@ -82,8 +78,9 @@ void test_coordinator::start() {
dummy_worker
worker
{
this
};
actor_config
cfg
{
&
worker
};
auto
&
sys
=
system
();
utility_actors_
[
printer_id
]
=
make_actor
<
dummy_printer
,
actor
>
(
sys
.
next_actor_id
(),
sys
.
node
(),
&
sys
,
cfg
);
utility_actors_
[
printer_id
]
=
make_actor
<
dummy_printer
,
actor
>
(
sys
.
next_actor_id
(),
sys
.
node
(),
&
sys
,
cfg
);
}
void
test_coordinator
::
stop
()
{
...
...
@@ -161,6 +158,5 @@ void test_coordinator::inline_all_enqueues_helper() {
after_next_enqueue
([
=
]
{
inline_all_enqueues_helper
();
});
}
}
// namespace caf
}
// namespace scheduler
}
// namespace caf
libcaf_core/test/decorator/sequencer.cpp
View file @
f4c5842b
...
...
@@ -24,8 +24,7 @@
#include "caf/all.hpp"
#define ERROR_HANDLER \
[&](error& err) { CAF_FAIL(system.render(err)); }
#define ERROR_HANDLER [&](error& err) { CAF_FAIL(system.render(err)); }
using
namespace
caf
;
...
...
@@ -33,12 +32,8 @@ namespace {
behavior
testee
(
event_based_actor
*
self
)
{
return
{
[](
int
v
)
{
return
2
*
v
;
},
[
=
]
{
self
->
quit
();
}
[](
int
v
)
{
return
2
*
v
;
},
[
=
]
{
self
->
quit
();
},
};
}
...
...
@@ -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
>>
;
first_stage
::
behavior_type
typed_first_stage
()
{
return
[](
int
i
)
{
return
std
::
make_tuple
(
i
*
2.0
,
i
*
4.0
);
return
{
[](
int
i
)
{
return
std
::
make_tuple
(
i
*
2.0
,
i
*
4.0
);
},
};
}
second_stage
::
behavior_type
typed_second_stage
()
{
return
[](
double
x
,
double
y
)
{
return
x
*
y
;
return
{
[](
double
x
,
double
y
)
{
return
x
*
y
;
},
};
}
...
...
@@ -140,14 +135,12 @@ CAF_TEST(request_response_promise) {
auto
h
=
f
*
g
;
anon_send_exit
(
h
,
exit_reason
::
kill
);
CAF_CHECK
(
exited
(
h
));
self
->
request
(
h
,
infinite
,
1
).
receive
(
[](
int
)
{
CAF_CHECK
(
false
);
},
[](
error
err
)
{
CAF_CHECK_EQUAL
(
err
.
code
(),
static_cast
<
uint8_t
>
(
sec
::
request_receiver_down
));
}
);
self
->
request
(
h
,
infinite
,
1
)
.
receive
([](
int
)
{
CAF_CHECK
(
false
);
},
[](
error
err
)
{
CAF_CHECK_EQUAL
(
err
.
code
(),
static_cast
<
uint8_t
>
(
sec
::
request_receiver_down
));
});
}
// single composition of distinct actors
...
...
@@ -155,25 +148,17 @@ CAF_TEST(dot_composition_1) {
auto
first
=
system
.
spawn
(
typed_first_stage
);
auto
second
=
system
.
spawn
(
typed_second_stage
);
auto
first_then_second
=
second
*
first
;
self
->
request
(
first_then_second
,
infinite
,
42
).
receive
(
[](
double
res
)
{
CAF_CHECK_EQUAL
(
res
,
(
42
*
2.0
)
*
(
42
*
4.0
));
},
ERROR_HANDLER
);
self
->
request
(
first_then_second
,
infinite
,
42
)
.
receive
([](
double
res
)
{
CAF_CHECK_EQUAL
(
res
,
(
42
*
2.0
)
*
(
42
*
4.0
));
},
ERROR_HANDLER
);
}
// multiple self composition
CAF_TEST
(
dot_composition_2
)
{
auto
dbl_actor
=
system
.
spawn
(
testee
);
auto
dbl_x4_actor
=
dbl_actor
*
dbl_actor
*
dbl_actor
*
dbl_actor
;
self
->
request
(
dbl_x4_actor
,
infinite
,
1
).
receive
(
[](
int
v
)
{
CAF_CHECK_EQUAL
(
v
,
16
);
},
ERROR_HANDLER
);
auto
dbl_x4_actor
=
dbl_actor
*
dbl_actor
*
dbl_actor
*
dbl_actor
;
self
->
request
(
dbl_x4_actor
,
infinite
,
1
)
.
receive
([](
int
v
)
{
CAF_CHECK_EQUAL
(
v
,
16
);
},
ERROR_HANDLER
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/decorator/splitter.cpp
View file @
f4c5842b
...
...
@@ -24,8 +24,7 @@
#include "caf/all.hpp"
#define ERROR_HANDLER \
[&](error& err) { CAF_FAIL(system.render(err)); }
#define ERROR_HANDLER [&](error& err) { CAF_FAIL(system.render(err)); }
using
namespace
caf
;
...
...
@@ -36,19 +35,15 @@ using second_stage = typed_actor<replies_to<double, double>::with<double>,
replies_to
<
double
>::
with
<
double
>>
;
first_stage
::
behavior_type
typed_first_stage
()
{
return
[](
double
x
)
{
return
std
::
make_tuple
(
x
*
2.0
,
x
*
4.0
);
return
{
[](
double
x
)
{
return
std
::
make_tuple
(
x
*
2.0
,
x
*
4.0
);
},
};
}
second_stage
::
behavior_type
typed_second_stage
()
{
return
{
[](
double
x
,
double
y
)
{
return
x
*
y
;
},
[](
double
x
)
{
return
23.0
*
x
;
}
[](
double
x
,
double
y
)
{
return
x
*
y
;
},
[](
double
x
)
{
return
23.0
*
x
;
},
};
}
...
...
@@ -105,14 +100,14 @@ CAF_TEST(kill_second) {
CAF_TEST
(
untyped_splicing
)
{
init_untyped
();
self
->
request
(
first_and_second
,
infinite
,
42.0
)
.
receive
(
[](
double
x
,
double
y
,
double
z
)
{
CAF_CHECK_EQUAL
(
x
,
(
42.0
*
2.0
));
CAF_CHECK_EQUAL
(
y
,
(
42.0
*
4
.0
));
CAF_CHECK_EQUAL
(
z
,
(
23.0
*
42
.0
));
},
ERROR_HANDLER
);
self
->
request
(
first_and_second
,
infinite
,
42.0
)
.
receive
(
[](
double
x
,
double
y
,
double
z
)
{
CAF_CHECK_EQUAL
(
x
,
(
42.0
*
2
.0
));
CAF_CHECK_EQUAL
(
y
,
(
42.0
*
4
.0
));
CAF_CHECK_EQUAL
(
z
,
(
23.0
*
42.0
));
},
ERROR_HANDLER
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/detail/limited_vector.cpp
View file @
f4c5842b
...
...
@@ -28,13 +28,14 @@ using caf::detail::limited_vector;
CAF_TEST
(
basics
)
{
using
std
::
equal
;
int
arr1
[]
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
4
>
vec1
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
5
>
vec2
{
4
,
3
,
2
,
1
};
int
arr1
[]{
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
,
4
>
vec3
;
for
(
int
i
=
1
;
i
<=
4
;
++
i
)
vec3
.
push_back
(
i
);
limited_vector
<
int
,
4
>
vec4
{
1
,
2
};
limited_vector
<
int
,
2
>
vec5
{
3
,
4
};
for
(
int
i
=
1
;
i
<=
4
;
++
i
)
vec3
.
push_back
(
i
);
limited_vector
<
int
,
4
>
vec4
{
1
,
2
};
limited_vector
<
int
,
2
>
vec5
{
3
,
4
};
vec4
.
insert
(
vec4
.
end
(),
vec5
.
begin
(),
vec5
.
end
());
auto
vec6
=
vec4
;
CAF_CHECK_EQUAL
(
vec1
.
size
(),
4u
);
...
...
@@ -54,22 +55,22 @@ CAF_TEST(basics) {
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
(),
vec2
.
rbegin
()));
limited_vector
<
int
,
10
>
vec7
{
5
,
9
};
limited_vector
<
int
,
10
>
vec8
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
10
>
vec9
{
6
,
7
,
8
};
limited_vector
<
int
,
10
>
vec7
{
5
,
9
};
limited_vector
<
int
,
10
>
vec8
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
10
>
vec9
{
6
,
7
,
8
};
vec7
.
insert
(
vec7
.
begin
()
+
1
,
vec9
.
begin
(),
vec9
.
end
());
vec7
.
insert
(
vec7
.
begin
(),
vec8
.
begin
(),
vec8
.
end
());
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
());
CAF_CHECK_EQUAL
(
vec7
.
full
(),
true
);
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
))));
vec7
.
assign
(
std
::
begin
(
arr2
),
std
::
end
(
arr2
));
CAF_CHECK
((
std
::
equal
(
vec7
.
begin
(),
vec7
.
end
(),
std
::
begin
(
arr2
))));
vec7
.
assign
(
5
,
0
);
CAF_CHECK_EQUAL
(
vec7
.
size
(),
5u
);
CAF_CHECK
(
(
std
::
all_of
(
vec7
.
begin
(),
vec7
.
end
(),
[](
int
i
)
{
return
i
==
0
;
})));
CAF_CHECK
(
(
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 {
struct
atom_parser_consumer
{
atom_value
x
;
inline
void
value
(
atom_value
y
)
{
void
value
(
atom_value
y
)
{
x
=
y
;
}
};
...
...
@@ -70,7 +70,7 @@ CAF_TEST(empty 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
(
"'a b c'"
),
atom
(
"a b c"
));
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) {
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"
,
"{"
,
"}"
));
...
...
libcaf_core/test/detail/parser/read_number_or_timespan.cpp
View file @
f4c5842b
...
...
@@ -132,4 +132,3 @@ CAF_TEST(invalid timespans) {
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/detail/parser/read_string.cpp
View file @
f4c5842b
...
...
@@ -57,7 +57,7 @@ struct fixture {
};
// 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
;
result
.
assign
(
str
,
str_len
);
return
result
;
...
...
@@ -77,7 +77,7 @@ CAF_TEST(empty string) {
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"("a b c")"
),
"a b c"
_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) {
auto
cycle
=
detail
::
gcd
(
credit_interval
.
count
(),
force_batch_interval
.
count
());
CAF_CHECK_EQUAL
(
cycle
,
50
);
auto
force_batch_frequency
=
static_cast
<
size_t
>
(
force_batch_interval
.
count
()
/
cycle
);
auto
force_batch_frequency
=
static_cast
<
size_t
>
(
force_batch_interval
.
count
()
/
cycle
);
auto
credit_frequency
=
static_cast
<
size_t
>
(
credit_interval
.
count
()
/
cycle
);
detail
::
tick_emitter
tctrl
{
time_point
{
timespan
{
100
}}};
tctrl
.
interval
(
timespan
{
cycle
});
...
...
@@ -149,4 +149,3 @@ CAF_TEST(next_timeout) {
next
=
tctrl
.
next_timeout
(
now
,
{
5
,
7
});
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() {
return
42
;
}
class
instance_counting_wrapper
final
:
public
int_fun
::
wrapper
{
class
instance_counting_wrapper
final
:
public
int_fun
::
wrapper
{
public:
instance_counting_wrapper
(
size_t
*
instance_counter
)
:
instance_counter_
(
instance_counter
)
{
...
...
libcaf_core/test/detail/unordered_flat_map.cpp
View file @
f4c5842b
...
...
@@ -117,14 +117,14 @@ CAF_TEST(default_constructed) {
}
CAF_TEST
(
initializer_list_constructed
)
{
unordered_flat_map
<
int
,
int
>
zs
{{
1
,
10
},
{
2
,
20
},
{
3
,
30
},
{
4
,
40
}};
unordered_flat_map
<
int
,
int
>
zs
{{
1
,
10
},
{
2
,
20
},
{
3
,
30
},
{
4
,
40
}};
CAF_CHECK_EQUAL
(
zs
.
size
(),
4u
);
CAF_CHECK_EQUAL
(
zs
,
ivec
({{
1
,
10
},
{
2
,
20
},
{
3
,
30
},
{
4
,
40
}}));
}
CAF_TEST
(
range_constructed
)
{
kvp_vec
<
int
>
tmp
{{
1
,
10
},
{
2
,
20
},
{
3
,
30
},
{
4
,
40
}};
unordered_flat_map
<
int
,
int
>
zs
(
tmp
.
begin
(),
tmp
.
end
());
unordered_flat_map
<
int
,
int
>
zs
(
tmp
.
begin
(),
tmp
.
end
());
CAF_CHECK_EQUAL
(
zs
.
size
(),
4u
);
CAF_CHECK_EQUAL
(
zs
,
tmp
);
}
...
...
@@ -171,11 +171,9 @@ CAF_TEST(exceptions) {
try
{
auto
x
=
xs
.
at
(
10
);
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"
);
}
catch
(...)
{
}
catch
(...)
{
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) {
}
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
g
;
fun_type
*
selected
=
&
f
;
...
...
@@ -191,9 +191,7 @@ CAF_TEST(alternating_consumer) {
return
task_result
::
resume
;
};
/// Define a function object that alternates between f and g.
auto
h
=
[
&
](
inode
&
x
)
{
return
(
*
selected
)(
x
);
};
auto
h
=
[
&
](
inode
&
x
)
{
return
(
*
selected
)(
x
);
};
// 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.
fill
(
queue
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
...
...
@@ -236,5 +234,4 @@ CAF_TEST(to_string) {
CAF_CHECK_EQUAL
(
deep_to_string
(
queue
),
"[1, 2, 3, 4]"
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/intrusive/fifo_inbox.cpp
View file @
f4c5842b
...
...
@@ -132,9 +132,7 @@ CAF_TEST(unblock) {
CAF_TEST
(
await
)
{
std
::
mutex
mx
;
std
::
condition_variable
cv
;
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_back
(
mx
,
cv
,
1
);
}};
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_back
(
mx
,
cv
,
1
);
}};
inbox
.
synchronized_await
(
mx
,
cv
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"1"
);
t
.
join
();
...
...
@@ -152,9 +150,7 @@ CAF_TEST(timed_await) {
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_CHECK_EQUAL
(
fetch
(),
"1"
);
tout
+=
std
::
chrono
::
hours
(
1000
);
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_back
(
mx
,
cv
,
2
);
}};
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_back
(
mx
,
cv
,
2
);
}};
res
=
inbox
.
synchronized_await
(
mx
,
cv
,
tout
);
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"2"
);
...
...
libcaf_core/test/intrusive/lifo_inbox.cpp
View file @
f4c5842b
...
...
@@ -125,9 +125,7 @@ CAF_TEST(unblock) {
CAF_TEST
(
await
)
{
std
::
mutex
mx
;
std
::
condition_variable
cv
;
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_front
(
mx
,
cv
,
1
);
}};
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_front
(
mx
,
cv
,
1
);
}};
inbox
.
synchronized_await
(
mx
,
cv
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"1"
);
t
.
join
();
...
...
@@ -145,9 +143,7 @@ CAF_TEST(timed_await) {
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_CHECK_EQUAL
(
fetch
(),
"1"
);
tout
+=
std
::
chrono
::
hours
(
1000
);
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_front
(
mx
,
cv
,
2
);
}};
std
::
thread
t
{[
&
]
{
inbox
.
synchronized_emplace_front
(
mx
,
cv
,
2
);
}};
res
=
inbox
.
synchronized_await
(
mx
,
cv
,
tout
);
CAF_REQUIRE_EQUAL
(
res
,
true
);
CAF_REQUIRE_EQUAL
(
close_and_fetch
(),
"2"
);
...
...
libcaf_core/test/intrusive/wdrr_dynamic_multiplexed_queue.cpp
View file @
f4c5842b
...
...
@@ -35,7 +35,7 @@ namespace {
struct
inode
:
singly_linked
<
inode
>
{
int
value
;
inode
(
int
x
=
0
)
:
value
(
x
)
{
inode
(
int
x
=
0
)
noexcept
:
value
(
x
)
{
// nop
}
};
...
...
@@ -55,7 +55,7 @@ struct nested_inode_policy {
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
;
}
...
...
@@ -65,8 +65,8 @@ struct nested_inode_policy {
// nop
}
nested_inode_policy
(
nested_inode_policy
&&
)
=
default
;
nested_inode_policy
&
operator
=
(
nested_inode_policy
&&
)
=
default
;
nested_inode_policy
(
nested_inode_policy
&&
)
noexcept
=
default
;
nested_inode_policy
&
operator
=
(
nested_inode_policy
&&
)
noexcept
=
default
;
};
struct
inode_policy
{
...
...
@@ -86,15 +86,15 @@ struct inode_policy {
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
;
}
static
inline
bool
enabled
(
const
queue_type
&
)
{
static
bool
enabled
(
const
queue_type
&
)
noexcept
{
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
;
}
...
...
@@ -210,5 +210,4 @@ CAF_TEST(to_string) {
CAF_CHECK_EQUAL
(
deep_to_string
(
queue
),
"[3, 1, 4, 2]"
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/intrusive/wdrr_fixed_multiplexed_queue.cpp
View file @
f4c5842b
...
...
@@ -86,10 +86,8 @@ public:
using
nested_queue_type
=
drr_queue
<
inode_policy
>
;
using
queue_type
=
wdrr_fixed_multiplexed_queue
<
inode_policy
,
high_prio_queue
,
nested_queue_type
,
nested_queue_type
>
;
using
queue_type
=
wdrr_fixed_multiplexed_queue
<
inode_policy
,
high_prio_queue
,
nested_queue_type
,
nested_queue_type
>
;
struct
fetch_helper
{
std
::
string
result
;
...
...
libcaf_core/test/policy/categorized.cpp
View file @
f4c5842b
...
...
@@ -59,7 +59,7 @@ struct mailbox_policy {
using
mailbox_type
=
intrusive
::
fifo_inbox
<
mailbox_policy
>
;
struct
fixture
{};
struct
fixture
{};
struct
consumer
{
std
::
vector
<
int
>
ints
;
...
...
@@ -75,7 +75,7 @@ struct consumer {
template
<
class
Key
,
class
Queue
,
class
...
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
;
}
};
...
...
libcaf_io/src/detail/socket_guard.cpp
View file @
f4c5842b
...
...
@@ -19,9 +19,9 @@
#include "caf/detail/socket_guard.hpp"
#ifdef CAF_WINDOWS
# include <winsock2.h>
#
include <winsock2.h>
#else
# include <unistd.h>
#
include <unistd.h>
#endif
#include "caf/logger.hpp"
...
...
@@ -52,4 +52,4 @@ void socket_guard::close() {
}
}
// namespace detail
}
// namespace
detail
}
// namespace
caf
libcaf_io/src/io/abstract_broker.cpp
View file @
f4c5842b
...
...
@@ -16,11 +16,11 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/
none
.hpp"
#include "caf/
actor_system
.hpp"
#include "caf/config.hpp"
#include "caf/logger.hpp"
#include "caf/actor_system.hpp"
#include "caf/make_counted.hpp"
#include "caf/none.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/io/broker.hpp"
...
...
@@ -34,8 +34,8 @@
namespace
caf
{
namespace
io
{
void
abstract_broker
::
enqueue
(
strong_actor_ptr
src
,
message_id
mid
,
message
msg
,
execution_unit
*
)
{
void
abstract_broker
::
enqueue
(
strong_actor_ptr
src
,
message_id
mid
,
message
msg
,
execution_unit
*
)
{
enqueue
(
make_mailbox_element
(
std
::
move
(
src
),
mid
,
{},
std
::
move
(
msg
)),
&
backend
());
}
...
...
@@ -137,8 +137,7 @@ void abstract_broker::enqueue_datagram(datagram_handle hdl,
x
->
enqueue_datagram
(
hdl
,
std
::
move
(
buf
));
}
void
abstract_broker
::
write
(
datagram_handle
hdl
,
size_t
bs
,
const
void
*
buf
)
{
void
abstract_broker
::
write
(
datagram_handle
hdl
,
size_t
bs
,
const
void
*
buf
)
{
auto
&
out
=
wr_buf
(
hdl
);
auto
first
=
reinterpret_cast
<
const
char
*>
(
buf
);
auto
last
=
first
+
bs
;
...
...
@@ -225,7 +224,8 @@ void abstract_broker::add_hdl_for_datagram_servant(datagram_servant_ptr 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
));
auto
ptr
=
backend
().
new_datagram_servant
(
fd
);
auto
hdl
=
ptr
->
hdl
();
...
...
@@ -233,9 +233,8 @@ datagram_handle abstract_broker::add_datagram_servant(network::native_socket fd)
return
hdl
;
}
datagram_handle
abstract_broker
::
add_datagram_servant_for_endpoint
(
network
::
native_socket
fd
,
const
network
::
ip_endpoint
&
ep
)
{
datagram_handle
abstract_broker
::
add_datagram_servant_for_endpoint
(
network
::
native_socket
fd
,
const
network
::
ip_endpoint
&
ep
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
));
auto
ptr
=
backend
().
new_datagram_servant_for_endpoint
(
fd
,
ep
);
auto
hdl
=
ptr
->
hdl
();
...
...
@@ -356,8 +355,8 @@ resumable::subtype_t abstract_broker::subtype() const {
return
io_actor
;
}
resumable
::
resume_result
abstract_broker
::
resume
(
execution_unit
*
ctx
,
size_t
mt
)
{
resumable
::
resume_result
abstract_broker
::
resume
(
execution_unit
*
ctx
,
size_t
mt
)
{
CAF_ASSERT
(
ctx
!=
nullptr
);
CAF_ASSERT
(
ctx
==
&
backend
());
return
scheduled_actor
::
resume
(
ctx
,
mt
);
...
...
libcaf_io/src/io/basp/header.cpp
View file @
f4c5842b
...
...
@@ -33,26 +33,20 @@ std::string to_bin(uint8_t x) {
return
res
;
}
std
::
string
to_string
(
const
header
&
hdr
)
{
std
::
string
to_string
(
const
header
&
hdr
)
{
std
::
ostringstream
oss
;
oss
<<
"{"
<<
to_string
(
hdr
.
operation
)
<<
", "
<<
to_bin
(
hdr
.
flags
)
<<
", "
<<
hdr
.
payload_len
<<
", "
<<
hdr
.
operation_data
<<
", "
<<
hdr
.
source_actor
<<
", "
<<
hdr
.
dest_actor
<<
"}"
;
oss
<<
"{"
<<
to_string
(
hdr
.
operation
)
<<
", "
<<
to_bin
(
hdr
.
flags
)
<<
", "
<<
hdr
.
payload_len
<<
", "
<<
hdr
.
operation_data
<<
", "
<<
hdr
.
source_actor
<<
", "
<<
hdr
.
dest_actor
<<
"}"
;
return
oss
.
str
();
}
bool
operator
==
(
const
header
&
lhs
,
const
header
&
rhs
)
{
return
lhs
.
operation
==
rhs
.
operation
&&
lhs
.
flags
==
rhs
.
flags
&&
lhs
.
payload_len
==
rhs
.
payload_len
&&
lhs
.
operation_data
==
rhs
.
operation_data
&&
lhs
.
source_actor
==
rhs
.
source_actor
&&
lhs
.
dest_actor
==
rhs
.
dest_actor
;
return
lhs
.
operation
==
rhs
.
operation
&&
lhs
.
flags
==
rhs
.
flags
&&
lhs
.
payload_len
==
rhs
.
payload_len
&&
lhs
.
operation_data
==
rhs
.
operation_data
&&
lhs
.
source_actor
==
rhs
.
source_actor
&&
lhs
.
dest_actor
==
rhs
.
dest_actor
;
}
namespace
{
...
...
libcaf_io/src/io/basp/instance.cpp
View file @
f4c5842b
...
...
@@ -33,7 +33,7 @@ namespace io {
namespace
basp
{
instance
::
callee
::
callee
(
actor_system
&
sys
,
proxy_registry
::
backend
&
backend
)
:
namespace_
(
sys
,
backend
)
{
:
namespace_
(
sys
,
backend
)
{
// nop
}
...
...
@@ -42,9 +42,7 @@ instance::callee::~callee() {
}
instance
::
instance
(
abstract_broker
*
parent
,
callee
&
lstnr
)
:
tbl_
(
parent
),
this_node_
(
parent
->
system
().
node
()),
callee_
(
lstnr
)
{
:
tbl_
(
parent
),
this_node_
(
parent
->
system
().
node
()),
callee_
(
lstnr
)
{
CAF_ASSERT
(
this_node_
!=
none
);
auto
workers
=
get_or
(
config
(),
"middleman.workers"
,
defaults
::
middleman
::
workers
);
...
...
@@ -52,9 +50,8 @@ instance::instance(abstract_broker* parent, callee& lstnr)
hub_
.
add_new_worker
(
queue_
,
proxies
());
}
connection_state
instance
::
handle
(
execution_unit
*
ctx
,
new_data_msg
&
dm
,
header
&
hdr
,
bool
is_payload
)
{
connection_state
instance
::
handle
(
execution_unit
*
ctx
,
new_data_msg
&
dm
,
header
&
hdr
,
bool
is_payload
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
dm
)
<<
CAF_ARG
(
is_payload
));
// function object providing cleanup code on errors
auto
err
=
[
&
]()
->
connection_state
{
...
...
@@ -90,7 +87,7 @@ connection_state instance::handle(execution_unit* ctx,
void
instance
::
handle_heartbeat
(
execution_unit
*
ctx
)
{
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
));
write_heartbeat
(
ctx
,
callee_
.
get_buffer
(
kvp
.
first
));
callee_
.
flush
(
kvp
.
first
);
...
...
@@ -116,8 +113,8 @@ void instance::write(execution_unit* ctx, const routing_table::route& r,
void
instance
::
add_published_actor
(
uint16_t
port
,
strong_actor_ptr
published_actor
,
std
::
set
<
std
::
string
>
published_interface
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
published_actor
)
<<
CAF_ARG
(
published_interface
));
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
published_
actor
)
<<
CAF_ARG
(
published_
interface
));
using
std
::
swap
;
auto
&
entry
=
published_actors_
[
port
];
swap
(
entry
.
first
,
published_actor
);
...
...
@@ -136,8 +133,7 @@ size_t instance::remove_published_actor(uint16_t port,
return
1
;
}
size_t
instance
::
remove_published_actor
(
const
actor_addr
&
whom
,
uint16_t
port
,
size_t
instance
::
remove_published_actor
(
const
actor_addr
&
whom
,
uint16_t
port
,
removed_published_actor
*
cb
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
whom
)
<<
CAF_ARG
(
port
));
size_t
result
=
0
;
...
...
@@ -169,23 +165,30 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
const
std
::
vector
<
strong_actor_ptr
>&
forwarding_stack
,
const
node_id
&
dest_node
,
uint64_t
dest_actor
,
uint8_t
flags
,
message_id
mid
,
const
message
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
sender
)
<<
CAF_ARG
(
dest_node
)
<<
CAF_ARG
(
mid
)
<<
CAF_ARG
(
msg
));
CAF_LOG_TRACE
(
CAF_ARG
(
sender
)
<<
CAF_ARG
(
dest_node
)
<<
CAF_ARG
(
mid
)
<<
CAF_ARG
(
msg
));
CAF_ASSERT
(
dest_node
&&
this_node_
!=
dest_node
);
auto
path
=
lookup
(
dest_node
);
if
(
!
path
)
return
false
;
auto
&
source_node
=
sender
?
sender
->
node
()
:
this_node_
;
if
(
dest_node
==
path
->
next_hop
&&
source_node
==
this_node_
)
{
header
hdr
{
message_type
::
direct_message
,
flags
,
0
,
mid
.
integer_value
(),
sender
?
sender
->
id
()
:
invalid_actor_id
,
dest_actor
};
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
return
sink
(
forwarding_stack
,
msg
);
});
header
hdr
{
message_type
::
direct_message
,
flags
,
0
,
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
);
}
else
{
header
hdr
{
message_type
::
routed_message
,
flags
,
0
,
mid
.
integer_value
(),
sender
?
sender
->
id
()
:
invalid_actor_id
,
dest_actor
};
header
hdr
{
message_type
::
routed_message
,
flags
,
0
,
mid
.
integer_value
(),
sender
?
sender
->
id
()
:
invalid_actor_id
,
dest_actor
};
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
return
sink
(
source_node
,
dest_node
,
forwarding_stack
,
msg
);
});
...
...
@@ -195,8 +198,8 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
return
true
;
}
void
instance
::
write
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
header
&
hdr
,
payload_writer
*
pw
)
{
void
instance
::
write
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
header
&
hdr
,
payload_writer
*
pw
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdr
));
binary_serializer
sink
{
ctx
,
buf
};
if
(
pw
!=
nullptr
)
{
...
...
@@ -235,26 +238,32 @@ void instance::write_server_handshake(execution_unit* ctx, buffer_type& out_buf,
}
return
sink
(
this_node_
,
app_ids
,
aid
,
iface
);
});
header
hdr
{
message_type
::
server_handshake
,
0
,
0
,
version
,
invalid_actor_id
,
invalid_actor_id
};
header
hdr
{
message_type
::
server_handshake
,
0
,
0
,
version
,
invalid_actor_id
,
invalid_actor_id
};
write
(
ctx
,
out_buf
,
hdr
,
&
writer
);
}
void
instance
::
write_client_handshake
(
execution_unit
*
ctx
,
buffer_type
&
buf
)
{
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
return
sink
(
this_node_
);
});
header
hdr
{
message_type
::
client_handshake
,
0
,
0
,
0
,
invalid_actor_id
,
invalid_actor_id
};
auto
writer
=
make_callback
(
[
&
](
serializer
&
sink
)
->
error
{
return
sink
(
this_node_
);
});
header
hdr
{
message_type
::
client_handshake
,
0
,
0
,
0
,
invalid_actor_id
,
invalid_actor_id
};
write
(
ctx
,
buf
,
hdr
,
&
writer
);
}
void
instance
::
write_monitor_message
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
const
node_id
&
dest_node
,
actor_id
aid
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
dest_node
)
<<
CAF_ARG
(
aid
));
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
return
sink
(
this_node_
,
dest_node
);
});
auto
writer
=
make_callback
(
[
&
](
serializer
&
sink
)
->
error
{
return
sink
(
this_node_
,
dest_node
);
});
header
hdr
{
message_type
::
monitor_message
,
0
,
0
,
0
,
invalid_actor_id
,
aid
};
write
(
ctx
,
buf
,
hdr
,
&
writer
);
}
...
...
@@ -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.
if
(
tbl_
.
lookup_direct
(
source_node
))
{
CAF_LOG_DEBUG
(
"close redundant direct connection:"
<<
CAF_ARG
(
source_node
));
CAF_LOG_DEBUG
(
"close redundant direct connection:"
<<
CAF_ARG
(
source_node
));
callee_
.
finalize_handshake
(
source_node
,
aid
,
sigs
);
return
false
;
}
...
...
@@ -354,8 +363,8 @@ bool instance::handle(execution_unit* ctx, connection_handle hdl, header& hdr,
}
// Drop repeated handshakes.
if
(
tbl_
.
lookup_direct
(
source_node
))
{
CAF_LOG_DEBUG
(
"received repeated client handshake:"
<<
CAF_ARG
(
source_node
));
CAF_LOG_DEBUG
(
"received repeated client handshake:"
<<
CAF_ARG
(
source_node
));
break
;
}
// 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 {
namespace
{
const
char
*
message_type_strings
[]
=
{
"server_handshake"
,
"client_handshake"
,
"direct_message"
,
"routed_message"
,
"proxy_creation"
,
"proxy_destruction"
,
"heartbeat"
"server_handshake"
,
"client_handshake"
,
"direct_message"
,
"routed_message"
,
"proxy_creation"
,
"proxy_destruction"
,
"heartbeat"
,
};
}
// namespace
...
...
libcaf_io/src/io/basp/routing_table.cpp
View file @
f4c5842b
...
...
@@ -24,8 +24,7 @@ namespace caf {
namespace
io
{
namespace
basp
{
routing_table
::
routing_table
(
abstract_broker
*
parent
)
:
parent_
(
parent
)
{
routing_table
::
routing_table
(
abstract_broker
*
parent
)
:
parent_
(
parent
)
{
// nop
}
...
...
libcaf_io/src/io/broker.cpp
View file @
f4c5842b
...
...
@@ -16,12 +16,12 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/none.hpp"
#include "caf/config.hpp"
#include "caf/make_counted.hpp"
#include "caf/none.hpp"
#include "caf/logger.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/logger.hpp"
#include "caf/io/broker.hpp"
#include "caf/io/middleman.hpp"
...
...
@@ -37,7 +37,7 @@ void broker::initialize() {
init_broker
();
auto
bhvr
=
make_behavior
();
CAF_LOG_DEBUG_IF
(
!
bhvr
,
"make_behavior() did not return a behavior:"
<<
CAF_ARG2
(
"alive"
,
alive
()));
<<
CAF_ARG2
(
"alive"
,
alive
()));
if
(
bhvr
)
{
// make_behavior() did return a behavior instead of using become()
CAF_LOG_DEBUG
(
"make_behavior() did return a valid behavior"
);
...
...
@@ -49,7 +49,6 @@ broker::broker(actor_config& cfg) : super(cfg) {
// nop
}
behavior
broker
::
make_behavior
()
{
behavior
res
;
if
(
initial_behavior_fac_
)
{
...
...
libcaf_io/src/io/connection_helper.cpp
View file @
f4c5842b
...
...
@@ -49,39 +49,37 @@ behavior connection_helper(stateful_actor<connection_helper_state>* self,
CAF_LOG_DEBUG
(
"received requested config:"
<<
CAF_ARG
(
msg
));
// whatever happens, we are done afterwards
self
->
quit
();
msg
.
apply
({
[
&
](
uint16_t
port
,
network
::
address_listing
&
addresses
)
{
if
(
item
==
"basp.default-connectivity-tcp"
)
{
auto
&
mx
=
self
->
system
().
middleman
().
backend
();
for
(
auto
&
kvp
:
addresses
)
{
for
(
auto
&
addr
:
kvp
.
second
)
{
auto
hdl
=
mx
.
new_tcp_scribe
(
addr
,
port
);
if
(
hdl
)
{
// gotcha! send scribe to our BASP broker
// to initiate handshake etc.
CAF_LOG_INFO
(
"connected directly:"
<<
CAF_ARG
(
addr
));
self
->
send
(
b
,
connect_atom
::
value
,
*
hdl
,
port
);
return
;
}
msg
.
apply
({[
&
](
uint16_t
port
,
network
::
address_listing
&
addresses
)
{
if
(
item
==
"basp.default-connectivity-tcp"
)
{
auto
&
mx
=
self
->
system
().
middleman
().
backend
();
for
(
auto
&
kvp
:
addresses
)
{
for
(
auto
&
addr
:
kvp
.
second
)
{
auto
hdl
=
mx
.
new_tcp_scribe
(
addr
,
port
);
if
(
hdl
)
{
// gotcha! send scribe to our BASP broker
// to initiate handshake etc.
CAF_LOG_INFO
(
"connected directly:"
<<
CAF_ARG
(
addr
));
self
->
send
(
b
,
connect_atom
::
value
,
*
hdl
,
port
);
return
;
}
}
CAF_LOG_INFO
(
"could not connect to node directly"
);
}
else
{
CAF_LOG_INFO
(
"aborted direct connection attempt, unknown item: "
<<
CAF_ARG
(
item
));
}
CAF_LOG_INFO
(
"could not connect to node directly"
);
}
else
{
CAF_LOG_INFO
(
"aborted direct connection attempt, unknown item: "
<<
CAF_ARG
(
item
));
}
});
}
}
);
},
after
(
autoconnect_timeout
)
>>
[
=
]
{
CAF_LOG_TRACE
(
CAF_ARG
(
""
));
// nothing heard in about 10 minutes... just a call it a day, then
CAF_LOG_INFO
(
"aborted direct connection attempt after 10min"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
}
after
(
autoconnect_timeout
)
>>
[
=
]
{
CAF_LOG_TRACE
(
CAF_ARG
(
""
));
// nothing heard in about 10 minutes... just a call it a day, then
CAF_LOG_INFO
(
"aborted direct connection attempt after 10min"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
},
};
}
}
// namespace io
}
// 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,
}
// namespace io
}
// namespace caf
libcaf_io/src/io/middleman.cpp
View file @
f4c5842b
...
...
@@ -18,49 +18,49 @@
#include "caf/io/middleman.hpp"
#include <tuple>
#include <cerrno>
#include <memory>
#include <cstring>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <tuple>
#include "caf/sec.hpp"
#include "caf/send.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/config.hpp"
#include "caf/logger.hpp"
#include "caf/node_id.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/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/scoped_actor.hpp"
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/typed_event_based_actor.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/test_multiplexer.hpp"
#include "caf/io/network/default_multiplexer.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/safe_equal.hpp"
#include "caf/detail/get_root_uuid.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/detail/get_mac_addresses.hpp"
#ifdef CAF_WINDOWS
#
include <io
.h>
#
include <fcntl
.h>
#
include <fcntl
.h>
#
include <io
.h>
#endif // CAF_WINDOWS
namespace
caf
{
...
...
@@ -106,8 +106,8 @@ expected<strong_actor_ptr> middleman::remote_spawn_impl(const node_id& nid,
std
::
set
<
std
::
string
>
s
,
duration
timeout
)
{
auto
f
=
make_function_view
(
actor_handle
(),
timeout
);
return
f
(
spawn_atom
::
value
,
nid
,
std
::
move
(
name
),
std
::
move
(
args
),
std
::
move
(
s
));
return
f
(
spawn_atom
::
value
,
nid
,
std
::
move
(
name
),
std
::
move
(
args
),
std
::
move
(
s
));
}
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,
return
{
[
self
](
get_atom
,
const
std
::
string
&
name
)
{
return
self
->
system
().
groups
().
get_local
(
name
);
}
}
,
};
};
auto
gn
=
system
().
spawn
<
hidden
+
lazy_init
>
(
group_nameserver
);
...
...
@@ -217,34 +217,25 @@ expected<group> middleman::remote_group(const std::string& group_identifier,
/// terminate the actor after both requests finish.
self
->
unbecome
();
auto
rp
=
self
->
make_response_promise
();
self
->
request
(
mm
,
infinite
,
connect_atom
::
value
,
host
,
port
)
.
then
(
[
=
](
const
node_id
&
,
strong_actor_ptr
&
ptr
,
const
std
::
set
<
std
::
string
>&
)
mutable
{
self
->
request
(
mm
,
infinite
,
connect_atom
::
value
,
host
,
port
)
.
then
(
[
=
](
const
node_id
&
,
strong_actor_ptr
&
ptr
,
const
std
::
set
<
std
::
string
>&
)
mutable
{
auto
hdl
=
actor_cast
<
actor
>
(
ptr
);
self
->
request
(
hdl
,
infinite
,
get_atom
::
value
,
group_identifier
)
.
then
(
[
=
](
group
&
result
)
mutable
{
rp
.
deliver
(
std
::
move
(
result
));
}
);
}
);
}
.
then
(
[
=
](
group
&
result
)
mutable
{
rp
.
deliver
(
std
::
move
(
result
));
});
});
},
};
};
// Spawn the helper actor and wait for the result.
expected
<
group
>
result
{
sec
::
cannot_connect_to_node
};
scoped_actor
self
{
system
(),
true
};
self
->
request
(
self
->
spawn
<
lazy_init
>
(
two_step_lookup
,
actor_handle
()),
infinite
,
get_atom
::
value
)
.
receive
(
[
&
](
group
&
grp
)
{
result
=
std
::
move
(
grp
);
},
[
&
](
error
&
err
)
{
result
=
std
::
move
(
err
);
}
);
self
->
request
(
self
->
spawn
<
lazy_init
>
(
two_step_lookup
,
actor_handle
()),
infinite
,
get_atom
::
value
)
.
receive
([
&
](
group
&
grp
)
{
result
=
std
::
move
(
grp
);
},
[
&
](
error
&
err
)
{
result
=
std
::
move
(
err
);
});
return
result
;
}
...
...
@@ -257,14 +248,11 @@ strong_actor_ptr middleman::remote_lookup(atom_value name, const node_id& nid) {
scoped_actor
self
{
system
(),
true
};
self
->
send
(
basp
,
forward_atom
::
value
,
nid
,
atom
(
"ConfigServ"
),
make_message
(
get_atom
::
value
,
name
));
self
->
receive
(
[
&
](
strong_actor_ptr
&
addr
)
{
result
=
std
::
move
(
addr
);
},
after
(
std
::
chrono
::
minutes
(
5
))
>>
[]
{
// nop
}
);
self
->
receive
([
&
](
strong_actor_ptr
&
addr
)
{
result
=
std
::
move
(
addr
);
},
after
(
std
::
chrono
::
minutes
(
5
))
>>
[]
{
// nop
});
return
result
;
}
...
...
@@ -281,7 +269,7 @@ void middleman::start() {
std
::
atomic
<
bool
>
init_done
{
false
};
std
::
mutex
mtx
;
std
::
condition_variable
cv
;
thread_
=
std
::
thread
{[
&
,
this
]
{
thread_
=
std
::
thread
{[
&
,
this
]
{
CAF_SET_LOGGER_SYS
(
&
system
());
detail
::
set_thread_name
(
"caf.multiplexer"
);
system
().
thread_started
();
...
...
@@ -342,14 +330,13 @@ void middleman::init(actor_system_config& cfg) {
defaults
::
middleman
::
network_backend
);
if
(
network_backend
==
atom
(
"testing"
))
{
cfg
.
set
(
"middleman.attach-utility-actors"
,
true
)
.
set
(
"middleman.manual-multiplexing"
,
true
);
.
set
(
"middleman.manual-multiplexing"
,
true
);
}
// add remote group module to config
struct
remote_groups
:
group_module
{
public:
remote_groups
(
middleman
&
parent
)
:
group_module
(
parent
.
system
(),
"remote"
),
parent_
(
parent
)
{
:
group_module
(
parent
.
system
(),
"remote"
),
parent_
(
parent
)
{
// nop
}
...
...
@@ -374,16 +361,16 @@ void middleman::init(actor_system_config& cfg) {
// logging not available at this stage
// add I/O-related types to config
cfg
.
add_message_type
<
network
::
protocol
>
(
"@protocol"
)
.
add_message_type
<
network
::
address_listing
>
(
"@address_listing"
)
.
add_message_type
<
network
::
receive_buffer
>
(
"@receive_buffer"
)
.
add_message_type
<
new_data_msg
>
(
"@new_data_msg"
)
.
add_message_type
<
new_connection_msg
>
(
"@new_connection_msg"
)
.
add_message_type
<
acceptor_closed_msg
>
(
"@acceptor_closed_msg"
)
.
add_message_type
<
connection_closed_msg
>
(
"@connection_closed_msg"
)
.
add_message_type
<
accept_handle
>
(
"@accept_handle"
)
.
add_message_type
<
connection_handle
>
(
"@connection_handle"
)
.
add_message_type
<
connection_passivated_msg
>
(
"@connection_passivated_msg"
)
.
add_message_type
<
acceptor_passivated_msg
>
(
"@acceptor_passivated_msg"
);
.
add_message_type
<
network
::
address_listing
>
(
"@address_listing"
)
.
add_message_type
<
network
::
receive_buffer
>
(
"@receive_buffer"
)
.
add_message_type
<
new_data_msg
>
(
"@new_data_msg"
)
.
add_message_type
<
new_connection_msg
>
(
"@new_connection_msg"
)
.
add_message_type
<
acceptor_closed_msg
>
(
"@acceptor_closed_msg"
)
.
add_message_type
<
connection_closed_msg
>
(
"@connection_closed_msg"
)
.
add_message_type
<
accept_handle
>
(
"@accept_handle"
)
.
add_message_type
<
connection_handle
>
(
"@connection_handle"
)
.
add_message_type
<
connection_passivated_msg
>
(
"@connection_passivated_msg"
)
.
add_message_type
<
acceptor_passivated_msg
>
(
"@acceptor_passivated_msg"
);
// Compute and set ID for this network node.
auto
this_node
=
node_id
::
default_data
::
local
(
cfg
);
system
().
node_
.
swap
(
this_node
);
...
...
libcaf_io/src/io/middleman_actor.cpp
View file @
f4c5842b
...
...
@@ -18,13 +18,13 @@
#include "caf/io/middleman_actor.hpp"
#include <tuple>
#include <stdexcept>
#include <tuple>
#include <utility>
#include "caf/actor_system.hpp"
#include "caf/spawn_options.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/spawn_options.hpp"
#include "caf/io/middleman_actor_impl.hpp"
...
...
@@ -33,8 +33,8 @@ namespace io {
middleman_actor
make_middleman_actor
(
actor_system
&
sys
,
actor
db
)
{
return
get_or
(
sys
.
config
(),
"middleman.attach-utility-actors"
,
false
)
?
sys
.
spawn
<
middleman_actor_impl
,
hidden
>
(
std
::
move
(
db
))
:
sys
.
spawn
<
middleman_actor_impl
,
detached
+
hidden
>
(
std
::
move
(
db
));
?
sys
.
spawn
<
middleman_actor_impl
,
hidden
>
(
std
::
move
(
db
))
:
sys
.
spawn
<
middleman_actor_impl
,
detached
+
hidden
>
(
std
::
move
(
db
));
}
}
// namespace io
...
...
libcaf_io/src/io/middleman_actor_impl.cpp
View file @
f4c5842b
...
...
@@ -18,32 +18,31 @@
#include "caf/io/middleman_actor_impl.hpp"
#include <tuple>
#include <stdexcept>
#include <tuple>
#include <utility>
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/actor.hpp"
#include "caf/logger.hpp"
#include "caf/node_id.hpp"
#include "caf/actor_proxy.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/io/basp_broker.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/network/interfaces.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/interfaces.hpp"
namespace
caf
{
namespace
io
{
middleman_actor_impl
::
middleman_actor_impl
(
actor_config
&
cfg
,
actor
default_broker
)
:
middleman_actor
::
base
(
cfg
),
broker_
(
std
::
move
(
default_broker
))
{
:
middleman_actor
::
base
(
cfg
),
broker_
(
std
::
move
(
default_broker
))
{
set_down_handler
([
=
](
down_msg
&
dm
)
{
auto
i
=
cached_tcp_
.
begin
();
auto
e
=
cached_tcp_
.
end
();
...
...
@@ -154,9 +153,9 @@ auto middleman_actor_impl::make_behavior() -> behavior_type {
[
=
](
spawn_atom
atm
,
node_id
&
nid
,
std
::
string
&
str
,
message
&
msg
,
std
::
set
<
std
::
string
>&
ifs
)
->
delegated
<
strong_actor_ptr
>
{
CAF_LOG_TRACE
(
""
);
delegate
(
broker_
,
forward_atom
::
value
,
nid
,
atom
(
"SpawnServ"
),
make_message
(
atm
,
std
::
move
(
str
),
std
::
move
(
msg
),
std
::
move
(
ifs
)));
delegate
(
broker_
,
forward_atom
::
value
,
nid
,
atom
(
"SpawnServ"
),
make_message
(
atm
,
std
::
move
(
str
),
std
::
move
(
msg
),
std
::
move
(
ifs
)));
return
{};
},
[
=
](
get_atom
atm
,
...
...
@@ -164,15 +163,15 @@ auto middleman_actor_impl::make_behavior() -> behavior_type {
CAF_LOG_TRACE
(
""
);
delegate
(
broker_
,
atm
,
std
::
move
(
nid
));
return
{};
}
}
,
};
}
middleman_actor_impl
::
put_res
middleman_actor_impl
::
put
(
uint16_t
port
,
strong_actor_ptr
&
whom
,
mpi_set
&
sigs
,
const
char
*
in
,
bool
reuse_addr
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
)
<<
CAF_ARG
(
in
)
<<
CAF_ARG
(
reuse_addr
));
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
)
<<
CAF_ARG
(
in
)
<<
CAF_ARG
(
reuse_addr
));
uint16_t
actual_port
;
// treat empty strings like nullptr
if
(
in
!=
nullptr
&&
in
[
0
]
==
'\0'
)
...
...
@@ -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_udp
(
uint16_t
port
,
strong_actor_ptr
&
whom
,
mpi_set
&
sigs
,
const
char
*
in
,
bool
reuse_addr
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
)
<<
CAF_ARG
(
in
)
<<
CAF_ARG
(
reuse_addr
));
CAF_LOG_TRACE
(
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
)
<<
CAF_ARG
(
in
)
<<
CAF_ARG
(
reuse_addr
));
uint16_t
actual_port
;
// treat empty strings like nullptr
if
(
in
!=
nullptr
&&
in
[
0
]
==
'\0'
)
...
...
@@ -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
);
}
expected
<
doorman_ptr
>
middleman_actor_impl
::
open
(
uint16_t
port
,
const
char
*
addr
,
bool
reuse
)
{
expected
<
doorman_ptr
>
middleman_actor_impl
::
open
(
uint16_t
port
,
const
char
*
addr
,
bool
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 {
namespace
network
{
acceptor
::
acceptor
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
:
event_handler
(
backend_ref
,
sockfd
),
sock_
(
invalid_native_socket
)
{
:
event_handler
(
backend_ref
,
sockfd
),
sock_
(
invalid_native_socket
)
{
// nop
}
...
...
libcaf_io/src/io/network/datagram_handler.cpp
View file @
f4c5842b
...
...
@@ -39,13 +39,13 @@ namespace network {
datagram_handler
::
datagram_handler
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
:
event_handler
(
backend_ref
,
sockfd
),
max_consecutive_reads_
(
get_or
(
backend
().
system
().
config
(),
"middleman.max-consecutive-reads"
,
defaults
::
middleman
::
max_consecutive_reads
)),
max_datagram_size_
(
receive_buffer_size
),
rd_buf_
(
receive_buffer_size
),
send_buffer_size_
(
0
)
{
:
event_handler
(
backend_ref
,
sockfd
),
max_consecutive_reads_
(
get_or
(
backend
().
system
().
config
(),
"middleman.max-consecutive-reads"
,
defaults
::
middleman
::
max_consecutive_reads
)),
max_datagram_size_
(
receive_buffer_size
),
rd_buf_
(
receive_buffer_size
),
send_buffer_size_
(
0
)
{
allow_udp_connreset
(
sockfd
,
false
);
auto
es
=
send_buffer_size
(
sockfd
);
if
(
!
es
)
...
...
@@ -74,7 +74,8 @@ void datagram_handler::write(datagram_handle hdl, const void* buf,
wr_offline_buf_
.
back
().
first
=
hdl
;
auto
cbuf
=
reinterpret_cast
<
const
char
*>
(
buf
);
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
)
{
...
...
@@ -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_
;
}
...
...
@@ -124,9 +126,13 @@ void datagram_handler::remove_endpoint(datagram_handle hdl) {
void
datagram_handler
::
removed_from_loop
(
operation
op
)
{
switch
(
op
)
{
case
operation
:
:
read
:
reader_
.
reset
();
break
;
case
operation
:
:
write
:
writer_
.
reset
();
break
;
case
operation
:
:
propagate_error
:
;
// nop
case
operation
:
:
read
:
reader_
.
reset
();
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) {
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
)
{
if
(
!
write_result
)
{
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() {
}
// namespace network
}
// namespace io
}
// namespace caf
libcaf_io/src/io/network/datagram_servant_impl.cpp
View file @
f4c5842b
...
...
@@ -30,20 +30,20 @@ namespace network {
datagram_servant_impl
::
datagram_servant_impl
(
default_multiplexer
&
mx
,
native_socket
sockfd
,
int64_t
id
)
:
datagram_servant
(
datagram_handle
::
from_int
(
id
)),
launched_
(
false
),
handler_
(
mx
,
sockfd
)
{
:
datagram_servant
(
datagram_handle
::
from_int
(
id
)),
launched_
(
false
),
handler_
(
mx
,
sockfd
)
{
// nop
}
bool
datagram_servant_impl
::
new_endpoint
(
network
::
receive_buffer
&
buf
)
{
CAF_LOG_TRACE
(
""
);
if
(
detached
())
// We are already disconnected from the broker while the multiplexer
// did not yet remove the socket, this can happen if an I/O event
// causes the broker to call close_all() while the pollset contained
// further activities for the broker.
return
false
;
// We are already disconnected from the broker while the multiplexer
// did not yet remove the socket, this can happen if an I/O event
// causes the broker to call close_all() while the pollset contained
// further activities for the broker.
return
false
;
// A datagram that has a source port of zero is valid and never requires a
// reply. In the case of CAF we can simply drop it as nothing but the
// handshake could be communicated which we could not reply to.
...
...
@@ -141,7 +141,6 @@ void datagram_servant_impl::remove_from_loop() {
handler_
.
passivate
();
}
void
datagram_servant_impl
::
detach_handles
()
{
for
(
auto
&
p
:
handler_
.
endpoints
())
{
if
(
p
.
first
!=
hdl
())
...
...
libcaf_io/src/io/network/default_multiplexer.cpp
View file @
f4c5842b
...
...
@@ -20,19 +20,19 @@
#include <utility>
#include "caf/actor_system_config.hpp"
#include "caf/config.hpp"
#include "caf/defaults.hpp"
#include "caf/optional.hpp"
#include "caf/make_counted.hpp"
#include "caf/
actor_system_config
.hpp"
#include "caf/
optional
.hpp"
#include "caf/io/broker.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/protocol.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/socket_guard.hpp"
...
...
@@ -40,42 +40,42 @@
#include "caf/scheduler/abstract_coordinator.hpp"
#ifdef CAF_WINDOWS
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif // WIN32_LEAN_AND_MEAN
# ifndef NOMINMAX
# define NOMINMAX
# endif
# ifdef CAF_MINGW
# undef _WIN32_WINNT
# undef WINVER
# define _WIN32_WINNT WindowsVista
# define WINVER WindowsVista
# include <w32api.h>
# endif
# include <io.h>
# include <windows.h>
# include <winsock2.h>
# include <ws2ipdef.h>
# include <ws2tcpip.h>
#else
# include <unistd.h>
# include <arpa/inet.h>
# include <cerrno>
# include <fcntl.h>
# include <netdb.h>
# include <netinet/in.h>
# include <netinet/ip.h>
# include <netinet/tcp.h>
# include <sys/socket.h>
# include <sys/types.h>
#ifdef CAF_POLL_MULTIPLEXER
# include <poll.h>
#elif defined(CAF_EPOLL_MULTIPLEXER)
# include <sys/epoll.h>
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif // WIN32_LEAN_AND_MEAN
# ifndef NOMINMAX
# define NOMINMAX
# endif
# ifdef CAF_MINGW
# undef _WIN32_WINNT
# undef WINVER
# define _WIN32_WINNT WindowsVista
# define WINVER WindowsVista
# include <w32api.h>
# endif
# include <io.h>
# include <windows.h>
# include <winsock2.h>
# include <ws2ipdef.h>
# include <ws2tcpip.h>
#else
# error "neither CAF_POLL_MULTIPLEXER nor CAF_EPOLL_MULTIPLEXER defined"
#endif
# include <arpa/inet.h>
# include <cerrno>
# include <fcntl.h>
# include <netdb.h>
# include <netinet/in.h>
# include <netinet/ip.h>
# include <netinet/tcp.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <unistd.h>
# ifdef CAF_POLL_MULTIPLEXER
# include <poll.h>
# elif defined(CAF_EPOLL_MULTIPLEXER)
# include <sys/epoll.h>
# else
# error "neither CAF_POLL_MULTIPLEXER nor CAF_EPOLL_MULTIPLEXER defined"
# endif
#endif
...
...
@@ -119,344 +119,339 @@ namespace network {
// poll vs epoll backend
#ifdef CAF_POLL_MULTIPLEXER
# ifndef POLLRDHUP
# define POLLRDHUP POLLHUP
# endif
# ifndef POLLPRI
# define POLLPRI POLLIN
# endif
# ifdef CAF_WINDOWS
// From the MSDN: If the POLLPRI flag is set on a socket for the Microsoft
// Winsock provider, the WSAPoll function will fail.
const
event_mask_type
input_mask
=
POLLIN
;
# else
const
event_mask_type
input_mask
=
POLLIN
|
POLLPRI
;
# endif
const
event_mask_type
error_mask
=
POLLRDHUP
|
POLLERR
|
POLLHUP
|
POLLNVAL
;
const
event_mask_type
output_mask
=
POLLOUT
;
#
ifndef POLLRDHUP
#
define POLLRDHUP POLLHUP
#
endif
#
ifndef POLLPRI
#
define POLLPRI POLLIN
#
endif
#
ifdef CAF_WINDOWS
// From the MSDN: If the POLLPRI flag is set on a socket for the Microsoft
// Winsock provider, the WSAPoll function will fail.
const
event_mask_type
input_mask
=
POLLIN
;
#
else
const
event_mask_type
input_mask
=
POLLIN
|
POLLPRI
;
#
endif
const
event_mask_type
error_mask
=
POLLRDHUP
|
POLLERR
|
POLLHUP
|
POLLNVAL
;
const
event_mask_type
output_mask
=
POLLOUT
;
#else
const
event_mask_type
input_mask
=
EPOLLIN
;
const
event_mask_type
error_mask
=
EPOLLRDHUP
|
EPOLLERR
|
EPOLLHUP
;
const
event_mask_type
output_mask
=
EPOLLOUT
;
const
event_mask_type
input_mask
=
EPOLLIN
;
const
event_mask_type
error_mask
=
EPOLLRDHUP
|
EPOLLERR
|
EPOLLHUP
;
const
event_mask_type
output_mask
=
EPOLLOUT
;
#endif
// -- Platform-dependent abstraction over epoll() or poll() --------------------
#ifdef CAF_EPOLL_MULTIPLEXER
// In this implementation, shadow_ is the number of sockets we have
// registered to epoll.
default_multiplexer
::
default_multiplexer
(
actor_system
*
sys
)
:
multiplexer
(
sys
),
epollfd_
(
invalid_native_socket
),
shadow_
(
1
),
pipe_reader_
(
*
this
),
servant_ids_
(
0
),
max_throughput_
(
0
){
init
();
epollfd_
=
epoll_create1
(
EPOLL_CLOEXEC
);
if
(
epollfd_
==
-
1
)
{
CAF_LOG_ERROR
(
"epoll_create1: "
<<
strerror
(
errno
));
exit
(
errno
);
}
// handle at most 64 events at a time
pollset_
.
resize
(
64
);
pipe_
=
create_pipe
();
pipe_reader_
.
init
(
pipe_
.
first
);
epoll_event
ee
;
ee
.
events
=
input_mask
;
ee
.
data
.
ptr
=
&
pipe_reader_
;
if
(
epoll_ctl
(
epollfd_
,
EPOLL_CTL_ADD
,
pipe_reader_
.
fd
(),
&
ee
)
<
0
)
{
CAF_LOG_ERROR
(
"epoll_ctl: "
<<
strerror
(
errno
));
exit
(
errno
);
}
// In this implementation, shadow_ is the number of sockets we have
// registered to epoll.
default_multiplexer
::
default_multiplexer
(
actor_system
*
sys
)
:
multiplexer
(
sys
),
epollfd_
(
invalid_native_socket
),
shadow_
(
1
),
pipe_reader_
(
*
this
),
servant_ids_
(
0
),
max_throughput_
(
0
)
{
init
();
epollfd_
=
epoll_create1
(
EPOLL_CLOEXEC
);
if
(
epollfd_
==
-
1
)
{
CAF_LOG_ERROR
(
"epoll_create1: "
<<
strerror
(
errno
));
exit
(
errno
);
}
// handle at most 64 events at a time
pollset_
.
resize
(
64
);
pipe_
=
create_pipe
();
pipe_reader_
.
init
(
pipe_
.
first
);
epoll_event
ee
;
ee
.
events
=
input_mask
;
ee
.
data
.
ptr
=
&
pipe_reader_
;
if
(
epoll_ctl
(
epollfd_
,
EPOLL_CTL_ADD
,
pipe_reader_
.
fd
(),
&
ee
)
<
0
)
{
CAF_LOG_ERROR
(
"epoll_ctl: "
<<
strerror
(
errno
));
exit
(
errno
);
}
}
bool
default_multiplexer
::
poll_once_impl
(
bool
block
)
{
CAF_LOG_TRACE
(
"epoll()-based multiplexer"
);
CAF_ASSERT
(
block
==
false
||
internally_posted_
.
empty
());
// Keep running in case of `EINTR`.
for
(;;)
{
int
presult
=
epoll_wait
(
epollfd_
,
pollset_
.
data
(),
static_cast
<
int
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
CAF_LOG_DEBUG
(
"epoll_wait() on"
<<
shadow_
<<
"sockets reported"
<<
presult
<<
"event(s)"
);
if
(
presult
<
0
)
{
switch
(
errno
)
{
case
EINTR
:
{
// a signal was caught
// just try again
continue
;
}
default:
{
perror
(
"epoll_wait() failed"
);
CAF_CRITICAL
(
"epoll_wait() failed"
);
}
bool
default_multiplexer
::
poll_once_impl
(
bool
block
)
{
CAF_LOG_TRACE
(
"epoll()-based multiplexer"
);
CAF_ASSERT
(
block
==
false
||
internally_posted_
.
empty
());
// Keep running in case of `EINTR`.
for
(;;)
{
int
presult
=
epoll_wait
(
epollfd_
,
pollset_
.
data
(),
static_cast
<
int
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
CAF_LOG_DEBUG
(
"epoll_wait() on"
<<
shadow_
<<
"sockets reported"
<<
presult
<<
"event(s)"
);
if
(
presult
<
0
)
{
switch
(
errno
)
{
case
EINTR
:
{
// a signal was caught
// just try again
continue
;
}
default:
{
perror
(
"epoll_wait() failed"
);
CAF_CRITICAL
(
"epoll_wait() failed"
);
}
}
if
(
presult
==
0
)
return
false
;
auto
iter
=
pollset_
.
begin
();
auto
last
=
iter
+
presult
;
for
(;
iter
!=
last
;
++
iter
)
{
auto
ptr
=
reinterpret_cast
<
event_handler
*>
(
iter
->
data
.
ptr
);
auto
fd
=
ptr
?
ptr
->
fd
()
:
pipe_
.
first
;
handle_socket_event
(
fd
,
static_cast
<
int
>
(
iter
->
events
),
ptr
);
}
handle_internal_events
();
return
true
;
}
if
(
presult
==
0
)
return
false
;
auto
iter
=
pollset_
.
begin
();
auto
last
=
iter
+
presult
;
for
(;
iter
!=
last
;
++
iter
)
{
auto
ptr
=
reinterpret_cast
<
event_handler
*>
(
iter
->
data
.
ptr
);
auto
fd
=
ptr
?
ptr
->
fd
()
:
pipe_
.
first
;
handle_socket_event
(
fd
,
static_cast
<
int
>
(
iter
->
events
),
ptr
);
}
handle_internal_events
();
return
true
;
}
}
void
default_multiplexer
::
run
()
{
CAF_LOG_TRACE
(
"epoll()-based multiplexer"
);
while
(
shadow_
>
0
)
poll_once
(
true
);
}
void
default_multiplexer
::
run
()
{
CAF_LOG_TRACE
(
"epoll()-based multiplexer"
);
while
(
shadow_
>
0
)
poll_once
(
true
);
}
void
default_multiplexer
::
handle
(
const
default_multiplexer
::
event
&
e
)
{
CAF_LOG_TRACE
(
"e.fd = "
<<
CAF_ARG
(
e
.
fd
)
<<
", mask = "
void
default_multiplexer
::
handle
(
const
default_multiplexer
::
event
&
e
)
{
CAF_LOG_TRACE
(
"e.fd = "
<<
CAF_ARG
(
e
.
fd
)
<<
", mask = "
<<
CAF_ARG
(
e
.
mask
));
// ptr is only allowed to nullptr if fd is our pipe
// read handle which is only registered for input
CAF_ASSERT
(
e
.
ptr
!=
nullptr
||
e
.
fd
==
pipe_
.
first
);
if
(
e
.
ptr
&&
e
.
ptr
->
eventbf
()
==
e
.
mask
)
{
// nop
return
;
}
auto
old
=
e
.
ptr
?
e
.
ptr
->
eventbf
()
:
input_mask
;
if
(
e
.
ptr
)
{
e
.
ptr
->
eventbf
(
e
.
mask
);
}
epoll_event
ee
;
ee
.
events
=
static_cast
<
uint32_t
>
(
e
.
mask
);
ee
.
data
.
ptr
=
e
.
ptr
;
int
op
;
if
(
e
.
mask
==
0
)
{
CAF_LOG_DEBUG
(
"attempt to remove socket "
<<
CAF_ARG
(
e
.
fd
)
<<
" from epoll"
);
op
=
EPOLL_CTL_DEL
;
--
shadow_
;
}
else
if
(
old
==
0
)
{
CAF_LOG_DEBUG
(
"attempt to add socket "
<<
CAF_ARG
(
e
.
fd
)
<<
" to epoll"
);
op
=
EPOLL_CTL_ADD
;
++
shadow_
;
}
else
{
CAF_LOG_DEBUG
(
"modify epoll event mask for socket "
<<
CAF_ARG
(
e
.
fd
)
<<
": "
<<
CAF_ARG
(
old
)
<<
" -> "
<<
CAF_ARG
(
e
.
mask
));
// ptr is only allowed to nullptr if fd is our pipe
// read handle which is only registered for input
CAF_ASSERT
(
e
.
ptr
!=
nullptr
||
e
.
fd
==
pipe_
.
first
);
if
(
e
.
ptr
&&
e
.
ptr
->
eventbf
()
==
e
.
mask
)
{
// nop
return
;
}
auto
old
=
e
.
ptr
?
e
.
ptr
->
eventbf
()
:
input_mask
;
if
(
e
.
ptr
){
e
.
ptr
->
eventbf
(
e
.
mask
);
}
epoll_event
ee
;
ee
.
events
=
static_cast
<
uint32_t
>
(
e
.
mask
);
ee
.
data
.
ptr
=
e
.
ptr
;
int
op
;
if
(
e
.
mask
==
0
)
{
CAF_LOG_DEBUG
(
"attempt to remove socket "
<<
CAF_ARG
(
e
.
fd
)
<<
" from epoll"
);
op
=
EPOLL_CTL_DEL
;
--
shadow_
;
}
else
if
(
old
==
0
)
{
CAF_LOG_DEBUG
(
"attempt to add socket "
<<
CAF_ARG
(
e
.
fd
)
<<
" to epoll"
);
op
=
EPOLL_CTL_ADD
;
++
shadow_
;
}
else
{
CAF_LOG_DEBUG
(
"modify epoll event mask for socket "
<<
CAF_ARG
(
e
.
fd
)
<<
": "
<<
CAF_ARG
(
old
)
<<
" -> "
<<
CAF_ARG
(
e
.
mask
));
op
=
EPOLL_CTL_MOD
;
}
if
(
epoll_ctl
(
epollfd_
,
op
,
e
.
fd
,
&
ee
)
<
0
)
{
switch
(
last_socket_error
())
{
// supplied file descriptor is already registered
case
EEXIST
:
CAF_LOG_ERROR
(
"file descriptor registered twice"
);
--
shadow_
;
break
;
// op was EPOLL_CTL_MOD or EPOLL_CTL_DEL,
// and fd is not registered with this epoll instance.
case
ENOENT
:
CAF_LOG_ERROR
(
"cannot delete file descriptor "
"because it isn't registered"
);
if
(
e
.
mask
==
0
)
{
++
shadow_
;
}
break
;
default:
CAF_LOG_ERROR
(
strerror
(
errno
));
perror
(
"epoll_ctl() failed"
);
CAF_CRITICAL
(
"epoll_ctl() failed"
);
}
}
if
(
e
.
ptr
)
{
auto
remove_from_loop_if_needed
=
[
&
](
int
flag
,
operation
flag_op
)
{
if
((
old
&
flag
)
&&
!
(
e
.
mask
&
flag
))
{
e
.
ptr
->
removed_from_loop
(
flag_op
);
op
=
EPOLL_CTL_MOD
;
}
if
(
epoll_ctl
(
epollfd_
,
op
,
e
.
fd
,
&
ee
)
<
0
)
{
switch
(
last_socket_error
())
{
// supplied file descriptor is already registered
case
EEXIST
:
CAF_LOG_ERROR
(
"file descriptor registered twice"
);
--
shadow_
;
break
;
// op was EPOLL_CTL_MOD or EPOLL_CTL_DEL,
// and fd is not registered with this epoll instance.
case
ENOENT
:
CAF_LOG_ERROR
(
"cannot delete file descriptor "
"because it isn't registered"
);
if
(
e
.
mask
==
0
)
{
++
shadow_
;
}
};
remove_from_loop_if_needed
(
input_mask
,
operation
::
read
);
remove_from_loop_if_needed
(
output_mask
,
operation
::
write
);
break
;
default:
CAF_LOG_ERROR
(
strerror
(
errno
));
perror
(
"epoll_ctl() failed"
);
CAF_CRITICAL
(
"epoll_ctl() failed"
);
}
}
size_t
default_multiplexer
::
num_socket_handlers
()
const
noexcept
{
return
shadow_
;
if
(
e
.
ptr
)
{
auto
remove_from_loop_if_needed
=
[
&
](
int
flag
,
operation
flag_op
)
{
if
((
old
&
flag
)
&&
!
(
e
.
mask
&
flag
))
{
e
.
ptr
->
removed_from_loop
(
flag_op
);
}
};
remove_from_loop_if_needed
(
input_mask
,
operation
::
read
);
remove_from_loop_if_needed
(
output_mask
,
operation
::
write
);
}
}
#else // CAF_EPOLL_MULTIPLEXER
size_t
default_multiplexer
::
num_socket_handlers
()
const
noexcept
{
return
shadow_
;
}
// 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
// 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.
// 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
// 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
// stores our pollset, the latter stores our pointers. Both vectors
// are sorted by the file descriptor. This allows us to quickly,
// i.e., O(1), access the actual object when handling socket events.
default_multiplexer
::
default_multiplexer
(
actor_system
*
sys
)
:
multiplexer
(
sys
),
epollfd_
(
-
1
),
pipe_reader_
(
*
this
),
servant_ids_
(
0
)
{
init
();
// initial setup
pipe_
=
create_pipe
();
pipe_reader_
.
init
(
pipe_
.
first
);
pollfd
pipefd
;
pipefd
.
fd
=
pipe_reader_
.
fd
();
pipefd
.
events
=
input_mask
;
pipefd
.
revents
=
0
;
pollset_
.
push_back
(
pipefd
);
shadow_
.
push_back
(
&
pipe_reader_
);
}
#else // CAF_EPOLL_MULTIPLEXER
bool
default_multiplexer
::
poll_once_impl
(
bool
block
)
{
CAF_LOG_TRACE
(
"poll()-based multiplexer"
);
CAF_ASSERT
(
block
==
false
||
internally_posted_
.
empty
());
// we store the results of poll() in a separate vector , because
// altering the pollset while traversing it is not exactly a
// bright idea ...
struct
fd_event
{
native_socket
fd
;
// our file descriptor
short
mask
;
// the event mask returned by poll()
event_handler
*
ptr
;
// nullptr in case of a pipe event
};
std
::
vector
<
fd_event
>
poll_res
;
for
(;;)
{
int
presult
;
# ifdef CAF_WINDOWS
presult
=
::
WSAPoll
(
pollset_
.
data
(),
static_cast
<
ULONG
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
# else
presult
=
::
poll
(
pollset_
.
data
(),
static_cast
<
nfds_t
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
# endif
if
(
presult
<
0
)
{
switch
(
last_socket_error
())
{
case
EINTR
:
{
CAF_LOG_DEBUG
(
"received EINTR, try again"
);
// a signal was caught
// just try again
break
;
}
case
ENOMEM
:
{
CAF_LOG_ERROR
(
"poll() failed for reason ENOMEM"
);
// there's not much we can do other than try again
// in hope someone else releases memory
break
;
}
default:
{
perror
(
"poll() failed"
);
CAF_CRITICAL
(
"poll() failed"
);
}
// 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
// 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.
// 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
// 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
// stores our pollset, the latter stores our pointers. Both vectors
// are sorted by the file descriptor. This allows us to quickly,
// i.e., O(1), access the actual object when handling socket events.
default_multiplexer
::
default_multiplexer
(
actor_system
*
sys
)
:
multiplexer
(
sys
),
epollfd_
(
-
1
),
pipe_reader_
(
*
this
),
servant_ids_
(
0
)
{
init
();
// initial setup
pipe_
=
create_pipe
();
pipe_reader_
.
init
(
pipe_
.
first
);
pollfd
pipefd
;
pipefd
.
fd
=
pipe_reader_
.
fd
();
pipefd
.
events
=
input_mask
;
pipefd
.
revents
=
0
;
pollset_
.
push_back
(
pipefd
);
shadow_
.
push_back
(
&
pipe_reader_
);
}
bool
default_multiplexer
::
poll_once_impl
(
bool
block
)
{
CAF_LOG_TRACE
(
"poll()-based multiplexer"
);
CAF_ASSERT
(
block
==
false
||
internally_posted_
.
empty
());
// we store the results of poll() in a separate vector , because
// altering the pollset while traversing it is not exactly a
// bright idea ...
struct
fd_event
{
native_socket
fd
;
// our file descriptor
short
mask
;
// the event mask returned by poll()
event_handler
*
ptr
;
// nullptr in case of a pipe event
};
std
::
vector
<
fd_event
>
poll_res
;
for
(;;)
{
int
presult
;
# ifdef CAF_WINDOWS
presult
=
::
WSAPoll
(
pollset_
.
data
(),
static_cast
<
ULONG
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
# else
presult
=
::
poll
(
pollset_
.
data
(),
static_cast
<
nfds_t
>
(
pollset_
.
size
()),
block
?
-
1
:
0
);
# endif
if
(
presult
<
0
)
{
switch
(
last_socket_error
())
{
case
EINTR
:
{
CAF_LOG_DEBUG
(
"received EINTR, try again"
);
// a signal was caught
// just try again
break
;
}
continue
;
// rinse and repeat
}
CAF_LOG_DEBUG
(
"poll() on"
<<
pollset_
.
size
()
<<
"sockets reported"
<<
presult
<<
"event(s)"
);
if
(
presult
==
0
)
return
false
;
// scan pollset for events first, because we might alter pollset_
// while running callbacks (not a good idea while traversing it)
CAF_LOG_DEBUG
(
"scan pollset for socket events"
);
for
(
size_t
i
=
0
;
i
<
pollset_
.
size
()
&&
presult
>
0
;
++
i
)
{
auto
&
pfd
=
pollset_
[
i
];
if
(
pfd
.
revents
!=
0
)
{
CAF_LOG_DEBUG
(
"event on socket:"
<<
CAF_ARG
(
pfd
.
fd
)
<<
CAF_ARG
(
pfd
.
revents
));
poll_res
.
push_back
({
pfd
.
fd
,
pfd
.
revents
,
shadow_
[
i
]});
pfd
.
revents
=
0
;
--
presult
;
// stop as early as possible
case
ENOMEM
:
{
CAF_LOG_ERROR
(
"poll() failed for reason ENOMEM"
);
// there's not much we can do other than try again
// in hope someone else releases memory
break
;
}
default:
{
perror
(
"poll() failed"
);
CAF_CRITICAL
(
"poll() failed"
);
}
}
CAF_LOG_DEBUG
(
CAF_ARG
(
poll_res
.
size
()));
for
(
auto
&
e
:
poll_res
)
{
// we try to read/write as much as possible by ignoring
// error states as long as there are still valid
// operations possible on the socket
handle_socket_event
(
e
.
fd
,
e
.
mask
,
e
.
ptr
);
continue
;
// rinse and repeat
}
CAF_LOG_DEBUG
(
"poll() on"
<<
pollset_
.
size
()
<<
"sockets reported"
<<
presult
<<
"event(s)"
);
if
(
presult
==
0
)
return
false
;
// scan pollset for events first, because we might alter pollset_
// while running callbacks (not a good idea while traversing it)
CAF_LOG_DEBUG
(
"scan pollset for socket events"
);
for
(
size_t
i
=
0
;
i
<
pollset_
.
size
()
&&
presult
>
0
;
++
i
)
{
auto
&
pfd
=
pollset_
[
i
];
if
(
pfd
.
revents
!=
0
)
{
CAF_LOG_DEBUG
(
"event on socket:"
<<
CAF_ARG
(
pfd
.
fd
)
<<
CAF_ARG
(
pfd
.
revents
));
poll_res
.
push_back
({
pfd
.
fd
,
pfd
.
revents
,
shadow_
[
i
]});
pfd
.
revents
=
0
;
--
presult
;
// stop as early as possible
}
poll_res
.
clear
();
handle_internal_events
();
return
true
;
}
CAF_LOG_DEBUG
(
CAF_ARG
(
poll_res
.
size
()));
for
(
auto
&
e
:
poll_res
)
{
// we try to read/write as much as possible by ignoring
// error states as long as there are still valid
// operations possible on the socket
handle_socket_event
(
e
.
fd
,
e
.
mask
,
e
.
ptr
);
}
poll_res
.
clear
();
handle_internal_events
();
return
true
;
}
}
void
default_multiplexer
::
run
()
{
CAF_LOG_TRACE
(
"poll()-based multiplexer:"
<<
CAF_ARG
(
input_mask
)
<<
CAF_ARG
(
output_mask
)
<<
CAF_ARG
(
error_mask
));
while
(
!
pollset_
.
empty
())
poll_once
(
true
);
void
default_multiplexer
::
run
()
{
CAF_LOG_TRACE
(
"poll()-based multiplexer:"
<<
CAF_ARG
(
input_mask
)
<<
CAF_ARG
(
output_mask
)
<<
CAF_ARG
(
error_mask
));
while
(
!
pollset_
.
empty
())
poll_once
(
true
);
}
void
default_multiplexer
::
handle
(
const
default_multiplexer
::
event
&
e
)
{
CAF_ASSERT
(
e
.
fd
!=
invalid_native_socket
);
CAF_ASSERT
(
pollset_
.
size
()
==
shadow_
.
size
());
CAF_LOG_TRACE
(
CAF_ARG
(
e
.
fd
)
<<
CAF_ARG
(
e
.
mask
));
auto
last
=
pollset_
.
end
();
auto
i
=
std
::
lower_bound
(
pollset_
.
begin
(),
last
,
e
.
fd
,
[](
const
pollfd
&
lhs
,
native_socket
rhs
)
{
return
lhs
.
fd
<
rhs
;
});
pollfd
new_element
;
new_element
.
fd
=
e
.
fd
;
new_element
.
events
=
static_cast
<
short
>
(
e
.
mask
);
new_element
.
revents
=
0
;
int
old_mask
=
0
;
if
(
e
.
ptr
!=
nullptr
)
{
old_mask
=
e
.
ptr
->
eventbf
();
e
.
ptr
->
eventbf
(
e
.
mask
);
}
void
default_multiplexer
::
handle
(
const
default_multiplexer
::
event
&
e
)
{
CAF_ASSERT
(
e
.
fd
!=
invalid_native_socket
);
CAF_ASSERT
(
pollset_
.
size
()
==
shadow_
.
size
());
CAF_LOG_TRACE
(
CAF_ARG
(
e
.
fd
)
<<
CAF_ARG
(
e
.
mask
));
auto
last
=
pollset_
.
end
();
auto
i
=
std
::
lower_bound
(
pollset_
.
begin
(),
last
,
e
.
fd
,
[](
const
pollfd
&
lhs
,
native_socket
rhs
)
{
return
lhs
.
fd
<
rhs
;
});
pollfd
new_element
;
new_element
.
fd
=
e
.
fd
;
new_element
.
events
=
static_cast
<
short
>
(
e
.
mask
);
new_element
.
revents
=
0
;
int
old_mask
=
0
;
if
(
e
.
ptr
!=
nullptr
)
{
old_mask
=
e
.
ptr
->
eventbf
();
e
.
ptr
->
eventbf
(
e
.
mask
);
// calculate shadow of i
multiplexer_poll_shadow_data
::
iterator
j
;
if
(
i
==
last
)
{
j
=
shadow_
.
end
();
}
else
{
j
=
shadow_
.
begin
();
std
::
advance
(
j
,
distance
(
pollset_
.
begin
(),
i
));
}
// modify vectors
if
(
i
==
last
)
{
// append
if
(
e
.
mask
!=
0
)
{
pollset_
.
push_back
(
new_element
);
shadow_
.
push_back
(
e
.
ptr
);
}
// calculate shadow of i
multiplexer_poll_shadow_data
::
iterator
j
;
if
(
i
==
last
)
{
j
=
shadow_
.
end
();
}
else
if
(
i
->
fd
==
e
.
fd
)
{
// modify
if
(
e
.
mask
==
0
)
{
// delete item
pollset_
.
erase
(
i
);
shadow_
.
erase
(
j
);
}
else
{
j
=
shadow_
.
begin
();
std
::
advance
(
j
,
distance
(
pollset_
.
begin
(),
i
));
// update event mask of existing entry
CAF_ASSERT
(
*
j
==
e
.
ptr
);
i
->
events
=
static_cast
<
short
>
(
e
.
mask
);
}
// modify vectors
if
(
i
==
last
)
{
// append
if
(
e
.
mask
!=
0
)
{
pollset_
.
push_back
(
new_element
);
shadow_
.
push_back
(
e
.
ptr
);
}
}
else
if
(
i
->
fd
==
e
.
fd
)
{
// modify
if
(
e
.
mask
==
0
)
{
// delete item
pollset_
.
erase
(
i
);
shadow_
.
erase
(
j
);
}
else
{
// update event mask of existing entry
CAF_ASSERT
(
*
j
==
e
.
ptr
);
i
->
events
=
static_cast
<
short
>
(
e
.
mask
);
}
if
(
e
.
ptr
!=
nullptr
)
{
auto
remove_from_loop_if_needed
=
[
&
](
int
flag
,
operation
flag_op
)
{
if
(((
old_mask
&
flag
)
!=
0
)
&&
((
e
.
mask
&
flag
)
==
0
))
{
e
.
ptr
->
removed_from_loop
(
flag_op
);
}
};
remove_from_loop_if_needed
(
input_mask
,
operation
::
read
);
remove_from_loop_if_needed
(
output_mask
,
operation
::
write
);
}
}
else
{
// insert at iterator pos
pollset_
.
insert
(
i
,
new_element
);
shadow_
.
insert
(
j
,
e
.
ptr
);
if
(
e
.
ptr
!=
nullptr
)
{
auto
remove_from_loop_if_needed
=
[
&
](
int
flag
,
operation
flag_op
)
{
if
(((
old_mask
&
flag
)
!=
0
)
&&
((
e
.
mask
&
flag
)
==
0
))
{
e
.
ptr
->
removed_from_loop
(
flag_op
);
}
};
remove_from_loop_if_needed
(
input_mask
,
operation
::
read
);
remove_from_loop_if_needed
(
output_mask
,
operation
::
write
);
}
}
else
{
// insert at iterator pos
pollset_
.
insert
(
i
,
new_element
);
shadow_
.
insert
(
j
,
e
.
ptr
);
}
}
size_t
default_multiplexer
::
num_socket_handlers
()
const
noexcept
{
return
pollset_
.
size
();
}
size_t
default_multiplexer
::
num_socket_handlers
()
const
noexcept
{
return
pollset_
.
size
();
}
#endif // CAF_EPOLL_MULTIPLEXER
...
...
@@ -515,19 +510,19 @@ void default_multiplexer::del(operation op, native_socket fd,
CAF_ASSERT
(
fd
!=
invalid_native_socket
);
// ptr == nullptr is only allowed when removing our pipe read handle
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
);
}
void
default_multiplexer
::
wr_dispatch_request
(
resumable
*
ptr
)
{
intptr_t
ptrval
=
reinterpret_cast
<
intptr_t
>
(
ptr
);
// on windows, we actually have sockets, otherwise we have file handles
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
auto
res
=
::
send
(
pipe_
.
second
,
reinterpret_cast
<
socket_send_ptr
>
(
&
ptrval
),
sizeof
(
ptrval
),
no_sigpipe_io_flag
);
#
else
#else
auto
res
=
::
write
(
pipe_
.
second
,
&
ptrval
,
sizeof
(
ptrval
));
#
endif
#endif
if
(
res
<=
0
)
{
// pipe closed, discard resumable
intrusive_ptr_release
(
ptr
);
...
...
@@ -548,6 +543,7 @@ multiplexer::supervisor_ptr default_multiplexer::make_supervisor() {
auto
ptr
=
this_
;
ptr
->
dispatch
([
=
]
{
ptr
->
close_pipe
();
});
}
private:
default_multiplexer
*
this_
;
};
...
...
@@ -586,12 +582,12 @@ void default_multiplexer::handle_socket_event(native_socket fd, int mask,
}
void
default_multiplexer
::
init
()
{
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
WSADATA
WinsockData
;
if
(
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
WinsockData
)
!=
0
)
{
CAF_CRITICAL
(
"WSAStartup failed"
);
CAF_CRITICAL
(
"WSAStartup failed"
);
}
#
endif
#endif
namespace
sr
=
defaults
::
scheduler
;
max_throughput_
=
get_or
(
system
().
config
(),
"scheduler.max-throughput"
,
sr
::
max_throughput
);
...
...
@@ -629,8 +625,7 @@ void default_multiplexer::resume(intrusive_ptr<resumable> ptr) {
// Don't touch reference count of shutdown helpers.
ptr
.
release
();
break
;
default:
;
// Done. Release reference to resumable.
default:
;
// Done. Release reference to resumable.
}
}
...
...
@@ -649,9 +644,9 @@ default_multiplexer::~default_multiplexer() {
// do cleanup for pipe reader manually, since WSACleanup needs to happen last
close_socket
(
pipe_reader_
.
fd
());
pipe_reader_
.
init
(
invalid_native_socket
);
#
ifdef CAF_WINDOWS
#ifdef CAF_WINDOWS
WSACleanup
();
#
endif
#endif
}
void
default_multiplexer
::
exec_later
(
resumable
*
ptr
)
{
...
...
@@ -749,19 +744,15 @@ void default_multiplexer::handle_internal_events() {
template
<
int
Family
>
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_ARG
(
fd
)
<<
CAF_ARG
(
host
));
<<
CAF_ARG
(
fd
)
<<
CAF_ARG
(
host
));
static_assert
(
Family
==
AF_INET
||
Family
==
AF_INET6
,
"invalid family"
);
using
sockaddr_type
=
typename
std
::
conditional
<
Family
==
AF_INET
,
sockaddr_in
,
sockaddr_in6
>::
type
;
using
sockaddr_type
=
typename
std
::
conditional
<
Family
==
AF_INET
,
sockaddr_in
,
sockaddr_in6
>::
type
;
sockaddr_type
sa
;
memset
(
&
sa
,
0
,
sizeof
(
sockaddr_type
));
inet_pton
(
Family
,
host
.
c_str
(),
&
addr_of
(
sa
));
family_of
(
sa
)
=
Family
;
port_of
(
sa
)
=
htons
(
port
);
port_of
(
sa
)
=
htons
(
port
);
return
connect
(
fd
,
reinterpret_cast
<
const
sockaddr
*>
(
&
sa
),
sizeof
(
sa
))
==
0
;
}
...
...
@@ -787,8 +778,8 @@ new_tcp_connection(const std::string& host, uint16_t port,
detail
::
socket_guard
sguard
(
fd
);
if
(
proto
==
ipv6
)
{
if
(
ip_connect
<
AF_INET6
>
(
fd
,
res
->
first
,
port
))
{
CAF_LOG_INFO
(
"successfully connected to (IPv6):"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
CAF_LOG_INFO
(
"successfully connected to (IPv6):"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
return
sguard
.
release
();
}
sguard
.
close
();
...
...
@@ -797,11 +788,11 @@ new_tcp_connection(const std::string& host, uint16_t port,
}
if
(
!
ip_connect
<
AF_INET
>
(
fd
,
res
->
first
,
port
))
{
CAF_LOG_WARNING
(
"could not connect to:"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
return
make_error
(
sec
::
cannot_connect_to_node
,
"ip_connect failed"
,
host
,
port
);
return
make_error
(
sec
::
cannot_connect_to_node
,
"ip_connect failed"
,
host
,
port
);
}
CAF_LOG_INFO
(
"successfully connected to (IPv4):"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
CAF_LOG_INFO
(
"successfully connected to (IPv4):"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
return
sguard
.
release
();
}
...
...
@@ -849,12 +840,8 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr,
reinterpret_cast
<
setsockopt_ptr
>
(
&
on
),
static_cast
<
socket_size_type
>
(
sizeof
(
on
))));
}
using
sockaddr_type
=
typename
std
::
conditional
<
Family
==
AF_INET
,
sockaddr_in
,
sockaddr_in6
>::
type
;
using
sockaddr_type
=
typename
std
::
conditional
<
Family
==
AF_INET
,
sockaddr_in
,
sockaddr_in6
>::
type
;
sockaddr_type
sa
;
memset
(
&
sa
,
0
,
sizeof
(
sockaddr_type
));
family_of
(
sa
)
=
Family
;
...
...
@@ -882,8 +869,9 @@ expected<native_socket> new_tcp_acceptor_impl(uint16_t port, const char* addr,
for
(
auto
&
elem
:
addrs
)
{
auto
hostname
=
elem
.
first
.
c_str
();
auto
p
=
elem
.
second
==
ipv4
?
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_INET
>
(
port
,
hostname
,
reuse_addr
,
any
)
:
new_ip_acceptor_impl
<
AF_INET6
>
(
port
,
hostname
,
reuse_addr
,
any
);
if
(
!
p
)
{
CAF_LOG_DEBUG
(
p
.
error
());
continue
;
...
...
@@ -893,9 +881,9 @@ expected<native_socket> new_tcp_acceptor_impl(uint16_t port, const char* addr,
}
if
(
fd
==
invalid_native_socket
)
{
CAF_LOG_WARNING
(
"could not open tcp socket on:"
<<
CAF_ARG
(
port
)
<<
CAF_ARG
(
addr_str
));
return
make_error
(
sec
::
cannot_open_port
,
"tcp socket creation failed"
,
port
,
addr_str
);
<<
CAF_ARG
(
addr_str
));
return
make_error
(
sec
::
cannot_open_port
,
"tcp socket creation failed"
,
port
,
addr_str
);
}
detail
::
socket_guard
sguard
{
fd
};
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,
for
(
auto
&
elem
:
addrs
)
{
auto
host
=
elem
.
first
.
c_str
();
auto
p
=
elem
.
second
==
ipv4
?
new_ip_acceptor_impl
<
AF_INET
,
SOCK_DGRAM
>
(
port
,
host
,
reuse
,
any
)
:
new_ip_acceptor_impl
<
AF_INET6
,
SOCK_DGRAM
>
(
port
,
host
,
reuse
,
any
);
?
new_ip_acceptor_impl
<
AF_INET
,
SOCK_DGRAM
>
(
port
,
host
,
reuse
,
any
)
:
new_ip_acceptor_impl
<
AF_INET6
,
SOCK_DGRAM
>
(
port
,
host
,
reuse
,
any
);
if
(
!
p
)
{
CAF_LOG_DEBUG
(
p
.
error
());
continue
;
...
...
@@ -947,9 +937,9 @@ new_local_udp_endpoint_impl(uint16_t port, const char* addr, bool reuse,
}
if
(
fd
==
invalid_native_socket
)
{
CAF_LOG_WARNING
(
"could not open udp socket on:"
<<
CAF_ARG
(
port
)
<<
CAF_ARG
(
addr_str
));
return
make_error
(
sec
::
cannot_open_port
,
"udp socket creation failed"
,
port
,
addr_str
);
<<
CAF_ARG
(
addr_str
));
return
make_error
(
sec
::
cannot_open_port
,
"udp socket creation failed"
,
port
,
addr_str
);
}
CAF_LOG_DEBUG
(
CAF_ARG
(
fd
));
return
std
::
make_pair
(
fd
,
proto
);
...
...
libcaf_io/src/io/network/doorman_impl.cpp
View file @
f4c5842b
...
...
@@ -29,8 +29,7 @@ namespace io {
namespace
network
{
doorman_impl
::
doorman_impl
(
default_multiplexer
&
mx
,
native_socket
sockfd
)
:
doorman
(
network
::
accept_hdl_from_socket
(
sockfd
)),
acceptor_
(
mx
,
sockfd
)
{
:
doorman
(
network
::
accept_hdl_from_socket
(
sockfd
)),
acceptor_
(
mx
,
sockfd
)
{
// nop
}
...
...
libcaf_io/src/io/network/event_handler.cpp
View file @
f4c5842b
...
...
@@ -23,9 +23,9 @@
#include "caf/io/network/default_multiplexer.hpp"
#ifdef CAF_WINDOWS
# include <winsock2.h>
#
include <winsock2.h>
#else
# include <sys/socket.h>
#
include <sys/socket.h>
#endif
namespace
caf
{
...
...
libcaf_io/src/io/network/interfaces.cpp
View file @
f4c5842b
...
...
@@ -20,28 +20,28 @@
#include "caf/config.hpp"
#include <algorithm>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#ifdef CAF_WINDOWS
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# endif
# include <iostream>
#
include <winsock2
.h>
#
include <ws2tcpip
.h>
#
include <iphlpapi
.h>
#
ifndef _WIN32_WINNT
#
define _WIN32_WINNT 0x0600
#
endif
#
include <iostream>
#
include <iphlpapi
.h>
#
include <winsock2
.h>
#
include <ws2tcpip
.h>
#else
#
include <sys/sock
et.h>
#
include <netinet/in
.h>
# include <net/if.h>
#
include <unistd
.h>
#
include <netdb
.h>
#
include <ifaddrs
.h>
#
include <sys/ioctl
.h>
#
include <arpa/inet
.h>
#
include <arpa/in
et.h>
#
include <ifaddrs
.h>
#
include <net/if.h>
#
include <netdb
.h>
#
include <netinet/in
.h>
#
include <sys/ioctl
.h>
#
include <sys/socket
.h>
#
include <unistd
.h>
#endif
#include <memory>
...
...
@@ -56,9 +56,8 @@ namespace io {
namespace
network
{
// {interface_name => {protocol => address}}
using
interfaces_map
=
std
::
map
<
std
::
string
,
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>>
;
using
interfaces_map
=
std
::
map
<
std
::
string
,
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>>
;
template
<
class
T
>
void
*
vptr
(
T
*
ptr
)
{
...
...
@@ -71,17 +70,16 @@ void* fetch_in_addr(int family, sockaddr* addr) {
return
vptr
(
&
reinterpret_cast
<
sockaddr_in6
*>
(
addr
)
->
sin6_addr
);
}
int
fetch_addr_str
(
bool
get_ipv4
,
bool
get_ipv6
,
char
(
&
buf
)[
INET6_ADDRSTRLEN
],
int
fetch_addr_str
(
bool
get_ipv4
,
bool
get_ipv6
,
char
(
&
buf
)[
INET6_ADDRSTRLEN
],
sockaddr
*
addr
)
{
if
(
addr
==
nullptr
)
return
AF_UNSPEC
;
auto
family
=
addr
->
sa_family
;
auto
in_addr
=
fetch_in_addr
(
family
,
addr
);
return
((
family
==
AF_INET
&&
get_ipv4
)
||
(
family
==
AF_INET6
&&
get_ipv6
))
&&
inet_ntop
(
family
,
in_addr
,
buf
,
INET6_ADDRSTRLEN
)
==
buf
?
family
:
AF_UNSPEC
;
&&
inet_ntop
(
family
,
in_addr
,
buf
,
INET6_ADDRSTRLEN
)
==
buf
?
family
:
AF_UNSPEC
;
}
#ifdef CAF_WINDOWS
...
...
@@ -100,21 +98,21 @@ void for_each_address(bool get_ipv4, bool get_ipv6, F fun) {
tmp
=
reinterpret_cast
<
IP_ADAPTER_ADDRESSES
*>
(
malloc
(
tmp_size
));
if
(
!
tmp
)
CAF_RAISE_ERROR
(
"malloc() failed"
);
retval
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
nullptr
,
tmp
,
&
tmp_size
);
retval
=
GetAdaptersAddresses
(
AF_UNSPEC
,
GAA_FLAG_INCLUDE_PREFIX
,
nullptr
,
tmp
,
&
tmp_size
);
}
while
(
retval
==
ERROR_BUFFER_OVERFLOW
&&
++
try_nr
<
max_tries
);
std
::
unique_ptr
<
IP_ADAPTER_ADDRESSES
,
decltype
(
free
)
*>
ifs
{
tmp
,
free
};
if
(
retval
!=
NO_ERROR
)
{
std
::
cerr
<<
"Call to GetAdaptersAddresses failed with error: "
<<
retval
<<
std
::
endl
;
std
::
cerr
<<
"Call to GetAdaptersAddresses failed with error: "
<<
retval
<<
std
::
endl
;
if
(
retval
==
ERROR_NO_DATA
)
{
std
::
cerr
<<
"No addresses were found for the requested parameters"
<<
std
::
endl
;
}
else
{
void
*
msgbuf
=
nullptr
;
if
(
FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
nullptr
,
retval
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
(
LPTSTR
)
&
msgbuf
,
0
,
nullptr
))
{
...
...
@@ -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
);
if
(
family
!=
AF_UNSPEC
)
fun
(
i
->
ifa_name
,
family
==
AF_INET
?
protocol
::
ipv4
:
protocol
::
ipv6
,
(
i
->
ifa_flags
&
IFF_LOOPBACK
)
!=
0
,
buffer
);
(
i
->
ifa_flags
&
IFF_LOOPBACK
)
!=
0
,
buffer
);
}
}
...
...
@@ -181,24 +178,24 @@ void interfaces::traverse(consumer f) {
interfaces_map
interfaces
::
list_all
(
bool
include_localhost
)
{
interfaces_map
result
;
traverse_impl
(
{
protocol
::
ipv4
,
protocol
::
ipv6
}
,
[
&
](
const
char
*
name
,
protocol
::
network
p
,
bool
lo
,
const
char
*
addr
)
{
if
(
include_localhost
||
!
lo
)
result
[
name
][
p
].
emplace_back
(
addr
);
});
traverse_impl
(
{
protocol
::
ipv4
,
protocol
::
ipv6
},
[
&
](
const
char
*
name
,
protocol
::
network
p
,
bool
lo
,
const
char
*
addr
)
{
if
(
include_localhost
||
!
lo
)
result
[
name
][
p
].
emplace_back
(
addr
);
});
return
result
;
}
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>
interfaces
::
list_addresses
(
bool
include_localhost
)
{
std
::
map
<
protocol
::
network
,
std
::
vector
<
std
::
string
>>
result
;
traverse_impl
(
{
protocol
::
ipv4
,
protocol
::
ipv6
}
,
[
&
](
const
char
*
,
protocol
::
network
p
,
bool
lo
,
const
char
*
addr
)
{
if
(
include_localhost
||
!
lo
)
result
[
p
].
emplace_back
(
addr
);
});
traverse_impl
(
{
protocol
::
ipv4
,
protocol
::
ipv6
},
[
&
](
const
char
*
,
protocol
::
network
p
,
bool
lo
,
const
char
*
addr
)
{
if
(
include_localhost
||
!
lo
)
result
[
p
].
emplace_back
(
addr
);
});
return
result
;
}
...
...
@@ -266,8 +263,7 @@ interfaces::server_address(uint16_t port, const char* host,
auto
family
=
fetch_addr_str
(
true
,
true
,
buffer
,
i
->
ai_addr
);
if
(
family
!=
AF_UNSPEC
)
{
results
.
emplace_back
(
std
::
string
{
buffer
},
family
==
AF_INET
?
protocol
::
ipv4
:
protocol
::
ipv6
);
family
==
AF_INET
?
protocol
::
ipv4
:
protocol
::
ipv6
);
}
}
std
::
stable_sort
(
std
::
begin
(
results
),
std
::
end
(
results
),
...
...
libcaf_io/src/io/network/ip_endpoint.cpp
View file @
f4c5842b
...
...
@@ -24,17 +24,17 @@
#include "caf/sec.hpp"
#ifdef CAF_WINDOWS
#
include <winsock2
.h>
#
include <windows
.h>
#
include <ws2tcpip
.h>
#
include <ws2ipdef
.h>
#
include <windows
.h>
#
include <winsock2
.h>
#
include <ws2ipdef
.h>
#
include <ws2tcpip
.h>
#else
#
include <unistd
.h>
# include <cerrno>
#
include <arpa/inet
.h>
#
include <sys/socket
.h>
#
include <netinet/in
.h>
#
include <netinet/ip
.h>
#
include <arpa/inet
.h>
#
include <cerrno>
#
include <netinet/in
.h>
#
include <netinet/ip
.h>
#
include <sys/socket
.h>
#
include <unistd
.h>
#endif
#ifdef CAF_WINDOWS
...
...
@@ -91,7 +91,7 @@ void ip_endpoint::clear() {
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
;
}
...
...
@@ -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
)
{
auto
same
=
false
;
if
(
*
lhs
.
clength
()
==
*
rhs
.
clength
()
&&
lhs
.
caddress
()
->
sa_family
==
rhs
.
caddress
()
->
sa_family
)
{
if
(
*
lhs
.
clength
()
==
*
rhs
.
clength
()
&&
lhs
.
caddress
()
->
sa_family
==
rhs
.
caddress
()
->
sa_family
)
{
switch
(
lhs
.
caddress
()
->
sa_family
)
{
case
AF_INET
:
{
auto
*
la
=
reinterpret_cast
<
const
sockaddr_in
*>
(
lhs
.
caddress
());
...
...
@@ -158,15 +158,19 @@ std::string host(const ip_endpoint& ep) {
char
addr
[
INET6_ADDRSTRLEN
];
if
(
*
ep
.
clength
()
==
0
)
return
""
;
switch
(
ep
.
caddress
()
->
sa_family
)
{
switch
(
ep
.
caddress
()
->
sa_family
)
{
case
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
()));
break
;
case
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
()));
break
;
default:
...
...
@@ -180,12 +184,14 @@ uint16_t port(const ip_endpoint& ep) {
uint16_t
port
=
0
;
if
(
*
ep
.
clength
()
==
0
)
return
0
;
switch
(
ep
.
caddress
()
->
sa_family
)
{
switch
(
ep
.
caddress
()
->
sa_family
)
{
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
;
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
;
default:
// nop
...
...
@@ -200,12 +206,12 @@ uint32_t family(const ip_endpoint& ep) {
return
ep
.
caddress
()
->
sa_family
;
}
error
load_endpoint
(
ip_endpoint
&
ep
,
uint32_t
&
f
,
std
::
string
&
h
,
uint16_t
&
p
,
size_t
&
l
)
{
error
load_endpoint
(
ip_endpoint
&
ep
,
uint32_t
&
f
,
std
::
string
&
h
,
uint16_t
&
p
,
size_t
&
l
)
{
ep
.
clear
();
if
(
l
>
0
)
{
*
ep
.
length
()
=
l
;
switch
(
f
)
{
switch
(
f
)
{
case
AF_INET
:
{
auto
*
addr
=
reinterpret_cast
<
sockaddr_in
*>
(
ep
.
address
());
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,
return
none
;
}
error
save_endpoint
(
ip_endpoint
&
ep
,
uint32_t
&
f
,
std
::
string
&
h
,
uint16_t
&
p
,
size_t
&
l
)
{
error
save_endpoint
(
ip_endpoint
&
ep
,
uint32_t
&
f
,
std
::
string
&
h
,
uint16_t
&
p
,
size_t
&
l
)
{
if
(
*
ep
.
length
()
>
0
)
{
f
=
family
(
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) {
ptr
.
swap
(
parent_
);
detach_from
(
raw_ptr
);
if
(
invoke_disconnect_message
)
{
auto
mptr
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
{},
detach_message
());
auto
mptr
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
{},
detach_message
());
switch
(
raw_ptr
->
consume
(
*
mptr
))
{
case
im_success
:
raw_ptr
->
finalize
();
...
...
libcaf_io/src/io/network/multiplexer.cpp
View file @
f4c5842b
...
...
@@ -24,8 +24,7 @@ namespace io {
namespace
network
{
multiplexer
::
multiplexer
(
actor_system
*
sys
)
:
execution_unit
(
sys
),
tid_
(
std
::
this_thread
::
get_id
())
{
:
execution_unit
(
sys
),
tid_
(
std
::
this_thread
::
get_id
())
{
// nop
}
...
...
libcaf_io/src/io/network/native_socket.cpp
View file @
f4c5842b
...
...
@@ -18,40 +18,40 @@
#include "caf/io/network/native_socket.hpp"
#include "caf/sec.hpp"
#include "caf/logger.hpp"
#include "caf/sec.hpp"
#include "caf/detail/call_cfun.hpp"
#include "caf/io/network/protocol.hpp"
#ifdef CAF_WINDOWS
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# ifndef NOMINMAX
# define NOMINMAX
# endif
# ifdef CAF_MINGW
# undef _WIN32_WINNT
# undef WINVER
# define _WIN32_WINNT WindowsVista
# define WINVER WindowsVista
# include <w32api.h>
# endif
#
include <winsock2
.h>
#
include <windows
.h>
#
include <ws2tcpip
.h>
#
include <ws2ipdef
.h>
#
ifndef WIN32_LEAN_AND_MEAN
#
define WIN32_LEAN_AND_MEAN
#
endif
#
ifndef NOMINMAX
#
define NOMINMAX
#
endif
#
ifdef CAF_MINGW
#
undef _WIN32_WINNT
#
undef WINVER
#
define _WIN32_WINNT WindowsVista
#
define WINVER WindowsVista
#
include <w32api.h>
#
endif
#
include <windows
.h>
#
include <winsock2
.h>
#
include <ws2ipdef
.h>
#
include <ws2tcpip
.h>
#else
#
include <cerrno
>
#
include <fcntl.h
>
#
include <unistd
.h>
#
include <arpa/inet
.h>
#
include <sys/socket
.h>
#
include <netinet/in
.h>
#
include <netinet/ip
.h>
#
include <netinet/tcp
.h>
#
include <arpa/inet.h
>
#
include <cerrno
>
#
include <fcntl
.h>
#
include <netinet/in
.h>
#
include <netinet/ip
.h>
#
include <netinet/tcp
.h>
#
include <sys/socket
.h>
#
include <unistd
.h>
#endif
using
std
::
string
;
...
...
@@ -66,7 +66,8 @@ auto port_of(sockaddr_in6& what) -> decltype(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
)
{
case
AF_INET
:
return
port_of
(
reinterpret_cast
<
sockaddr_in
&>
(
what
));
...
...
@@ -85,266 +86,265 @@ namespace io {
namespace
network
{
#ifdef CAF_WINDOWS
const
int
ec_out_of_memory
=
WSAENOBUFS
;
const
int
ec_interrupted_syscall
=
WSAEINTR
;
const
int
ec_out_of_memory
=
WSAENOBUFS
;
const
int
ec_interrupted_syscall
=
WSAEINTR
;
#else
const
int
ec_out_of_memory
=
ENOMEM
;
const
int
ec_interrupted_syscall
=
EINTR
;
const
int
ec_out_of_memory
=
ENOMEM
;
const
int
ec_interrupted_syscall
=
EINTR
;
#endif
// platform-dependent SIGPIPE setup
#if defined(CAF_MACOS) || defined(CAF_IOS) || defined(CAF_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_io_flag
=
0
;
// 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_io_flag
=
0
;
#elif defined(CAF_WINDOWS)
// Do nothing on Windows (SIGPIPE does not exist).
const
int
no_sigpipe_socket_flag
=
0
;
const
int
no_sigpipe_io_flag
=
0
;
// Do nothing on Windows (SIGPIPE does not exist).
const
int
no_sigpipe_socket_flag
=
0
;
const
int
no_sigpipe_io_flag
=
0
;
#else
// Use flags to recv/send on Linux/Android but no socket option.
const
int
no_sigpipe_socket_flag
=
0
;
const
int
no_sigpipe_io_flag
=
MSG_NOSIGNAL
;
// Use flags to recv/send on Linux/Android but no socket option.
const
int
no_sigpipe_socket_flag
=
0
;
const
int
no_sigpipe_io_flag
=
MSG_NOSIGNAL
;
#endif
#ifndef CAF_WINDOWS
int
last_socket_error
()
{
return
errno
;
}
int
last_socket_error
()
{
return
errno
;
}
void
close_socket
(
native_socket
fd
)
{
close
(
fd
);
}
void
close_socket
(
native_socket
fd
)
{
close
(
fd
);
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
EAGAIN
||
errcode
==
EWOULDBLOCK
;
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
EAGAIN
||
errcode
==
EWOULDBLOCK
;
}
string
last_socket_error_as_string
()
{
return
strerror
(
errno
);
}
string
last_socket_error_as_string
()
{
return
strerror
(
errno
);
}
string
socket_error_as_string
(
int
errcode
)
{
return
strerror
(
errcode
);
}
string
socket_error_as_string
(
int
errcode
)
{
return
strerror
(
errcode
);
}
expected
<
void
>
child_process_inherit
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
// read flags for fd
CALL_CFUN
(
rf
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_GETFD
));
// calculate and set new flags
auto
wf
=
(
!
new_value
)
?
(
rf
|
FD_CLOEXEC
)
:
(
rf
&
(
~
(
FD_CLOEXEC
)));
CALL_CFUN
(
set_res
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_SETFD
,
wf
));
return
unit
;
}
expected
<
void
>
child_process_inherit
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
// read flags for fd
CALL_CFUN
(
rf
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_GETFD
));
// calculate and set new flags
auto
wf
=
(
!
new_value
)
?
(
rf
|
FD_CLOEXEC
)
:
(
rf
&
(
~
(
FD_CLOEXEC
)));
CALL_CFUN
(
set_res
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_SETFD
,
wf
));
return
unit
;
}
expected
<
void
>
keepalive
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
int
value
=
new_value
?
1
:
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_KEEPALIVE
,
&
value
,
static_cast
<
unsigned
>
(
sizeof
(
value
))));
return
unit
;
}
expected
<
void
>
keepalive
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
int
value
=
new_value
?
1
:
0
;
expected
<
void
>
nonblocking
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
// read flags for fd
CALL_CFUN
(
rf
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_GETFL
,
0
));
// calculate and set new flags
auto
wf
=
new_value
?
(
rf
|
O_NONBLOCK
)
:
(
rf
&
(
~
(
O_NONBLOCK
)));
CALL_CFUN
(
set_res
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_SETFL
,
wf
));
return
unit
;
}
expected
<
void
>
allow_sigpipe
(
native_socket
fd
,
bool
new_value
)
{
if
(
no_sigpipe_socket_flag
!=
0
)
{
int
value
=
new_value
?
0
:
1
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_KEEPALIVE
,
&
value
,
setsockopt
(
fd
,
SOL_SOCKET
,
no_sigpipe_socket_flag
,
&
value
,
static_cast
<
unsigned
>
(
sizeof
(
value
))));
return
unit
;
}
expected
<
void
>
nonblocking
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
// read flags for fd
CALL_CFUN
(
rf
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_GETFL
,
0
));
// calculate and set new flags
auto
wf
=
new_value
?
(
rf
|
O_NONBLOCK
)
:
(
rf
&
(
~
(
O_NONBLOCK
)));
CALL_CFUN
(
set_res
,
detail
::
cc_not_minus1
,
"fcntl"
,
fcntl
(
fd
,
F_SETFL
,
wf
));
return
unit
;
}
expected
<
void
>
allow_sigpipe
(
native_socket
fd
,
bool
new_value
)
{
if
(
no_sigpipe_socket_flag
!=
0
)
{
int
value
=
new_value
?
0
:
1
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
SOL_SOCKET
,
no_sigpipe_socket_flag
,
&
value
,
static_cast
<
unsigned
>
(
sizeof
(
value
))));
}
return
unit
;
}
return
unit
;
}
expected
<
void
>
allow_udp_connreset
(
native_socket
,
bool
)
{
// nop; SIO_UDP_CONNRESET only exists on Windows
return
unit
;
}
expected
<
void
>
allow_udp_connreset
(
native_socket
,
bool
)
{
// nop; SIO_UDP_CONNRESET only exists on Windows
return
unit
;
}
std
::
pair
<
native_socket
,
native_socket
>
create_pipe
()
{
int
pipefds
[
2
];
if
(
pipe
(
pipefds
)
!=
0
)
{
perror
(
"pipe"
);
exit
(
EXIT_FAILURE
);
}
// note pipe2 is better to avoid races in setting CLOEXEC (but not posix)
child_process_inherit
(
pipefds
[
0
],
false
);
child_process_inherit
(
pipefds
[
1
],
false
);
return
{
pipefds
[
0
],
pipefds
[
1
]};
std
::
pair
<
native_socket
,
native_socket
>
create_pipe
()
{
int
pipefds
[
2
];
if
(
pipe
(
pipefds
)
!=
0
)
{
perror
(
"pipe"
);
exit
(
EXIT_FAILURE
);
}
// note pipe2 is better to avoid races in setting CLOEXEC (but not posix)
child_process_inherit
(
pipefds
[
0
],
false
);
child_process_inherit
(
pipefds
[
1
],
false
);
return
{
pipefds
[
0
],
pipefds
[
1
]};
}
#else // CAF_WINDOWS
int
last_socket_error
()
{
return
WSAGetLastError
();
}
int
last_socket_error
()
{
return
WSAGetLastError
();
}
void
close_socket
(
native_socket
fd
)
{
closesocket
(
fd
);
}
void
close_socket
(
native_socket
fd
)
{
closesocket
(
fd
);
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
WSAEWOULDBLOCK
||
errcode
==
WSATRY_AGAIN
;
}
bool
would_block_or_temporarily_unavailable
(
int
errcode
)
{
return
errcode
==
WSAEWOULDBLOCK
||
errcode
==
WSATRY_AGAIN
;
}
string
last_socket_error_as_string
()
{
return
socket_error_as_string
(
last_socket_error
());
}
string
last_socket_error_as_string
()
{
return
socket_error_as_string
(
last_socket_error
());
}
string
socket_error_as_string
(
int
errcode
)
{
LPTSTR
errorText
=
NULL
;
FormatMessage
(
// use system message tables to retrieve error text
FORMAT_MESSAGE_FROM_SYSTEM
// allocate buffer on local heap for error text
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
// Important! will fail otherwise, since we're not
// (and CANNOT) pass insertion parameters
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
nullptr
,
// unused with FORMAT_MESSAGE_FROM_SYSTEM
errcode
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
(
LPTSTR
)
&
errorText
,
// output
0
,
// minimum size for output buffer
nullptr
);
// arguments - see note
string
result
;
if
(
errorText
!=
nullptr
)
{
result
=
errorText
;
// release memory allocated by FormatMessage()
LocalFree
(
errorText
);
}
return
result
;
string
socket_error_as_string
(
int
errcode
)
{
LPTSTR
errorText
=
NULL
;
FormatMessage
(
// use system message tables to retrieve error text
FORMAT_MESSAGE_FROM_SYSTEM
// allocate buffer on local heap for error text
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
// Important! will fail otherwise, since we're not
// (and CANNOT) pass insertion parameters
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
nullptr
,
// unused with FORMAT_MESSAGE_FROM_SYSTEM
errcode
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
(
LPTSTR
)
&
errorText
,
// output
0
,
// minimum size for output buffer
nullptr
);
// arguments - see note
string
result
;
if
(
errorText
!=
nullptr
)
{
result
=
errorText
;
// release memory allocated by FormatMessage()
LocalFree
(
errorText
);
}
return
result
;
}
expected
<
void
>
child_process_inherit
(
native_socket
fd
,
bool
new_value
)
{
// nop; FIXME: possible to implement via SetHandleInformation ?
return
unit
;
}
expected
<
void
>
child_process_inherit
(
native_socket
fd
,
bool
new_value
)
{
// nop; FIXME: possible to implement via SetHandleInformation ?
return
unit
;
}
expected
<
void
>
keepalive
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
char
value
=
new_value
?
1
:
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_KEEPALIVE
,
&
value
,
static_cast
<
int
>
(
sizeof
(
value
))));
return
unit
;
}
expected
<
void
>
keepalive
(
native_socket
fd
,
bool
new_value
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
new_value
));
char
value
=
new_value
?
1
:
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
fd
,
SOL_SOCKET
,
SO_KEEPALIVE
,
&
value
,
static_cast
<
int
>
(
sizeof
(
value
))));
return
unit
;
}
expected
<
void
>
nonblocking
(
native_socket
fd
,
bool
new_value
)
{
u_long
mode
=
new_value
?
1
:
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"ioctlsocket"
,
ioctlsocket
(
fd
,
FIONBIO
,
&
mode
));
return
unit
;
}
expected
<
void
>
nonblocking
(
native_socket
fd
,
bool
new_value
)
{
u_long
mode
=
new_value
?
1
:
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"ioctlsocket"
,
ioctlsocket
(
fd
,
FIONBIO
,
&
mode
));
return
unit
;
}
expected
<
void
>
allow_sigpipe
(
native_socket
,
bool
)
{
// nop; SIGPIPE does not exist on Windows
return
unit
;
}
expected
<
void
>
allow_sigpipe
(
native_socket
,
bool
)
{
// nop; SIGPIPE does not exist on Windows
return
unit
;
}
expected
<
void
>
allow_udp_connreset
(
native_socket
fd
,
bool
new_value
)
{
DWORD
bytes_returned
=
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"WSAIoctl"
,
WSAIoctl
(
fd
,
_WSAIOW
(
IOC_VENDOR
,
12
),
&
new_value
,
sizeof
(
new_value
),
NULL
,
0
,
&
bytes_returned
,
NULL
,
NULL
));
return
unit
;
}
expected
<
void
>
allow_udp_connreset
(
native_socket
fd
,
bool
new_value
)
{
DWORD
bytes_returned
=
0
;
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"WSAIoctl"
,
WSAIoctl
(
fd
,
_WSAIOW
(
IOC_VENDOR
,
12
),
&
new_value
,
sizeof
(
new_value
),
NULL
,
0
,
&
bytes_returned
,
NULL
,
NULL
));
return
unit
;
}
/**************************************************************************\
* Based on work of others; *
* original header: *
* *
* Copyright 2007, 2010 by Nathan C. Myers <ncm@cantrip.org> *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* The name of the author must not be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
\**************************************************************************/
std
::
pair
<
native_socket
,
native_socket
>
create_pipe
()
{
socket_size_type
addrlen
=
sizeof
(
sockaddr_in
);
native_socket
socks
[
2
]
=
{
invalid_native_socket
,
invalid_native_socket
};
CALL_CRITICAL_CFUN
(
listener
,
detail
::
cc_valid_socket
,
"socket"
,
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
));
union
{
sockaddr_in
inaddr
;
sockaddr
addr
;
}
a
;
memset
(
&
a
,
0
,
sizeof
(
a
));
a
.
inaddr
.
sin_family
=
AF_INET
;
a
.
inaddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_LOOPBACK
);
a
.
inaddr
.
sin_port
=
0
;
// makes sure all sockets are closed in case of an error
auto
guard
=
detail
::
make_scope_guard
([
&
]
{
auto
e
=
WSAGetLastError
();
close_socket
(
listener
);
close_socket
(
socks
[
0
]);
close_socket
(
socks
[
1
]);
WSASetLastError
(
e
);
});
// bind listener to a local port
int
reuse
=
1
;
CALL_CRITICAL_CFUN
(
tmp1
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
listener
,
SOL_SOCKET
,
SO_REUSEADDR
,
reinterpret_cast
<
char
*>
(
&
reuse
),
static_cast
<
int
>
(
sizeof
(
reuse
))));
CALL_CRITICAL_CFUN
(
tmp2
,
detail
::
cc_zero
,
"bind"
,
bind
(
listener
,
&
a
.
addr
,
static_cast
<
int
>
(
sizeof
(
a
.
inaddr
))));
// read the port in use: win32 getsockname may only set the port number
// (http://msdn.microsoft.com/library/ms738543.aspx):
memset
(
&
a
,
0
,
sizeof
(
a
));
CALL_CRITICAL_CFUN
(
tmp3
,
detail
::
cc_zero
,
"getsockname"
,
getsockname
(
listener
,
&
a
.
addr
,
&
addrlen
));
a
.
inaddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_LOOPBACK
);
a
.
inaddr
.
sin_family
=
AF_INET
;
// set listener to listen mode
CALL_CRITICAL_CFUN
(
tmp5
,
detail
::
cc_zero
,
"listen"
,
listen
(
listener
,
1
));
// create read-only end of the pipe
DWORD
flags
=
0
;
CALL_CRITICAL_CFUN
(
read_fd
,
detail
::
cc_valid_socket
,
"WSASocketW"
,
WSASocketW
(
AF_INET
,
SOCK_STREAM
,
0
,
nullptr
,
0
,
flags
));
CALL_CRITICAL_CFUN
(
tmp6
,
detail
::
cc_zero
,
"connect"
,
connect
(
read_fd
,
&
a
.
addr
,
static_cast
<
int
>
(
sizeof
(
a
.
inaddr
))));
// get write-only end of the pipe
CALL_CRITICAL_CFUN
(
write_fd
,
detail
::
cc_valid_socket
,
"accept"
,
accept
(
listener
,
nullptr
,
nullptr
));
/**************************************************************************\
* Based on work of others; *
* original header: *
* *
* Copyright 2007, 2010 by Nathan C. Myers <ncm@cantrip.org> *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* The name of the author must not be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
\**************************************************************************/
std
::
pair
<
native_socket
,
native_socket
>
create_pipe
()
{
socket_size_type
addrlen
=
sizeof
(
sockaddr_in
);
native_socket
socks
[
2
]
=
{
invalid_native_socket
,
invalid_native_socket
};
CALL_CRITICAL_CFUN
(
listener
,
detail
::
cc_valid_socket
,
"socket"
,
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
));
union
{
sockaddr_in
inaddr
;
sockaddr
addr
;
}
a
;
memset
(
&
a
,
0
,
sizeof
(
a
));
a
.
inaddr
.
sin_family
=
AF_INET
;
a
.
inaddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_LOOPBACK
);
a
.
inaddr
.
sin_port
=
0
;
// makes sure all sockets are closed in case of an error
auto
guard
=
detail
::
make_scope_guard
([
&
]
{
auto
e
=
WSAGetLastError
();
close_socket
(
listener
);
guard
.
disable
();
return
std
::
make_pair
(
read_fd
,
write_fd
);
}
close_socket
(
socks
[
0
]);
close_socket
(
socks
[
1
]);
WSASetLastError
(
e
);
});
// bind listener to a local port
int
reuse
=
1
;
CALL_CRITICAL_CFUN
(
tmp1
,
detail
::
cc_zero
,
"setsockopt"
,
setsockopt
(
listener
,
SOL_SOCKET
,
SO_REUSEADDR
,
reinterpret_cast
<
char
*>
(
&
reuse
),
static_cast
<
int
>
(
sizeof
(
reuse
))));
CALL_CRITICAL_CFUN
(
tmp2
,
detail
::
cc_zero
,
"bind"
,
bind
(
listener
,
&
a
.
addr
,
static_cast
<
int
>
(
sizeof
(
a
.
inaddr
))));
// read the port in use: win32 getsockname may only set the port number
// (http://msdn.microsoft.com/library/ms738543.aspx):
memset
(
&
a
,
0
,
sizeof
(
a
));
CALL_CRITICAL_CFUN
(
tmp3
,
detail
::
cc_zero
,
"getsockname"
,
getsockname
(
listener
,
&
a
.
addr
,
&
addrlen
));
a
.
inaddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_LOOPBACK
);
a
.
inaddr
.
sin_family
=
AF_INET
;
// set listener to listen mode
CALL_CRITICAL_CFUN
(
tmp5
,
detail
::
cc_zero
,
"listen"
,
listen
(
listener
,
1
));
// create read-only end of the pipe
DWORD
flags
=
0
;
CALL_CRITICAL_CFUN
(
read_fd
,
detail
::
cc_valid_socket
,
"WSASocketW"
,
WSASocketW
(
AF_INET
,
SOCK_STREAM
,
0
,
nullptr
,
0
,
flags
));
CALL_CRITICAL_CFUN
(
tmp6
,
detail
::
cc_zero
,
"connect"
,
connect
(
read_fd
,
&
a
.
addr
,
static_cast
<
int
>
(
sizeof
(
a
.
inaddr
))));
// get write-only end of the pipe
CALL_CRITICAL_CFUN
(
write_fd
,
detail
::
cc_valid_socket
,
"accept"
,
accept
(
listener
,
nullptr
,
nullptr
));
close_socket
(
listener
);
guard
.
disable
();
return
std
::
make_pair
(
read_fd
,
write_fd
);
}
#endif
...
...
@@ -353,7 +353,7 @@ expected<int> send_buffer_size(native_socket fd) {
socket_size_type
ret_size
=
sizeof
(
size
);
CALL_CFUN
(
res
,
detail
::
cc_zero
,
"getsockopt"
,
getsockopt
(
fd
,
SOL_SOCKET
,
SO_SNDBUF
,
reinterpret_cast
<
getsockopt_ptr
>
(
&
size
),
&
ret_size
));
reinterpret_cast
<
getsockopt_ptr
>
(
&
size
),
&
ret_size
));
return
size
;
}
...
...
@@ -392,20 +392,20 @@ expected<string> local_addr_of_fd(native_socket fd) {
socket_size_type
st_len
=
sizeof
(
st
);
sockaddr
*
sa
=
reinterpret_cast
<
sockaddr
*>
(
&
st
);
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
)
{
case
AF_INET
:
return
inet_ntop
(
AF_INET
,
&
reinterpret_cast
<
sockaddr_in
*>
(
sa
)
->
sin_addr
,
addr
,
sizeof
(
addr
));
case
AF_INET6
:
return
inet_ntop
(
AF_INET6
,
&
reinterpret_cast
<
sockaddr_in6
*>
(
sa
)
->
sin6_addr
,
addr
,
sizeof
(
addr
));
&
reinterpret_cast
<
sockaddr_in6
*>
(
sa
)
->
sin6_addr
,
addr
,
sizeof
(
addr
));
default:
break
;
}
return
make_error
(
sec
::
invalid_protocol_family
,
"local_addr_of_fd"
,
sa
->
sa_family
);
return
make_error
(
sec
::
invalid_protocol_family
,
"local_addr_of_fd"
,
sa
->
sa_family
);
}
expected
<
uint16_t
>
local_port_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
);
sockaddr
*
sa
=
reinterpret_cast
<
sockaddr
*>
(
&
st
);
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
)
{
case
AF_INET
:
return
inet_ntop
(
AF_INET
,
&
reinterpret_cast
<
sockaddr_in
*>
(
sa
)
->
sin_addr
,
addr
,
sizeof
(
addr
));
case
AF_INET6
:
return
inet_ntop
(
AF_INET6
,
&
reinterpret_cast
<
sockaddr_in6
*>
(
sa
)
->
sin6_addr
,
addr
,
sizeof
(
addr
));
&
reinterpret_cast
<
sockaddr_in6
*>
(
sa
)
->
sin6_addr
,
addr
,
sizeof
(
addr
));
default:
break
;
}
return
make_error
(
sec
::
invalid_protocol_family
,
"remote_addr_of_fd"
,
sa
->
sa_family
);
return
make_error
(
sec
::
invalid_protocol_family
,
"remote_addr_of_fd"
,
sa
->
sa_family
);
}
expected
<
uint16_t
>
remote_port_of_fd
(
native_socket
fd
)
{
...
...
@@ -453,7 +453,7 @@ namespace {
static
constexpr
int
read_channel
=
SD_RECEIVE
;
static
constexpr
int
write_channel
=
SD_SEND
;
static
constexpr
int
both_channels
=
SD_BOTH
;
#else // CAF_WINDOWS
#else
// CAF_WINDOWS
static
constexpr
int
read_channel
=
SHUT_RD
;
static
constexpr
int
write_channel
=
SHUT_WR
;
static
constexpr
int
both_channels
=
SHUT_RDWR
;
...
...
libcaf_io/src/io/network/pipe_reader.cpp
View file @
f4c5842b
...
...
@@ -20,14 +20,14 @@
#include <cstdint>
#include "caf/io/network/pipe_reader.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/io/network/pipe_reader.hpp"
#ifdef CAF_WINDOWS
# include <winsock2.h>
#
include <winsock2.h>
#else
#
include <unistd
.h>
#
include <sys/socket
.h>
#
include <sys/socket
.h>
#
include <unistd
.h>
#endif
namespace
caf
{
...
...
@@ -35,7 +35,7 @@ namespace io {
namespace
network
{
pipe_reader
::
pipe_reader
(
default_multiplexer
&
dm
)
:
event_handler
(
dm
,
invalid_native_socket
)
{
:
event_handler
(
dm
,
invalid_native_socket
)
{
// nop
}
...
...
@@ -50,12 +50,12 @@ void pipe_reader::graceful_shutdown() {
resumable
*
pipe_reader
::
try_read_next
()
{
std
::
intptr_t
ptrval
;
// on windows, we actually have sockets, otherwise we have file handles
#
ifdef CAF_WINDOWS
auto
res
=
recv
(
fd
(),
reinterpret_cast
<
socket_recv_ptr
>
(
&
ptrval
),
sizeof
(
ptrval
),
0
);
#
else
auto
res
=
read
(
fd
(),
&
ptrval
,
sizeof
(
ptrval
));
#
endif
#ifdef CAF_WINDOWS
auto
res
=
recv
(
fd
(),
reinterpret_cast
<
socket_recv_ptr
>
(
&
ptrval
),
sizeof
(
ptrval
),
0
);
#else
auto
res
=
read
(
fd
(),
&
ptrval
,
sizeof
(
ptrval
));
#endif
if
(
res
!=
sizeof
(
ptrval
))
return
nullptr
;
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) {
}
// namespace network
}
// namespace io
}
// namespace caf
libcaf_io/src/io/network/receive_buffer.cpp
View file @
f4c5842b
...
...
@@ -33,9 +33,7 @@ namespace io {
namespace
network
{
receive_buffer
::
receive_buffer
()
noexcept
:
buffer_
(
nullptr
),
capacity_
(
0
),
size_
(
0
)
{
:
buffer_
(
nullptr
),
capacity_
(
0
),
size_
(
0
)
{
// nop
}
...
...
@@ -44,12 +42,12 @@ receive_buffer::receive_buffer(size_type count) : receive_buffer() {
}
receive_buffer
::
receive_buffer
(
receive_buffer
&&
other
)
noexcept
:
receive_buffer
()
{
:
receive_buffer
()
{
swap
(
other
);
}
receive_buffer
::
receive_buffer
(
const
receive_buffer
&
other
)
:
receive_buffer
(
other
.
size
())
{
:
receive_buffer
(
other
.
size
())
{
std
::
copy
(
other
.
cbegin
(),
other
.
cend
(),
buffer_
.
get
());
}
...
...
@@ -72,7 +70,7 @@ void receive_buffer::resize(size_type new_size) {
void
receive_buffer
::
reserve
(
size_type
new_size
)
{
if
(
new_size
>
capacity_
)
increase_by
(
new_size
-
capacity_
);
increase_by
(
new_size
-
capacity_
);
}
void
receive_buffer
::
shrink_to_fit
()
{
...
...
@@ -126,7 +124,8 @@ void receive_buffer::shrink_by(size_t bytes) {
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_
)
{
auto
dist
=
(
pos
==
nullptr
)
?
0
:
std
::
distance
(
begin
(),
pos
);
increase_by
(
std
::
max
(
capacity_
,
min_size
));
...
...
@@ -138,6 +137,6 @@ receive_buffer::iterator receive_buffer::insert(iterator pos, value_type value)
return
pos
;
}
}
// name
ps
ace network
}
// name
sp
ace network
}
// namespace io
}
// namespace caf
libcaf_io/src/io/network/scribe_impl.cpp
View file @
f4c5842b
...
...
@@ -29,9 +29,9 @@ namespace io {
namespace
network
{
scribe_impl
::
scribe_impl
(
default_multiplexer
&
mx
,
native_socket
sockfd
)
:
scribe
(
network
::
conn_hdl_from_socket
(
sockfd
)),
launched_
(
false
),
stream_
(
mx
,
sockfd
)
{
:
scribe
(
network
::
conn_hdl_from_socket
(
sockfd
)),
launched_
(
false
),
stream_
(
mx
,
sockfd
)
{
// nop
}
...
...
libcaf_io/src/io/network/stream.cpp
View file @
f4c5842b
...
...
@@ -31,13 +31,13 @@ namespace io {
namespace
network
{
stream
::
stream
(
default_multiplexer
&
backend_ref
,
native_socket
sockfd
)
:
event_handler
(
backend_ref
,
sockfd
),
max_consecutive_reads_
(
get_or
(
backend
().
system
().
config
(),
"middleman.max-consecutive-reads"
,
defaults
::
middleman
::
max_consecutive_reads
)),
read_threshold_
(
1
),
collected_
(
0
),
written_
(
0
)
{
:
event_handler
(
backend_ref
,
sockfd
),
max_consecutive_reads_
(
get_or
(
backend
().
system
().
config
(),
"middleman.max-consecutive-reads"
,
defaults
::
middleman
::
max_consecutive_reads
)),
read_threshold_
(
1
),
collected_
(
0
),
written_
(
0
)
{
configure_read
(
receive_policy
::
at_most
(
1024
));
}
...
...
@@ -62,7 +62,7 @@ void stream::configure_read(receive_policy::config config) {
void
stream
::
write
(
const
void
*
buf
,
size_t
num_bytes
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
num_bytes
));
auto
first
=
reinterpret_cast
<
const
char
*>
(
buf
);
auto
last
=
first
+
num_bytes
;
auto
last
=
first
+
num_bytes
;
wr_offline_buf_
.
insert
(
wr_offline_buf_
.
end
(),
first
,
last
);
}
...
...
@@ -80,9 +80,13 @@ void stream::flush(const manager_ptr& mgr) {
void
stream
::
removed_from_loop
(
operation
op
)
{
CAF_LOG_TRACE
(
CAF_ARG2
(
"fd"
,
fd_
)
<<
CAF_ARG
(
op
));
switch
(
op
)
{
case
operation
:
:
read
:
reader_
.
reset
();
break
;
case
operation
:
:
write
:
writer_
.
reset
();
break
;
case
operation
:
:
propagate_error
:
;
// nop
case
operation
:
:
read
:
reader_
.
reset
();
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) {
return
false
;
collected_
+=
rb
;
if
(
collected_
>=
read_threshold_
)
{
auto
res
=
reader_
->
consume
(
&
backend
(),
rd_buf_
.
data
(),
collected_
);
auto
res
=
reader_
->
consume
(
&
backend
(),
rd_buf_
.
data
(),
collected_
);
prepare_next_read
();
if
(
!
res
)
{
passivate
();
...
...
libcaf_io/src/io/network/test_multiplexer.cpp
View file @
f4c5842b
...
...
@@ -36,44 +36,39 @@ constexpr size_t receive_buffer_size = std::numeric_limits<uint16_t>::max();
test_multiplexer
::
scribe_data
::
scribe_data
(
shared_buffer_type
input
,
shared_buffer_type
output
)
:
vn_buf_ptr
(
std
::
move
(
input
)),
wr_buf_ptr
(
std
::
move
(
output
)),
vn_buf
(
*
vn_buf_ptr
),
wr_buf
(
*
wr_buf_ptr
),
stopped_reading
(
false
),
passive_mode
(
false
),
ack_writes
(
false
)
{
:
vn_buf_ptr
(
std
::
move
(
input
)),
wr_buf_ptr
(
std
::
move
(
output
)),
vn_buf
(
*
vn_buf_ptr
),
wr_buf
(
*
wr_buf_ptr
),
stopped_reading
(
false
),
passive_mode
(
false
),
ack_writes
(
false
)
{
// nop
}
test_multiplexer
::
doorman_data
::
doorman_data
()
:
port
(
0
),
stopped_reading
(
false
),
passive_mode
(
false
)
{
:
port
(
0
),
stopped_reading
(
false
),
passive_mode
(
false
)
{
// nop
}
test_multiplexer
::
datagram_data
::
datagram_data
(
shared_job_queue_type
input
,
shared_job_queue_type
output
)
:
vn_buf_ptr
(
std
::
move
(
input
)),
wr_buf_ptr
(
std
::
move
(
output
)),
vn_buf
(
*
vn_buf_ptr
),
wr_buf
(
*
wr_buf_ptr
),
rd_buf
(
datagram_handle
::
from_int
(
0
),
receive_buffer_size
),
stopped_reading
(
false
),
passive_mode
(
false
),
ack_writes
(
false
),
port
(
0
),
local_port
(
0
),
datagram_size
(
receive_buffer_size
)
{
test_multiplexer
::
datagram_data
::
datagram_data
(
shared_job_queue_type
input
,
shared_job_queue_type
output
)
:
vn_buf_ptr
(
std
::
move
(
input
)),
wr_buf_ptr
(
std
::
move
(
output
)),
vn_buf
(
*
vn_buf_ptr
),
wr_buf
(
*
wr_buf_ptr
),
rd_buf
(
datagram_handle
::
from_int
(
0
),
receive_buffer_size
),
stopped_reading
(
false
),
passive_mode
(
false
),
ack_writes
(
false
),
port
(
0
),
local_port
(
0
),
datagram_size
(
receive_buffer_size
)
{
// nop
}
test_multiplexer
::
test_multiplexer
(
actor_system
*
sys
)
:
multiplexer
(
sys
),
inline_runnables_
(
0
),
servant_ids_
(
0
)
{
:
multiplexer
(
sys
),
inline_runnables_
(
0
),
servant_ids_
(
0
)
{
CAF_ASSERT
(
sys
!=
nullptr
);
}
...
...
@@ -126,6 +121,7 @@ scribe_ptr test_multiplexer::new_scribe(connection_handle hdl) {
void
remove_from_loop
()
override
{
mpx_
->
passive_mode
(
hdl
())
=
true
;
}
private:
test_multiplexer
*
mpx_
;
};
...
...
@@ -203,6 +199,7 @@ doorman_ptr test_multiplexer::new_doorman(accept_handle hdl, uint16_t port) {
void
remove_from_loop
()
override
{
mpx_
->
passive_mode
(
hdl
())
=
true
;
}
private:
test_multiplexer
*
mpx_
;
};
...
...
@@ -251,15 +248,17 @@ expected<doorman_ptr> test_multiplexer::new_tcp_doorman(uint16_t desired_port,
datagram_servant_ptr
test_multiplexer
::
new_datagram_servant
(
native_socket
)
{
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
test_multiplexer
::
new_datagram_servant_for_endpoint
(
native_socket
,
const
ip_endpoint
&
)
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_CRITICAL
(
"test_multiplexer::new_datagram_servant_for_endpoint called with "
"native socket"
);
CAF_CRITICAL
(
"test_multiplexer::new_datagram_servant_for_endpoint called with "
"native socket"
);
}
expected
<
datagram_servant_ptr
>
...
...
@@ -289,8 +288,8 @@ test_multiplexer::new_remote_udp_endpoint(const std::string& host,
}
expected
<
datagram_servant_ptr
>
test_multiplexer
::
new_local_udp_endpoint
(
uint16_t
desired_port
,
const
char
*
,
bool
)
{
test_multiplexer
::
new_local_udp_endpoint
(
uint16_t
desired_port
,
const
char
*
,
bool
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
desired_port
));
datagram_handle
hdl
;
uint16_t
port
=
0
;
...
...
@@ -327,7 +326,7 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
class
impl
:
public
datagram_servant
{
public:
impl
(
datagram_handle
dh
,
test_multiplexer
*
mpx
)
:
datagram_servant
(
dh
),
mpx_
(
mpx
)
{
:
datagram_servant
(
dh
),
mpx_
(
mpx
)
{
// nop
}
bool
new_endpoint
(
network
::
receive_buffer
&
buf
)
override
{
...
...
@@ -355,8 +354,7 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
buf
.
first
=
dh
;
return
buf
.
second
;
}
void
enqueue_datagram
(
datagram_handle
dh
,
std
::
vector
<
char
>
buf
)
override
{
void
enqueue_datagram
(
datagram_handle
dh
,
std
::
vector
<
char
>
buf
)
override
{
auto
&
q
=
mpx_
->
output_queue
(
dh
);
q
.
emplace_back
(
dh
,
std
::
move
(
buf
));
}
...
...
@@ -398,7 +396,8 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
mpx_
->
passive_mode
(
hdl
())
=
true
;
}
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
{
auto
data
=
mpx_
->
data_for_hdl
(
hdl
());
...
...
@@ -417,6 +416,7 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
data
->
servants
.
clear
();
data
->
servants
.
emplace
(
hdl
());
}
private:
test_multiplexer
*
mpx_
;
};
...
...
@@ -442,7 +442,6 @@ int64_t test_multiplexer::next_endpoint_id() {
return
servant_ids_
++
;
}
bool
test_multiplexer
::
is_known_port
(
uint16_t
x
)
const
{
auto
pred1
=
[
&
](
const
doorman_data_map
::
value_type
&
y
)
{
return
x
==
y
.
second
.
port
;
...
...
@@ -471,8 +470,9 @@ bool test_multiplexer::is_known_handle(datagram_handle x) const {
return
x
==
y
.
second
;
};
return
datagram_data_
.
count
(
x
)
>
0
||
std
::
any_of
(
local_endpoints_
.
begin
(),
local_endpoints_
.
end
(),
pred1
)
||
std
::
any_of
(
remote_endpoints_
.
begin
(),
remote_endpoints_
.
end
(),
pred2
);
||
std
::
any_of
(
local_endpoints_
.
begin
(),
local_endpoints_
.
end
(),
pred1
)
||
std
::
any_of
(
remote_endpoints_
.
begin
(),
remote_endpoints_
.
end
(),
pred2
);
}
auto
test_multiplexer
::
make_supervisor
()
->
supervisor_ptr
{
...
...
@@ -669,7 +669,7 @@ void test_multiplexer::prepare_connection(accept_handle src,
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
CAF_ASSERT
(
this
!=
&
peer
);
CAF_LOG_TRACE
(
CAF_ARG
(
src
)
<<
CAF_ARG
(
hdl
)
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
)
<<
CAF_ARG
(
peer_hdl
));
<<
CAF_ARG
(
peer_hdl
));
auto
input
=
std
::
make_shared
<
buffer_type
>
();
auto
output
=
std
::
make_shared
<
buffer_type
>
();
CAF_LOG_DEBUG
(
"insert scribe data for"
<<
CAF_ARG
(
hdl
));
...
...
@@ -681,8 +681,9 @@ void test_multiplexer::prepare_connection(accept_handle src,
if
(
!
res2
.
second
)
CAF_RAISE_ERROR
(
"prepare_connection: peer handle already in use"
);
CAF_LOG_INFO
(
"acceptor"
<<
src
<<
"has connection"
<<
hdl
<<
"ready for incoming connect from"
<<
host
<<
":"
<<
port
<<
"from peer with connection handle"
<<
peer_hdl
);
<<
"ready for incoming connect from"
<<
host
<<
":"
<<
port
<<
"from peer with connection handle"
<<
peer_hdl
);
if
(
doormen_
.
count
(
port
)
==
0
)
provide_acceptor
(
port
,
src
);
add_pending_connect
(
src
,
hdl
);
...
...
@@ -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
;
}
bool
test_multiplexer
::
has_pending_remote_endpoint
(
std
::
string
x
,
uint16_t
y
)
{
bool
test_multiplexer
::
has_pending_remote_endpoint
(
std
::
string
x
,
uint16_t
y
)
{
CAF_ASSERT
(
std
::
this_thread
::
get_id
()
==
tid_
);
guard_type
guard
{
mx_
};
return
remote_endpoints_
.
count
(
std
::
make_pair
(
std
::
move
(
x
),
y
))
>
0
;
...
...
@@ -894,7 +894,8 @@ bool test_multiplexer::read_data(datagram_handle hdl) {
return
false
;
auto
ditr
=
datagram_data_
.
find
(
hdl
);
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
;
auto
&
data
=
ditr
->
second
;
if
(
data
->
vn_buf
.
back
().
second
.
empty
())
...
...
@@ -1032,8 +1033,7 @@ void test_multiplexer::exec(resumable_ptr& ptr) {
case
resumable
:
:
awaiting_message
:
intrusive_ptr_release
(
ptr
.
get
());
break
;
default:
;
// ignored
default:
;
// ignored
}
}
...
...
libcaf_io/src/io/scribe.cpp
View file @
f4c5842b
...
...
@@ -71,10 +71,10 @@ void scribe::data_transferred(execution_unit* ctx, size_t written,
mailbox_element
::
forwarding_stack
{},
transferred_t
{
hdl
(),
written
,
remaining
}};
invoke_mailbox_element_impl
(
ctx
,
tmp
);
//data_transferred_msg tmp{hdl(), written, remaining};
//auto ptr = make_mailbox_element(nullptr, invalid_message_id, {}, tmp);
//parent()->context(ctx);
//parent()->consume(std::move(ptr));
//
data_transferred_msg tmp{hdl(), written, remaining};
//
auto ptr = make_mailbox_element(nullptr, invalid_message_id, {}, tmp);
//
parent()->context(ctx);
//
parent()->consume(std::move(ptr));
}
}
// namespace io
...
...
libcaf_io/src/policy/tcp.cpp
View file @
f4c5842b
...
...
@@ -24,19 +24,19 @@
#include "caf/logger.hpp"
#ifdef CAF_WINDOWS
# include <winsock2.h>
#
include <winsock2.h>
#else
#
include <sys/types
.h>
#
include <sys/socket
.h>
#
include <sys/socket
.h>
#
include <sys/types
.h>
#endif
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
::
native_socket
;
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_size_type
;
namespace
caf
{
namespace
policy
{
...
...
libcaf_io/test/io/basp_broker.cpp
View file @
f4c5842b
...
...
@@ -37,7 +37,7 @@ namespace {
using
caf
::
make_message_id
;
struct
anything
{
};
struct
anything
{};
anything
any_vals
;
...
...
@@ -92,7 +92,9 @@ struct node {
std
::
string
name
;
node_id
id
;
connection_handle
connection
;
union
{
scoped_actor
dummy_actor
;
};
union
{
scoped_actor
dummy_actor
;
};
node
()
{
// nop
...
...
@@ -147,7 +149,7 @@ public:
CAF_MESSAGE
(
"Jupiter: "
<<
to_string
(
jupiter
().
id
));
CAF_MESSAGE
(
"Mars: "
<<
to_string
(
mars
().
id
));
CAF_REQUIRE_NOT_EQUAL
(
this_node_
,
jupiter
().
id
);
CAF_REQUIRE_NOT_EQUAL
(
jupiter
().
id
,
mars
().
id
);
CAF_REQUIRE_NOT_EQUAL
(
jupiter
().
id
,
mars
().
id
);
}
~
fixture
()
{
...
...
@@ -257,13 +259,13 @@ public:
return
{
hdr
,
std
::
move
(
payload
)};
}
void
connect_node
(
node
&
n
,
optional
<
accept_handle
>
ax
=
none
,
actor_id
published_actor_id
=
invalid_actor_id
,
const
set
<
string
>&
published_actor_ifs
=
std
::
set
<
std
::
string
>
{})
{
void
connect_node
(
node
&
n
,
optional
<
accept_handle
>
ax
=
none
,
actor_id
published_actor_id
=
invalid_actor_id
,
const
set
<
string
>&
published_actor_ifs
=
std
::
set
<
std
::
string
>
{})
{
auto
src
=
ax
?
*
ax
:
ahdl_
;
CAF_MESSAGE
(
"connect remote node "
<<
n
.
name
<<
", connection ID = "
<<
n
.
connection
.
id
()
CAF_MESSAGE
(
"connect remote node "
<<
n
.
name
<<
", connection ID = "
<<
n
.
connection
.
id
()
<<
", acceptor ID = "
<<
src
.
id
());
auto
hdl
=
n
.
connection
;
mpx_
->
add_pending_connect
(
src
,
hdl
);
...
...
@@ -339,13 +341,10 @@ public:
}
template
<
class
...
Ts
>
mock_t
&
receive
(
connection_handle
hdl
,
maybe
<
basp
::
message_type
>
operation
,
maybe
<
uint8_t
>
flags
,
maybe
<
uint32_t
>
payload_len
,
mock_t
&
receive
(
connection_handle
hdl
,
maybe
<
basp
::
message_type
>
operation
,
maybe
<
uint8_t
>
flags
,
maybe
<
uint32_t
>
payload_len
,
maybe
<
uint64_t
>
operation_data
,
maybe
<
actor_id
>
source_actor
,
maybe
<
actor_id
>
dest_actor
,
maybe
<
actor_id
>
source_actor
,
maybe
<
actor_id
>
dest_actor
,
const
Ts
&
...
xs
)
{
CAF_MESSAGE
(
"expect #"
<<
num
);
buffer
buf
;
...
...
@@ -368,7 +367,7 @@ public:
auto
end
=
first
+
hdr
.
payload_len
;
payload
.
assign
(
first
,
end
);
CAF_MESSAGE
(
"erase "
<<
std
::
distance
(
ob
.
begin
(),
end
)
<<
" bytes from output buffer"
);
<<
" bytes from output buffer"
);
ob
.
erase
(
ob
.
begin
(),
end
);
}
else
{
ob
.
erase
(
ob
.
begin
(),
ob
.
begin
()
+
basp
::
header_size
);
...
...
@@ -394,9 +393,9 @@ public:
mock_t
mock
(
connection_handle
hdl
,
basp
::
header
hdr
,
const
Ts
&
...
xs
)
{
buffer
buf
;
to_buf
(
buf
,
hdr
,
nullptr
,
xs
...);
CAF_MESSAGE
(
"virtually send "
<<
to_string
(
hdr
.
operation
)
<<
" with "
<<
(
buf
.
size
()
-
basp
::
header_size
)
<<
" bytes payload"
);
CAF_MESSAGE
(
"virtually send "
<<
to_string
(
hdr
.
operation
)
<<
" with "
<<
(
buf
.
size
()
-
basp
::
header_size
)
<<
" bytes payload"
);
mpx
()
->
virtual_send
(
hdl
,
buf
);
return
{
this
};
}
...
...
@@ -430,7 +429,6 @@ public:
scheduler_type
&
sched
;
middleman_actor
mma
;
autoconn_enabled_fixture
()
:
fixture
(
true
),
sched
(
dynamic_cast
<
scheduler_type
&>
(
sys
.
scheduler
())),
...
...
@@ -462,9 +460,12 @@ CAF_TEST(empty_server_handshake) {
basp
::
header
hdr
;
buffer
payload
;
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
()),
basp
::
version
,
invalid_actor_id
,
invalid_actor_id
};
basp
::
version
,
invalid_actor_id
,
invalid_actor_id
};
CAF_CHECK
(
basp
::
valid
(
hdr
));
CAF_CHECK
(
basp
::
is_handshake
(
hdr
));
CAF_CHECK_EQUAL
(
to_string
(
hdr
),
to_string
(
expected
));
...
...
@@ -480,9 +481,12 @@ CAF_TEST(non_empty_server_handshake) {
basp
::
header
hdr
;
buffer
payload
;
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
()),
basp
::
version
,
invalid_actor_id
,
invalid_actor_id
};
basp
::
version
,
invalid_actor_id
,
invalid_actor_id
};
CAF_CHECK
(
basp
::
valid
(
hdr
));
CAF_CHECK
(
basp
::
is_handshake
(
hdr
));
CAF_CHECK_EQUAL
(
to_string
(
hdr
),
to_string
(
expected
));
...
...
@@ -509,8 +513,7 @@ CAF_TEST(remote_address_and_port) {
// all test nodes have address "test" and connection handle ID as port
CAF_CHECK_EQUAL
(
addr
,
"test"
);
CAF_CHECK_EQUAL
(
port
,
mars
().
connection
.
id
());
}
);
});
}
CAF_TEST
(
client_handshake_and_dispatch
)
{
...
...
@@ -528,23 +531,17 @@ CAF_TEST(client_handshake_and_dispatch) {
CAF_REQUIRE
(
proxies
().
count_proxies
(
jupiter
().
id
)
==
1
);
// must've send remote node a message that this proxy is monitored now
// receive the message
self
()
->
receive
(
[](
int
a
,
int
b
,
int
c
)
{
CAF_CHECK_EQUAL
(
a
,
1
);
CAF_CHECK_EQUAL
(
b
,
2
);
CAF_CHECK_EQUAL
(
c
,
3
);
return
a
+
b
+
c
;
}
);
self
()
->
receive
([](
int
a
,
int
b
,
int
c
)
{
CAF_CHECK_EQUAL
(
a
,
1
);
CAF_CHECK_EQUAL
(
b
,
2
);
CAF_CHECK_EQUAL
(
c
,
3
);
return
a
+
b
+
c
;
});
CAF_MESSAGE
(
"exec message of forwarding proxy"
);
mpx
()
->
exec_runnable
();
// deserialize and send message from out buf
dispatch_out_buf
(
jupiter
().
connection
);
jupiter
().
dummy_actor
->
receive
(
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
6
);
}
);
jupiter
().
dummy_actor
->
receive
([](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
6
);
});
}
CAF_TEST
(
message_forwarding
)
{
...
...
@@ -579,8 +576,8 @@ CAF_TEST(remote_actor_and_send) {
CAF_REQUIRE
(
mpx
()
->
has_pending_scribe
(
lo
,
4242
));
auto
mm1
=
sys
.
middleman
().
actor_handle
();
actor
result
;
auto
f
=
self
()
->
request
(
mm1
,
infinite
,
connect_atom
::
value
,
lo
,
uint16_t
{
4242
});
auto
f
=
self
()
->
request
(
mm1
,
infinite
,
connect_atom
::
value
,
lo
,
uint16_t
{
4242
});
// wait until BASP broker has received and processed the connect message
while
(
!
aut
()
->
valid
(
jupiter
().
connection
))
mpx
()
->
exec_runnable
();
...
...
@@ -621,14 +618,11 @@ CAF_TEST(remote_actor_and_send) {
CAF_REQUIRE
(
proxy
==
res
);
result
=
actor_cast
<
actor
>
(
res
);
},
[
&
](
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
sys
.
render
(
err
));
}
);
[
&
](
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
sys
.
render
(
err
));
});
CAF_MESSAGE
(
"send message to proxy"
);
anon_send
(
actor_cast
<
actor
>
(
result
),
42
);
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
,
no_flags
,
any_vals
,
default_operation_data
,
invalid_actor_id
,
jupiter
().
dummy_actor
->
id
(),
std
::
vector
<
strong_actor_ptr
>
{},
...
...
@@ -639,23 +633,19 @@ CAF_TEST(remote_actor_and_send) {
{
basp
::
message_type
::
direct_message
,
0
,
0
,
0
,
jupiter
().
dummy_actor
->
id
(),
self
()
->
id
()},
std
::
vector
<
strong_actor_ptr
>
{},
make_message
(
"hi there!"
));
self
()
->
receive
(
[
&
](
const
string
&
str
)
{
CAF_CHECK_EQUAL
(
to_string
(
self
()
->
current_sender
()),
to_string
(
result
));
CAF_CHECK_EQUAL
(
self
()
->
current_sender
(),
result
.
address
());
CAF_CHECK_EQUAL
(
str
,
"hi there!"
);
}
);
self
()
->
receive
([
&
](
const
string
&
str
)
{
CAF_CHECK_EQUAL
(
to_string
(
self
()
->
current_sender
()),
to_string
(
result
));
CAF_CHECK_EQUAL
(
self
()
->
current_sender
(),
result
.
address
());
CAF_CHECK_EQUAL
(
str
,
"hi there!"
);
});
}
CAF_TEST
(
actor_serialize_and_deserialize
)
{
auto
testee_impl
=
[](
event_based_actor
*
testee_self
)
->
behavior
{
testee_self
->
set_default_handler
(
reflect_and_quit
);
return
{
[]
{
// nop
}
};
return
{[]
{
// nop
}};
};
connect_node
(
jupiter
());
auto
prx
=
proxies
().
get_or_put
(
jupiter
().
id
,
jupiter
().
dummy_actor
->
id
());
...
...
@@ -711,12 +701,10 @@ CAF_TEST(indirect_connections) {
any_vals
,
no_operation_data
,
invalid_actor_id
,
jupiter
().
dummy_actor
->
id
(),
this_node
(),
jupiter
().
id
);
CAF_MESSAGE
(
"receive message from jupiter"
);
self
()
->
receive
(
[](
const
std
::
string
&
str
)
->
std
::
string
{
CAF_CHECK_EQUAL
(
str
,
"hello from jupiter!"
);
return
"hello from earth!"
;
}
);
self
()
->
receive
([](
const
std
::
string
&
str
)
->
std
::
string
{
CAF_CHECK_EQUAL
(
str
,
"hello from jupiter!"
);
return
"hello from earth!"
;
});
mpx
()
->
exec_runnable
();
// process forwarded message in basp_broker
mock
().
receive
(
mars
().
connection
,
basp
::
message_type
::
routed_message
,
no_flags
,
any_vals
,
default_operation_data
,
self
()
->
id
(),
...
...
@@ -807,12 +795,10 @@ CAF_TEST(automatic_connection) {
check_node_in_tbl
(
jupiter
());
check_node_in_tbl
(
mars
());
CAF_MESSAGE
(
"receive message from jupiter"
);
self
()
->
receive
(
[](
const
std
::
string
&
str
)
->
std
::
string
{
CAF_CHECK_EQUAL
(
str
,
"hello from jupiter!"
);
return
"hello from earth!"
;
}
);
self
()
->
receive
([](
const
std
::
string
&
str
)
->
std
::
string
{
CAF_CHECK_EQUAL
(
str
,
"hello from jupiter!"
);
return
"hello from earth!"
;
});
mpx
()
->
exec_runnable
();
// process forwarded message in basp_broker
CAF_MESSAGE
(
"response message must take direct route now"
);
mock
().
receive
(
jupiter
().
connection
,
basp
::
message_type
::
direct_message
,
...
...
libcaf_io/test/io/broker.cpp
View file @
f4c5842b
...
...
@@ -22,8 +22,8 @@
#include "caf/test/dsl.hpp"
#include <memory>
#include <iostream>
#include <memory>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
...
...
@@ -39,58 +39,53 @@ using pong_atom = caf::atom_constant<caf::atom("pong")>;
using
publish_atom
=
caf
::
atom_constant
<
caf
::
atom
(
"publish"
)
>
;
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
);
auto
count
=
std
::
make_shared
<
size_t
>
(
0
);
self
->
become
(
return
{
[
=
](
kickoff_atom
,
const
actor
&
pong
)
{
CAF_MESSAGE
(
"received `kickoff_atom`"
);
self
->
send
(
pong
,
ping_atom
::
value
,
1
);
self
->
become
(
[
=
](
pong_atom
,
int
value
)
->
std
::
tuple
<
atom_value
,
int
>
{
if
(
++*
count
>=
num_pings
)
{
CAF_MESSAGE
(
"received "
<<
num_pings
<<
" pings, call self->quit"
);
self
->
quit
();
}
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
self
->
become
([
=
](
pong_atom
,
int
value
)
->
std
::
tuple
<
atom_value
,
int
>
{
if
(
++*
count
>=
num_pings
)
{
CAF_MESSAGE
(
"received "
<<
num_pings
<<
" pings, call self->quit"
);
self
->
quit
();
}
);
}
);
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"
);
self
->
set_down_handler
([
=
](
down_msg
&
dm
)
{
CAF_MESSAGE
(
"received down_msg{"
<<
to_string
(
dm
.
reason
)
<<
"}"
);
self
->
quit
(
dm
.
reason
);
});
self
->
become
(
return
{
[
=
](
ping_atom
,
int
value
)
->
std
::
tuple
<
atom_value
,
int
>
{
CAF_MESSAGE
(
"received `ping_atom`"
);
self
->
monitor
(
self
->
current_sender
());
// set next behavior
self
->
become
(
[](
ping_atom
,
int
val
)
{
return
std
::
make_tuple
(
pong_atom
::
value
,
val
);
}
);
self
->
become
([](
ping_atom
,
int
val
)
{
return
std
::
make_tuple
(
pong_atom
::
value
,
val
);
});
// reply to 'ping'
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_REQUIRE
(
self
->
subtype
()
==
resumable
::
io_actor
);
CAF_CHECK
(
self
!=
nullptr
);
self
->
monitor
(
buddy
);
// assume exactly one connection
CAF_REQUIRE
(
self
->
connections
().
size
()
==
1
);
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
atom_value
)
+
sizeof
(
int
)));
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
atom_value
)
+
sizeof
(
int
)));
auto
write
=
[
=
](
atom_value
type
,
int
value
)
{
auto
&
buf
=
self
->
wr_buf
(
hdl
);
auto
first
=
reinterpret_cast
<
char
*>
(
&
type
);
...
...
@@ -104,7 +99,7 @@ void peer_fun(broker* self, connection_handle hdl, const actor& buddy) {
if
(
dm
.
source
==
buddy
)
self
->
quit
(
dm
.
reason
);
});
self
->
become
(
return
{
[
=
](
const
connection_closed_msg
&
)
{
CAF_MESSAGE
(
"received connection_closed_msg"
);
self
->
quit
();
...
...
@@ -124,8 +119,8 @@ void peer_fun(broker* self, connection_handle hdl, const actor& buddy) {
[
=
](
pong_atom
,
int
value
)
{
CAF_MESSAGE
(
"received: pong "
<<
value
);
write
(
pong_atom
::
value
,
value
);
}
)
;
}
,
}
;
}
behavior
peer_acceptor_fun
(
broker
*
self
,
const
actor
&
buddy
)
{
...
...
@@ -141,7 +136,7 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) {
if
(
!
res
)
return
std
::
move
(
res
.
error
());
return
res
->
second
;
}
}
,
};
}
...
...
@@ -153,8 +148,8 @@ void run_client(int argc, char** argv, uint16_t port) {
actor_system
system
{
cfg
};
auto
p
=
system
.
spawn
(
ping
,
size_t
{
10
});
CAF_MESSAGE
(
"spawn_client..."
);
auto
cl
=
unbox
(
system
.
middleman
().
spawn_client
(
peer_fun
,
"127.0.0.1"
,
port
,
p
));
auto
cl
=
unbox
(
system
.
middleman
().
spawn_client
(
peer_fun
,
"127.0.0.1"
,
port
,
p
));
CAF_MESSAGE
(
"spawn_client finished"
);
anon_send
(
p
,
kickoff_atom
::
value
,
cl
);
CAF_MESSAGE
(
"`kickoff_atom` has been send"
);
...
...
@@ -171,17 +166,15 @@ void run_server(int argc, char** argv) {
auto
serv
=
system
.
middleman
().
spawn_broker
(
peer_acceptor_fun
,
system
.
spawn
(
pong
));
std
::
thread
child
;
self
->
request
(
serv
,
infinite
,
publish_atom
::
value
).
receive
(
[
&
](
uint16_t
port
)
{
CAF_MESSAGE
(
"server is running on port "
<<
port
);
child
=
std
::
thread
([
=
]
{
run_client
(
argc
,
argv
,
port
);
self
->
request
(
serv
,
infinite
,
publish_atom
::
value
)
.
receive
(
[
&
](
uint16_t
port
)
{
CAF_MESSAGE
(
"server is running on port "
<<
port
);
child
=
std
::
thread
([
=
]
{
run_client
(
argc
,
argv
,
port
);
});
},
[
&
](
const
error
&
err
)
{
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
});
},
[
&
](
const
error
&
err
)
{
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
}
);
self
->
await_all_other_actors_done
();
child
.
join
();
}
...
...
libcaf_io/test/io/http_broker.cpp
View file @
f4c5842b
...
...
@@ -21,14 +21,14 @@
#define CAF_SUITE io_http_broker
#include "caf/test/unit_test.hpp"
#include <cassert>
#include <algorithm>
#include <cassert>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
using
std
::
cout
;
using
std
::
cerr
;
using
std
::
cout
;
using
std
::
endl
;
using
namespace
caf
;
...
...
@@ -131,17 +131,19 @@ behavior http_worker(http_broker* self, connection_handle hdl) {
}
else
if
(
msg
.
buf
.
back
()
==
'\n'
)
{
self
->
state
.
ps
=
receive_new_line
;
// we've got a clean cut
}
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
if
(
self
->
state
.
ps
!=
receive_new_line
)
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
())
{
auto
&
out
=
self
->
wr_buf
(
hdl
);
// we only look at the first line in our example and reply with
our
//
OK message if we receive exactly "GET / HTTP/1.1", otherwise
// we send a 404 HTTP response
// we only look at the first line in our example and reply with
//
our OK message if we receive exactly "GET / HTTP/1.1",
//
otherwise
we send a 404 HTTP response
if
(
lines
.
front
()
==
http_valid_get
)
out
.
insert
(
out
.
end
(),
std
::
begin
(
http_ok
),
std
::
end
(
http_ok
));
else
...
...
@@ -151,9 +153,7 @@ behavior http_worker(http_broker* self, connection_handle hdl) {
self
->
quit
();
}
},
[
=
](
const
connection_closed_msg
&
)
{
self
->
quit
();
}
[
=
](
const
connection_closed_msg
&
)
{
self
->
quit
();
},
};
}
...
...
@@ -163,15 +163,16 @@ behavior server(broker* self) {
[
=
](
const
new_connection_msg
&
ncm
)
{
CAF_MESSAGE
(
"fork on new connection"
);
self
->
fork
(
http_worker
,
ncm
.
handle
);
}
}
,
};
}
class
fixture
{
public:
using
multiplexer_type
=
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
);
// spawn the actor-under-test
aut_
=
system
.
middleman
().
spawn_broker
(
server
);
...
...
@@ -202,10 +203,10 @@ public:
mock_t
&
expect
(
const
std
::
string
&
x
)
{
auto
&
buf
=
this_
->
mpx_
->
output_buffer
(
this_
->
connection_
);
CAF_REQUIRE
(
(
buf
.
size
()
>=
x
.
size
()
));
CAF_REQUIRE
(
(
std
::
equal
(
buf
.
begin
(),
buf
.
begin
()
+
static_cast
<
ptrdiff_t
>
(
x
.
size
()),
x
.
begin
()
)));
CAF_REQUIRE
(
buf
.
size
()
>=
x
.
size
(
));
CAF_REQUIRE
(
std
::
equal
(
buf
.
begin
(),
buf
.
begin
()
+
static_cast
<
ptrdiff_t
>
(
x
.
size
()),
x
.
begin
(
)));
buf
.
erase
(
buf
.
begin
(),
buf
.
begin
()
+
static_cast
<
ptrdiff_t
>
(
x
.
size
()));
return
*
this
;
}
...
...
libcaf_io/test/io/network/ip_endpoint.cpp
View file @
f4c5842b
...
...
@@ -45,29 +45,26 @@ public:
};
struct
fixture
{
template
<
class
T
,
class
...
Ts
>
std
::
vector
<
char
>
serialize
(
T
&
x
,
Ts
&
...
xs
)
{
std
::
vector
<
char
>
buf
;
binary_serializer
bs
{
&
context
,
buf
};
bs
(
x
,
xs
...);
return
buf
;
}
template
<
class
T
,
class
...
Ts
>
std
::
vector
<
char
>
serialize
(
T
&
x
,
Ts
&
...
xs
)
{
std
::
vector
<
char
>
buf
;
binary_serializer
bs
{
&
context
,
buf
};
bs
(
x
,
xs
...);
return
buf
;
}
template
<
class
T
,
class
...
Ts
>
void
deserialize
(
const
std
::
vector
<
char
>&
buf
,
T
&
x
,
Ts
&
...
xs
)
{
binary_deserializer
bd
{
&
context
,
buf
};
bd
(
x
,
xs
...);
}
fixture
()
:
cfg
(),
system
(
cfg
),
context
(
&
system
)
{
}
template
<
class
T
,
class
...
Ts
>
void
deserialize
(
const
std
::
vector
<
char
>&
buf
,
T
&
x
,
Ts
&
...
xs
)
{
binary_deserializer
bd
{
&
context
,
buf
};
bd
(
x
,
xs
...);
}
config
cfg
;
actor_system
system
;
scoped_execution_unit
context
;
fixture
()
:
cfg
(),
system
(
cfg
),
context
(
&
system
)
{
}
config
cfg
;
actor_system
system
;
scoped_execution_unit
context
;
};
}
// namespace
...
...
libcaf_io/test/io/receive_buffer.cpp
View file @
f4c5842b
...
...
@@ -35,7 +35,7 @@ struct fixture {
receive_buffer
b
;
std
::
vector
<
char
>
vec
;
fixture
()
:
b
(
1024ul
),
vec
{
'h'
,
'a'
,
'l'
,
'l'
,
'o'
}
{
fixture
()
:
b
(
1024ul
),
vec
{
'h'
,
'a'
,
'l'
,
'l'
,
'o'
}
{
// nop
}
...
...
@@ -101,27 +101,24 @@ CAF_TEST(resize) {
a
.
resize
(
1024
);
std
::
fill
(
a
.
begin
(),
a
.
end
(),
'a'
);
auto
cnt
=
0
;
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
++
cnt
;
return
c
==
'a'
;
}));
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
++
cnt
;
return
c
==
'a'
;
}));
CAF_CHECK_EQUAL
(
cnt
,
1024
);
a
.
resize
(
10
);
cnt
=
0
;
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
++
cnt
;
return
c
==
'a'
;
}));
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
++
cnt
;
return
c
==
'a'
;
}));
CAF_CHECK_EQUAL
(
cnt
,
10
);
a
.
resize
(
1024
);
cnt
=
0
;
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
++
cnt
;
return
c
==
'a'
;
}));
CAF_CHECK
(
std
::
all_of
(
a
.
begin
(),
a
.
end
(),
[
&
](
char
c
)
{
++
cnt
;
return
c
==
'a'
;
}));
CAF_CHECK_EQUAL
(
cnt
,
1024
);
}
...
...
@@ -136,7 +133,7 @@ CAF_TEST(push_back) {
}
CAF_TEST
(
insert
)
{
for
(
auto
c
:
vec
)
for
(
auto
c
:
vec
)
a
.
insert
(
a
.
end
(),
c
);
CAF_CHECK_EQUAL
(
as_string
(
a
),
"hallo"
);
a
.
insert
(
a
.
begin
(),
'!'
);
...
...
libcaf_io/test/io/remote_actor.cpp
View file @
f4c5842b
...
...
@@ -21,10 +21,10 @@
#define CAF_SUITE io_dynamic_remote_actor
#include "caf/test/dsl.hpp"
#include <
vector
>
#include <
algorithm
>
#include <sstream>
#include <utility>
#include <
algorithm
>
#include <
vector
>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
...
...
@@ -57,10 +57,10 @@ struct fixture {
io
::
middleman
&
client_side_mm
;
fixture
()
:
server_side
(
server_side_config
),
server_side_mm
(
server_side
.
middleman
()),
client_side
(
client_side_config
),
client_side_mm
(
client_side
.
middleman
())
{
:
server_side
(
server_side_config
),
server_side_mm
(
server_side
.
middleman
()),
client_side
(
client_side_config
),
client_side_mm
(
client_side
.
middleman
())
{
// nop
}
};
...
...
@@ -71,26 +71,23 @@ behavior make_pong_behavior() {
++
val
;
CAF_MESSAGE
(
"pong with "
<<
val
);
return
val
;
}
}
,
};
}
behavior
make_ping_behavior
(
event_based_actor
*
self
,
const
actor
&
pong
)
{
CAF_MESSAGE
(
"ping with "
<<
0
);
self
->
send
(
pong
,
0
);
return
{
[
=
](
int
val
)
->
int
{
if
(
val
==
3
)
{
CAF_MESSAGE
(
"ping with exit"
);
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
CAF_MESSAGE
(
"ping quits"
);
self
->
quit
();
}
CAF_MESSAGE
(
"ping with "
<<
val
);
return
val
;
return
{[
=
](
int
val
)
->
int
{
if
(
val
==
3
)
{
CAF_MESSAGE
(
"ping with exit"
);
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
CAF_MESSAGE
(
"ping quits"
);
self
->
quit
();
}
};
CAF_MESSAGE
(
"ping with "
<<
val
);
return
val
;
}};
}
behavior
make_sort_behavior
()
{
...
...
@@ -100,7 +97,7 @@ behavior make_sort_behavior() {
std
::
sort
(
vec
.
begin
(),
vec
.
end
());
CAF_MESSAGE
(
"sorter sent: "
<<
deep_to_string
(
vec
));
return
std
::
move
(
vec
);
}
}
,
};
}
...
...
@@ -114,7 +111,7 @@ behavior make_sort_requester_behavior(event_based_actor* self,
CAF_CHECK_EQUAL
(
vec
,
expected_vec
);
self
->
send_exit
(
sorter
,
exit_reason
::
user_shutdown
);
self
->
quit
();
}
}
,
};
}
...
...
@@ -123,7 +120,7 @@ behavior fragile_mirror(event_based_actor* self) {
[
=
](
int
i
)
{
self
->
quit
(
exit_reason
::
user_shutdown
);
return
i
;
}
}
,
};
}
...
...
@@ -132,9 +129,7 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
self
->
link_to
(
buddy
);
self
->
send
(
buddy
,
42
);
return
{
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
42
);
}
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
42
);
},
};
}
...
...
@@ -160,8 +155,9 @@ CAF_TEST(identity_semantics) {
CAF_TEST
(
ping_pong
)
{
// server side
auto
port
=
unbox
(
server_side_mm
.
publish
(
server_side
.
spawn
(
make_pong_behavior
),
0
,
local_host
));
auto
port
=
unbox
(
server_side_mm
.
publish
(
server_side
.
spawn
(
make_pong_behavior
),
0
,
local_host
));
// client side
auto
pong
=
unbox
(
client_side_mm
.
remote_actor
(
local_host
,
port
));
client_side
.
spawn
(
make_ping_behavior
,
pong
);
...
...
@@ -169,8 +165,9 @@ CAF_TEST(ping_pong) {
CAF_TEST
(
custom_message_type
)
{
// server side
auto
port
=
unbox
(
server_side_mm
.
publish
(
server_side
.
spawn
(
make_sort_behavior
),
0
,
local_host
));
auto
port
=
unbox
(
server_side_mm
.
publish
(
server_side
.
spawn
(
make_sort_behavior
),
0
,
local_host
));
// client side
auto
sorter
=
unbox
(
client_side_mm
.
remote_actor
(
local_host
,
port
));
client_side
.
spawn
(
make_sort_requester_behavior
,
sorter
);
...
...
libcaf_io/test/io/remote_group.cpp
View file @
f4c5842b
...
...
@@ -21,8 +21,8 @@
#define CAF_SUITE io_dynamic_remote_group
#include "caf/test/io_dsl.hpp"
#include <vector>
#include <algorithm>
#include <vector>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
...
...
@@ -49,11 +49,7 @@ size_t received_messages = 0u;
behavior
group_receiver
(
event_based_actor
*
self
)
{
self
->
set_default_handler
(
reflect_and_quit
);
return
{
[](
ok_atom
)
{
++
received_messages
;
}
};
return
{[](
ok_atom
)
{
++
received_messages
;
}};
}
// Our server is `mars` and our client is `earth`.
...
...
libcaf_io/test/io/remote_spawn.cpp
View file @
f4c5842b
...
...
@@ -21,12 +21,12 @@
#define CAF_SUITE io_remote_spawn
#include "caf/test/dsl.hpp"
#include <thread>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <thread>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
...
...
@@ -43,13 +43,9 @@ using calculator = typed_actor<replies_to<add_atom, int, int>::with<int>,
// function-based, dynamically typed, event-based API
behavior
calculator_fun
(
event_based_actor
*
)
{
return
behavior
{
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
},
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
}
return
{
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
},
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
},
};
}
...
...
@@ -61,12 +57,8 @@ public:
behavior
make_behavior
()
override
{
return
{
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
},
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
}
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
},
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
},
};
}
};
...
...
@@ -74,12 +66,8 @@ public:
// function-based, statically typed, event-based API
calculator
::
behavior_type
typed_calculator_fun
()
{
return
{
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
},
[](
sub_atom
,
int
a
,
int
b
)
{
return
a
-
b
;
}
[](
add_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) {
CAF_REQUIRE_EQUAL
(
f1
(
sub_atom
::
value
,
10
,
20
),
-
10
);
f1
.
reset
();
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
);
self
->
request
(
dyn_calc
,
infinite
,
add_atom
::
value
,
10
,
20
).
receive
(
[](
int
result
)
{
CAF_CHECK_EQUAL
(
result
,
30
);
},
[
&
](
const
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
sys
.
render
(
err
));
});
self
->
request
(
dyn_calc
,
infinite
,
add_atom
::
value
,
10
,
20
)
.
receive
([](
int
result
)
{
CAF_CHECK_EQUAL
(
result
,
30
);
},
[
&
](
const
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
sys
.
render
(
err
));
});
anon_send_exit
(
dyn_calc
,
exit_reason
::
kill
);
mm
.
close
(
port
);
}
...
...
libcaf_io/test/io/triggering.cpp
View file @
f4c5842b
...
...
@@ -16,16 +16,16 @@
* 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 <memory>
#include <iostream>
#include <memory>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
using
namespace
std
;
using
namespace
caf
;
...
...
@@ -44,12 +44,8 @@ behavior client(broker* self, connection_handle hdl) {
self
->
configure_read
(
hdl
,
receive_policy
::
at_least
(
1
));
self
->
flush
(
hdl
);
return
{
[
=
](
const
new_data_msg
&
)
{
CAF_FAIL
(
"server unexpectedly sent data"
);
},
[
=
](
const
connection_closed_msg
&
)
{
self
->
quit
();
}
[
=
](
const
new_data_msg
&
)
{
CAF_FAIL
(
"server unexpectedly sent data"
);
},
[
=
](
const
connection_closed_msg
&
)
{
self
->
quit
();
},
};
}
...
...
@@ -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
CAF_MESSAGE
(
"server is done"
);
self
->
quit
();
}
}
,
};
}
...
...
@@ -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
self
->
send
(
self
,
ok_atom
::
value
);
},
[
=
](
ok_atom
)
{
self
->
become
(
server1_stage4
(
self
));
}
[
=
](
ok_atom
)
{
self
->
become
(
server1_stage4
(
self
));
},
};
}
...
...
@@ -118,7 +112,7 @@ behavior server1_stage2(stateful_actor<server1_state, broker>* self) {
CAF_REQUIRE_EQUAL
(
self
->
state
.
received
,
5u
);
CAF_REQUIRE_NOT_EQUAL
(
self
->
state
.
peer
,
invalid_connection_handle
);
self
->
become
(
server1_stage3
(
self
));
}
}
,
};
}
...
...
@@ -130,7 +124,7 @@ behavior server1(stateful_actor<server1_state, broker>* self) {
self
->
state
.
peer
=
nc
.
handle
;
self
->
configure_read
(
nc
.
handle
,
receive_policy
::
exactly
(
10
));
self
->
become
(
server1_stage2
(
self
));
}
}
,
};
}
...
...
@@ -144,14 +138,12 @@ struct server2_state {
behavior
server2_stage4
(
stateful_actor
<
server2_state
,
broker
>*
self
)
{
CAF_MESSAGE
(
"enter server stage 4"
);
return
{
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
acceptor_passivated_msg
&
)
{
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
16u
);
CAF_MESSAGE
(
"server is done"
);
self
->
quit
();
}
}
,
};
}
...
...
@@ -161,9 +153,7 @@ behavior server2_stage4(stateful_actor<server2_state, broker>* self) {
behavior
server2_stage3
(
stateful_actor
<
server2_state
,
broker
>*
self
)
{
CAF_MESSAGE
(
"enter server stage 3"
);
return
{
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
acceptor_passivated_msg
&
cp
)
{
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
11u
);
// 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) {
[
=
](
ok_atom
,
accept_handle
hdl
)
{
self
->
trigger
(
hdl
,
5
);
self
->
become
(
server2_stage4
(
self
));
}
}
,
};
}
...
...
@@ -181,14 +171,12 @@ behavior server2_stage2(stateful_actor<server2_state, broker>* self) {
CAF_MESSAGE
(
"enter server stage 2"
);
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
1u
);
return
{
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
new_connection_msg
&
)
{
self
->
state
.
accepted
+=
1
;
},
[
=
](
const
acceptor_passivated_msg
&
cp
)
{
CAF_REQUIRE_EQUAL
(
self
->
state
.
accepted
,
6u
);
self
->
trigger
(
cp
.
handle
,
5
);
self
->
become
(
server2_stage3
(
self
));
}
}
,
};
}
...
...
@@ -199,7 +187,7 @@ behavior server2(stateful_actor<server2_state, broker>* self) {
self
->
state
.
accepted
+=
1
;
self
->
trigger
(
nc
.
source
,
5
);
self
->
become
(
server2_stage2
(
self
));
}
}
,
};
}
...
...
@@ -253,8 +241,8 @@ CAF_TEST(trigger_acceptor) {
std
::
thread
child
{[
&
]
{
// 16 clients will succeed to connect
for
(
int
i
=
0
;
i
<
16
;
++
i
)
{
auto
cl
=
client_system
.
middleman
().
spawn_client
(
client
,
"localhost"
,
port
);
auto
cl
=
client_system
.
middleman
().
spawn_client
(
client
,
"localhost"
,
port
);
CAF_REQUIRE
(
cl
);
}
}};
...
...
libcaf_io/test/io/typed_broker.cpp
View file @
f4c5842b
...
...
@@ -21,8 +21,8 @@
#define CAF_SUITE io_typed_broker
#include "caf/test/dsl.hpp"
#include <memory>
#include <iostream>
#include <memory>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
...
...
@@ -43,11 +43,14 @@ using kickoff_atom = caf::atom_constant<atom("kickoff")>;
using
peer
=
connection_handler
::
extend
<
reacts_to
<
ping_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
)
{
CAF_MESSAGE
(
"num_pings: "
<<
num_pings
);
...
...
@@ -56,17 +59,14 @@ behavior ping(event_based_actor* self, size_t num_pings) {
[
=
](
kickoff_atom
,
const
peer
&
pong
)
{
CAF_MESSAGE
(
"received `kickoff_atom`"
);
self
->
send
(
pong
,
ping_atom
::
value
,
1
);
self
->
become
(
[
=
](
pong_atom
,
int
value
)
->
std
::
tuple
<
ping_atom
,
int
>
{
if
(
++*
count
>=
num_pings
)
{
CAF_MESSAGE
(
"received "
<<
num_pings
<<
" pings, call self->quit"
);
self
->
quit
();
}
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
self
->
become
([
=
](
pong_atom
,
int
value
)
->
std
::
tuple
<
ping_atom
,
int
>
{
if
(
++*
count
>=
num_pings
)
{
CAF_MESSAGE
(
"received "
<<
num_pings
<<
" pings, call self->quit"
);
self
->
quit
();
}
);
}
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
});
},
};
}
...
...
@@ -81,15 +81,13 @@ behavior pong(event_based_actor* self) {
CAF_MESSAGE
(
"received: 'ping', "
<<
value
);
self
->
monitor
(
self
->
current_sender
());
// set next behavior
self
->
become
(
[](
ping_atom
,
int
val
)
{
//CAF_MESSAGE("received: 'ping', " << val);
return
std
::
make_tuple
(
pong_atom
::
value
,
val
);
}
);
self
->
become
([](
ping_atom
,
int
val
)
{
// CAF_MESSAGE("received: 'ping', " << val);
return
std
::
make_tuple
(
pong_atom
::
value
,
val
);
});
// reply to 'ping'
return
std
::
make_tuple
(
pong_atom
::
value
,
value
);
}
}
,
};
}
...
...
@@ -99,8 +97,8 @@ peer::behavior_type peer_fun(peer::broker_pointer self, connection_handle hdl,
self
->
monitor
(
buddy
);
// assume exactly one connection
CAF_REQUIRE_EQUAL
(
self
->
connections
().
size
(),
1u
);
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
atom_value
)
+
sizeof
(
int
)));
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
atom_value
)
+
sizeof
(
int
)));
auto
write
=
[
=
](
atom_value
x
,
int
y
)
{
auto
&
buf
=
self
->
wr_buf
(
hdl
);
binary_serializer
sink
{
self
->
system
(),
buf
};
...
...
@@ -137,7 +135,7 @@ peer::behavior_type peer_fun(peer::broker_pointer self, connection_handle hdl,
[
=
](
pong_atom
,
int
value
)
{
CAF_MESSAGE
(
"received: 'pong', "
<<
value
);
write
(
pong_atom
::
value
,
value
);
}
}
,
};
}
...
...
@@ -158,7 +156,7 @@ acceptor::behavior_type acceptor_fun(acceptor::broker_pointer self,
if
(
dm
)
return
get
<
1
>
(
*
dm
);
return
std
::
move
(
dm
.
error
());
}
}
,
};
}
...
...
@@ -170,8 +168,8 @@ void run_client(int argc, char** argv, uint16_t port) {
actor_system
system
{
cfg
};
auto
p
=
system
.
spawn
(
ping
,
size_t
{
10
});
CAF_MESSAGE
(
"spawn_client_typed..."
);
auto
cl
=
unbox
(
system
.
middleman
().
spawn_client
(
peer_fun
,
"localhost"
,
port
,
p
));
auto
cl
=
unbox
(
system
.
middleman
().
spawn_client
(
peer_fun
,
"localhost"
,
port
,
p
));
CAF_MESSAGE
(
"spawn_client_typed finished"
);
anon_send
(
p
,
kickoff_atom
::
value
,
cl
);
CAF_MESSAGE
(
"`kickoff_atom` has been send"
);
...
...
@@ -186,17 +184,13 @@ void run_server(int argc, char** argv) {
scoped_actor
self
{
system
};
auto
serv
=
system
.
middleman
().
spawn_broker
(
acceptor_fun
,
system
.
spawn
(
pong
));
std
::
thread
child
;
self
->
request
(
serv
,
infinite
,
publish_atom
::
value
).
receive
(
[
&
](
uint16_t
port
)
{
CAF_MESSAGE
(
"server is running on port "
<<
port
);
child
=
std
::
thread
([
=
]
{
run_client
(
argc
,
argv
,
port
);
});
},
[
&
](
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
system
.
render
(
err
));
}
);
self
->
request
(
serv
,
infinite
,
publish_atom
::
value
)
.
receive
(
[
&
](
uint16_t
port
)
{
CAF_MESSAGE
(
"server is running on port "
<<
port
);
child
=
std
::
thread
([
=
]
{
run_client
(
argc
,
argv
,
port
);
});
},
[
&
](
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
system
.
render
(
err
));
});
self
->
await_all_other_actors_done
();
CAF_MESSAGE
(
"wait for client system"
);
child
.
join
();
...
...
libcaf_io/test/io/typed_remote_actor.cpp
View file @
f4c5842b
...
...
@@ -21,12 +21,12 @@
#define CAF_SUITE io_typed_remote_actor
#include "caf/test/dsl.hpp"
#include <thread>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <thread>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
...
...
@@ -65,19 +65,17 @@ using server_type = typed_actor<replies_to<ping>::with<pong>>;
using
client_type
=
typed_actor
<>
;
server_type
::
behavior_type
server
()
{
return
{
[](
const
ping
&
p
)
->
pong
{
CAF_CHECK_EQUAL
(
p
.
value
,
42
);
return
pong
{
p
.
value
};
}
};
return
{[](
const
ping
&
p
)
->
pong
{
CAF_CHECK_EQUAL
(
p
.
value
,
42
);
return
pong
{
p
.
value
};
}};
}
void
run_client
(
int
argc
,
char
**
argv
,
uint16_t
port
)
{
actor_system_config
cfg
;
cfg
.
load
<
io
::
middleman
>
()
.
add_message_type
<
ping
>
(
"ping"
)
.
add_message_type
<
pong
>
(
"pong"
);
.
add_message_type
<
ping
>
(
"ping"
)
.
add_message_type
<
pong
>
(
"pong"
);
if
(
auto
err
=
cfg
.
parse
(
argc
,
argv
))
CAF_FAIL
(
"failed to parse config: "
<<
to_string
(
err
));
actor_system
sys
{
cfg
};
...
...
@@ -88,8 +86,8 @@ void run_client(int argc, char** argv, uint16_t port) {
CAF_REQUIRE
(
!
res
);
CAF_MESSAGE
(
sys
.
render
(
res
.
error
()));
CAF_MESSAGE
(
"connect to typed_remote_actor"
);
auto
serv
=
unbox
(
sys
.
middleman
().
remote_actor
<
server_type
>
(
"127.0.0.1"
,
port
));
auto
serv
=
unbox
(
sys
.
middleman
().
remote_actor
<
server_type
>
(
"127.0.0.1"
,
port
));
auto
f
=
make_function_view
(
serv
);
CAF_CHECK_EQUAL
(
f
(
ping
{
42
}),
pong
{
42
});
anon_send_exit
(
serv
,
exit_reason
::
user_shutdown
);
...
...
@@ -98,9 +96,9 @@ void run_client(int argc, char** argv, uint16_t port) {
void
run_server
(
int
argc
,
char
**
argv
)
{
actor_system_config
cfg
;
cfg
.
load
<
io
::
middleman
>
()
.
add_message_type
<
ping
>
(
"ping"
)
.
add_message_type
<
pong
>
(
"pong"
)
.
parse
(
argc
,
argv
);
.
add_message_type
<
ping
>
(
"ping"
)
.
add_message_type
<
pong
>
(
"pong"
)
.
parse
(
argc
,
argv
);
actor_system
sys
{
cfg
};
auto
port
=
unbox
(
sys
.
middleman
().
publish
(
sys
.
spawn
(
server
),
0
,
"127.0.0.1"
));
CAF_REQUIRE
(
port
!=
0
);
...
...
@@ -114,4 +112,3 @@ CAF_TEST(test_typed_remote_actor) {
auto
argv
=
test
::
engine
::
argv
();
run_server
(
argc
,
argv
);
}
libcaf_io/test/io/unpublish.cpp
View file @
f4c5842b
...
...
@@ -21,9 +21,9 @@
#define CAF_SUITE io_unpublish
#include "caf/test/dsl.hpp"
#include <atomic>
#include <new>
#include <thread>
#include <atomic>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
...
...
@@ -45,11 +45,9 @@ public:
}
behavior
make_behavior
()
override
{
return
{
[]
{
// nop
}
};
return
{[]
{
// nop
}};
}
};
...
...
@@ -78,17 +76,18 @@ struct fixture {
bool
expect_fail
=
false
)
{
actor
result
;
scoped_actor
self
{
system
,
true
};
self
->
request
(
system
.
middleman
().
actor_handle
(),
infinite
,
connect_atom
::
value
,
hostname
,
port
).
receive
(
[
&
](
node_id
&
,
strong_actor_ptr
&
res
,
std
::
set
<
std
::
string
>&
xs
)
{
CAF_REQUIRE
(
xs
.
empty
());
if
(
res
)
result
=
actor_cast
<
actor
>
(
std
::
move
(
res
));
},
[
&
](
error
&
)
{
// nop
}
);
self
->
request
(
system
.
middleman
().
actor_handle
(),
infinite
,
connect_atom
::
value
,
hostname
,
port
)
.
receive
(
[
&
](
node_id
&
,
strong_actor_ptr
&
res
,
std
::
set
<
std
::
string
>&
xs
)
{
CAF_REQUIRE
(
xs
.
empty
());
if
(
res
)
result
=
actor_cast
<
actor
>
(
std
::
move
(
res
));
},
[
&
](
error
&
)
{
// nop
});
if
(
expect_fail
)
CAF_REQUIRE
(
!
result
);
else
...
...
@@ -97,7 +96,9 @@ struct fixture {
}
config
cfg
;
union
{
actor_system
system
;
};
// manually control ctor/dtor
union
{
actor_system
system
;
};
// manually control ctor/dtor
actor
testee
;
};
...
...
libcaf_openssl/src/openssl/manager.cpp
View file @
f4c5842b
...
...
@@ -23,8 +23,8 @@ CAF_PUSH_WARNINGS
#include <openssl/ssl.h>
CAF_POP_WARNINGS
#include <vector>
#include <mutex>
#include <vector>
#include "caf/actor_control_block.hpp"
#include "caf/actor_system.hpp"
...
...
@@ -33,8 +33,8 @@ CAF_POP_WARNINGS
#include "caf/raise_error.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/basp_broker.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/openssl/middleman_actor.hpp"
...
...
@@ -97,8 +97,10 @@ manager::~manager() {
void
manager
::
start
()
{
CAF_LOG_TRACE
(
""
);
manager_
=
make_middleman_actor
(
system
(),
system
().
middleman
().
named_broker
<
io
::
basp_broker
>
(
atom
(
"BASP"
)));
manager_
=
make_middleman_actor
(
system
(),
system
()
.
middleman
()
.
named_broker
<
io
::
basp_broker
>
(
atom
(
"BASP"
)));
}
void
manager
::
stop
()
{
...
...
libcaf_openssl/src/openssl/middleman_actor.cpp
View file @
f4c5842b
...
...
@@ -18,36 +18,36 @@
#include "caf/io/middleman_actor.hpp"
#include <tuple>
#include <stdexcept>
#include <tuple>
#include <utility>
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/actor.hpp"
#include "caf/logger.hpp"
#include "caf/node_id.hpp"
#include "caf/actor_proxy.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/io/basp_broker.hpp"
#include "caf/io/system_messages.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/stream_impl.hpp"
#include "caf/io/network/doorman_impl.hpp"
#include "caf/io/network/default_multiplexer.hpp"
#include "caf/openssl/session.hpp"
#ifdef CAF_WINDOWS
# include <winsock2.h>
# include <ws2tcpip.h> // socket_size_type, etc. (MSVC20xx)
#
include <winsock2.h>
#
include <ws2tcpip.h> // socket_size_type, etc. (MSVC20xx)
#else
#
include <sys/types
.h>
#
include <sys/socket
.h>
#
include <sys/socket
.h>
#
include <sys/types
.h>
#endif
namespace
caf
{
...
...
@@ -84,9 +84,9 @@ struct ssl_policy {
if
(
result
==
io
::
network
::
invalid_native_socket
)
{
auto
err
=
io
::
network
::
last_socket_error
();
if
(
!
io
::
network
::
would_block_or_temporarily_unavailable
(
err
))
CAF_LOG_ERROR
(
"accept failed:"
<<
io
::
network
::
socket_error_as_string
(
err
));
return
false
;
CAF_LOG_ERROR
(
"accept failed:"
<<
io
::
network
::
socket_error_as_string
(
err
));
return
false
;
}
io
::
network
::
child_process_inherit
(
result
,
false
);
CAF_LOG_DEBUG
(
CAF_ARG
(
fd
)
<<
CAF_ARG
(
result
));
...
...
@@ -102,105 +102,104 @@ private:
};
class
scribe_impl
:
public
io
::
scribe
{
public:
scribe_impl
(
default_mpx
&
mpx
,
native_socket
sockfd
,
session_ptr
sptr
)
:
scribe
(
io
::
network
::
conn_hdl_from_socket
(
sockfd
)),
launched_
(
false
),
stream_
(
mpx
,
sockfd
,
std
::
move
(
sptr
))
{
// nop
}
public:
scribe_impl
(
default_mpx
&
mpx
,
native_socket
sockfd
,
session_ptr
sptr
)
:
scribe
(
io
::
network
::
conn_hdl_from_socket
(
sockfd
)),
launched_
(
false
),
stream_
(
mpx
,
sockfd
,
std
::
move
(
sptr
))
{
// nop
}
~
scribe_impl
()
override
{
CAF_LOG_TRACE
(
""
);
}
~
scribe_impl
()
override
{
CAF_LOG_TRACE
(
""
);
}
void
configure_read
(
io
::
receive_policy
::
config
config
)
override
{
CAF_LOG_TRACE
(
CAF_ARG
(
config
));
stream_
.
configure_read
(
config
);
if
(
!
launched_
)
launch
();
}
void
configure_read
(
io
::
receive_policy
::
config
config
)
override
{
CAF_LOG_TRACE
(
CAF_ARG
(
config
));
stream_
.
configure_read
(
config
);
if
(
!
launched_
)
launch
();
}
void
ack_writes
(
bool
enable
)
override
{
CAF_LOG_TRACE
(
CAF_ARG
(
enable
));
stream_
.
ack_writes
(
enable
);
}
void
ack_writes
(
bool
enable
)
override
{
CAF_LOG_TRACE
(
CAF_ARG
(
enable
));
stream_
.
ack_writes
(
enable
);
}
std
::
vector
<
char
>&
wr_buf
()
override
{
return
stream_
.
wr_buf
();
}
std
::
vector
<
char
>&
wr_buf
()
override
{
return
stream_
.
wr_buf
();
}
std
::
vector
<
char
>&
rd_buf
()
override
{
return
stream_
.
rd_buf
();
}
std
::
vector
<
char
>&
rd_buf
()
override
{
return
stream_
.
rd_buf
();
}
void
graceful_shutdown
()
override
{
CAF_LOG_TRACE
(
""
);
stream_
.
graceful_shutdown
();
detach
(
&
stream_
.
backend
(),
false
);
}
void
graceful_shutdown
()
override
{
CAF_LOG_TRACE
(
""
);
stream_
.
graceful_shutdown
();
detach
(
&
stream_
.
backend
(),
false
);
}
void
flush
()
override
{
CAF_LOG_TRACE
(
""
);
stream_
.
flush
(
this
);
}
void
flush
()
override
{
CAF_LOG_TRACE
(
""
);
stream_
.
flush
(
this
);
}
std
::
string
addr
()
const
override
{
auto
x
=
io
::
network
::
remote_addr_of_fd
(
stream_
.
fd
());
if
(
!
x
)
return
""
;
return
*
x
;
}
std
::
string
addr
()
const
override
{
auto
x
=
io
::
network
::
remote_addr_of_fd
(
stream_
.
fd
());
if
(
!
x
)
return
""
;
return
*
x
;
}
uint16_t
port
()
const
override
{
auto
x
=
io
::
network
::
remote_port_of_fd
(
stream_
.
fd
());
if
(
!
x
)
return
0
;
return
*
x
;
}
uint16_t
port
()
const
override
{
auto
x
=
io
::
network
::
remote_port_of_fd
(
stream_
.
fd
());
if
(
!
x
)
return
0
;
return
*
x
;
}
void
launch
()
{
CAF_LOG_TRACE
(
""
);
CAF_ASSERT
(
!
launched_
);
launched_
=
true
;
stream_
.
start
(
this
);
// This schedules the scribe in case SSL still needs to call SSL_connect
// or SSL_accept. Otherwise, the backend simply removes the socket for
// write operations after the first "nop write".
stream_
.
force_empty_write
(
this
);
}
void
launch
()
{
CAF_LOG_TRACE
(
""
);
CAF_ASSERT
(
!
launched_
);
launched_
=
true
;
stream_
.
start
(
this
);
// This schedules the scribe in case SSL still needs to call SSL_connect
// or SSL_accept. Otherwise, the backend simply removes the socket for
// write operations after the first "nop write".
stream_
.
force_empty_write
(
this
);
}
void
add_to_loop
()
override
{
CAF_LOG_TRACE
(
""
);
stream_
.
activate
(
this
);
}
void
add_to_loop
()
override
{
CAF_LOG_TRACE
(
""
);
stream_
.
activate
(
this
);
}
void
remove_from_loop
()
override
{
CAF_LOG_TRACE
(
""
);
stream_
.
passivate
();
}
void
remove_from_loop
()
override
{
CAF_LOG_TRACE
(
""
);
stream_
.
passivate
();
}
private:
bool
launched_
;
io
::
network
::
stream_impl
<
ssl_policy
>
stream_
;
private:
bool
launched_
;
io
::
network
::
stream_impl
<
ssl_policy
>
stream_
;
};
class
doorman_impl
:
public
io
::
network
::
doorman_impl
{
public:
doorman_impl
(
default_mpx
&
mx
,
native_socket
sockfd
)
:
io
::
network
::
doorman_impl
(
mx
,
sockfd
)
{
:
io
::
network
::
doorman_impl
(
mx
,
sockfd
)
{
// nop
}
bool
new_connection
()
override
{
CAF_LOG_TRACE
(
""
);
if
(
detached
())
// we are already disconnected from the broker while the multiplexer
// did not yet remove the socket, this can happen if an I/O event causes
// the broker to call close_all() while the pollset contained
// further activities for the broker
return
false
;
// we are already disconnected from the broker while the multiplexer
// did not yet remove the socket, this can happen if an I/O event causes
// the broker to call close_all() while the pollset contained
// further activities for the broker
return
false
;
auto
&
dm
=
acceptor_
.
backend
();
auto
fd
=
acceptor_
.
accepted_socket
();
io
::
network
::
nonblocking
(
fd
,
true
);
...
...
@@ -219,7 +218,7 @@ public:
class
middleman_actor_impl
:
public
io
::
middleman_actor_impl
{
public:
middleman_actor_impl
(
actor_config
&
cfg
,
actor
default_broker
)
:
io
::
middleman_actor_impl
(
cfg
,
std
::
move
(
default_broker
))
{
:
io
::
middleman_actor_impl
(
cfg
,
std
::
move
(
default_broker
))
{
// nop
}
...
...
@@ -240,8 +239,8 @@ protected:
CAF_LOG_ERROR
(
"Unable to create SSL session for connection"
);
return
sec
::
cannot_connect_to_node
;
}
CAF_LOG_DEBUG
(
"successfully created an SSL session for:"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
CAF_LOG_DEBUG
(
"successfully created an SSL session for:"
<<
CAF_ARG
(
host
)
<<
CAF_ARG
(
port
));
return
make_counted
<
scribe_impl
>
(
mpx
(),
*
fd
,
std
::
move
(
sssn
));
}
...
...
@@ -264,8 +263,8 @@ private:
io
::
middleman_actor
make_middleman_actor
(
actor_system
&
sys
,
actor
db
)
{
return
!
get_or
(
sys
.
config
(),
"middleman.attach-utility-actors"
,
false
)
?
sys
.
spawn
<
middleman_actor_impl
,
detached
+
hidden
>
(
std
::
move
(
db
))
:
sys
.
spawn
<
middleman_actor_impl
,
hidden
>
(
std
::
move
(
db
));
?
sys
.
spawn
<
middleman_actor_impl
,
detached
+
hidden
>
(
std
::
move
(
db
))
:
sys
.
spawn
<
middleman_actor_impl
,
hidden
>
(
std
::
move
(
db
));
}
}
// namespace openssl
...
...
libcaf_openssl/src/openssl/publish.cpp
View file @
f4c5842b
...
...
@@ -20,11 +20,11 @@
#include <set>
#include "caf/actor_control_block.hpp"
#include "caf/actor_system.hpp"
#include "caf/atom.hpp"
#include "caf/expected.hpp"
#include "caf/actor_system.hpp"
#include "caf/function_view.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/openssl/manager.hpp"
...
...
@@ -46,4 +46,3 @@ expected<uint16_t> publish(actor_system& sys, const strong_actor_ptr& whom,
}
// namespace openssl
}
// namespace caf
libcaf_openssl/src/openssl/remote_actor.cpp
View file @
f4c5842b
...
...
@@ -18,10 +18,10 @@
#include "caf/openssl/remote_actor.hpp"
#include "caf/sec.hpp"
#include "caf/atom.hpp"
#include "caf/expected.hpp"
#include "caf/function_view.hpp"
#include "caf/sec.hpp"
#include "caf/openssl/manager.hpp"
...
...
@@ -54,4 +54,3 @@ expected<strong_actor_ptr> remote_actor(actor_system& sys,
}
// namespace openssl
}
// namespace caf
libcaf_openssl/src/openssl/session.cpp
View file @
f4c5842b
...
...
@@ -32,8 +32,8 @@ CAF_POP_WARNINGS
// Unfortunately there's no sane way to configure OpenSSL properly.
#ifdef CAF_LINUX
#include "caf/detail/scope_guard.hpp"
#include <signal.h>
#
include "caf/detail/scope_guard.hpp"
#
include <signal.h>
# define CAF_BLOCK_SIGPIPE() \
sigset_t sigpipe_mask; \
...
...
@@ -55,7 +55,7 @@ CAF_POP_WARNINGS
#else
#define CAF_BLOCK_SIGPIPE() static_cast<void>(0)
#
define CAF_BLOCK_SIGPIPE() static_cast<void>(0)
#endif // CAF_LINUX
...
...
@@ -74,11 +74,11 @@ int pem_passwd_cb(char* buf, int size, int, void* ptr) {
}
// namespace
session
::
session
(
actor_system
&
sys
)
:
sys_
(
sys
),
ctx_
(
nullptr
),
ssl_
(
nullptr
),
connecting_
(
false
),
accepting_
(
false
)
{
:
sys_
(
sys
),
ctx_
(
nullptr
),
ssl_
(
nullptr
),
connecting_
(
false
),
accepting_
(
false
)
{
// nop
}
...
...
@@ -231,10 +231,10 @@ SSL_CTX* session::create_ssl_context() {
SSL_FILETYPE_PEM
)
!=
1
)
CAF_RAISE_ERROR
(
"cannot load private key"
);
auto
cafile
=
(
cfg
.
openssl_cafile
.
size
()
>
0
?
cfg
.
openssl_cafile
.
c_str
()
:
nullptr
);
auto
capath
=
(
cfg
.
openssl_capath
.
size
()
>
0
?
cfg
.
openssl_capath
.
c_str
()
:
nullptr
);
auto
cafile
=
(
cfg
.
openssl_cafile
.
size
()
>
0
?
cfg
.
openssl_cafile
.
c_str
()
:
nullptr
);
auto
capath
=
(
cfg
.
openssl_capath
.
size
()
>
0
?
cfg
.
openssl_capath
.
c_str
()
:
nullptr
);
if
(
cafile
||
capath
)
{
if
(
SSL_CTX_load_verify_locations
(
ctx
,
cafile
,
capath
)
!=
1
)
CAF_RAISE_ERROR
(
"cannot load trusted CA certificates"
);
...
...
libcaf_openssl/test/openssl/authentication.cpp
View file @
f4c5842b
...
...
@@ -62,46 +62,42 @@ public:
}
static
std
::
string
data_dir
()
{
std
::
string
path
{
::
caf
::
test
::
engine
::
path
()};
path
=
path
.
substr
(
0
,
path
.
find_last_of
(
"/"
));
// TODO: https://github.com/actor-framework/actor-framework/issues/555
path
+=
"/../../libcaf_openssl/test"
;
char
rpath
[
PATH_MAX
];
std
::
string
path
{
::
caf
::
test
::
engine
::
path
()};
path
=
path
.
substr
(
0
,
path
.
find_last_of
(
"/"
));
// TODO: https://github.com/actor-framework/actor-framework/issues/555
path
+=
"/../../libcaf_openssl/test"
;
char
rpath
[
PATH_MAX
];
#ifndef CAF_WINDOWS
auto
rp
=
realpath
(
path
.
c_str
(),
rpath
);
auto
rp
=
realpath
(
path
.
c_str
(),
rpath
);
#else
auto
rp
=
GetFullPathName
(
path
.
c_str
(),
PATH_MAX
,
rpath
,
nullptr
);
auto
rp
=
GetFullPathName
(
path
.
c_str
(),
PATH_MAX
,
rpath
,
nullptr
);
#endif
std
::
string
result
;
if
(
rp
)
result
=
rpath
;
return
result
;
std
::
string
result
;
if
(
rp
)
result
=
rpath
;
return
result
;
}
};
behavior
make_pong_behavior
()
{
return
{
[](
int
val
)
->
int
{
++
val
;
CAF_MESSAGE
(
"pong "
<<
val
);
return
val
;
}
};
return
{[](
int
val
)
->
int
{
++
val
;
CAF_MESSAGE
(
"pong "
<<
val
);
return
val
;
}};
}
behavior
make_ping_behavior
(
event_based_actor
*
self
,
const
actor
&
pong
)
{
CAF_MESSAGE
(
"ping "
<<
0
);
self
->
send
(
pong
,
0
);
return
{
[
=
](
int
val
)
->
int
{
CAF_MESSAGE
(
"ping "
<<
val
);
if
(
val
>=
3
)
{
CAF_MESSAGE
(
"terminate ping"
);
self
->
quit
();
}
return
val
;
return
{[
=
](
int
val
)
->
int
{
CAF_MESSAGE
(
"ping "
<<
val
);
if
(
val
>=
3
)
{
CAF_MESSAGE
(
"terminate ping"
);
self
->
quit
();
}
};
return
val
;
}};
}
struct
fixture
{
...
...
@@ -110,8 +106,12 @@ struct fixture {
config
server_side_config
;
config
client_side_config
;
bool
initialized
;
union
{
actor_system
server_side
;
};
union
{
actor_system
client_side
;
};
union
{
actor_system
server_side
;
};
union
{
actor_system
client_side
;
};
sched_t
*
ssched
;
sched_t
*
csched
;
...
...
@@ -132,15 +132,14 @@ struct fixture {
server_side_config
.
openssl_passphrase
=
"12345"
;
// check whether all files exist before setting config parameters
std
::
string
dummy
;
std
::
pair
<
const
char
*
,
std
::
string
*>
cfg
[]
{
{
"ca.pem"
,
&
server_side_config
.
openssl_cafile
},
{
"cert.1.pem"
,
&
server_side_config
.
openssl_certificate
},
{
"key.1.enc.pem"
,
&
server_side_config
.
openssl_key
},
{
"ca.pem"
,
skip_client_side_ca
?
&
dummy
:
&
client_side_config
.
openssl_cafile
},
{
"cert.2.pem"
,
&
client_side_config
.
openssl_certificate
},
{
"key.2.pem"
,
&
client_side_config
.
openssl_key
}
};
std
::
pair
<
const
char
*
,
std
::
string
*>
cfg
[]{{
"ca.pem"
,
&
server_side_config
.
openssl_cafile
},
{
"cert.1.pem"
,
&
server_side_config
.
openssl_certificate
},
{
"key.1.enc.pem"
,
&
server_side_config
.
openssl_key
},
{
"ca.pem"
,
skip_client_side_ca
?
&
dummy
:
&
client_side_config
.
openssl_cafile
},
{
"cert.2.pem"
,
&
client_side_config
.
openssl_certificate
},
{
"key.2.pem"
,
&
client_side_config
.
openssl_key
}};
// return if any file is unreadable or non-existend
for
(
auto
&
x
:
cfg
)
{
auto
path
=
cd
+
x
.
first
;
...
...
@@ -195,8 +194,8 @@ struct fixture {
CAF_TEST_FIXTURE_SCOPE
(
authentication
,
fixture
)
using
openssl
::
remote_actor
;
using
openssl
::
publish
;
using
openssl
::
remote_actor
;
CAF_TEST
(
authentication_success
)
{
if
(
!
init
(
false
))
...
...
libcaf_openssl/test/openssl/remote_actor.cpp
View file @
f4c5842b
...
...
@@ -23,10 +23,10 @@
#define CAF_SUITE openssl_dynamic_remote_actor
#include "caf/test/dsl.hpp"
#include <
vector
>
#include <
algorithm
>
#include <sstream>
#include <utility>
#include <
algorithm
>
#include <
vector
>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
...
...
@@ -44,8 +44,7 @@ public:
load
<
io
::
middleman
>
();
load
<
openssl
::
manager
>
();
add_message_type
<
std
::
vector
<
int
>>
(
"std::vector<int>"
);
actor_system_config
::
parse
(
test
::
engine
::
argc
(),
test
::
engine
::
argv
());
actor_system_config
::
parse
(
test
::
engine
::
argc
(),
test
::
engine
::
argv
());
// Setting the "max consecutive reads" to 1 is highly likely to cause
// OpenSSL to buffer data internally and report "pending" data after a read
// operation. This will trigger `must_read_more` in the SSL read policy
...
...
@@ -72,7 +71,7 @@ behavior make_pong_behavior() {
++
val
;
CAF_MESSAGE
(
"pong with "
<<
val
);
return
val
;
}
}
,
};
}
...
...
@@ -83,14 +82,13 @@ behavior make_ping_behavior(event_based_actor* self, const actor& pong) {
[
=
](
int
val
)
->
int
{
if
(
val
==
3
)
{
CAF_MESSAGE
(
"ping with exit"
);
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
CAF_MESSAGE
(
"ping quits"
);
self
->
quit
();
}
CAF_MESSAGE
(
"ping with "
<<
val
);
return
val
;
}
}
,
};
}
...
...
@@ -109,11 +107,12 @@ behavior make_sort_behavior() {
std
::
sort
(
vec
.
begin
(),
vec
.
end
());
CAF_MESSAGE
(
"sorter sent: "
<<
to_string
(
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
});
return
{
[
=
](
const
std
::
vector
<
int
>&
vec
)
{
...
...
@@ -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
]);
self
->
send_exit
(
sorter
,
exit_reason
::
user_shutdown
);
self
->
quit
();
}
}
,
};
}
...
...
@@ -131,7 +130,7 @@ behavior fragile_mirror(event_based_actor* self) {
[
=
](
int
i
)
{
self
->
quit
(
exit_reason
::
user_shutdown
);
return
i
;
}
}
,
};
}
...
...
@@ -140,9 +139,7 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
self
->
link_to
(
buddy
);
self
->
send
(
buddy
,
42
);
return
{
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
42
);
}
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
42
);
},
};
}
...
...
@@ -150,8 +147,8 @@ behavior linking_actor(event_based_actor* self, const actor& buddy) {
CAF_TEST_FIXTURE_SCOPE
(
dynamic_remote_actor_tests
,
fixture
)
using
openssl
::
remote_actor
;
using
openssl
::
publish
;
using
openssl
::
remote_actor
;
CAF_TEST_DISABLED
(
identity_semantics
)
{
// server side
...
...
@@ -171,8 +168,8 @@ CAF_TEST_DISABLED(identity_semantics) {
CAF_TEST_DISABLED
(
ping_pong
)
{
// server side
auto
port
=
unbox
(
publish
(
server_side
.
spawn
(
make_pong_behavior
),
0
,
local_host
));
auto
port
=
unbox
(
publish
(
server_side
.
spawn
(
make_pong_behavior
),
0
,
local_host
));
// client side
auto
pong
=
unbox
(
remote_actor
(
client_side
,
local_host
,
port
));
client_side
.
spawn
(
make_ping_behavior
,
pong
);
...
...
@@ -180,8 +177,8 @@ CAF_TEST_DISABLED(ping_pong) {
CAF_TEST_DISABLED
(
custom_message_type
)
{
// server side
auto
port
=
unbox
(
publish
(
server_side
.
spawn
(
make_sort_behavior
),
0
,
local_host
));
auto
port
=
unbox
(
publish
(
server_side
.
spawn
(
make_sort_behavior
),
0
,
local_host
));
// client side
auto
sorter
=
unbox
(
remote_actor
(
client_side
,
local_host
,
port
));
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