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

Method putFile

Libraries/Http/HttpAsyncFileServer.cpp:335–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333}
334
335Result HttpAsyncFileServer::putFile(HttpAsyncFileServer::Stream& stream, HttpConnection& connection,
336 StringSpan filePath)
337{
338 StringPath path;
339 SC_TRY(path.assign(directory.view()));
340 SC_TRY(path.append("/"));
341 SC_TRY(path.append(filePath));
342 const size_t totalFileUploadBytes = static_cast<size_t>(connection.request.getBodyBytesRemaining());
343 FileDescriptor fd;
344 SC_TRY(fd.open(path.view(), FileOpen::Write));
345 if (totalFileUploadBytes == 0)
346 {
347 SC_TRY(fd.close());
348 return connection.response.sendEmpty(201);
349 }
350
351 SC_TRY(stream.writableFileStream.init(connection.buffersPool, *eventLoop, fd));
352 SC_TRY(stream.writableFileStream.request.executeOn(stream.writableFileStreamTask, *threadPool));
353 fd.detach();
354 stream.writableFileStream.setAutoCloseDescriptor(true);
355
356 HttpConnection& asyncConnection = static_cast<HttpConnection&>(connection);
357
358 stream.putFileListener.connection = &asyncConnection;
359 const bool addedFinishListener =
360 stream.writableFileStream.eventFinish.addListener<HttpAsyncFileServer::Stream::PutFileListener,
361 &HttpAsyncFileServer::Stream::PutFileListener::onFinish>(
362 stream.putFileListener);
363 SC_HTTP_ASSERT_RELEASE(addedFinishListener);
364
365 connection.pipeline.source = &connection.request.getReadableStream();
366 connection.pipeline.sinks[0] = &stream.writableFileStream;
367 SC_TRY(connection.pipeline.pipe());
368 SC_TRY(connection.pipeline.start());
369 return Result(true);
370}
371
372void HttpAsyncFileServer::Stream::PutFileListener::onFinish()
373{

Callers

nothing calls this directly

Calls 13

sendEmptyMethod · 0.80
executeOnMethod · 0.80
ResultClass · 0.50
assignMethod · 0.45
viewMethod · 0.45
appendMethod · 0.45
openMethod · 0.45
closeMethod · 0.45
initMethod · 0.45
detachMethod · 0.45
pipeMethod · 0.45

Tested by

no test coverage detected