Commit 1f9aa431 authored by Dominik Charousset's avatar Dominik Charousset

Initial scaffold for UDP abstraction

parent bb953534
......@@ -199,13 +199,42 @@ class broker : public extend<local_actor>::
*/
buffer_type& wr_buf(connection_handle hdl);
void write(connection_handle hdl, size_t buf_size, const void* buf);
/**
* @brief Writes @p data into the buffer for given connection.
*/
void write(connection_handle hdl, size_t data_size, const void* data);
/**
* @brief Sends the content of the buffer for given connection.
*/
void flush(connection_handle hdl);
struct datagram_handle {
buffer_type* buf;
datagram_endpoint dest;
};
/**
* @brief Returns a new buffer for the given endpoint. Note that each call
* to this member function will return a new buffer.
*/
datagram_handle new_datagram(datagram_endpoint ep);
/**
* @brief Sends the datagram.
*/
void send_datagram(datagram_handle ep);
inline void send_datagram(datagram_endpoint ep,
size_t data_size,
const void* data) {
auto hdl = new_datagram(ep);
auto first = reinterpret_cast<const char*>(data);
auto last = first + data_size;
hdl.buf->insert(hdl.buf->end(), first, last);
send_datagram(hdl);
}
/**
* @brief Returns the number of open connections.
*/
......@@ -338,6 +367,12 @@ class broker : public extend<local_actor>::
return ptr->hdl();
}
template<class DatagramSocket>
datagram_source_handle add_datagram_source(DatagramSocket sock) {
// ToDo: implement me
return invalid_datagram_source_handle;
}
void enqueue(const actor_addr&, message_id, message,
execution_unit*) override;
......
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the Boost Software License, Version 1.0. See *
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_IO_DATAGRAM_ENDPOINT_HPP
#define CPPA_IO_DATAGRAM_ENDPOINT_HPP
#include <memory>
#include "cppa/io/network.hpp"
namespace cppa {
namespace io {
using datagram_endpoint = std::shared_ptr<network::datagram_endpoint_data>;
} // namespace io
} // namespace cppa
#endif // CPPA_IO_DATAGRAM_ENDPOINT_HPP
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the Boost Software License, Version 1.0. See *
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_IO_DATAGRAM_SOURCE_HANDLE_HPP
#define CPPA_IO_DATAGRAM_SOURCE_HANDLE_HPP
#include "cppa/io_handle.hpp"
namespace cppa {
namespace io {
/**
* @brief Generic handle type for identifying connections.
*/
class datagram_source_handle : public io_handle<datagram_source_handle> {
friend class io_handle<datagram_source_handle>;
using super = io_handle<datagram_source_handle>;
public:
constexpr datagram_source_handle() { }
private:
inline datagram_source_handle(int64_t handle_id) : super{handle_id} { }
};
constexpr datagram_source_handle invalid_datagram_source_handle{};
} // namespace io
} // namespace cppa
#endif // CPPA_IO_DATAGRAM_SOURCE_HANDLE_HPP
......@@ -50,6 +50,7 @@
#else
# include <unistd.h>
# include <errno.h>
# include <sys/socket.h>
#endif
// poll vs epoll backend
......@@ -122,6 +123,11 @@ namespace network {
constexpr int ec_interrupted_syscall = EINTR;
#endif
struct datagram_endpoint_data {
sockaddr addr;
socklen_t addrlen;
};
/**
* @brief Platform-specific native socket type.
*/
......
......@@ -28,6 +28,9 @@
#include "cppa/accept_handle.hpp"
#include "cppa/connection_handle.hpp"
#include "cppa/io/datagram_endpoint.hpp"
#include "cppa/io/datagram_source_handle.hpp"
#include "cppa/detail/tbind.hpp"
#include "cppa/detail/type_list.hpp"
......@@ -48,7 +51,6 @@ struct exit_msg {
* @brief The exit reason of the terminated actor.
*/
uint32_t reason;
};
/**
......@@ -63,7 +65,6 @@ struct down_msg {
* @brief The exit reason of the terminated actor.
*/
uint32_t reason;
};
/**
......@@ -78,7 +79,6 @@ struct sync_exited_msg {
* @brief The exit reason of the terminated actor.
*/
uint32_t reason;
};
template<typename T>
......@@ -107,7 +107,6 @@ struct group_down_msg {
* @brief The source of this message, i.e., the now unreachable group.
*/
group source;
};
inline bool operator==(const group_down_msg& lhs, const group_down_msg& rhs) {
......@@ -124,7 +123,7 @@ inline bool operator!=(const group_down_msg& lhs, const group_down_msg& rhs) {
* This system message does not have any fields, because the message ID
* sent alongside this message identifies the matching request that timed out.
*/
struct sync_timeout_msg {};
struct sync_timeout_msg { };
/**
* @relates exit_msg
......@@ -149,7 +148,6 @@ struct timeout_msg {
* @brief Actor-specific timeout ID.
*/
uint32_t timeout_id;
};
inline bool operator==(const timeout_msg& lhs, const timeout_msg& rhs) {
......@@ -172,7 +170,6 @@ struct new_connection_msg {
* @brief The handle for the new connection.
*/
connection_handle handle;
};
inline bool operator==(const new_connection_msg& lhs,
......@@ -190,14 +187,13 @@ inline bool operator!=(const new_connection_msg& lhs,
*/
struct new_data_msg {
/**
* @brief Handle to the related connection
* @brief Handle to the related connection.
*/
connection_handle handle;
/**
* @brief Buffer containing the received data.
*/
std::vector<char> buf;
};
inline bool operator==(const new_data_msg& lhs, const new_data_msg& rhs) {
......@@ -208,6 +204,24 @@ inline bool operator!=(const new_data_msg& lhs, const new_data_msg& rhs) {
return !(lhs == rhs);
}
/**
* @brief Signalizes a newly arrived datagram for a {@link broker}.
*/
struct new_datagram_msg {
/**
* @brief Handle to the related datagram source.
*/
io::datagram_source_handle handle;
/**
* @brief Handle to the sender of this datagram.
*/
io::datagram_endpoint endpoint;
/**
* @brief Buffer containing the received data.
*/
std::vector<char> buf;
};
/**
* @brief Signalizes that a {@link broker} connection has been closed.
*/
......@@ -216,7 +230,6 @@ struct connection_closed_msg {
* @brief Handle to the closed connection.
*/
connection_handle handle;
};
inline bool operator==(const connection_closed_msg& lhs,
......@@ -237,7 +250,6 @@ struct acceptor_closed_msg {
* @brief Handle to the closed connection.
*/
accept_handle handle;
};
inline bool operator==(const acceptor_closed_msg& lhs,
......
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