Compare commits
No commits in common. "de2073422c8294f67429b10c665ea7d695f1a099" and "8d4f540bccbefab128530f80224a6ae02053ef9f" have entirely different histories.
de2073422c
...
8d4f540bcc
19 changed files with 204 additions and 167 deletions
|
|
@ -123,5 +123,5 @@ This library is licensed under the GNU Lesser General Public License version 3.0
|
|||
|
||||
## Copyright
|
||||
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Network
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Thread
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
|
|||
71
project.cpp
71
project.cpp
|
|
@ -1,71 +0,0 @@
|
|||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
||||
constexpr std::array<std::string_view, 6> networkInterfaces = {
|
||||
"interfaces/Crafter.Network",
|
||||
"interfaces/Crafter.Network-ClientTCP",
|
||||
"interfaces/Crafter.Network-ListenerTCP",
|
||||
"interfaces/Crafter.Network-ClientHTTP",
|
||||
"interfaces/Crafter.Network-ListenerHTTP",
|
||||
"interfaces/Crafter.Network-HTTP",
|
||||
};
|
||||
constexpr std::array<std::string_view, 4> networkImplementations = {
|
||||
"implementations/Crafter.Network-ClientTCP",
|
||||
"implementations/Crafter.Network-ListenerTCP",
|
||||
"implementations/Crafter.Network-ClientHTTP",
|
||||
"implementations/Crafter.Network-ListenerHTTP",
|
||||
};
|
||||
|
||||
std::vector<std::string> depArgs(args.begin(), args.end());
|
||||
Configuration* thread = GitProject({
|
||||
.source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Thread.git" },
|
||||
.args = depArgs,
|
||||
});
|
||||
|
||||
Configuration cfg;
|
||||
cfg.path = "./";
|
||||
cfg.name = "Crafter.Network";
|
||||
cfg.outputName = "Crafter.Network";
|
||||
cfg.type = ConfigurationType::LibraryStatic;
|
||||
ApplyStandardArgs(cfg, args);
|
||||
cfg.dependencies = { thread };
|
||||
{
|
||||
std::array<fs::path, 6> ifaces;
|
||||
std::ranges::copy(networkInterfaces, ifaces.begin());
|
||||
std::array<fs::path, 4> impls;
|
||||
std::ranges::copy(networkImplementations, impls.begin());
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
}
|
||||
|
||||
auto addTest = [&](std::string name, fs::path implFile) {
|
||||
Test t;
|
||||
t.config.path = "./";
|
||||
t.config.name = std::move(name);
|
||||
t.config.outputName = t.config.name;
|
||||
t.config.target = cfg.target;
|
||||
t.config.debug = cfg.debug;
|
||||
t.config.march = cfg.march;
|
||||
t.config.mtune = cfg.mtune;
|
||||
t.config.type = ConfigurationType::Executable;
|
||||
t.config.dependencies = { thread };
|
||||
std::array<fs::path, 6> ifaces;
|
||||
std::ranges::copy(networkInterfaces, ifaces.begin());
|
||||
std::array<fs::path, 5> impls;
|
||||
std::ranges::copy(networkImplementations, impls.begin());
|
||||
impls[4] = std::move(implFile);
|
||||
t.config.GetInterfacesAndImplementations(ifaces, impls);
|
||||
cfg.tests.push_back(std::move(t));
|
||||
};
|
||||
|
||||
addTest("ShouldCompile", "tests/ShouldCompile");
|
||||
addTest("ShouldRecieveHTTP", "tests/ShouldRecieveHTTP");
|
||||
addTest("ShouldSendHTTP", "tests/ShouldSendHTTP");
|
||||
addTest("ShouldSendRecieveHTTP", "tests/ShouldSendRecieveHTTP");
|
||||
addTest("ShouldSendRecieveKeepaliveHTTP", "tests/ShouldSendRecieveKeepaliveHTTP");
|
||||
addTest("ShouldSendRecieveLargeHTTP", "tests/ShouldSendRecieveLargeHTTP");
|
||||
|
||||
return cfg;
|
||||
}
|
||||
99
project.json
Normal file
99
project.json
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"name": "crafter-network",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "base",
|
||||
"interfaces": ["interfaces/Crafter.Network-ClientTCP", "interfaces/Crafter.Network-ListenerTCP", "interfaces/Crafter.Network", "interfaces/Crafter.Network-ListenerHTTP", "interfaces/Crafter.Network-ClientHTTP", "interfaces/Crafter.Network-HTTP"],
|
||||
"implementations": ["implementations/Crafter.Network-ClientTCP", "implementations/Crafter.Network-ListenerTCP", "implementations/Crafter.Network-ListenerHTTP", "implementations/Crafter.Network-ClientHTTP"]
|
||||
},
|
||||
{
|
||||
"name": "lib",
|
||||
"extends": ["base"],
|
||||
"type":"library",
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Thread.git",
|
||||
"configuration":"lib"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lib-debug",
|
||||
"extends": ["lib"],
|
||||
"debug": true
|
||||
},
|
||||
{
|
||||
"name": "lib-shared",
|
||||
"extends": ["base"],
|
||||
"type":"shared-library",
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Thread.git",
|
||||
"configuration":"lib-shared"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"tests":[
|
||||
{
|
||||
"name": "should-compile",
|
||||
"implementations": ["tests/ShouldCompile"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"./project.json",
|
||||
"configuration":"lib-shared"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should-recieve-http",
|
||||
"implementations": ["tests/ShouldRecieveHTTP"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"./project.json",
|
||||
"configuration":"lib-shared"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should-send-http",
|
||||
"implementations": ["tests/ShouldSendHTTP"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"./project.json",
|
||||
"configuration":"lib-shared"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should-send-recieve-http",
|
||||
"implementations": ["tests/ShouldSendRecieveHTTP"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"./project.json",
|
||||
"configuration":"lib-shared"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should-send-recieve-keepalive-http",
|
||||
"implementations": ["tests/ShouldSendRecieveKeepaliveHTTP"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"./project.json",
|
||||
"configuration":"lib-shared"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "should-send-recieve-large-http",
|
||||
"implementations": ["tests/ShouldSendRecieveLargeHTTP"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"./project.json",
|
||||
"configuration":"lib-shared"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -20,8 +20,10 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -22,22 +22,23 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
bool success = false;
|
||||
ListenerAsyncHTTP listener(8081, {{"/", [&](const HTTPRequest& request) {
|
||||
ListenerAsyncHTTP listener(8080, {{"/", [&](const HTTPRequest& request) {
|
||||
success = true;
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
system("curl http://localhost:8081 > /dev/null 2>&1");
|
||||
system("curl http://localhost:8080 > /dev/null 2>&1");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (success) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string("Did not receive");
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
return new std::string(e.what());
|
||||
}
|
||||
std::println("Did not receive");
|
||||
return 1;
|
||||
} catch (std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -20,12 +20,14 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
ClientHTTP client("httpbin.org", 80);
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/get", "httpbin.org"));
|
||||
if (response.status == "200 OK") {
|
||||
return 0;
|
||||
if(response.status == "200 OK") {
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string(response.body);
|
||||
}
|
||||
}
|
||||
std::println("{}", response.body);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -22,20 +22,22 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
ListenerAsyncHTTP listener(8082, {{"/", [&](const HTTPRequest& request) {
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
bool success = false;
|
||||
ListenerAsyncHTTP listener(8080, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
ClientHTTP client("localhost", 8082);
|
||||
ClientHTTP client("localhost", 8080);
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
if (response.status == "200 OK" && response.body == "Hello World!") {
|
||||
return 0;
|
||||
if(response.status == "200 OK" && response.body == "Hello World!") {
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string(response.status +response.body);
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
return new std::string(e.what());
|
||||
}
|
||||
std::println("{}{}", response.status, response.body);
|
||||
return 1;
|
||||
} catch (std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -22,27 +22,28 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
ListenerAsyncHTTP listener(8083, {{"/", [&](const HTTPRequest& request) {
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
ListenerAsyncHTTP listener(8080, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
ClientHTTP client("localhost", 8083);
|
||||
ClientHTTP client("localhost", 8080);
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (response.status != "200 OK" || response.body != "Hello World!") {
|
||||
std::println("{}{}", response.status, response.body);
|
||||
return 1;
|
||||
}
|
||||
if(response.status == "200 OK" && response.body == "Hello World!") {
|
||||
response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (response.status != "200 OK" || response.body != "Hello World!") {
|
||||
std::println("{}{}", response.status, response.body);
|
||||
return 1;
|
||||
if(response.status == "200 OK" && response.body == "Hello World!") {
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string(response.status +response.body);
|
||||
}
|
||||
} else {
|
||||
return new std::string(response.status +response.body);
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
return new std::string(e.what());
|
||||
}
|
||||
return 0;
|
||||
} catch (std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -22,8 +22,9 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
ListenerAsyncHTTP listener(8084, {{ "/", [&](const HTTPRequest& request) {
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
ListenerAsyncHTTP listener(8080, {{ "/", [&](const HTTPRequest& request) {
|
||||
if (request.body.size() > 1'000'000) {
|
||||
return CreateResponseHTTP("200 OK", "Large request received: " + std::to_string(request.body.size()) + " bytes");
|
||||
}
|
||||
|
|
@ -32,17 +33,17 @@ int main() {
|
|||
}});
|
||||
|
||||
try {
|
||||
ClientHTTP client("localhost", 8084);
|
||||
ClientHTTP client("localhost", 8080);
|
||||
std::string large_body(10 * 1024 * 1024, 'A');
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("POST", "/", "localhost", large_body));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (response.status == "200 OK" && response.body.find("Large request received") != std::string::npos) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string("Unexpected response: " + response.status + " " + response.body);
|
||||
}
|
||||
std::println("Unexpected response: {} {}", response.status, response.body);
|
||||
return 1;
|
||||
} catch (const std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
return new std::string(e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue