You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 23, 2025. It is now read-only.
Copy file name to clipboardexpand all lines: README.md
+31-6
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# Web Server
2
-
###What it is
3
-
It's a web server made using liburing, to run on Linux operating systems with Kernel version >= 5.8.<br>
2
+
## What it is
3
+
It's a multithreaded asynchronous web server made using liburing, to run on Linux operating systems with Kernel version >= 5.8.<br>
4
4
It looks for files to server in the `public` subdirectory.
5
5
6
-
###Configuration
6
+
## Configuration
7
7
A .config file is used to set the locations of the private key, the fullchain file, whether or not to use TLS, and what port to serve on for normal HTTP or TLS.
8
8
For example:
9
9
```
@@ -16,7 +16,7 @@ SERVER_THREADS: 10
16
16
```
17
17
It's supposed to be in the same directory as the server.
18
18
19
-
###Libraries/header files used
19
+
## Libraries/header files used
20
20
Readerwriterqueue for a thread-safe concurrent queue:<br>
-`./compile.sh` uses `cmake` and `make` to configure and build the project, and all the source code (and the `CMakeLists.txt` file) are in the `src` subdirectory.
31
31
-`*.tcc` files are used to provide template definitions, which are then included in header files
32
32
-`./src/header` contains the header files for use in all the other `*.cpp` and `*.tcc` files
33
-
-`./src/common` has code used across files/more general in nature (such as the `SIGINT` handler)
33
+
-`./src/helper` has code used across files/more general in nature (such as the `SIGINT` handler)
34
34
-`./src/tcp_server` contains code for the main TCP/TLS server
35
35
-`./src/web_server` has the code for implementing HTTP and WebSockets
36
36
-`main.cpp` ties those together to provide a demo
37
37
38
+
### TCP Server
39
+
The TCP server, accessed via `tcp_tls_server::server<T>(...)` (where `T` is the server type, either `server_type::TLS` or `server_type::NON_TLS`) is an asyncrhonous simple TCP server, which takes as arguments some callbacks, the port to host on, a custom object (i.e the web server here), and a fullchain certificate and private key for TLS.<br>
40
+
The callbacks are:
41
+
- the accept callback (called when a new socket is accepted)
42
+
- the close callback (called when a socket is closed for some reason - used to basically clean up resources used by that client)
43
+
- the read callback (called with any data that was read from that socket)
44
+
- the write callback (called after something has been written to that socket, e.g a file)
45
+
- the event callback (called when something uses the `notify_event()` function on the server, used for any custom event logic)
46
+
- the custom read callback (called after something has been read from a file descriptor of your choosing using `custom_read_req(...)`
47
+
The web server plugs in the web server and using the callbacks interacts with any sockets.
48
+
49
+
### Web Server
50
+
Can support websockets and fulfills basic HTTP 1.0 requests, it takes no arguments, but requires you to call `set_tcp_server(...)` with a pointer to an instance of a TCP Server before it can be used.
51
+
52
+
It makes use of a simple LRU cache, and, for use with the Central Web Server, has some lock free thread safe queues and functions to go along with them to safely send data back and forth between threads.
53
+
54
+
### Central Web Server
55
+
Currently broadcasts a small message periodically.
56
+
57
+
A small text message is turned into a websocket message and stored into a vector in the `data_store` class, and a pointer to that data and some information is broadcast to a set of threads, each with a separate Web Server and TCP server on them (the TCP server's use the same asynchronous backend since that bit is thread safe), and each Web Server broadcasts it to each connected websocket client.
58
+
59
+
After the message has been written to all the clients, each thread notifies the Central Web Server that the data has been written on that thread, and once all the Web Servers have notified the Central Web Server, that message is freed from the `data_store`'s vector.
60
+
61
+
This all goes to allow dealing with websocket connection interactions centrally if need be.
62
+
38
63
### Known issues
39
64
It's possible you get really high CPU usage due to `inotify_init()` failing and returning `-1`, so the `read`'s which followed would return `-9` and hence get stuck in a loop of failed reads, this may be due to errno `24`. Simply increase the inotify max user instances with `sudo sysctl fs.inotify.max_user_instances=256`, or some other command relating to increasing the number of possible `fd`'s on a system, this would probably fix the issue on the next startup.
0 commit comments