Commit d4020bfe authored by Joseph Noir's avatar Joseph Noir

WIP Unifies datagram sink and source in endpoint

parent 2690ac42
......@@ -30,6 +30,7 @@
#include "caf/io/fwd.hpp"
#include "caf/io/accept_handle.hpp"
#include "caf/io/receive_policy.hpp"
#include "caf/io/endpoint_handle.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/connection_handle.hpp"
#include "caf/io/datagram_sink_handle.hpp"
......@@ -38,6 +39,7 @@
#include "caf/io/network/native_socket.hpp"
#include "caf/io/network/stream_manager.hpp"
#include "caf/io/network/acceptor_manager.hpp"
#include "caf/io/network/endpoint_manager.hpp"
#include "caf/io/network/datagram_sink_manager.hpp"
#include "caf/io/network/datagram_source_manager.hpp"
......@@ -86,6 +88,7 @@ public:
// even brokers need friends
friend class scribe;
friend class doorman;
friend class endpoint;
friend class datagram_sink;
friend class datagram_source;
......@@ -340,6 +343,9 @@ protected:
using datagram_source_map = std::unordered_map<datagram_source_handle,
intrusive_ptr<datagram_source>>;
using endpoint_map = std::unordered_map<endpoint_handle,
intrusive_ptr<endpoint>>;
/// @cond PRIVATE
// meta programming utility
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2016 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_IO_ENDPOINT_HPP
#define CAF_IO_ENDPOINT_HPP
#include "caf/message.hpp"
#include "caf/io/broker_servant.hpp"
#include "caf/io/endpoint_handle.hpp"
#include "caf/io/system_messages.hpp"
#include "caf/io/network/endpoint_manager.hpp"
namespace caf {
namespace io {
using endpoint_base = broker_servant<network::endpoint_manager,
endpoint_handle,
datagram_sent_msg>;
/// Manages writing and reading on a datagram endpoint.
/// @ingroup Broker
class endpoint : public endpoint_base {
public:
endpoint(abstract_broker* parent, datagram_sink_handle hdl);
~endpoint();
/// Enables or disables write notifications.
virtual void ack_writes(bool enable) = 0;
/// Configure buffer size for next accepted datagram.
virtual void configure_datagram_size(size_t buf_size) = 0;
/// Returns the current write buffer.
virtual std::vector<char>& wr_buf() = 0;
/// Returns the current input buffer.
virtual std::vector<char>& rd_buf() = 0;
bool consume(execution_unit* ctx, const void* buf, size_t besize) override;
void datagram_sent(execution_unit* ctx, size_t num_bytes) override;
void io_failure(execution_unit* ctx, network::operation op) override;
// needs to be launched explicitly, TODO: Does it?
// Can't configure_datagram_size do that?
virtual void launch() = 0;
protected:
message detach_message() override;
};
} // namespace io
} // namespace caf
#endif // CAF_IO_ENDPOINT_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2016 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_IO_ENDPOINT_HANDLE_HPP
#define CAF_IO_ENDPOINT_HANDLE_HPP
#include "caf/error.hpp"
#include "caf/io/handle.hpp"
#include "caf/meta/type_name.hpp"
namespace caf {
namespace io {
struct invalid_endpoint_handle_t {
constexpr invalid_endpoint_handle_t() {
// nop
}
};
constexpr invalid_endpoint_handle_t invalid_endpoint_handle
= invalid_endpoint_handle_t{};
/// Generic handle type for managing local and remote datagram endpoints.
class endpoint_handle : public handle<endpoint_handle,
invalid_endpoint_handle_t> {
public:
friend class handle<endpoint_handle, invalid_endpoint_handle_t>;
using super = handle<endpoint_handle,invalid_endpoint_handle_t>;
constexpr endpoint_handle() {
// nop
}
constexpr endpoint_handle(const invalid_endpoint_handle_t&) {
// nop
}
template <class Inspector>
friend typename Inspector::result_type inspect(Inspector& f,
endpoint_handle& x) {
return f(meta::type_name("endpoint_handle"), x.id_);
}
private:
inline endpoint_handle(int64_t handle_id) : super(handle_id) {
// nop
}
};
} // namespace ios
} // namespace caf
namespace std {
template<>
struct hash<caf::io::endpoint_handle> {
size_t operator()(const caf::io::endpoint_handle& hdl) const {
hash<int64_t> f;
return f(hdl.id());
}
};
} // namespace std
#endif // CAF_IO_ENDPOINT_HANDLE_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2016 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_IO_NETWORK_ENDPOINT_MANAGER_HPP
#define CAF_IO_NETWORK_ENDPOINT_MANAGER_HPP
#include "caf/io/network/manager.hpp"
namespace caf {
namespace io {
namespace network {
/// An endpoint manager configures datagram endpoints and provides callbacks
/// for incoming data as well as for error handling.
class endpoint_manager : public manager {
public:
endpoint_manager(abstract_broker* ptr);
~endpoint_manager();
/// Called by the underlying I/O device whenever it received data.
/// @returns `true` if the manager accepts further reads, otherwise `false`.
virtual bool consume(execution_unit* ctx, const void* buf, size_t bsize) = 0;
/// Called by the underlying I/O device whenever it sent a datagram.
virtual void datagram_sent(execution_unit* ctx, size_t num_bytes) = 0;
};
} // namespace network
} // namespace io
} // namespace caf
#endif // CAF_IO_NETWORK_ENDPOINT_MANAGER_HPP
......@@ -29,6 +29,7 @@
#include "caf/io/handle.hpp"
#include "caf/io/accept_handle.hpp"
#include "caf/io/endpoint_handle.hpp"
#include "caf/io/connection_handle.hpp"
#include "caf/io/datagram_sink_handle.hpp"
#include "caf/io/datagram_source_handle.hpp"
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2016 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/io/endpoint.hpp"
#include "caf/logger.hpp"
namespace caf {
namespace io {
endpoint::endpoint(abstract_broker* parent, datagram_sink_handle hdl)
: endpoint_base(parent, hdl) {
// nop
}
endpoint::~endpoint() {
CAF_LOG_TRACE("");
}
message endpoint::detach_message() {
return make_message(endpoint_closed_msg{hdl()});
}
} // namespace io
} // namespace caf
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