diff --git a/.gitignore b/.gitignore index 759184d..9580e1b 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,5 @@ Mkfile.old dkms.conf .vscode -bin/ \ No newline at end of file +bin/ +__pycache__/ \ No newline at end of file diff --git a/Makefile b/Makefile index 3024aa6..55caabd 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ -server: fast-wsgi/server.c +server: fastwsgi/server.c mkdir -p bin - gcc -Illhttp/include llhttp/src/*.c fast-wsgi/request.c fast-wsgi/server.c fast-wsgi/constants.c -o bin/server -luv -I/usr/include/python3.8 -lpython3.8 -O3 \ No newline at end of file + gcc -Illhttp/include llhttp/src/*.c fastwsgi/request.c fastwsgi/server.c fastwsgi/constants.c -o bin/server -luv -I/usr/include/python3.8 -lpython3.8 -O3 \ No newline at end of file diff --git a/README.md b/README.md index 9d40c1e..e4aa0dc 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/jamesroberts/fast-wsgi.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/jamesroberts/fast-wsgi/context:cpp) [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/jamesroberts/fast-wsgi.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/jamesroberts/fast-wsgi/context:python) -# Fast WSGI -#### Note: Fast WSGI is still under development... +# FastWSGI +#### Note: FastWSGI is still under development... -Fast WSGI is an ultra fast WSGI server for Python 3. +FastWSGI is an ultra fast WSGI server for Python 3. It is mostly written in C. It makes use of [libuv](https://github.com/libuv/libuv) and [llhttp](https://github.com/nodejs/llhttp) under the hood for blazing fast performance. @@ -15,7 +15,7 @@ It is mostly written in C. It makes use of [libuv](https://github.com/libuv/libu See [example.py](https://github.com/jamesroberts/fast-wsgi/blob/main/example.py) for more details. ```python -import fast_wsgi +import fastwsgi from flask import Flask app = Flask(__name__) @@ -27,7 +27,7 @@ def hello_world(): if __name__ == "__main__": - fast_wsgi.run(wsgi_app=app, host="0.0.0.0", port=5000) + fastwsgi.run(wsgi_app=app, host="0.0.0.0", port=5000) ``` @@ -35,11 +35,11 @@ if __name__ == "__main__": ```python def application(environ, start_response): - start_response('200 OK', [('Content-Type', 'text/html')]) + start_response("200 OK", [("Content-Type", "text/html")]) return [b"Hello, World!"] if __name__ == "__main__": - fast_wsgi.run(wsgi_app=application, host="0.0.0.0", port=5000) + fastwsgi.run(wsgi_app=application, host="0.0.0.0", port=5000) ``` diff --git a/example.py b/example.py index ca1a8d9..85bf8e3 100644 --- a/example.py +++ b/example.py @@ -1,4 +1,4 @@ -import fast_wsgi +import fastwsgi from flask import Flask app = Flask(__name__) @@ -9,5 +9,10 @@ def hello_world(): return "Hello, World!", 200 +def application(environ, start_response): + start_response('200 OK', [('Content-Type', 'text/html')]) + return [b"Hello, World!"] + + if __name__ == "__main__": - fast_wsgi.run(wsgi_app=app, host="0.0.0.0", port=5000) + fastwsgi.run(wsgi_app=application, host="0.0.0.0", port=5000) diff --git a/fast_wsgi.py b/fastwsgi.py similarity index 82% rename from fast_wsgi.py rename to fastwsgi.py index 55072a6..d045775 100644 --- a/fast_wsgi.py +++ b/fastwsgi.py @@ -1,6 +1,6 @@ import os import signal -import _fast_wsgi +import _fastwsgi NUM_WORKERS = 4 @@ -19,7 +19,7 @@ def run_multi_process_server(app): print(f"Worker process added with PID: {pid}") else: try: - _fast_wsgi.run_server(app, HOST, PORT, BACKLOG, 0) + _fastwsgi.run_server(app, HOST, PORT, BACKLOG, 0) except KeyboardInterrupt: exit() @@ -35,5 +35,5 @@ def run_multi_process_server(app): def run(wsgi_app, host, port, backlog=1024): print("Starting server...") enable_logging = 0 - _fast_wsgi.run_server(wsgi_app, host, port, backlog, enable_logging) + _fastwsgi.run_server(wsgi_app, host, port, backlog, enable_logging) # run_multi_process_server(app) diff --git a/fast-wsgi/constants.c b/fastwsgi/constants.c similarity index 100% rename from fast-wsgi/constants.c rename to fastwsgi/constants.c diff --git a/fast-wsgi/constants.h b/fastwsgi/constants.h similarity index 100% rename from fast-wsgi/constants.h rename to fastwsgi/constants.h diff --git a/fast-wsgi/fast-wsgimodule.c b/fastwsgi/fastwsgimodule.c similarity index 77% rename from fast-wsgi/fast-wsgimodule.c rename to fastwsgi/fastwsgimodule.c index 643e261..53a9660 100644 --- a/fast-wsgi/fast-wsgimodule.c +++ b/fastwsgi/fastwsgimodule.c @@ -8,12 +8,12 @@ static PyMethodDef FastWsgiFunctions[] = { static struct PyModuleDef module = { PyModuleDef_HEAD_INIT, - "fast_wsgi", - "fast_wsgi Python module", + "fastwsgi", + "fastwsgi Python module", -1, FastWsgiFunctions, }; -PyMODINIT_FUNC PyInit__fast_wsgi(void) { +PyMODINIT_FUNC PyInit__fastwsgi(void) { return PyModule_Create(&module); } \ No newline at end of file diff --git a/fast-wsgi/filewrapper.c b/fastwsgi/filewrapper.c similarity index 100% rename from fast-wsgi/filewrapper.c rename to fastwsgi/filewrapper.c diff --git a/fast-wsgi/filewrapper.h b/fastwsgi/filewrapper.h similarity index 100% rename from fast-wsgi/filewrapper.h rename to fastwsgi/filewrapper.h diff --git a/fast-wsgi/request.c b/fastwsgi/request.c similarity index 100% rename from fast-wsgi/request.c rename to fastwsgi/request.c diff --git a/fast-wsgi/request.h b/fastwsgi/request.h similarity index 100% rename from fast-wsgi/request.h rename to fastwsgi/request.h diff --git a/fast-wsgi/server.c b/fastwsgi/server.c similarity index 99% rename from fast-wsgi/server.c rename to fastwsgi/server.c index b7d2ae3..829cbca 100644 --- a/fast-wsgi/server.c +++ b/fastwsgi/server.c @@ -19,6 +19,7 @@ void close_cb(uv_handle_t* handle) { free(handle); } + void write_cb(uv_write_t* req, int status) { if (status) { fprintf(stderr, "Write error %s\n", uv_strerror(status)); diff --git a/fast-wsgi/server.h b/fastwsgi/server.h similarity index 100% rename from fast-wsgi/server.h rename to fastwsgi/server.h diff --git a/setup.py b/setup.py index f95f62b..2974a8b 100644 --- a/setup.py +++ b/setup.py @@ -2,10 +2,10 @@ import glob from distutils.core import Extension, setup -SOURCE_FILES = glob.glob("fast-wsgi/*.c") + glob.glob("llhttp/src/*.c") +SOURCE_FILES = glob.glob("fastwsgi/*.c") + glob.glob("llhttp/src/*.c") module = Extension( - "_fast_wsgi", + "_fastwsgi", sources=SOURCE_FILES, libraries=['uv'], include_dirs=["llhttp/include"], @@ -13,7 +13,7 @@ module = Extension( ) setup( - name="fast_wsgi", + name="fastwsgi", version="0.1", description="An ultra fast WSGI server for Python 3", ext_modules=[module]