---
source: boltffi_bindgen/src/render/kotlin/templates.rs
assertion_line: 1031
expression: template.render().unwrap()
---
class Connection internal constructor(internal val handle: Long) : AutoCloseable {
    private val closed = AtomicBoolean(false)

    constructor(url: String) : this(
        kotlin.run {
            val urlWire = WireWriterPool.acquire(BoltFFIWire.sizeString(url))
        kotlin.run {
            val wire = urlWire.writer
            BoltFFIWire.writeString(url)
        }
            try {
                val handle = Native.boltffi_connection_open(urlWire.ptr, urlWire.len)
                if (handle == 0L) throw FfiException(1, takeLastErrorMessage())
                handle
            } finally {
                urlWire.close()
            }
        }
    )

    override fun close() {
        if (!closed.compareAndSet(false, true)) return
        Native.boltffi_connection_free(handle)
    }
}
