Commit 482279b8 for whisper.cpp

commit 482279b8a18855ba741d7b88c30fcb3874691f59
Author: Vincenzo Reina <vincenzoreinaa05@gmail.com>
Date:   Fri Oct 30 06:51:01 2026 +0100

    server : add support for .sock communication (#4124)

    * server : add support for .sock communication

    * server : change constant definition

diff --git a/examples/server/README.md b/examples/server/README.md
index 8d4c802b..92ee3423 100644
--- a/examples/server/README.md
+++ b/examples/server/README.md
@@ -44,7 +44,7 @@ options:
   -m FNAME,  --model FNAME       [models/ggml-base.en.bin] model path
   -oved D,   --ov-e-device DNAME [CPU    ] the OpenVINO device used for encode inference
   -dtw MODEL --dtw MODEL         [       ] compute token-level timestamps
-  --host HOST,                   [127.0.0.1] Hostname/ip-adress for the server
+  --host HOST,                   [127.0.0.1] Hostname/ip-adress for the server, or a unix socket path ending in .sock
   --port PORT,                   [8080   ] Port number for the server
   --public PATH,                 [examples/server/public] Path to the public folder
   --request-path PATH,           [       ] Request path for all requests
diff --git a/examples/server/server.cpp b/examples/server/server.cpp
index b745f4d7..8e8f9bd9 100644
--- a/examples/server/server.cpp
+++ b/examples/server/server.cpp
@@ -168,7 +168,7 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
     fprintf(stderr, "  -oved D,   --ov-e-device DNAME         [%-7s] the OpenVINO device used for encode inference\n",  params.openvino_encode_device.c_str());
     // server params
     fprintf(stderr, "  -dtw MODEL --dtw MODEL                 [%-7s] compute token-level timestamps\n",                          params.dtw.c_str());
-    fprintf(stderr, "  --host HOST,                           [%-7s] Hostname/ip-adress for the server\n",                       sparams.hostname.c_str());
+    fprintf(stderr, "  --host HOST,                           [%-7s] Hostname/ip-adress for the server, or a unix socket path ending in .sock\n", sparams.hostname.c_str());
     fprintf(stderr, "  --port PORT,                           [%-7d] Port number for the server\n",                              sparams.port);
     fprintf(stderr, "  --public PATH,                         [%-7s] Path to the public folder\n",                               sparams.public_path.c_str());
     fprintf(stderr, "  --request-path PATH,                   [%-7s] Request path for all requests\n",                           sparams.request_path.c_str());
@@ -1253,10 +1253,27 @@ int main(int argc, char ** argv) {
     svr->set_read_timeout(sparams.read_timeout);
     svr->set_write_timeout(sparams.write_timeout);

-    if (!svr->bind_to_port(sparams.hostname, sparams.port))
-    {
-        fprintf(stderr, "\ncouldn't bind to server socket: hostname=%s port=%d\n\n",
-                sparams.hostname.c_str(), sparams.port);
+    // a host ending in ".sock" is the path of a unix domain socket
+    constexpr std::string_view sock_ext = ".sock";
+    const bool is_sock = sparams.hostname.size() >= sock_ext.size() &&
+        sparams.hostname.compare(sparams.hostname.size() - sock_ext.size(), sock_ext.size(), sock_ext) == 0;
+
+    bool was_bound = false;
+    if (is_sock) {
+        svr->set_address_family(AF_UNIX);
+        // AF_UNIX ignores the port, but bind_to_port requires a nonzero value
+        was_bound = svr->bind_to_port(sparams.hostname, 8080);
+    } else {
+        was_bound = svr->bind_to_port(sparams.hostname, sparams.port);
+    }
+
+    if (!was_bound) {
+        if (is_sock) {
+            fprintf(stderr, "\ncouldn't bind to unix socket: %s\n\n", sparams.hostname.c_str());
+        } else {
+            fprintf(stderr, "\ncouldn't bind to server socket: hostname=%s port=%d\n\n",
+                    sparams.hostname.c_str(), sparams.port);
+        }
         return 1;
     }

@@ -1264,7 +1281,11 @@ int main(int argc, char ** argv) {
     svr->set_base_dir(sparams.public_path);

     // to make it ctrl+clickable:
-    printf("\nwhisper server listening at http://%s:%d\n\n", sparams.hostname.c_str(), sparams.port);
+    if (is_sock) {
+        printf("\nwhisper server listening at unix://%s\n\n", sparams.hostname.c_str());
+    } else {
+        printf("\nwhisper server listening at http://%s:%d\n\n", sparams.hostname.c_str(), sparams.port);
+    }

     shutdown_handler = [&](int signal) {
         printf("\nCaught signal %d, shutting down gracefully...\n", signal);