madsim_tokio_postgres/
cancel_query.rs

1use crate::client::SocketConfig;
2use crate::config::{Host, SslMode};
3use crate::tls::MakeTlsConnect;
4use crate::{cancel_query_raw, connect_socket, Error, Socket};
5use std::io;
6
7pub(crate) async fn cancel_query<T>(
8    config: Option<SocketConfig>,
9    ssl_mode: SslMode,
10    mut tls: T,
11    process_id: i32,
12    secret_key: i32,
13) -> Result<(), Error>
14where
15    T: MakeTlsConnect<Socket>,
16{
17    let config = match config {
18        Some(config) => config,
19        None => {
20            return Err(Error::connect(io::Error::new(
21                io::ErrorKind::InvalidInput,
22                "unknown host",
23            )))
24        }
25    };
26
27    let hostname = match &config.host {
28        Host::Tcp(host) => &**host,
29        // postgres doesn't support TLS over unix sockets, so the choice here doesn't matter
30        #[cfg(all(unix, not(madsim)))]
31        Host::Unix(_) => "",
32    };
33    let tls = tls
34        .make_tls_connect(hostname)
35        .map_err(|e| Error::tls(e.into()))?;
36
37    let socket = connect_socket::connect_socket(
38        &config.host,
39        config.port,
40        config.connect_timeout,
41        config.keepalives,
42        config.keepalives_idle,
43    )
44    .await?;
45
46    cancel_query_raw::cancel_query_raw(socket, ssl_mode, tls, process_id, secret_key).await
47}