Skip to content

Commit bbb8b77

Browse files
committed
ipc: Add .ipc.connectWait to ignore timeout
- Bug fix: Passing integer port throws 'type'
1 parent 2d6c07d commit bbb8b77

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/ipc.q

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,16 @@
6262
:.ipc.connectWithTimeout[hostPort;::];
6363
};
6464

65+
/ Open a connection to the specified target host/port and allow waiting indefinitely until the process responds
66+
/ @param hostPort (HostPort) The target process to connect to
67+
/ @return (Integer) The handle to that process if the connection is successful
68+
/ @see .ipc.connectWithTimeout
69+
.ipc.connectWait:{[hostPort]
70+
:.ipc.connectWithTimeout[hostPort; 0];
71+
};
72+
6573
/ Open a connection to the specified target host/port with a maximum timeout period.
66-
/ NOTE: Passwords can be configured to not be printed to via logging. However, the password will always be present
67-
/ in .ipc.outbound
74+
/ NOTE: Passwords can be configured to not be printed to via logging
6875
/ @param hostPort (HostPort) The target process to connect to
6976
/ @param timeout (Integer) The maximum time to wait for a connection. Pass generic null to use the default
7077
/ @return (Integer) The handle to that process if the connection is successful
@@ -77,11 +84,16 @@
7784
'"IllegalArgumentException";
7885
];
7986

80-
if[.util.isEmpty timeout;
87+
$[.util.isEmpty timeout;
8188
timeout:.ipc.cfg.defaultConnectTimeout;
89+
0 > timeout;
90+
'"IllegalArgumentException"
8291
];
8392

84-
logHostPort:string .type.ensureHostPortSymbol hostPort;
93+
hostPort:.type.ensureHostPortSymbol hostPort;
94+
95+
logHostPort:string hostPort;
96+
logTimeout:$[timeout in 0 0Wi; "waiting indefinitely"; "timeout ",string[timeout]," ms"];
8597

8698
if[not .ipc.cfg.logPasswordsDuringConnect;
8799
if[4 = count where ":" = string hostPort;
@@ -92,7 +104,7 @@
92104
];
93105
];
94106

95-
.log.if.info "Attempting to connect to ",logHostPort," (timeout ",string[timeout]," ms)";
107+
.log.if.info ("Attempting to connect to {} ({})"; logHostPort; logTimeout);
96108

97109
h:@[hopen; (hostPort; timeout); { (`CONN_FAIL;x) }];
98110

@@ -114,9 +126,9 @@
114126
/ @see .q.hclose
115127
.ipc.disconnect:{[h]
116128
closeRes:@[hclose;h;{ (`FAILED_TO_CLOSE;x) }];
117-
129+
118130
.ipc.i.connectionClosed h;
119-
131+
120132
if[`FAILED_TO_CLOSE~first closeRes;
121133
.log.if.warn "Failed to close handle ",string[h],". Error - ",last closeRes;
122134
:0b;

0 commit comments

Comments
 (0)