小编Shu*_*ump的帖子

防止FIFO关闭/重用关闭的FIFO

请考虑以下情形:

test创建一个名为FIFO的FIFO .在一个终端窗口(A)中,我运行cat <test并在另一个终端窗口(B)中运行cat >test.现在可以在窗口B中写入并在窗口A中获得输出.也可以终止进程A并重新启动它,并且仍然可以使用此设置作为可疑的.但是,如果你在窗口B中终止进程,B将(据我所知)通过FIFO发送一个EOF来处理A并终止它.

实际上,如果您运行的进程不会终止于EOF,您仍然无法使用重定向到进程的FIFO.我认为这是因为这个FIFO被认为是封闭的.

反正有办法解决这个问题吗?

我遇到这个问题的原因是因为我想将命令发送到在屏幕会话中运行的我的Minecraft服务器.例如:echo "command" >FIFO_to_server.这可以通过单独使用屏幕来实现,但我对屏幕不太满意我认为仅使用管道的解决方案将更简单,更清洁.

unix named-pipes fifo eof

17
推荐指数
2
解决办法
7744
查看次数

迭代来自std :: tuple向量的选定向量

我正在尝试在C++ 11/14中静态实现实体组件系统模式.我已经设法为我的实体创建一个容器,我正在尝试添加功能来处理里面的数据.这是我到目前为止的代码:

template<typename... Components>
struct Entity {
  std::tuple<Components...> comps;

  Entity() = default;
  Entity(Components... cs) {
    comps = std::make_tuple(cs...);
  };
};

template<typename... EntityTypes>
struct EntityCollection {
  std::tuple<std::vector<EntityTypes>...> entities;

  template<typename EntityType>
  void add(EntityType e) {
    auto& cont = std::get<std::vector<EntityType>>(entities);
    cont.push_back(e);
  };

  template<typename... Components, typename F>
  void for_each_containing(F f) {
     // todo... apply f on all entities for which 'Components' 
     // are a subset of those in the entity.
  };

};
Run Code Online (Sandbox Code Playgroud)

我已经看到使用boost fusion(和stl适配器)和通用lambdas循环遍历元组中所有元素的代码:

// inside entity class
void update() {
  for_each(comps, [](auto& c) …
Run Code Online (Sandbox Code Playgroud)

c++ boost template-meta-programming c++14

3
推荐指数
1
解决办法
648
查看次数

标签 统计

boost ×1

c++ ×1

c++14 ×1

eof ×1

fifo ×1

named-pipes ×1

template-meta-programming ×1

unix ×1