PgStream

internal class PgStream(val host: String, val port: Int, val loginTimeoutSecs: Int = 10, notificationBufferCapacity: Int = 256, val noticeHandler: NoticeHandler? = null, val sslConfiguration: SslConfiguration? = null, val cancelSignalTimeoutSecs: Int = 10) : AutoCloseable

Represents a connection stream to a PostgreSQL database. Handles reading and writing of PostgreSQL wire protocol messages.

Parameters

notificationBufferCapacity

Capacity of the buffer for asynchronous notifications.

Constructors

Link copied to clipboard
constructor(host: String, port: Int, loginTimeoutSecs: Int = 10, notificationBufferCapacity: Int = 256, noticeHandler: NoticeHandler? = null, sslConfiguration: SslConfiguration? = null, cancelSignalTimeoutSecs: Int = 10)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The transfer that last held this connection in copy mode, live or spent.

Link copied to clipboard

Seconds allowed for a cancel request sent on this connection's behalf, covering both its connect and its reads. Carried here for the same reason.

Link copied to clipboard

True while a COPY operation holds the connection in copy mode.

Link copied to clipboard

True while a statement is being executed on this connection, from the first message sent until the exchange is fully drained.

Link copied to clipboard

The hostname or IP address of the PostgreSQL server.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether the connection ended up encrypted, whatever sslmode asked for.

Link copied to clipboard
Link copied to clipboard

Timeout in seconds for the initial connection and login process.

Link copied to clipboard
Link copied to clipboard

The socket's read timeout, in milliseconds, with 0 meaning no limit.

Link copied to clipboard
Link copied to clipboard
val notifications: SharedFlow<PgNotification>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The certificate the server presented during the TLS handshake, or null on a plaintext connection and on the rare TLS connection where the peer never authenticated itself.

Link copied to clipboard
val port: Int

The port number of the PostgreSQL server.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The SSL settings this connection was established with, kept so that a second connection opened on its behalf - a cancel request - can be given the same treatment.

Link copied to clipboard

False until the startup handshake reaches its first ReadyForQuery.

Link copied to clipboard

The transaction status the server reported on its last ReadyForQuery: I outside a transaction block, T inside one, E inside one that has failed.

Functions

Link copied to clipboard

Blocks until the server closes this connection, discarding anything it sends beforehand.

Link copied to clipboard

Marks the start of an exchange, refusing to begin one while another is already running. Every call must be paired with endExchange in a finally.

Link copied to clipboard

Guards any operation that needs the protocol stream to itself.

Link copied to clipboard
open override fun close()

Closes the connection stream, sending a Terminate message if the socket is still open.

Link copied to clipboard

Closes the socket without the Terminate that close sends first.

Link copied to clipboard

Marks the end of an exchange.

Link copied to clipboard
fun flush()

Flushes the underlying output stream, forcing any buffered bytes to be written out.

Link copied to clipboard

Attempts to receive a backend message if one is immediately available or within the timeout. Returns null if no message is available (e.g. timeout reached while polling).

Link copied to clipboard

Receives a single backend message synchronously, blocking until data is available.

Link copied to clipboard

Sends a frontend message to the PostgreSQL server.

Link copied to clipboard
fun upgradeToSSL(host: String, port: Int, config: SslConfiguration)

Upgrades the current connection to use SSL/TLS.