Skip to content

Commit 8a88986

Browse files
committed
ipc: Add support for auto-translating 'localhost' TCP/IP to UDS
1 parent bbb8b77 commit 8a88986

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/ipc.q

+37-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
/ for logging with asterisks. If true, the plain-text password will be logged
2222
.ipc.cfg.logPasswordsDuringConnect:0b;
2323

24+
/ If enabled, any connection attempt that is made to a process on the local server will be re-routed via Unix Domain Sockets
25+
/ rather than localhost TCP (only on supported Operating Systems)
26+
.ipc.cfg.forceUnixDomainSocketsForLocalhost:1b;
27+
2428

2529
/ Provides current state of all connections that were initiated by an external process. This will
2630
/ only be populated if .ipc.cfg.enableInboundConnTracking is enabled on library initialisation
@@ -33,11 +37,29 @@
3337
/ @see .ipc.connectWithTimeout
3438
.ipc.outbound:`handle xkey flip `handle`targetHostPort`connectTime!"ISP"$\:();
3539

40+
/ The Operating Systems that support Unix Domain Sockets
41+
.ipc.udsSupportedOs:`l`v`m;
42+
43+
/ List of host names / IP addresses that are always classified as 'local' and therefore should default to UDS if enabled
44+
/ On library initialisation, additional hosts are added
45+
.ipc.localhostAddresses:`localhost`127.0.0.1;
46+
47+
/ Combination of '.ipc.cfg.forceUnixDomainSocketsForLocalhost' and if the current OS supports UDS
48+
/ @see .ipc.init
49+
.ipc.udsEnabled:0b;
50+
3651

3752
.ipc.init:{
3853
if[.ipc.cfg.enableInboundConnTracking;
3954
.ipc.i.enableInboundConnTracking[];
4055
];
56+
57+
.ipc.localhostAddresses:.ipc.localhostAddresses union .z.h,.Q.host[.z.a],.convert.ipOctalToSymbol each (.z.a; .Q.addr .z.h);
58+
.log.if.debug ("Local host names and IP addresses: {}"; .ipc.localhostAddresses);
59+
60+
.ipc.udsEnabled:.ipc.cfg.forceUnixDomainSocketsForLocalhost & (`$first string .z.o) in .ipc.udsSupportedOs;
61+
62+
.log.if.info ("IPC library initialised [ UDS Enabled: {} ]"; `no`yes .ipc.udsEnabled);
4163
};
4264

4365

@@ -89,9 +111,23 @@
89111
0 > timeout;
90112
'"IllegalArgumentException"
91113
];
92-
114+
93115
hostPort:.type.ensureHostPortSymbol hostPort;
94116

117+
if[.ipc.udsEnabled;
118+
hpSplit:":" vs string hostPort;
119+
host:`localhost^`$hpSplit 1;
120+
121+
if[host in .ipc.localhostAddresses;
122+
udsHostPort:`$":unix://",":" sv 2_ hpSplit;
123+
];
124+
125+
if[0 < count udsHostPort;
126+
.log.if.debug ("Host/port translated to Unix Domain Socket [ Original: {} ] [ Now: {} ]"; hostPort; udsHostPort);
127+
hostPort:udsHostPort;
128+
];
129+
];
130+
95131
logHostPort:string hostPort;
96132
logTimeout:$[timeout in 0 0Wi; "waiting indefinitely"; "timeout ",string[timeout]," ms"];
97133

0 commit comments

Comments
 (0)