move build system to cmake

This commit is contained in:
Nicholas Orlowsky 2024-05-10 06:09:40 -05:00
parent c31db4d2a8
commit 734e37de37
Signed by: nickorlow
GPG key ID: 838827D8C4611687
4 changed files with 21 additions and 53 deletions

View file

@ -1,8 +1,10 @@
FROM alpine as build-env
RUN apk add --no-cache build-base python3
RUN apk add --no-cache build-base python3 cmake
COPY ./src/ .
RUN make build-release
RUN rm -rf CMakeCache.txt CMakeFiles
RUN cmake -DCMAKE_BUILD_TYPE=Release .
RUN make anthracite-bin
FROM alpine
RUN apk add --no-cache build-base

View file

@ -1,34 +0,0 @@
.PHONY: format lint build build-release build-docker run debug
build-supplemental:
cd ./build && ./version.sh && python3 ./error_gen.py
build: build-supplemental
g++ main.cpp --std=c++20 -g -o ./anthracite
build-release: build-supplemental
g++ main.cpp --std=c++20 -O3 -o ./anthracite
build-docker:
docker build . -t anthracite
run: build
./anthracite 8080
run-test: build
./anthracite 8080 ./test_www
debug: build
gdb --args ./anthracite 8080
debug-test: build
gdb --args ./anthracite 8080 ./test_www
format:
clang-format *.cpp -i
lint:
clang-tidy *.cpp
lint-fix:
clang-tidy *.cpp -fix -fix-errors

View file

@ -19,21 +19,21 @@ constexpr int max_worker_threads = 128;
void handle_client(anthracite_socket s, backend& b, file_backend& fb, std::mutex& thread_wait_mutex, std::condition_variable& thread_wait_condvar, int& active_threads)
{
while(true) {
std::string raw_request = s.recv_message(HTTP_HEADER_BYTES);
if(raw_request == "") {
break;
}
http_request req(raw_request, s.get_client_ip());
std::unique_ptr<http_response> resp = req.is_supported_version() ? b.handle_request(req) : fb.handle_error(http_status_codes::HTTP_VERSION_NOT_SUPPORTED);
log_request_and_response(req, resp);
std::string header = resp->header_to_string();
s.send_message(header);
s.send_message(resp->content());
resp.reset();
if(req.close_connection()) {
break;
}
while (true) {
std::string raw_request = s.recv_message(HTTP_HEADER_BYTES);
if (raw_request == "") {
break;
}
http_request req(raw_request, s.get_client_ip());
std::unique_ptr<http_response> resp = req.is_supported_version() ? b.handle_request(req) : fb.handle_error(http_status_codes::HTTP_VERSION_NOT_SUPPORTED);
log_request_and_response(req, resp);
std::string header = resp->header_to_string();
s.send_message(header);
s.send_message(resp->content());
resp.reset();
if (req.close_connection()) {
break;
}
}
s.close_conn();
{

View file

@ -6,9 +6,9 @@
#include <netinet/in.h>
#include <sstream>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#include <unordered_map>
#include <sys/time.h>
constexpr int MAX_QUEUE_LENGTH = 100;
@ -79,7 +79,7 @@ public:
int result = recv(client_socket, response, sizeof(response), 0);
if (result < 1) {
return "";
return "";
}
response[buffer_size] = '\0';