Skip to content

Commit

Permalink
🌊add build and test workflow
Browse files Browse the repository at this point in the history
🐛fixed some compile errors
  • Loading branch information
Lord-Turmoil committed Nov 26, 2024
1 parent fe44b13 commit 3a23843
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 11 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Based on https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml

name: Build and Test

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
BUILD_TYPE: Release

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j $(nproc)

test:
runs-on: ubuntu-latest
needs: build

steps:
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
---

[![Build & Test](https://github.com/Lord-Turmoil/minet-core/actions/workflows/build-and-test.yml/badge.svg?branch=main)](https://github.com/Lord-Turmoil/minet-core/actions/workflows/build-and-test.yml)

# Prologue

**minet core** is a C++ HTTP server library that mimics the design of ASP.NET Core. It is designed to be a lightweight, high-performance, and easy-to-use library for building web applications in C++.
Expand Down
1 change: 1 addition & 0 deletions include/minet/common/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <unordered_map>
#include <vector>
#include <string>
#include "minet/common/Base.h"

MINET_BEGIN
Expand Down
1 change: 1 addition & 0 deletions include/minet/io/Stream.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <sys/types.h> // ssize_t
#include <vector>
#include "minet/common/Base.h"

Expand Down
4 changes: 4 additions & 0 deletions include/minet/io/StreamReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class StreamReader
StreamReader& operator=(const StreamReader& other) = delete;
StreamReader& operator=(StreamReader&& other) noexcept = delete;

/**
* @brief Read one character from the stream.
* @return -1 on EOF, otherwise the char read.
*/
virtual int Read() = 0;
virtual ssize_t Read(char* buffer, size_t length) = 0;

Expand Down
1 change: 1 addition & 0 deletions include/minet/utils/Network.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <netinet/in.h>
#include <sys/types.h> // ssize_t
#include "minet/common/Base.h"

MINET_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion src/common/Common.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <algorithm>

#include <cctype>
#include "minet/common/Log.h"

MINET_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion src/io/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ssize_t BufferInputStream::Read(char* buffer, size_t length)
{
if (_offset >= _buffer.size())
{
return EOF;
return -1;
}

size_t size = std::min(length, _buffer.size() - _offset);
Expand Down
4 changes: 2 additions & 2 deletions src/io/StreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ BufferedStreamReader::~BufferedStreamReader()
int BufferedStreamReader::Read()
{
_Flush();
return IsEof() ? EOF : *_head++;
return IsEof() ? -1 : *_head++;
}

ssize_t BufferedStreamReader::Read(char* buffer, size_t length)
{
if (IsEof())
{
return EOF;
return -1;
}

size_t remaining = length;
Expand Down
14 changes: 7 additions & 7 deletions src/utils/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void RequestParser::_NextToken()
static constexpr char delimiters[] = " :\r\n";

int ch = _Next();
if (ch == EOF)
if (ch == -1)
{
_currentToken.Type = RequestTokenType::End;
return;
Expand Down Expand Up @@ -178,12 +178,12 @@ void RequestParser::_NextToken()

_currentToken.Type = RequestTokenType::String;
_currentToken.Value.clear();
while ((ch != EOF) && (strchr(delimiters, ch) == nullptr))
while ((ch != -1) && (strchr(delimiters, ch) == nullptr))
{
_currentToken.Value.push_back(static_cast<char>(ch));
ch = _Next();
}
if (ch != EOF)
if (ch != -1)
{
_Rewind(static_cast<char>(ch));
}
Expand All @@ -199,7 +199,7 @@ void RequestParser::_NextString()
static constexpr char delimiters[] = "\r\n";

int ch = _Next();
if (ch == EOF)
if (ch == -1)
{
_currentToken.Type = RequestTokenType::End;
return;
Expand All @@ -209,7 +209,7 @@ void RequestParser::_NextString()
{
ch = _Next();
}
if (ch == EOF)
if (ch == -1)
{
_currentToken.Type = RequestTokenType::End;
return;
Expand All @@ -231,12 +231,12 @@ void RequestParser::_NextString()

_currentToken.Type = RequestTokenType::String;
_currentToken.Value.clear();
while ((ch != EOF) && (strchr(delimiters, ch) == nullptr))
while ((ch != -1) && (strchr(delimiters, ch) == nullptr))
{
_currentToken.Value.push_back(static_cast<char>(ch));
ch = _Next();
}
if (ch != EOF)
if (ch != -1)
{
_Rewind(static_cast<char>(ch));
}
Expand Down

0 comments on commit 3a23843

Please sign in to comment.