Fix #1511: support domain sockets (#1514)

This commit is contained in:
Michiel Borkent 2023-03-09 16:57:17 +01:00 committed by GitHub
parent 5ad161a059
commit e74e7ed2ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 0 deletions

View file

@ -11,6 +11,7 @@ A preview of the next release can be installed from
- [#1507](https://github.com/babashka/babashka/issues/1507): Expose methods on java.lang.VirtualThread ([@lispyclouds](https://github.com/lispyclouds))
- [#1510](https://github.com/babashka/babashka/issues/1510): add virtual thread interop on `Thread`
- [#1511](https://github.com/babashka/babashka/issues/1511): support domain sockets
## 1.2.174 (2023-03-01)

View file

@ -329,6 +329,7 @@
java.net.HttpURLConnection
java.net.InetAddress
java.net.InetSocketAddress
java.net.StandardProtocolFamily
java.net.ServerSocket
java.net.Socket
java.net.SocketException
@ -351,6 +352,8 @@
java.nio.file.StandardOpenOption
java.nio.channels.FileChannel
java.nio.channels.FileChannel$MapMode
java.nio.channels.ServerSocketChannel
java.nio.channels.SocketChannel
java.nio.charset.Charset
java.nio.charset.CoderResult
java.nio.charset.CharsetEncoder
@ -659,6 +662,10 @@
java.nio.CharBuffer
(instance? java.nio.channels.FileChannel v)
java.nio.channels.FileChannel
(instance? java.nio.channels.ServerSocketChannel v)
java.nio.channels.ServerSocketChannel
(instance? java.nio.channels.SocketChannel v)
java.nio.channels.SocketChannel
(instance? java.net.CookieStore v)
java.net.CookieStore
;; this makes interop on reified classes work

View file

@ -0,0 +1,40 @@
(import java.net.UnixDomainSocketAddress
java.net.StandardProtocolFamily
[java.nio.channels ServerSocketChannel SocketChannel])
(require '[clojure.java.io :as io])
(def sockaddr (UnixDomainSocketAddress/of
(-> (doto (io/file "/tmp/sock")
(.deleteOnExit))
str)))
;; server
(def server
(future
(let [ch (ServerSocketChannel/open StandardProtocolFamily/UNIX)]
(.bind ch sockaddr)
(.accept ch))))
(Thread/sleep 100)
;; client
(let [ch (SocketChannel/open StandardProtocolFamily/UNIX)
ch (loop [retry 0]
(let [v (try (.connect ch sockaddr)
(catch Exception e e))]
(if (instance? Exception v)
(if (< retry 10)
(do (Thread/sleep 100)
(recur (inc retry)))
(throw v))
v)))]
#_(prn :ch ch)
#_(.close ch))
@server
(when-not (System/getProperty "babashka.version")
(shutdown-agents))
:success

View file

@ -19,3 +19,7 @@
(def t (Thread. (fn [])))
(def vt (Thread/startVirtualThread (fn [])))
[(.isVirtual t) (.isVirtual vt)]))))))
(deftest domain-sockets-test
(when-not test-utils/windows?
(is (= :success (bb nil (slurp "test-resources/domain_sockets.bb"))))))