Skip to content

Commit

Permalink
Merge pull request #645 from openziti/ziti-ssl-socket-close
Browse files Browse the repository at this point in the history
make sure ZitiSSLSocket is correctly closed
  • Loading branch information
ekoby authored Oct 9, 2024
2 parents ddc8264 + acc77a1 commit cab1b71
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions ziti/src/main/kotlin/org/openziti/net/internal/ZitiSSLSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
}
}
}
}

0 comments on commit cab1b71

Please sign in to comment.