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

Function copyThenSend

Examples/AwaitFileCourier/AwaitFileCourier.cpp:70–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70static AwaitTask copyThenSend(AwaitEventLoop& await, ThreadPool& threadPool, StringSpan sourcePath, StringSpan copyPath,
71 SocketDescriptor& sender, SocketDescriptor& receiver, Span<char> receiveBuffer,
72 AwaitSocketReceiveResult& received)
73{
74 SC_CO_TRY(co_await await.fsCopyFile(threadPool, sourcePath, copyPath));
75
76 FileDescriptor copiedFile;
77 SC_CO_TRY(co_await await.fsOpen(threadPool, copyPath, FileOpen::Read, copiedFile));
78
79 AwaitFileSendOptions sendOptions;
80 sendOptions.threadPool = &threadPool;
81 sendOptions.length = receiveBuffer.sizeInBytes();
82
83 AwaitFileSendResult sendResult;
84 SC_CO_TRY(co_await await.fileSend(copiedFile, sender, sendResult, sendOptions));
85 SC_CO_TRY(co_await await.fsClose(threadPool, copiedFile));
86
87 if (not sendResult.complete or sendResult.bytesTransferred != receiveBuffer.sizeInBytes())
88 {
89 co_return Result::Error("AwaitFileCourier incomplete fileSend");
90 }
91
92 SC_CO_TRY(co_await await.receiveExact(receiver, receiveBuffer, &received));
93 co_return Result(true);
94}
95
96static Result runAwaitFileCourier()
97{

Callers 1

runAwaitFileCourierFunction · 0.85

Calls 8

fsCopyFileMethod · 0.80
fsOpenMethod · 0.80
fsCloseMethod · 0.80
receiveExactMethod · 0.80
ErrorEnum · 0.50
ResultClass · 0.50
sizeInBytesMethod · 0.45
fileSendMethod · 0.45

Tested by

no test coverage detected