about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--main.py7
-rw-r--r--src/config.py3
2 files changed, 7 insertions, 3 deletions
diff --git a/main.py b/main.py
index f03b354..574c58b 100644
--- a/main.py
+++ b/main.py
@@ -93,8 +93,9 @@ class HTTPServer:
         self.buf_len: int = packet_size
         self.port: int = port
 
-        # client thread list and server thread
+        # client thread list
         self.client_threads: list[threading.Thread] = []
+        self.semaphore: threading.Semaphore = threading.Semaphore(CLIENT_MAX_PROCESS)
 
         # add signaling
         self.stop_event = threading.Event()
@@ -141,6 +142,7 @@ class HTTPServer:
         :param client: client ssl socket
         """
 
+        self.semaphore.acquire()
         try:
             request = self._recv_request(client)
             if request is not None:
@@ -159,6 +161,7 @@ class HTTPServer:
 
         # Remove self from thread list and close the connection
         self.client_threads.remove(threading.current_thread())
+        self.semaphore.release()
         client.close()
 
     def _client_request_handler(self, client: usocket, request: Request):
@@ -289,7 +292,7 @@ class HTTPServer:
 
 
 def main():
-    init_path_map(True)
+    init_path_map(verbose=True)
     server = HTTPServer(port=13700)
     server.start()
 
diff --git a/src/config.py b/src/config.py
index 18c136b..e72477e 100644
--- a/src/config.py
+++ b/src/config.py
@@ -1,7 +1,8 @@
 # generic
 BUFFER_LENGTH = 65536           # 64 KiB
 BUFFER_MAX_SIZE = 2**30 * 0.5   # 512 MiB
-CLIENT_MAX_AMOUNT = 64
+CLIENT_MAX_AMOUNT = 512         # max requests at once, after which the connections are dropped
+CLIENT_MAX_PROCESS = 32         # max processing threads at once
 
 # API
 API_FILE_RANDOM_MIN_SIZE_LIMIT = 1              # 1 byte