From acc77a1aa421415970e5da0e72a4d2ff59e97f83 Mon Sep 17 00:00:00 2001 From: eugene Date: Wed, 9 Oct 2024 14:02:10 -0400 Subject: [PATCH] make sure ZitiSSLSocket is correctly closed --- .../openziti/net/internal/ZitiSSLSocket.kt | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ziti/src/main/kotlin/org/openziti/net/internal/ZitiSSLSocket.kt b/ziti/src/main/kotlin/org/openziti/net/internal/ZitiSSLSocket.kt index 449e0ccf..49da5765 100644 --- a/ziti/src/main/kotlin/org/openziti/net/internal/ZitiSSLSocket.kt +++ b/ziti/src/main/kotlin/org/openziti/net/internal/ZitiSSLSocket.kt @@ -52,7 +52,12 @@ class ZitiSSLSocket(val transport: Socket, val engine: SSLEngine) : } inner class Output : OutputStream() { - val buffer = ByteBuffer.allocate(32 * 1024) + private val buffer = ByteBuffer.allocate(32 * 1024) + + override fun close() { + this@ZitiSSLSocket.close() + } + override fun write(b: Int) { buffer.put(b.toByte()) } @@ -81,7 +86,7 @@ class ZitiSSLSocket(val transport: Socket, val engine: SSLEngine) : } } - val output = Output() + private val output = Output() override fun getOutputStream(): OutputStream { doHandshake() return output @@ -93,6 +98,10 @@ class ZitiSSLSocket(val transport: Socket, val engine: SSLEngine) : } private val input: InputStream = transport.getInputStream() + override fun close() { + this@ZitiSSLSocket.close() + } + override fun read(): Int { val buf = ByteArray(1) val read = read(buf, 0, 1) @@ -269,4 +278,16 @@ class ZitiSSLSocket(val transport: Socket, val engine: SSLEngine) : override fun setEnableSessionCreation(flag: Boolean) { engine.enableSessionCreation = flag } + + override fun isClosed(): Boolean { + return transport.isClosed + } + + override fun close() { + if (!isClosed) { + runCatching { + transport.close() + } + } + } } \ No newline at end of file