如何重新启用由另一端关闭的 istream FIFO
How to re-enable an istream FIFO closed by the other end?
我正在使用istream
通过FIFO接收数据。一旦另一端关闭它,尽管我清除了eof
位,但我无法再次做好准备。badbit
总是在那里。
如何在阅读模式下重新启用我的先进先出?
这是我的代码片段:
std::istream &os;
// ...
try {
os.get(tmp, length+1);
}
catch(std::exception const& e)
{
std::cerr << "exception failure caught: " << e.what() << 'n';
}
if ((os.rdstate() & std::ios_base::eofbit) > 0) {
os.clear();
os.seekg(0, std::ios::beg);
}
解决方案最终是将 std::ifstream 替换为 std::filebuf,并在 istream 不再可用时关闭 filebuf
std::filebuf fb;
while (1==1)
{
if fb.open(myfifo, std::ios::binary|std::ios::in)
{
std::istream infifo(&fb);
while (infifo)
{
infifo >> *tmp;
// do your job
}
fb.close();
}
相关文章:
- 为什么istream不支持右值提取
- 将无符号char*转换为std::istream*C++
- 需要从 istream 和 ostream 派生 iostream
- 使用std::istream::peek()总是安全的吗
- 即使我读取了所有内容,在FIFO上打开的QSocketNotifier也会一直启动
- 使用 istream 参数读取的 istream 函数
- istream std::cin如何修改自定义istream缓冲区
- 为什么我在使用 istream 迭代器时会出现 seg 错误?
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- 在清除 istream 之前,我不应该需要取消获取它吗?
- C++,如何根据运行时条件构造引用不同 istream 对象的对象?
- RAII 等效于 FIFO 发布订单
- 如何将QByteArray转换为std::istream或std::ifstream?
- 逗号在重载 ostream 和 istream 在结构中分开
- 为什么 Clang std::ostream 写一个 std::istream 无法读取的双精度?
- 使用堆的优先级队列,具有相同键的值不遵循 FIFO(先进先出)
- 从函数返回 istream 的正确方法
- 阅读从 istream 到矢量的不同类型列表
- 关于 istream 中的错误处理的问题
- 如何重新启用由另一端关闭的 istream FIFO