Last active
September 26, 2021 21:07
-
-
Save duanebester/980be9358af63167ee5cab7761ca4b5e to your computer and use it in GitHub Desktop.
Getting and Closing a Buffer Socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn connected? [^SocketChannel client] | |
(or (.isConnected client) (.isOpen client))) | |
(defn get-buffer-socket | |
[^Integer port ^String address] | |
(let [client (SocketChannel/open) | |
address (InetSocketAddress. address port)] | |
(.configureBlocking client true) | |
(.connect client address) | |
(init-buffer-socket client))) | |
(defn close-buffer-socket [{:keys [in out ^SocketChannel client] | |
:as this}] | |
(when (connected? client) | |
(async/close! in) | |
(async/close! out) | |
(.shutdownInput client) | |
(.shutdownOutput client) | |
(.close client) | |
(assoc this :client nil :in nil :out nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment