chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.98k stars 1.22k forks source link

Inconsistent Return of readable_pipe on Windows #1442

Open manipuladordedados opened 8 months ago

manipuladordedados commented 8 months ago

Currently, on Windows, readable_pipe returns ERROR_BROKEN_PIPE instead of error::misc_errors::eof. This behavior is inconsistent with other platforms.

phprus commented 8 months ago

Could you provide a code sample with this error?

manipuladordedados commented 8 months ago

Could you provide a code sample with this error?

int main()
{
  asio::io_context ioc;
  asio::readable_pipe pipei{ioc};
  asio::writable_pipe pipeo{ioc};

  asio::connect_pipe(pipei, pipeo);

  pipeo.write_some(asio::buffer(".", 1));
  pipeo.close();

  char buf[1];
  pipei.read_some(asio::buffer(buf));
  std::cout << buf[0] << std::endl;

  try {
    pipei.read_some(asio::buffer(buf));
  } catch (const std::exception& e) {
    std::cout << e.what() << std::endl;
  }
}