Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
HttpAsyncServer.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "HttpServer.h"
5namespace SC
6{
7#if SC_COMPILER_MSVC
8#pragma warning(push)
9#pragma warning(disable : 4251)
10#endif
11struct SC_COMPILER_EXPORT HttpAsyncServer
12{
20
23
26
28 [[nodiscard]] bool isStarted() const { return started; }
29
32 Span<AsyncBufferView> buffers);
33
36
37 private:
38 AsyncBuffersPool buffersPool;
39
42
43 bool started = false;
44 bool stopping = false;
45
46 void onNewClient(AsyncSocketAccept::Result& result);
47 void closeAsync(HttpServerClient& requestClient);
48
49 void onStreamReceive(HttpServerClient& client, AsyncBufferView::ID bufferID);
50
51 AsyncEventLoop* eventLoop = nullptr;
52 SocketDescriptor serverSocket;
53 AsyncSocketAccept asyncServerAccept;
54};
55#if SC_COMPILER_MSVC
56#pragma warning(pop)
57#endif
58} // namespace SC
unsigned short uint16_t
Platform independent (2) bytes unsigned int.
Definition PrimitiveTypes.h:37
Definition AsyncStreams.h:51
Holds a Span of AsyncBufferView (allocated by user) holding available memory for the streams.
Definition AsyncStreams.h:139
Asynchronous I/O (files, sockets, timers, processes, fs events, threads wake-up) (see Async) AsyncEve...
Definition Async.h:1198
Starts a socket accept operation, obtaining a new socket from a listening socket.
Definition Async.h:469
Definition HttpAsyncServer.h:12
Result start(AsyncEventLoop &loop, StringSpan address, uint16_t port, HttpServer::Memory &memory)
Starts the http server on the given AsyncEventLoop, address and port.
bool isStarted() const
Returns true if the server has been started.
Definition HttpAsyncServer.h:28
void setupStreamsMemory(Span< AsyncReadableStream::Request > readQueue, Span< AsyncWritableStream::Request > writeQueue, Span< AsyncBufferView > buffers)
Enables using AsyncStreams instead of raw Async Send and Receive.
HttpServer httpServer
The underlying http server.
Definition HttpAsyncServer.h:35
Result stopAsync()
Stops http server asynchronously pushing cancel and close requests for next SC::AsyncEventLoop::runOn...
Result stopSync()
Stops http server synchronously waiting for SC::AsyncEventLoop::runNoWait to cancel or close all requ...
Definition HttpServer.h:108
Definition HttpServer.h:155
Async Http server.
Definition HttpServer.h:153
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
Low-level OS socket handle.
Definition Socket.h:153
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37