| 77 | |
| 78 | |
| 79 | Try<Nothing> prepare_async(int_fd fd) |
| 80 | { |
| 81 | if (fd.is_overlapped()) { |
| 82 | // TODO(andschwa): Remove this check, see MESOS-9097. |
| 83 | if (!libwinio_loop) { |
| 84 | return Error("Windows IOCP event loop is not initialized"); |
| 85 | } |
| 86 | |
| 87 | return libwinio_loop->registerHandle(fd); |
| 88 | } |
| 89 | |
| 90 | // For non-overlapped fds, we will only error if it's not a disk file, since |
| 91 | // those are "fast" devices, so blocking IO should be okay. This is the same |
| 92 | // as Linux's `O_NONBLOCK`, which doesn't work on regular files. |
| 93 | if (fd.type() == os::WindowsFD::Type::SOCKET) { |
| 94 | return Error("Got a non-overlapped socket"); |
| 95 | } |
| 96 | |
| 97 | DWORD type = ::GetFileType(fd); |
| 98 | if (type != FILE_TYPE_DISK) { |
| 99 | WindowsError error; |
| 100 | return Error(std::string( |
| 101 | "io::prepare_async only accepts disk files for non-overlapped files. " |
| 102 | "Got type: ") + stringify(type) + " with possible error: " + |
| 103 | error.message); |
| 104 | } |
| 105 | |
| 106 | return Nothing(); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | Try<bool> is_async(int_fd fd) |