Skip to main content

Module connection

Module connection 

Source
Expand description

Low-level synchronous connection handling over the PostgreSQL wire protocol.

RawConnection provides the message-level interface to a Hyper server: startup/authentication handshake, simple and extended query execution, and the COPY data path. It is generic over the transport stream S (TCP, Unix domain socket, named pipe, or TLS-wrapped variants).

§Wire Protocol Overview

Communication follows the PostgreSQL v3 message protocol. Each message has a 1-byte type tag, a 4-byte length (including itself), and a variable-length body. The connection maintains separate read and write BytesMut buffers to amortize syscall overhead.

§Query Protocols

  • Simple Query: A single Query('Q') message; the server responds with RowDescription, zero or more DataRow, CommandComplete, and ReadyForQuery. Results are in text format.

  • Extended Query (HyperBinary): Parse / Bind / Describe / Execute / Sync sequence requesting format code 2 (HyperBinary, little-endian binary). Results are zero-copy-friendly DataRow messages. Used by Client::query_fast and Client::query_streaming.

§Connection Health

A desynchronized flag tracks whether the wire protocol has fallen out of sync (e.g., a bounded drain exceeded its budget). Once set, all subsequent operations fast-fail. The only recovery is to drop the connection and open a new one. Pool layers should check RawConnection::is_healthy during recycle.

Structs§

RawConnection
A raw connection to a Hyper server.

Constants§

POST_ERROR_DRAIN_CAP
Maximum number of messages RawConnection::consume_error (and its async sibling) will read while draining the tail of a failed request.