pub struct Connection { /* private fields */ }Implementations§
Source§impl Connection
impl Connection
Sourcepub fn new(config: Config) -> Result<Self>
pub fn new(config: Config) -> Result<Self>
Validate config and queue the first message, so output() is already
non-empty on return: the StartupMessage, or with SslMode::Prefer/
Require the SSLRequest. Send it as soon as the transport connects;
nothing else will produce it.
use turnloop_postgres::{Config, Connection, SslMode};
let c = Connection::new(Config::default())?;
assert!(c.output().windows(5).any(|w| w == b"user\0"), "StartupMessage");
let tls = Connection::new(Config { ssl: SslMode::Require, ..Config::default() })?;
assert_eq!(tls.output(), [0, 0, 0, 8, 4, 210, 22, 47], "SSLRequest");Sourcepub fn config(&self) -> &Config
pub fn config(&self) -> &Config
The configuration this connection was built from. On ScramNeeded,
build ScramSha256 from config().password; the host keeps no copy.
pub fn output(&self) -> &[u8] ⓘ
pub fn consume_output(&mut self, n: usize) -> Result<()>
pub fn receive(&mut self, bytes: &[u8]) -> Result<()>
Sourcepub fn tls_established(&mut self) -> Result<()>
pub fn tls_established(&mut self) -> Result<()>
Acknowledge TLS without channel-binding data (plain SCRAM fallback).
Sourcepub fn tls_established_with_channel_binding(
&mut self,
available: bool,
) -> Result<()>
pub fn tls_established_with_channel_binding( &mut self, available: bool, ) -> Result<()>
Acknowledge verified TLS and whether the host can supply tls-server-end-point
data to start_scram. The core prefers PLUS only when data is available.
pub fn start_scram(&mut self, scram: ScramSha256) -> Result<()>
pub fn query( &mut self, token: Token, sql: &str, deadline: Option<Instant>, ) -> Result<()>
Sourcepub fn execute(
&mut self,
token: Token,
query: ExtendedQuery<'_>,
deadline: Option<Instant>,
) -> Result<()>
pub fn execute( &mut self, token: Token, query: ExtendedQuery<'_>, deadline: Option<Instant>, ) -> Result<()>
Every operation ends in Sync, so an error cannot discard a later token.
pub fn copy_data(&mut self, bytes: &[u8]) -> Result<()>
pub fn copy_finish(&mut self, error: Option<&str>) -> Result<()>
Sourcepub fn cancel_request(&self) -> Option<[u8; 16]>
pub fn cancel_request(&self) -> Option<[u8; 16]>
Send on a NEW connection; the main stream remains owned by this state machine.
pub fn transaction_status(&self) -> TransactionStatus
pub fn is_ready(&self) -> bool
pub fn pending_count(&self) -> usize
pub fn next_timeout(&self) -> Option<Instant>
pub fn handle_timeout(&mut self, now: Instant)
Sourcepub fn abort(&mut self, reason: Error)
pub fn abort(&mut self, reason: Error)
Transport EOF, TLS failure, cancellation or malformed input terminates all pending tokens once. Pull Completed events followed by Closed.
pub fn end(&mut self) -> Result<()>
Sourcepub fn next_event(&mut self) -> Result<Option<Event<'_>>>
pub fn next_event(&mut self) -> Result<Option<Event<'_>>>
Pull the next borrowed event. A terminal server ErrorResponse returns
Error::ConnectionAborted immediately and makes the session unusable.
Continue pulling to drain one Aborted completion per pending token, then
Closed; a later transport abort cannot replace the server diagnostic.
After ScramNeeded, pulling again before start_scram returns
Error::State instead of Ok(None): an unanswered SCRAM request is a
host error, not idleness. The connection is unchanged, so start_scram
(or abort) is still accepted afterwards.