tokio_postgres_fork/
cancel_query_raw.rs

1use crate::config::{SslMode, SslNegotiation};
2use crate::tls::TlsConnect;
3use crate::{connect_tls, Error};
4use bytes::BytesMut;
5use postgres_protocol::message::frontend;
6use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
7
8pub async fn cancel_query_raw<S, T>(
9    stream: S,
10    mode: SslMode,
11    negotiation: SslNegotiation,
12    tls: T,
13    has_hostname: bool,
14    process_id: i32,
15    secret_key: i32,
16) -> Result<(), Error>
17where
18    S: AsyncRead + AsyncWrite + Unpin,
19    T: TlsConnect<S>,
20{
21    let mut stream = connect_tls::connect_tls(stream, mode, negotiation, tls, has_hostname).await?;
22
23    let mut buf = BytesMut::new();
24    frontend::cancel_request(process_id, secret_key, &mut buf);
25
26    stream.write_all(&buf).await.map_err(Error::io)?;
27    stream.flush().await.map_err(Error::io)?;
28    stream.shutdown().await.map_err(Error::io)?;
29
30    Ok(())
31}