Commit 29f9b037 authored by Dominik Charousset's avatar Dominik Charousset

Pass a pointer to the socket manager to all layers

parent 7e4d9505
...@@ -132,7 +132,7 @@ public: ...@@ -132,7 +132,7 @@ public:
// -- initialization --------------------------------------------------------- // -- initialization ---------------------------------------------------------
error init(const settings& config) override { error init(const settings& config) override {
return protocol_.init(*this, config); return protocol_.init(static_cast<socket_manager*>(this), *this, config);
} }
// -- event callbacks -------------------------------------------------------- // -- event callbacks --------------------------------------------------------
......
...@@ -131,7 +131,7 @@ public: ...@@ -131,7 +131,7 @@ public:
// -- initialization --------------------------------------------------------- // -- initialization ---------------------------------------------------------
template <class Parent> template <class Parent>
error init(Parent& parent, const settings& config) { error init(socket_manager* owner, Parent& parent, const settings& config) {
namespace mm = defaults::middleman; namespace mm = defaults::middleman;
auto default_max_reads = static_cast<uint32_t>(mm::max_consecutive_reads); auto default_max_reads = static_cast<uint32_t>(mm::max_consecutive_reads);
max_consecutive_reads_ = get_or( max_consecutive_reads_ = get_or(
...@@ -153,7 +153,7 @@ public: ...@@ -153,7 +153,7 @@ public:
return std::move(socket_buf_size.error()); return std::move(socket_buf_size.error());
} }
access<Parent> this_layer{&parent, this}; access<Parent> this_layer{&parent, this};
return upper_layer_.init(this_layer, config); return upper_layer_.init(owner, this_layer, config);
} }
// -- event callbacks -------------------------------------------------------- // -- event callbacks --------------------------------------------------------
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
#include <algorithm> #include <algorithm>
#include "caf/detail/encode_base64.hpp" #include "caf/detail/encode_base64.hpp"
#include "caf/detail/move_if_not_ptr.hpp"
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/hash/sha1.hpp" #include "caf/hash/sha1.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/receive_policy.hpp" #include "caf/net/receive_policy.hpp"
#include "caf/pec.hpp" #include "caf/pec.hpp"
#include "caf/settings.hpp" #include "caf/settings.hpp"
...@@ -87,7 +87,8 @@ public: ...@@ -87,7 +87,8 @@ public:
// -- initialization --------------------------------------------------------- // -- initialization ---------------------------------------------------------
template <class LowerLayer> template <class LowerLayer>
error init(LowerLayer& down, const settings& config) { error init(socket_manager* owner, LowerLayer& down, const settings& config) {
owner_ = owner;
cfg_ = config; cfg_ = config;
down.configure_read(net::receive_policy::up_to(max_header_size)); down.configure_read(net::receive_policy::up_to(max_header_size));
return none; return none;
...@@ -199,7 +200,7 @@ private: ...@@ -199,7 +200,7 @@ private:
return false; return false;
} }
// Try initializing the upper layer. // Try initializing the upper layer.
if (auto err = upper_layer_.init(down, cfg_)) { if (auto err = upper_layer_.init(owner_, down, cfg_)) {
down.abort_reason(std::move(err)); down.abort_reason(std::move(err));
return false; return false;
} }
...@@ -266,6 +267,9 @@ private: ...@@ -266,6 +267,9 @@ private:
/// Stores the upper layer. /// Stores the upper layer.
UpperLayer upper_layer_; UpperLayer upper_layer_;
/// Stores a pointer to the owning manager for the delayed initialization.
socket_manager* owner_ = nullptr;
/// Holds a copy of the settings in order to delay initialization of the upper /// Holds a copy of the settings in order to delay initialization of the upper
/// layer until the handshake completed. /// layer until the handshake completed.
settings cfg_; settings cfg_;
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
caf::error init(const caf::settings& config) { caf::error init(const caf::settings& config) {
access this_layer{this}; access this_layer{this};
return upper_layer.init(this_layer, config); return upper_layer.init(nullptr, this_layer, config);
} }
caf::error init() { caf::error init() {
......
...@@ -42,7 +42,7 @@ struct app_t { ...@@ -42,7 +42,7 @@ struct app_t {
settings cfg; settings cfg;
template <class LowerLayer> template <class LowerLayer>
error init(LowerLayer&, const settings& init_cfg) { error init(net::socket_manager*, LowerLayer&, const settings& init_cfg) {
cfg = init_cfg; cfg = init_cfg;
return none; return none;
} }
......
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
~dummy_application() = default; ~dummy_application() = default;
template <class Parent> template <class Parent>
error init(Parent& parent, const settings&) { error init(socket_manager*, Parent& parent, const settings&) {
parent.configure_read(receive_policy::exactly(hello_manager.size())); parent.configure_read(receive_policy::exactly(hello_manager.size()));
return none; return none;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment