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
68/// Trait containing all [`struct@TcpConnection`] methods.
69///
70/// # Implementors
71///
72/// [`TcpConnection`][struct@crate::TcpConnection], [`TcpWrapperConnection`][struct@crate::TcpWrapperConnection]
73pub trait TcpConnectionExt: IsA<TcpConnection> + 'static {
74    /// Checks if graceful disconnects are used. See
75    /// g_tcp_connection_set_graceful_disconnect().
76    ///
77    /// # Returns
78    ///
79    /// [`true`] if graceful disconnect is used on close, [`false`] otherwise
80    #[doc(alias = "g_tcp_connection_get_graceful_disconnect")]
81    #[doc(alias = "get_graceful_disconnect")]
82    #[doc(alias = "graceful-disconnect")]
83    fn is_graceful_disconnect(&self) -> bool {
84        unsafe {
85            from_glib(ffi::g_tcp_connection_get_graceful_disconnect(
86                self.as_ref().to_glib_none().0,
87            ))
88        }
89    }
90
91    /// This enables graceful disconnects on close. A graceful disconnect
92    /// means that we signal the receiving end that the connection is terminated
93    /// and wait for it to close the connection before closing the connection.
94    ///
95    /// A graceful disconnect means that we can be sure that we successfully sent
96    /// all the outstanding data to the other end, or get an error reported.
97    /// However, it also means we have to wait for all the data to reach the
98    /// other side and for it to acknowledge this by closing the socket, which may
99    /// take a while. For this reason it is disabled by default.
100    /// ## `graceful_disconnect`
101    /// Whether to do graceful disconnects or not
102    #[doc(alias = "g_tcp_connection_set_graceful_disconnect")]
103    #[doc(alias = "graceful-disconnect")]
104    fn set_graceful_disconnect(&self, graceful_disconnect: bool) {
105        unsafe {
106            ffi::g_tcp_connection_set_graceful_disconnect(
107                self.as_ref().to_glib_none().0,
108                graceful_disconnect.into_glib(),
109            );
110        }
111    }
112
113    #[doc(alias = "graceful-disconnect")]
114    fn connect_graceful_disconnect_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
115        unsafe extern "C" fn notify_graceful_disconnect_trampoline<
116            P: IsA<TcpConnection>,
117            F: Fn(&P) + 'static,
118        >(
119            this: *mut ffi::GTcpConnection,
120            _param_spec: glib::ffi::gpointer,
121            f: glib::ffi::gpointer,
122        ) {
123            let f: &F = &*(f as *const F);
124            f(TcpConnection::from_glib_borrow(this).unsafe_cast_ref())
125        }
126        unsafe {
127            let f: Box_<F> = Box_::new(f);
128            connect_raw(
129                self.as_ptr() as *mut _,
130                c"notify::graceful-disconnect".as_ptr() as *const _,
131                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
132                    notify_graceful_disconnect_trampoline::<Self, F> as *const (),
133                )),
134                Box_::into_raw(f),
135            )
136        }
137    }
138}
139
140impl<O: IsA<TcpConnection>> TcpConnectionExt for O {}