gio/auto/
tcp_connection.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, IOStream, SocketConnection};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// This is the subclass of [`SocketConnection`][crate::SocketConnection] that is created
15    /// for TCP/IP sockets.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `graceful-disconnect`
21    ///  Whether [`IOStreamExt::close()`][crate::prelude::IOStreamExt::close()] does a graceful disconnect.
22    ///
23    /// Readable | Writeable
24    /// <details><summary><h4>SocketConnection</h4></summary>
25    ///
26    ///
27    /// #### `socket`
28    ///  The underlying [`Socket`][crate::Socket].
29    ///
30    /// Readable | Writeable | Construct Only
31    /// </details>
32    /// <details><summary><h4>IOStream</h4></summary>
33    ///
34    ///
35    /// #### `closed`
36    ///  Whether the stream is closed.
37    ///
38    /// Readable
39    ///
40    ///
41    /// #### `input-stream`
42    ///  The [`InputStream`][crate::InputStream] to read from.
43    ///
44    /// Readable
45    ///
46    ///
47    /// #### `output-stream`
48    ///  The [`OutputStream`][crate::OutputStream] to write to.
49    ///
50    /// Readable
51    /// </details>
52    ///
53    /// # Implements
54    ///
55    /// [`TcpConnectionExt`][trait@crate::prelude::TcpConnectionExt], [`SocketConnectionExt`][trait@crate::prelude::SocketConnectionExt], [`IOStreamExt`][trait@crate::prelude::IOStreamExt], [`trait@glib::ObjectExt`], [`IOStreamExtManual`][trait@crate::prelude::IOStreamExtManual]
56    #[doc(alias = "GTcpConnection")]
57    pub struct TcpConnection(Object<ffi::GTcpConnection, ffi::GTcpConnectionClass>) @extends SocketConnection, IOStream;
58
59    match fn {
60        type_ => || ffi::g_tcp_connection_get_type(),
61    }
62}
63
64impl TcpConnection {
65    pub const NONE: Option<&'static TcpConnection> = None;
66}
67
68mod sealed {
69    pub trait Sealed {}
70    impl<T: super::IsA<super::TcpConnection>> Sealed for T {}
71}
72
73/// Trait containing all [`struct@TcpConnection`] methods.
74///
75/// # Implementors
76///
77/// [`TcpConnection`][struct@crate::TcpConnection], [`TcpWrapperConnection`][struct@crate::TcpWrapperConnection]
78pub trait TcpConnectionExt: IsA<TcpConnection> + sealed::Sealed + 'static {
79    /// Checks if graceful disconnects are used. See
80    /// g_tcp_connection_set_graceful_disconnect().
81    ///
82    /// # Returns
83    ///
84    /// [`true`] if graceful disconnect is used on close, [`false`] otherwise
85    #[doc(alias = "g_tcp_connection_get_graceful_disconnect")]
86    #[doc(alias = "get_graceful_disconnect")]
87    #[doc(alias = "graceful-disconnect")]
88    fn is_graceful_disconnect(&self) -> bool {
89        unsafe {
90            from_glib(ffi::g_tcp_connection_get_graceful_disconnect(
91                self.as_ref().to_glib_none().0,
92            ))
93        }
94    }
95
96    /// This enables graceful disconnects on close. A graceful disconnect
97    /// means that we signal the receiving end that the connection is terminated
98    /// and wait for it to close the connection before closing the connection.
99    ///
100    /// A graceful disconnect means that we can be sure that we successfully sent
101    /// all the outstanding data to the other end, or get an error reported.
102    /// However, it also means we have to wait for all the data to reach the
103    /// other side and for it to acknowledge this by closing the socket, which may
104    /// take a while. For this reason it is disabled by default.
105    /// ## `graceful_disconnect`
106    /// Whether to do graceful disconnects or not
107    #[doc(alias = "g_tcp_connection_set_graceful_disconnect")]
108    #[doc(alias = "graceful-disconnect")]
109    fn set_graceful_disconnect(&self, graceful_disconnect: bool) {
110        unsafe {
111            ffi::g_tcp_connection_set_graceful_disconnect(
112                self.as_ref().to_glib_none().0,
113                graceful_disconnect.into_glib(),
114            );
115        }
116    }
117
118    #[doc(alias = "graceful-disconnect")]
119    fn connect_graceful_disconnect_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
120        unsafe extern "C" fn notify_graceful_disconnect_trampoline<
121            P: IsA<TcpConnection>,
122            F: Fn(&P) + 'static,
123        >(
124            this: *mut ffi::GTcpConnection,
125            _param_spec: glib::ffi::gpointer,
126            f: glib::ffi::gpointer,
127        ) {
128            let f: &F = &*(f as *const F);
129            f(TcpConnection::from_glib_borrow(this).unsafe_cast_ref())
130        }
131        unsafe {
132            let f: Box_<F> = Box_::new(f);
133            connect_raw(
134                self.as_ptr() as *mut _,
135                b"notify::graceful-disconnect\0".as_ptr() as *const _,
136                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
137                    notify_graceful_disconnect_trampoline::<Self, F> as *const (),
138                )),
139                Box_::into_raw(f),
140            )
141        }
142    }
143}
144
145impl<O: IsA<TcpConnection>> TcpConnectionExt for O {}