docs: handshake documentation

This commit is contained in:
Jindřich Moravec 2023-12-31 18:45:50 +01:00
parent eb8410718d
commit c61b6021db
5 changed files with 28 additions and 3 deletions

View file

@ -7,15 +7,20 @@ use crate::reader::backend::BackendProtoReader;
use crate::writer::frontend::FrontendProtoWriter;
use crate::writer::protowriter::ProtoFlush;
/// Performs client-side handshake with the server until the `ReadyForQuery` message is received.
/// For more info visit the [`55.2.1. Start-up`](https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-START-UP)
pub async fn do_client_handshake(
writer: &mut (impl FrontendProtoWriter + ProtoFlush),
reader: &mut impl BackendProtoReader,
request: HandshakeRequest,
) -> Result<HandshakeResponse, ClientHandshakeError> {
// Send StartupMessage without SSLRequest
let startup_message: StartupMessageData = request.into();
writer.write_startup_message(startup_message).await?;
writer.flush().await?;
// Wait for AuthenticationOk
let auth = reader.read_proto().await?;
if !matches!(
auth,
@ -24,6 +29,7 @@ pub async fn do_client_handshake(
return Err(ClientHandshakeError::UnexpectedAuthResponse(auth));
}
// Read server parameter messages until ReadyForQuery is received
let mut messages = Vec::new();
loop {
let msg = reader.read_proto().await?;