tokio_postgres/
cancel_token.rs1use crate::config::{SslMode, SslNegotiation};
2use crate::tls::TlsConnect;
3#[cfg(feature = "runtime")]
4use crate::{cancel_query, client::SocketConfig, tls::MakeTlsConnect, Socket};
5use crate::{cancel_query_raw, Error};
6use tokio::io::{AsyncRead, AsyncWrite};
7
8#[derive(Clone)]
11pub struct CancelToken {
12 #[cfg(feature = "runtime")]
13 pub(crate) socket_config: Option<SocketConfig>,
14 pub(crate) ssl_mode: SslMode,
15 pub(crate) ssl_negotiation: SslNegotiation,
16 pub(crate) process_id: i32,
17 pub(crate) secret_key: i32,
18}
19
20impl CancelToken {
21 #[cfg(feature = "runtime")]
34 pub async fn cancel_query<T>(&self, tls: T) -> Result<(), Error>
35 where
36 T: MakeTlsConnect<Socket>,
37 {
38 cancel_query::cancel_query(
39 self.socket_config.clone(),
40 self.ssl_mode,
41 self.ssl_negotiation,
42 tls,
43 self.process_id,
44 self.secret_key,
45 )
46 .await
47 }
48
49 pub async fn cancel_query_raw<S, T>(&self, stream: S, tls: T) -> Result<(), Error>
52 where
53 S: AsyncRead + AsyncWrite + Unpin,
54 T: TlsConnect<S>,
55 {
56 cancel_query_raw::cancel_query_raw(
57 stream,
58 self.ssl_mode,
59 self.ssl_negotiation,
60 tls,
61 true,
62 self.process_id,
63 self.secret_key,
64 )
65 .await
66 }
67}