Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
HttpAsyncFileServer.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../AsyncStreams/AsyncRequestStreams.h"
5#include "HttpAsyncServer.h"
6
7namespace SC
8{
10struct SC_COMPILER_EXPORT HttpAsyncFileServerStream
11{
12 AsyncPipeline pipeline;
13 ReadableFileStream readableFileStream;
14 AsyncTaskSequence readStreamTask;
15
17};
18
24struct SC_COMPILER_EXPORT HttpAsyncFileServer
25{
27 Result init(StringSpan directoryToServe, Span<HttpAsyncFileServerStream> fileStreams, AsyncBuffersPool& buffersPool,
28 AsyncEventLoop& eventLoop, ThreadPool& threadPool);
29
33
36
37 private:
38 StringPath directory;
39
41
42 AsyncBuffersPool* buffersPool = nullptr;
43 AsyncEventLoop* eventLoop = nullptr;
44 ThreadPool* threadPool;
45 struct Internal;
46};
47} // namespace SC
Holds a Span of AsyncBufferView (allocated by user) holding available memory for the streams.
Definition AsyncStreams.h:140
Asynchronous I/O (files, sockets, timers, processes, fs events, threads wake-up) (see Async) AsyncEve...
Definition Async.h:1195
Pipes read data from SC::AsyncReadableStream, forwarding them to SC::AsyncWritableStream.
Definition AsyncStreams.h:408
Definition AsyncStreams.h:179
An AsyncSequence using a SC::ThreadPool to execute one or more SC::AsyncRequest in a background threa...
Definition Async.h:925
Support class for HttpAsyncFileServer holding file stream and pipeline.
Definition HttpAsyncFileServer.h:11
Http file server statically serves files from a directory.
Definition HttpAsyncFileServer.h:25
Result init(StringSpan directoryToServe, Span< HttpAsyncFileServerStream > fileStreams, AsyncBuffersPool &buffersPool, AsyncEventLoop &eventLoop, ThreadPool &threadPool)
Initialize the web server on the given file system directory to serve.
Result serveFile(HttpConnection::ID index, StringSpan url, HttpResponse &response)
Serve the file requested by this Http Client on its channel Call this method in response to HttpConne...
void registerToServeFilesOn(HttpAsyncServer &server)
Registers to HttpConnectionsPool::onRequest callback to serve files from this file server.
Async Http Server.
Definition HttpAsyncServer.h:20
Definition HttpConnection.h:106
Outgoing message from the perspective of the participants of an HTTP transaction.
Definition HttpConnection.h:66
Uses an SC::AsyncFileRead to stream data from a file.
Definition AsyncRequestStreams.h:63
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:13
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
Pre-sized char array holding enough space to represent a file system path.
Definition StringPath.h:42
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37
Simple thread pool that executes tasks in a fixed number of worker threads.
Definition ThreadPool.h:38