stdin/stdout/stderr上的跨平台(linux/Win32)非阻塞C ++ IO [英] Cross-platform (linux/Win32) nonblocking C++ IO on stdin/stdout/stderr

查看:99
本文介绍了stdin/stdout/stderr上的跨平台(linux/Win32)非阻塞C ++ IO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过具有以下特征的stdin/stdout找到最佳的非阻塞IO解决方案:

I'm trying to find the best solution for nonblocking IO via stdin/stdout with the following characteristics:

  • 只要有足够的数据,就读取 n 个大小的块.
  • 如果没有足够的数据,则读取部分数据块.
  • 如果没有可用数据,请阻塞直到有一些数据为止(即使它可能小于 n ).
  • As long as there is enough data, read in n-sized chunks.
  • If there's not enough data, read in a partial chunk.
  • If there is no data available, block until there is some (even though it may be smaller than n).

目标是允许在处理控制"代码时立即有效地传输大型数据集(而不是让它们停留在某个部分填充的缓冲区中的某个地方).

The goal is to allow efficient transfer for large datasets while processing 'control' codes immediately (instead of having them linger in some partially-filled buffer somewhere).

我知道我可以通过使用线程和istream :: get()循环或编写一堆特定于平台的代码(因为您无法在Windows的文件句柄上选择())来实现这一点... (((还有istream :: readsome()看起来很有希望,但我在Google上发现的唯一结果是人们说它实际上不能很好地工作.))

I know I can achieve this by using threads and a istream::get() loop, or by writing a bunch of platform-specific code (since you can't select() on file handles in windows)... ((There is also istream::readsome() which seems promising, but the only results I can find on google were of people saying it doesn't actually work well.))

由于我没有使用这些API进行过多的编码,因此也许有更好的方法.

Since I haven't done much coding w/ these APIs, perhaps there is a better way.

推荐答案

也许 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆