Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure ZitiSSLSocket is correctly closed #645

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
[email protected]()
}

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() {
[email protected]()
}

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()
}
}
}
}