Skip to content

Commit

Permalink
Merge pull request #1 from ngn13/1.5-dev
Browse files Browse the repository at this point in the history
1.5
  • Loading branch information
ngn13 authored Nov 29, 2024
2 parents 8a3ae4a + 0759551 commit e41de11
Show file tree
Hide file tree
Showing 69 changed files with 1,703 additions and 4,802 deletions.
15 changes: 7 additions & 8 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: Left
AlignArrayOfStructures: Left
AlignConsecutiveAssignments:
Enabled: true
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
Expand All @@ -23,7 +23,7 @@ AlignConsecutiveDeclarations:
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
Expand All @@ -48,8 +48,8 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: false
BinPackParameters: true
BinPackArguments: false
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
Expand Down Expand Up @@ -170,7 +170,7 @@ RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortIncludes: false
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
Expand Down Expand Up @@ -223,4 +223,3 @@ WhitespaceSensitiveMacros:
- STRINGIZE
...


13 changes: 6 additions & 7 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Docker Images
name: Publish Docker Images
on:
push:
tags:
Expand All @@ -7,23 +7,22 @@ on:
jobs:
push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: 'Checkout GitHub Action'
- name: 'checkout the source code'
uses: actions/checkout@main

- name: 'Login to GitHub Container Registry'
- name: 'login to container registry'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: 'Build Inventory Image'
- name: 'build inventory image'
run: |
docker build . --tag ghcr.io/ngn13/ctorm:latest
docker build . --tag ghcr.io/ngn13/ctorm:latest ghcr.io/ngn13/ctorm:${GITHUB_REF##*/}
docker push ghcr.io/ngn13/ctorm:${GITHUB_REF##*/}
docker push ghcr.io/ngn13/ctorm:latest
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run Test Scripts
on: push

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: 'checkout the source code'
uses: actions/checkout@v3

- name: 'install dependencies'
run: |
sudo apt-get update
sudo apt-get install -y gcc make libcjson-dev
- name: 'build the library'
run: make

- name: 'install the library'
run: sudo make install

- name: 'build the examples'
run: make example

- name: 'run example #1'
run: |
./dist/example_hello &
./scripts/hello_test.sh
killall -9 example_hello
- name: 'run example #2'
run: |
./dist/example_echo &
./scripts/echo_test.sh
killall -9 example_echo
- name: 'run example #3'
run: |
./dist/example_middleware &
./scripts/middleware_test.sh
killall -9 example_middleware
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# dist directory for examples and the library
dist/
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu as build

RUN apt update
RUN apt install -y gcc make libcjson-dev libevent-dev dumb-init
RUN apt install -y gcc make libcjson-dev dumb-init

WORKDIR /pkg
COPY src ./src
Expand All @@ -12,5 +12,6 @@ RUN make
RUN make install

WORKDIR /
RUN rm -r /pkg
RUN rm -fr /pkg

ENTRYPOINT ["/usr/bin/dumb-init", "--"]
42 changes: 30 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
PREFIX = /usr
CC = gcc

DEBUG = 0
SRCS = $(wildcard src/*.c)
# sources
SRCS = $(shell find src/ -type f -name '*.c')
OBJS = $(patsubst src/%.c,dist/%.o,$(SRCS))
HDRS = $(wildcard include/*.h)
HDRS = $(wildcard include/*.h)

# compiler flags
CFLAGS = -O3 -march=native -fstack-protector-strong -fcf-protection=full -fstack-clash-protection
LIBS = -lpthread -levent -lcjson
LIBS = -lpthread

# options
CTORM_DEBUG = 0
CTORM_JSON_SUPPORT = 1

ifeq ($(CTORM_JSON_SUPPORT), 1)
LIBS += -lcjson
endif

dist/libctorm.so: $(OBJS)
mkdir -p dist
$(CC) -shared -o $@ $^ $(LIBS) $(CFLAGS)
all: dist dist/libctorm.so

dist/%.o: src/%.c
mkdir -p dist
$(CC) -c -Wall -fPIC -o $@ $^ $(LIBS) $(CFLAGS) -DDEBUG=${DEBUG}
dist:
mkdir -pv dist/encoding

dist/libctorm.so: $(OBJS)
$(CC) -shared -o $@ $^ $(LIBS) $(CFLAGS)

dist/%.o: src/%.c
$(CC) -c -Wall -fPIC -o $@ $^ $(LIBS) $(CFLAGS) \
-DCTORM_JSON_SUPPORT=$(CTORM_JSON_SUPPORT) \
-DCTORM_DEBUG=$(CTORM_DEBUG)

install:
install -m755 dist/libctorm.so $(DESTDIR)$(PREFIX)/lib/libctorm.so
Expand All @@ -26,9 +41,12 @@ uninstall:
rm -r $(DESTDIR)/usr/include/ctorm

format:
clang-format -i -style=file src/*.c include/*.h example/*/*.c
clang-format -i -style=file $(SRCS) $(HDRS) example/*/*.c

clean:
rm -rf dist

example:
$(MAKE) -C $@

.PHONY: test install uninstall format example
.PHONY: test install uninstall format clean example
33 changes: 11 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
_____/ /__________ ____ ___
/ ___/ __/ ___/ __ \/ __ `__ \
/ /__/ /_/ / / /_/ / / / / / /
\___/\__/_/ \____/_/ /_/ /_/ 1.4
\___/\__/_/ \____/_/ /_/ /_/ 1.5
```

# ctorm | simple web framework for C
![](https://img.shields.io/github/actions/workflow/status/ngn13/ctorm/docker.yml)
![](https://img.shields.io/github/actions/workflow/status/ngn13/ctorm/docker.yml?label=tests)
![](https://img.shields.io/github/v/tag/ngn13/ctorm?label=version)
![](https://img.shields.io/github/license/ngn13/ctorm)

ctorm is a libevent based, multi-threaded HTTP server for `HTTP/1.1` and `HTTP/1.0`.
It has a (fairly) easy API for general web server applications.
ctorm is a multi-threaded HTTP server for `HTTP/1.1` and `HTTP/1.0`.
It has an easy API for general web server applications.

### Important!!!
This software is pretty much in alpha state. I don't suggest you use ctorm on
production, however it can be used to build simple web applications just for fun.
> [!WARNING]
> This software is pretty much in alpha state. I don't suggest you use ctorm on
> production, however it can be used to build simple web applications just for fun.
I do plan to continue the development of this project, so please consider contributing
if you are interested.
Expand All @@ -31,29 +32,17 @@ if you are interested.
- Handling 404 (all) routes
- Sending files and static file serving

### Benchmarking
Benchmark results for hello world applications (see [benchmark](benchmark/)):

| Framework | Version | Time per request |
| ---------------- | ------------- | ---------------- |
| crow (C++) | v1.2.0 | ~4 ms |
| fiber (Go) | v3.0.0-beta.1 | ~4 ms |
| **ctorm (C)** | **1.4** | **~5 ms** |
| tide (Rust) | 0.16.0 | ~12 ms |
| express (NodeJS) | 4.19.2 | ~21 ms |

### Installation
You will need the following software in order to build and install ctorm:
- GCC and other general build tools (`build-essential`)
- libevent and it's headers (`libevent`, `libevent-dev`)
- cJSON and it's headers (`cjson`, `libcjson-dev`)
- If you want JSON support, cJSON and it's headers (`cjson`, `libcjson-dev`)
- tar (to extract the release archive)

First [download the latest release](https://github.com/ngn13/ctorm/tags) archive,
**do not compile from the latest commit unless you are doing development**:
```bash
wget https://github.com/ngn13/ctorm/archive/refs/tags/1.3.tar.gz
tar xf 1.3.tar.gz && cd ctorm-1.3
wget https://github.com/ngn13/ctorm/archive/refs/tags/1.5.tar.gz
tar xf 1.5.tar.gz && cd ctorm-1.5
```

Then use the `make` command to build and install:
Expand Down Expand Up @@ -121,7 +110,7 @@ CMD ["/app/server"]
### Development
For development, you can compile the library with debug mode:
```bash
make DEBUG=1
make CTORM_DEBUG=1
```
then you can use the example applications for testing:
```bash
Expand Down
5 changes: 0 additions & 5 deletions benchmark/.gitignore

This file was deleted.

16 changes: 0 additions & 16 deletions benchmark/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions benchmark/crow/main.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions benchmark/crow/test.sh

This file was deleted.

29 changes: 0 additions & 29 deletions benchmark/ctorm/main.c

This file was deleted.

10 changes: 0 additions & 10 deletions benchmark/ctorm/test.sh

This file was deleted.

12 changes: 0 additions & 12 deletions benchmark/express/index.js

This file was deleted.

Loading

0 comments on commit e41de11

Please sign in to comment.