[][src]Struct pg_wire::HandShakeProcess

pub struct HandShakeProcess { /* fields omitted */ }

Encapsulate protocol hand shake process

Examples

This example is not tested
use pg_wire::{HandShakeProcess, HandShakeStatus, HandShakeRequest};

let mut stream = accept_tcp_connection();
let mut process = HandShakeProcess::start();
let mut buffer: Option<Vec<u8>> = None;
loop {
    match process.next_stage(buffer.as_deref()) {
        Ok(HandShakeStatus::Requesting(HandShakeRequest::Buffer(len))) => {
            let mut buf = vec![b'0'; len];
            buffer = Some(stream.read(&mut buf));
        }
        Ok(HandShakeStatus::Requesting(HandShakeRequest::UpgradeToSsl)) => {
            stream.write_all(&[b'S']); // accepting tls connection from client
            stream = tls_stream(stream);
        }
        Ok(HandShakeStatus::Cancel(conn_id, secret_key)) => {
            handle_request_cancellation(conn_id, secret_key);
            break;
        }
        Ok(HandShakeStatus::Done(props)) => {
            handle_authentication_and_other_stuff();
            break;
        }
        Err(protocol_error) => {
            handle_protocol_error(protocol_error);
            break;
        }
    }
}

Implementations

impl Process[src]

pub fn start() -> Process[src]

Creates new process to make client <-> server hand shake

pub fn next_stage(&mut self, payload: Option<&[u8]>) -> Result<Status>[src]

Proceed to the next stage of client <-> server hand shake

Auto Trait Implementations

impl RefUnwindSafe for Process

impl Send for Process

impl Sync for Process

impl Unpin for Process

impl UnwindSafe for Process

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.