mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
Added cleanup interfaces for ipc chan
This commit is contained in:
parent
17dcde92bf
commit
28fdf17279
@ -29,8 +29,13 @@ struct IPC_EXPORT chan_impl {
|
||||
|
||||
static char const * name(ipc::handle_t h);
|
||||
|
||||
static std::size_t recv_count(ipc::handle_t h);
|
||||
static bool wait_for_recv(ipc::handle_t h, std::size_t r_count, std::uint64_t tm);
|
||||
// Force cleanup of all shared memory storage that handles depend on.
|
||||
static void clear(ipc::handle_t h) noexcept;
|
||||
static void clear_storage(char const * name) noexcept;
|
||||
static void clear_storage(prefix, char const * name) noexcept;
|
||||
|
||||
static std::size_t recv_count (ipc::handle_t h);
|
||||
static bool wait_for_recv(ipc::handle_t h, std::size_t r_count, std::uint64_t tm);
|
||||
|
||||
static bool send(ipc::handle_t h, void const * data, std::size_t size, std::uint64_t tm);
|
||||
static buff_t recv(ipc::handle_t h, std::uint64_t tm);
|
||||
@ -83,6 +88,19 @@ public:
|
||||
return detail_t::name(h_);
|
||||
}
|
||||
|
||||
// Clear shared memory files under opened handle.
|
||||
void clear() noexcept {
|
||||
detail_t::clear(h_);
|
||||
}
|
||||
|
||||
static void clear_storage(char const * name) noexcept {
|
||||
detail_t::clear_storage(name);
|
||||
}
|
||||
|
||||
static void clear_storage(prefix pref, char const * name) noexcept {
|
||||
detail_t::clear_storage(pref, name);
|
||||
}
|
||||
|
||||
ipc::handle_t handle() const noexcept {
|
||||
return h_;
|
||||
}
|
||||
|
||||
@ -136,6 +136,22 @@ struct conn_info_head {
|
||||
}
|
||||
}
|
||||
|
||||
void clear() noexcept {
|
||||
cc_waiter_.clear();
|
||||
wt_waiter_.clear();
|
||||
rd_waiter_.clear();
|
||||
acc_h_.clear();
|
||||
}
|
||||
|
||||
static void clear_storage(char const * prefix, char const * name) noexcept {
|
||||
auto p = ipc::make_string(prefix);
|
||||
auto n = ipc::make_string(name);
|
||||
ipc::detail::waiter::clear_storage(ipc::make_prefix(p, {"CC_CONN__", n}).c_str());
|
||||
ipc::detail::waiter::clear_storage(ipc::make_prefix(p, {"WT_CONN__", n}).c_str());
|
||||
ipc::detail::waiter::clear_storage(ipc::make_prefix(p, {"RD_CONN__", n}).c_str());
|
||||
ipc::shm::handle::clear_storage(ipc::make_prefix(p, {"AC_CONN__", n}).c_str());
|
||||
}
|
||||
|
||||
void quit_waiting() {
|
||||
cc_waiter_.quit_waiting();
|
||||
wt_waiter_.quit_waiting();
|
||||
@ -386,6 +402,20 @@ struct queue_generator {
|
||||
}
|
||||
}
|
||||
|
||||
void clear() noexcept {
|
||||
que_.clear();
|
||||
conn_info_head::clear();
|
||||
}
|
||||
|
||||
static void clear_storage(char const * prefix, char const * name) noexcept {
|
||||
queue_t::clear_storage(ipc::make_prefix(prefix, {
|
||||
"QU_CONN__",
|
||||
ipc::to_string(DataSize), "__",
|
||||
ipc::to_string(AlignSize), "__",
|
||||
name}).c_str());
|
||||
conn_info_head::clear_storage(prefix, name);
|
||||
}
|
||||
|
||||
void disconnect_receiver() {
|
||||
bool dis = que_.disconnect();
|
||||
this->quit_waiting();
|
||||
@ -739,6 +769,27 @@ char const * chan_impl<Flag>::name(ipc::handle_t h) {
|
||||
return (info == nullptr) ? nullptr : info->name_.c_str();
|
||||
}
|
||||
|
||||
template <typename Flag>
|
||||
void chan_impl<Flag>::clear(ipc::handle_t h) noexcept {
|
||||
disconnect(h);
|
||||
using conn_info_t = typename detail_impl<policy_t<Flag>>::conn_info_t;
|
||||
auto conn_info_p = static_cast<conn_info_t *>(h);
|
||||
if (conn_info_p == nullptr) return;
|
||||
conn_info_p->clear();
|
||||
destroy(h);
|
||||
}
|
||||
|
||||
template <typename Flag>
|
||||
void chan_impl<Flag>::clear_storage(char const * name) noexcept {
|
||||
chan_impl<Flag>::clear_storage({nullptr}, name);
|
||||
}
|
||||
|
||||
template <typename Flag>
|
||||
void chan_impl<Flag>::clear_storage(prefix pref, char const * name) noexcept {
|
||||
using conn_info_t = typename detail_impl<policy_t<Flag>>::conn_info_t;
|
||||
conn_info_t::clear_storage(pref.str, name);
|
||||
}
|
||||
|
||||
template <typename Flag>
|
||||
std::size_t chan_impl<Flag>::recv_count(ipc::handle_t h) {
|
||||
return detail_impl<policy_t<Flag>>::recv_count(h);
|
||||
|
||||
@ -131,6 +131,11 @@ public:
|
||||
return elems_ != nullptr;
|
||||
}
|
||||
|
||||
void clear() noexcept {
|
||||
base_t::clear();
|
||||
elems_ = nullptr;
|
||||
}
|
||||
|
||||
elems_t * elems() noexcept { return elems_; }
|
||||
elems_t const * elems() const noexcept { return elems_; }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user