4#include "../AsyncStreams/AsyncRequestStreams.h"
5#include "HttpConnection.h"
12template <
typename Base,
typename Derived>
15 static constexpr bool value = __is_base_of(Base, Derived);
25 size_t readQueueSize = 3;
26 size_t writeQueueSize = 3;
27 size_t buffersQueueSize = 6;
28 size_t headerBytesLength = 8 * 1024;
29 size_t streamBytesLength = 512 * 1024;
49template <
int ReadQueue,
int WriteQueue,
int HeaderBytes,
int StreamBytes>
56 char headerStorage[HeaderBytes];
57 char streamStorage[StreamBytes];
61 constexpr const size_t NumSlices = ReadQueue;
62 constexpr const size_t SliceLength = StreamBytes / NumSlices;
65 for (
size_t idx = 0; idx < NumSlices; ++idx)
72 HttpConnection::setHeaderMemory(headerStorage);
73 HttpConnection::buffersPool.setBuffers(buffers);
74 readableSocketStream.setReadQueue(readQueue);
75 writableSocketStream.setWriteQueue(writeQueue);
98 return initInternal({clients.data(), clients.sizeInElements(),
sizeof(T)});
101 template <
typename T,
105 return resizeInternal({clients.data(), clients.sizeInElements(),
sizeof(T)});
124 [[nodiscard]]
bool isStarted()
const {
return started; }
136 bool started =
false;
137 bool stopping =
false;
139 void onNewClient(AsyncSocketAccept::Result& result);
143 Result waitForStopToFinish();
unsigned short uint16_t
Platform independent (2) bytes unsigned int.
Definition PrimitiveTypes.h:37
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38
struct SC_COMPILER_EXPORT Function
Wraps function pointers, member functions and lambdas without ever allocating.
Definition Function.h:19
Definition AsyncStreams.h:52
A Span of bytes memory to be read or written by async streams.
Definition AsyncStreams.h:50
void setReusable(bool reusable)
Tags this AsyncBufferView as reusable after its refCount goes to zero.
Definition AsyncStreams.h:75
Asynchronous I/O (files, sockets, timers, processes, fs events, threads wake-up) (see Async) AsyncEve...
Definition Async.h:1195
Definition AsyncStreams.h:189
Starts a socket accept operation, obtaining a new socket from a listening socket.
Definition Async.h:466
Definition AsyncStreams.h:289
Definition HttpAsyncServer.h:24
Definition HttpAsyncServer.h:33
Contains fields used by HttpAsyncServer for each connection.
Definition HttpAsyncServer.h:22
Adds compile-time configurable read and write queues to HttpAsyncConnectionBase.
Definition HttpAsyncServer.h:51
Async Http Server.
Definition HttpAsyncServer.h:92
Result start(AsyncEventLoop &loop, StringSpan address, uint16_t port)
Starts the http server on the given AsyncEventLoop, address and port.
Result stop()
Stops http server asynchronously pushing cancel and close requests to the event loop.
Result init(Span< T > clients)
Initializes the async server with all needed memory buffers.
Definition HttpAsyncServer.h:96
Function< void(HttpConnection &)> onRequest
Called after enough data from a newly connected client has arrived, causing all headers to be parsed.
Definition HttpAsyncServer.h:129
bool isStarted() const
Returns true if the server has been started.
Definition HttpAsyncServer.h:124
Result close()
Closes the server, removing references to the memory buffers passed during init.
Http connection abstraction holding both the incoming and outgoing messages in an HTTP transaction.
Definition HttpConnection.h:100
A pool of HttpConnection that can be active or inactive.
Definition HttpConnection.h:189
Uses an SC::AsyncFileWrite to stream data from a socket.
Definition AsyncRequestStreams.h:74
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:13
Low-level OS socket handle.
Definition Socket.h:153
View over a contiguous sequence of items with a custom stride between elements.
Definition HttpConnection.h:145
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
constexpr bool sliceStartLength(SizeType offsetInElements, SizeType lengthInElements, Span &destination) const
Creates another Span, starting at an offset in elements from current Span of specified length.
Definition Span.h:121
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37
EnableIf conditionally defines a type if a boolean template parameter is true.
Definition TypeTraits.h:25
IsBaseOf evaluates to true if the type Base is a base class of Derived, false otherwise.
Definition HttpAsyncServer.h:14
Uses an SC::AsyncFileWrite to stream data to a socket.
Definition AsyncRequestStreams.h:80