Skip to content

Commit 81bc923

Browse files
committed
Http: Remove dependency on Containers library
1 parent 6f3ad88 commit 81bc923

File tree

10 files changed

+188
-204
lines changed

10 files changed

+188
-204
lines changed

Documentation/Libraries/Http.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
[SaneCppHttp.h](https://github.com/Pagghiu/SaneCppLibraries/releases/latest/download/SaneCppHttp.h) is a library implementing a hand-written http 1.1 parser, client and server.
88

99
# Dependencies
10-
- Dependencies: [Async](@ref library_async), [Containers](@ref library_containers)
11-
- All dependencies: [Async](@ref library_async), [Containers](@ref library_containers), [File](@ref library_file), [FileSystem](@ref library_file_system), [Foundation](@ref library_foundation), [Memory](@ref library_memory), [Socket](@ref library_socket), [Threading](@ref library_threading)
10+
- Dependencies: [Async](@ref library_async), [Memory](@ref library_memory)
11+
- All dependencies: [Async](@ref library_async), [File](@ref library_file), [FileSystem](@ref library_file_system), [Foundation](@ref library_foundation), [Memory](@ref library_memory), [Socket](@ref library_socket), [Threading](@ref library_threading)
1212

1313
![Dependency Graph](Http.svg)
1414

@@ -21,12 +21,13 @@
2121
# Status
2222
🟥 Draft
2323
In current state the library is able to host simple static website but it cannot be used for any internet facing application.
24+
Additionally its API will be changing heavily as it's undergoing major re-design to make it fully allocation free and extend it to support more of the HTTP 1.1 standard.
2425

2526
# Description
2627
The HTTP parser is an incremental parser, that will emit events as soon as a valid element has been successfully parsed.
2728
This allows handling incomplete responses without needing holding it entirely in memory.
2829

29-
The HTTP client and server are for now just some basic implementations and are missing some important feature.
30+
The HTTP client and server are for now just some basic implementations and are missing many important features.
3031

3132
# Videos
3233

Examples/SCExample/Examples/WebServerExample/WebServerExample.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ struct WebServerExampleViewState;
3535
struct SC::WebServerExampleModelState
3636
{
3737
String directory;
38-
String interface = "127.0.0.1";
39-
int32_t port = 8090;
40-
int32_t maxConcurrentRequests = 16;
38+
String interface = "127.0.0.1";
39+
int32_t port = 8090;
40+
int32_t maxClients = 32;
4141
};
4242

4343
SC_REFLECT_STRUCT_VISIT(SC::WebServerExampleModelState)
4444
SC_REFLECT_STRUCT_FIELD(0, directory)
4545
SC_REFLECT_STRUCT_FIELD(1, interface)
4646
SC_REFLECT_STRUCT_FIELD(2, port)
47-
SC_REFLECT_STRUCT_FIELD(3, maxConcurrentRequests)
47+
SC_REFLECT_STRUCT_FIELD(3, maxClients)
4848
SC_REFLECT_STRUCT_LEAVE()
4949

5050
struct SC::WebServerExampleViewState
@@ -66,11 +66,18 @@ struct SC::WebServerExampleModel
6666
HttpServer httpServer;
6767
HttpWebServer httpWebServer;
6868

69+
Span<HttpServerClient> clients;
70+
6971
Result start()
7072
{
73+
const size_t numClients = static_cast<size_t>(modelState.maxClients);
74+
75+
clients = {new HttpServerClient[numClients], numClients};
76+
HttpServer::Memory memory;
77+
memory.clients = clients;
7178
httpServer.onRequest.bind<HttpWebServer, &HttpWebServer::serveFile>(httpWebServer);
72-
SC_TRY(httpServer.start(*eventLoop, static_cast<uint32_t>(modelState.maxConcurrentRequests),
73-
modelState.interface.view(), static_cast<uint16_t>(modelState.port)));
79+
SC_TRY(
80+
httpServer.start(*eventLoop, modelState.interface.view(), static_cast<uint16_t>(modelState.port), memory));
7481
SC_TRY(httpWebServer.init(modelState.directory.view()));
7582
return Result(true);
7683
}
@@ -79,6 +86,8 @@ struct SC::WebServerExampleModel
7986
{
8087
SC_TRY(httpWebServer.stopAsync());
8188
SC_TRY(httpServer.stopSync());
89+
delete[] clients.data();
90+
clients = {};
8291
return Result(true);
8392
}
8493

Examples/SCExample/SCExample.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Libraries/Memory/Globals.h"
99
#include "Libraries/Memory/String.h"
1010
#include "Libraries/Socket/Socket.h"
11+
#include "Libraries/Strings/Console.h"
1112
#include "Libraries/Strings/StringBuilder.h"
1213
#include "Libraries/Time/Time.h"
1314
#include "SCExampleSokol.h"
@@ -237,10 +238,14 @@ SC::ApplicationSystem* gModelSystem = nullptr;
237238
SC::ApplicationViewState gViewState;
238239

239240
static sg_pass_action gGlobalPassAction;
241+
SC::Console* globalConsole;
240242

241243
sapp_desc sokol_main(int, char*[])
242244
{
243245
using namespace SC;
246+
Console console;
247+
globalConsole = &console;
248+
244249
Globals::init(Globals::Global);
245250
sapp_desc desc = {};
246251

Libraries/Http/HttpClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: MIT
33
#pragma once
44
#include "../Async/Async.h"
5-
#include "../Containers/Vector.h"
65
#include "../Foundation/StringSpan.h"
76
#include "../Memory/String.h"
87
#include "../Socket/Socket.h"

0 commit comments

Comments
 (0)