MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / open

Method open

Libraries/Async/Async.cpp:706–727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

704}
705
706SC::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
729SC::Result SC::AsyncFileSystemOperation::close(AsyncEventLoop& eventLoop, FileDescriptor::Handle handle)
730{

Callers 1

await_suspendMethod · 0.45

Calls 6

PlacementNewClass · 0.85
ErrorEnum · 0.50
startMethod · 0.45
getMethod · 0.45
detachMethod · 0.45

Tested by

no test coverage detected