-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8541e67
commit 844b044
Showing
8 changed files
with
2,623 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: C++20 | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
modules: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Checkout Drogon source code | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
fetch-depth: 0 | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt update | ||
sudo apt-get install -y cmake ninja-build clang | ||
sudo apt-get install -y libjsoncpp-dev uuid-dev libssl-dev zlib1g-dev libsqlite3-dev | ||
sudo apt-get install -y ninja-build libbrotli-dev | ||
cmake --version | ||
ninja --version | ||
clang++ --version | ||
- name: Clang Build Modules | ||
run: | | ||
mkdir build && cd build && pwd | ||
CC=clang CXX=clang++ cmake .. \ | ||
-DCMAKE_CXX_STANDARD=20 \ | ||
-GNinja \ | ||
-DDROGON_BUILD_MODULES=ON \ | ||
-DDROGON_BUILD_MODULES_EXAMPLE=ON \ | ||
-DBUILD_TESTING=OFF | ||
ninja -j 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.28) | ||
|
||
project(modules_example) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
# Default to C++ extensions being off. Clang's modules support have trouble | ||
# with extensions right now. | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
find_package(jsoncpp REQUIRED) | ||
find_package(OpenSSL REQUIRED) | ||
# set(CMAKE_PREFIX_PATH /root/github/drogon/build/nqf/lib/cmake/Drogon;/root/github/drogon/build/nqf/lib/cmake/Trantor) | ||
# find_package(Drogon REQUIRED) | ||
|
||
add_executable(module_client module_client.cpp) | ||
target_link_libraries(module_client drogon OpenSSL::SSL OpenSSL::Crypto uuid pthread dl) | ||
|
||
add_executable(module_std module_std.cpp) | ||
target_link_libraries(module_std PUBLIC drogon OpenSSL::SSL OpenSSL::Crypto uuid pthread dl) | ||
|
||
add_executable(module_server module_server.cpp) | ||
target_link_libraries(module_server PUBLIC drogon OpenSSL::SSL OpenSSL::Crypto uuid pthread dl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import drogon; | ||
import std; | ||
|
||
#include <trantor/utils/Logger.h> | ||
|
||
#ifdef __linux__ | ||
#include <sys/socket.h> | ||
#include <netinet/tcp.h> | ||
#endif | ||
|
||
using namespace drogon; | ||
|
||
int nth_resp = 0; | ||
|
||
int main() | ||
{ | ||
trantor::Logger::setLogLevel(trantor::Logger::kTrace); | ||
{ | ||
auto client = HttpClient::newHttpClient("http://www.baidu.com"); | ||
client->setSockOptCallback([](int fd) { | ||
std::cout << "setSockOptCallback:" << fd << std::endl; | ||
#ifdef __linux__ | ||
int optval = 10; | ||
::setsockopt(fd, | ||
SOL_TCP, | ||
TCP_KEEPCNT, | ||
&optval, | ||
static_cast<socklen_t>(sizeof optval)); | ||
::setsockopt(fd, | ||
SOL_TCP, | ||
TCP_KEEPIDLE, | ||
&optval, | ||
static_cast<socklen_t>(sizeof optval)); | ||
::setsockopt(fd, | ||
SOL_TCP, | ||
TCP_KEEPINTVL, | ||
&optval, | ||
static_cast<socklen_t>(sizeof optval)); | ||
#endif | ||
}); | ||
|
||
auto req = HttpRequest::newHttpRequest(); | ||
req->setMethod(drogon::Get); | ||
req->setPath("/s"); | ||
req->setParameter("wd", "wx"); | ||
req->setParameter("oq", "wx"); | ||
|
||
for (int i = 0; i < 10; ++i) | ||
{ | ||
client->sendRequest( | ||
req, [](ReqResult result, const HttpResponsePtr &response) { | ||
if (result != ReqResult::Ok) | ||
{ | ||
std::cout | ||
<< "error while sending request to server! result: " | ||
<< result << std::endl; | ||
return; | ||
} | ||
|
||
std::cout << "receive response!" << std::endl; | ||
// auto headers=response. | ||
++nth_resp; | ||
std::cout << response->getBody() << std::endl; | ||
auto cookies = response->cookies(); | ||
for (auto const &cookie : cookies) | ||
{ | ||
std::cout << cookie.first << "=" | ||
<< cookie.second.value() | ||
<< ":domain=" << cookie.second.domain() | ||
<< std::endl; | ||
} | ||
std::cout << "count=" << nth_resp << std::endl; | ||
}); | ||
} | ||
std::cout << "requestsBufferSize:" << client->requestsBufferSize() | ||
<< std::endl; | ||
} | ||
|
||
app().run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import drogon; | ||
import std; | ||
|
||
#include <trantor/utils/Logger.h> | ||
|
||
using namespace drogon; | ||
|
||
int main() | ||
{ | ||
trantor::Logger::setLogLevel(trantor::Logger::kTrace); | ||
app().registerHandler( | ||
"/", | ||
[](const HttpRequestPtr &request, | ||
std::function<void(const HttpResponsePtr &)> &&callback) { | ||
LOG_INFO << "connected:" | ||
<< (request->connected() ? "true" : "false"); | ||
auto resp = HttpResponse::newHttpResponse(); | ||
resp->setBody("Hello, World!"); | ||
callback(resp); | ||
}, | ||
{Get}); | ||
|
||
LOG_INFO << "Server running on 127.0.0.1:8848"; | ||
app().addListener("127.0.0.1", 8848).run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import std; | ||
|
||
int main() | ||
{ | ||
std::cout << "hello world" << std::endl; | ||
|
||
std::vector<std::string> vec; | ||
vec.emplace_back("hello world"); | ||
std::cout << vec.size() << std::endl; | ||
|
||
std::unordered_map<int, int> mp; | ||
mp.emplace(1, 2); | ||
std::cout << mp.size() << std::endl; | ||
|
||
auto it = | ||
std::ranges::find_if(vec, [](auto &&p) { return p == "hello world"; }); | ||
if (it != vec.end()) | ||
{ | ||
std::cout << "found" << std::endl; | ||
} | ||
|
||
std::unordered_set<int> s; | ||
s.insert(100); | ||
std::cout << s.size() << std::endl; | ||
|
||
std::shared_ptr<std::string> ptr_1; | ||
std::unique_ptr<std::string> ptr_2; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module; | ||
|
||
#include <drogon/drogon.h> | ||
#include <drogon/HttpSimpleController.h> | ||
#include <drogon/WebSocketClient.h> | ||
#include <drogon/WebSocketController.h> | ||
#include <drogon/PubSubService.h> | ||
#include <drogon/orm/Mapper.h> | ||
|
||
export module drogon; | ||
|
||
export namespace drogon | ||
{ | ||
|
||
using drogon::HttpClient; | ||
using drogon::HttpRequest; | ||
using drogon::HttpRequestPtr; | ||
using drogon::HttpResponse; | ||
using drogon::HttpResponsePtr; | ||
using drogon::MultiPartParser; | ||
using drogon::RequestStreamPtr; | ||
using drogon::ResponseStream; | ||
using drogon::ResponseStreamPtr; | ||
|
||
using drogon::ContentType; | ||
using drogon::HttpMethod; | ||
using drogon::HttpStatusCode; | ||
using drogon::ReqResult; | ||
using drogon::to_string; | ||
using drogon::to_string_view; | ||
using drogon::operator<<; | ||
using drogon::Version; | ||
using drogon::WebSocketMessageType; | ||
|
||
using drogon::HttpSimpleController; | ||
using drogon::HttpViewData; | ||
|
||
using drogon::PubSubService; | ||
using drogon::WebSocketClient; | ||
using drogon::WebSocketClientPtr; | ||
using drogon::WebSocketConnectionPtr; | ||
using drogon::WebSocketController; | ||
|
||
using drogon::app; | ||
|
||
using drogon::nosql::RedisClient; | ||
using drogon::nosql::RedisTransactionPtr; | ||
|
||
using drogon::orm::ConstRowIterator; | ||
using drogon::orm::DbClient; | ||
using drogon::orm::DrogonDbException; | ||
using drogon::orm::Field; | ||
using drogon::orm::Mapper; | ||
using drogon::orm::Result; | ||
|
||
} // namespace drogon |
Oops, something went wrong.