Skip to content

Distribute and run LLMs with a single file.

1.6 KB
Raw Blame
diff --git a/tools/server/server-http.cpp b/tools/server/server-http.cpp
--- a/llama.cpp/tools/server/server-http.cpp
+++ b/llama.cpp/tools/server/server-http.cpp
@@ -159,7 +159,7 @@ bool server_http_context::init(const common_params & params) {
 bool server_http_context::init_listener(const common_params & params) {
     auto & srv = pimpl->servers.back();
 
-#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
+#ifdef CPPHTTPLIB_SSL_ENABLED
     if (!params.ssl_file_key.empty() && !params.ssl_file_cert.empty()) {
         SRV_TRC("running with SSL: key = %s, cert = %s\n", params.ssl_file_key.c_str(), params.ssl_file_cert.c_str());
         srv = std::make_unique<httplib::SSLServer>(
@@ -491,7 +491,11 @@ self.addEventListener('activate', (e) => e.waitUntil((async () => {
     return true;
 }
 
-bool server_http_context::start() {
+bool server_http_context::bind_socket() {
+    if (is_bound) {
+        return true;
+    }
+
     // Bind and listen
 
     listening_addresses.clear();
@@ -524,6 +528,15 @@ bool server_http_context::start() {
                                               : string_format("%s://%s:%d", is_ssl ? "https" : "http", common_http_format_host(host).c_str(), port));
     }
 
+    is_bound = true;
+    return true;
+}
+
+bool server_http_context::start() {
+    if (!bind_socket()) {
+        return false;
+    }
+
     // n_threads_http fixed threads (always alive), plus up to 1024 dynamic threads destroyed after each request
     // ref: https://github.com/yhirose/cpp-httplib/pull/2368
     pimpl->pool = std::make_unique<httplib::ThreadPool>(pimpl->n_threads_http, pimpl->n_threads_http + 1024);