| 704 | } |
| 705 | |
| 706 | SC::Result SC::AsyncFileSystemOperation::open(AsyncEventLoop& eventLoop, StringSpan path, FileOpen mode) |
| 707 | { |
| 708 | SC_TRY(checkState()); |
| 709 | operation = Operation::Open; |
| 710 | new (&openData, PlacementNew()) OpenData({path, mode}); |
| 711 | SC_TRY(validate(eventLoop)); |
| 712 | if (not eventLoop.needsThreadPoolForFileOperations() and threadPoolMode != AsyncThreadPoolMode::ForceThreadPool) |
| 713 | { |
| 714 | return eventLoop.start(*this); |
| 715 | } |
| 716 | |
| 717 | loopWork.work = [&]() |
| 718 | { |
| 719 | FileDescriptor fd; |
| 720 | SC_TRY(fd.open(openData.path, openData.mode)); |
| 721 | auto res = fd.get(completionData.handle, SC::Result::Error("Open returned invalid handle")); |
| 722 | fd.detach(); // Detach the file descriptor from the loop work so that it is not closed when the callback ends |
| 723 | return res; |
| 724 | }; |
| 725 | loopWork.callback.bind<AsyncFileSystemOperation, &AsyncFileSystemOperation::onOperationCompleted>(*this); |
| 726 | return eventLoop.start(loopWork); |
| 727 | } |
| 728 | |
| 729 | SC::Result SC::AsyncFileSystemOperation::close(AsyncEventLoop& eventLoop, FileDescriptor::Handle handle) |
| 730 | { |
no test coverage detected