Take connect through io-call with the other three
connect is the fourth :capture-native-error binding in jolt.socket and was the one left behind: accept, recv and send were unwrapped, and the pair connect answers went on reaching neg? in frq.irc/open. It is only on the plain-socket path, which the TLS default never takes, so it only broke the :6667 fallback — and broke it as "Could not connect: class clojure.lang.PersistentVector cannot be cast to class java.lang.Number", which is what the fallback is for. Through jolt's io-call like its neighbours, waiting on writability: a socket that finishes connecting reports itself writable. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
77c1a08 parent: 7f86322 modified
src/frq/irc.clj +1 -1 | @@ -241,7 +241,7 @@ | ||
| 241 | 241 | (let [ip (#'socket/ip->str (socket/resolve-host host)) |
| 242 | 242 | fd (socket/c-socket af-inet sock-stream 0)] |
| 243 | 243 | (when (neg? fd) (throw (ex-info "socket() failed" {:host host}))) |
| 244 | - (let [rc (socket/c-connect fd (#'socket/make-sockaddr-in ip (int port)) 16)] | |
| 244 | + (let [rc (wire/connect! fd (#'socket/make-sockaddr-in ip (int port)) 16)] | |
| 245 | 245 | (when (neg? rc) |
| 246 | 246 | (socket/c-close fd) |
| 247 | 247 | (throw (ex-info "connect() failed" {:host host :ip ip :port port})))) |
| @@ -241,7 +241,7 @@ | |||
| 241 | (let [ip (#'socket/ip->str (socket/resolve-host host)) | 241 | (let [ip (#'socket/ip->str (socket/resolve-host host)) |
| 242 | fd (socket/c-socket af-inet sock-stream 0)] | 242 | fd (socket/c-socket af-inet sock-stream 0)] |
| 243 | (when (neg? fd) (throw (ex-info "socket() failed" {:host host}))) | 243 | (when (neg? fd) (throw (ex-info "socket() failed" {:host host}))) |
| 244 | - (let [rc (socket/c-connect fd (#'socket/make-sockaddr-in ip (int port)) 16)] | 244 | + (let [rc (wire/connect! fd (#'socket/make-sockaddr-in ip (int port)) 16)] |
| 245 | (when (neg? rc) | 245 | (when (neg? rc) |
| 246 | (socket/c-close fd) | 246 | (socket/c-close fd) |
| 247 | (throw (ex-info "connect() failed" {:host host :ip ip :port port})))) | 247 | (throw (ex-info "connect() failed" {:host host :ip ip :port port})))) |
modified
src/frq/wire.clj +11 -0 | @@ -38,6 +38,17 @@ | ||
| 38 | 38 | [fd buf len] |
| 39 | 39 | (io-call #(socket/c-recv fd buf len 0) fd :read)) |
| 40 | 40 | |
| 41 | +(defn connect! | |
| 42 | + "One `connect` to the address at `sa`, answering zero or a negative. | |
| 43 | + | |
| 44 | + `connect` is the fourth of these bindings and was left out of the round | |
| 45 | + that fixed the other three: it is only on the plain-socket path, which the | |
| 46 | + TLS default does not take, so its pair reached `neg?` unnoticed. The wait | |
| 47 | + is for writability — a socket that finishes connecting reports itself | |
| 48 | + writable, which is what jolt's poller is being asked about here." | |
| 49 | + [fd sa len] | |
| 50 | + (io-call #(socket/c-connect fd sa len) fd :write)) | |
| 51 | + | |
| 41 | 52 | (defn accept! |
| 42 | 53 | "One `accept` on a listening fd, answering the connected fd or a negative." |
| 43 | 54 | [fd] |
| @@ -38,6 +38,17 @@ | |||
| 38 | [fd buf len] | 38 | [fd buf len] |
| 39 | (io-call #(socket/c-recv fd buf len 0) fd :read)) | 39 | (io-call #(socket/c-recv fd buf len 0) fd :read)) |
| 40 | 40 | ||
| 41 | +(defn connect! | ||
| 42 | + "One `connect` to the address at `sa`, answering zero or a negative. | ||
| 43 | + | ||
| 44 | + `connect` is the fourth of these bindings and was left out of the round | ||
| 45 | + that fixed the other three: it is only on the plain-socket path, which the | ||
| 46 | + TLS default does not take, so its pair reached `neg?` unnoticed. The wait | ||
| 47 | + is for writability — a socket that finishes connecting reports itself | ||
| 48 | + writable, which is what jolt's poller is being asked about here." | ||
| 49 | + [fd sa len] | ||
| 50 | + (io-call #(socket/c-connect fd sa len) fd :write)) | ||
| 51 | + | ||
| 41 | (defn accept! | 52 | (defn accept! |
| 42 | "One `accept` on a listening fd, answering the connected fd or a negative." | 53 | "One `accept` on a listening fd, answering the connected fd or a negative." |
| 43 | [fd] | 54 | [fd] |