mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
- is_multi_producer:sender无限制;否则仅允许一个 - is_multi_consumer:receiver个数上限依赖is_broadcast指定;否则仅允许一个 - is_broadcast:receiver个数上限为32(uint_t<32>位数);否则无限制(uint_t<32>大小) 行为变更: 1. 在连接时根据模式检查sender/receiver是否超出上限,超出则返回false 2. 在send时确认是否允许发送(对receiver模式来说,send之前不会尝试确认sender个数) 3. 修正若干bug
65 lines
1.4 KiB
C++
Executable File
65 lines
1.4 KiB
C++
Executable File
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <limits> // std::numeric_limits
|
|
#include <new>
|
|
#include <utility>
|
|
|
|
namespace ipc {
|
|
|
|
// types
|
|
|
|
using byte_t = std::uint8_t;
|
|
|
|
template <std::size_t N>
|
|
struct uint;
|
|
|
|
template <> struct uint<8 > { using type = std::uint8_t ; };
|
|
template <> struct uint<16> { using type = std::uint16_t; };
|
|
template <> struct uint<32> { using type = std::uint32_t; };
|
|
template <> struct uint<64> { using type = std::uint64_t; };
|
|
|
|
template <std::size_t N>
|
|
using uint_t = typename uint<N>::type;
|
|
|
|
// constants
|
|
|
|
enum : std::size_t {
|
|
invalid_value = (std::numeric_limits<std::size_t>::max)(),
|
|
data_length = 64,
|
|
large_msg_limit = data_length,
|
|
large_msg_cache = 32,
|
|
default_timeout = 100 // ms
|
|
};
|
|
|
|
enum class relat { // multiplicity of the relationship
|
|
single,
|
|
multi
|
|
};
|
|
|
|
enum class trans { // transmission
|
|
unicast,
|
|
broadcast
|
|
};
|
|
|
|
// producer-consumer policy flag
|
|
|
|
template <relat Rp, relat Rc, trans Ts>
|
|
struct wr {};
|
|
|
|
template <typename WR>
|
|
struct relat_trait;
|
|
|
|
template <relat Rp, relat Rc, trans Ts>
|
|
struct relat_trait<wr<Rp, Rc, Ts>> {
|
|
constexpr static bool is_multi_producer = (Rp == relat::multi);
|
|
constexpr static bool is_multi_consumer = (Rc == relat::multi);
|
|
constexpr static bool is_broadcast = (Ts == trans::broadcast);
|
|
};
|
|
|
|
template <template <typename> class Policy, typename Flag>
|
|
struct relat_trait<Policy<Flag>> : relat_trait<Flag> {};
|
|
|
|
} // namespace ipc
|