commit 8a6c613

default  ·  2024-08-05 04:06:57 +0000 UTC
parent 972c3dc
Add support to unix sockets in snac_init().
1 files changed,  +20, -8
+20, -8
 1@@ -131,21 +131,33 @@ int snac_init(const char *basedir)
 2     xs *layout = xs_number_new(disk_layout);
 3     srv_config = xs_dict_set(srv_config, "layout", layout);
 4 
 5-    printf("Network address [%s]: ", xs_dict_get(srv_config, "address")); fflush(stdout);
 6+    int is_unix_socket = 0;
 7+
 8+    printf("Network address or full path to unix socket [%s]: ", xs_dict_get(srv_config, "address")); fflush(stdout);
 9     {
10         xs *i = xs_strip_i(xs_readline(stdin));
11-        if (*i)
12+        if (*i) {
13             srv_config = xs_dict_set(srv_config, "address", i);
14+
15+            if (*i == '/')
16+                is_unix_socket = 1;
17+        }
18     }
19 
20-    printf("Network port [%d]: ", (int)xs_number_get(xs_dict_get(srv_config, "port"))); fflush(stdout);
21-    {
22-        xs *i = xs_strip_i(xs_readline(stdin));
23-        if (*i) {
24-            xs *n = xs_number_new(atoi(i));
25-            srv_config = xs_dict_set(srv_config, "port", n);
26+    if (!is_unix_socket) {
27+        printf("Network port [%d]: ", (int)xs_number_get(xs_dict_get(srv_config, "port"))); fflush(stdout);
28+        {
29+            xs *i = xs_strip_i(xs_readline(stdin));
30+            if (*i) {
31+                xs *n = xs_number_new(atoi(i));
32+                srv_config = xs_dict_set(srv_config, "port", n);
33+            }
34         }
35     }
36+    else {
37+        xs *n = xs_number_new(0);
38+        srv_config = xs_dict_set(srv_config, "port", n);
39+    }
40 
41     printf("Host name: "); fflush(stdout);
42     {