gio/auto/
threaded_socket_service.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, SocketConnection, SocketListener, SocketService};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A `GThreadedSocketService` is a simple subclass of [`SocketService`][crate::SocketService]
16    /// that handles incoming connections by creating a worker thread and
17    /// dispatching the connection to it by emitting the
18    /// [`run`][struct@crate::ThreadedSocketService#run] signal] in the new thread.
19    ///
20    /// The signal handler may perform blocking I/O and need not return
21    /// until the connection is closed.
22    ///
23    /// The service is implemented using a thread pool, so there is a
24    /// limited amount of threads available to serve incoming requests.
25    /// The service automatically stops the [`SocketService`][crate::SocketService] from accepting
26    /// new connections when all threads are busy.
27    ///
28    /// As with [`SocketService`][crate::SocketService], you may connect to
29    /// [`run`][struct@crate::ThreadedSocketService#run], or subclass and override the default
30    /// handler.
31    ///
32    /// ## Properties
33    ///
34    ///
35    /// #### `max-threads`
36    ///  The maximum number of threads handling clients for this service.
37    ///
38    /// Readable | Writeable | Construct Only
39    /// <details><summary><h4>SocketService</h4></summary>
40    ///
41    ///
42    /// #### `active`
43    ///  Whether the service is currently accepting connections.
44    ///
45    /// Readable | Writeable | Construct
46    /// </details>
47    /// <details><summary><h4>SocketListener</h4></summary>
48    ///
49    ///
50    /// #### `listen-backlog`
51    ///  The number of outstanding connections in the listen queue.
52    ///
53    /// Readable | Writeable | Construct
54    /// </details>
55    ///
56    /// ## Signals
57    ///
58    ///
59    /// #### `run`
60    ///  The ::run signal is emitted in a worker thread in response to an
61    /// incoming connection. This thread is dedicated to handling
62    /// @connection and may perform blocking IO. The signal handler need
63    /// not return until the connection is closed.
64    ///
65    ///
66    /// <details><summary><h4>SocketService</h4></summary>
67    ///
68    ///
69    /// #### `incoming`
70    ///  The ::incoming signal is emitted when a new incoming connection
71    /// to @service needs to be handled. The handler must initiate the
72    /// handling of @connection, but may not block; in essence,
73    /// asynchronous operations must be used.
74    ///
75    /// @connection will be unreffed once the signal handler returns,
76    /// so you need to ref it yourself if you are planning to use it.
77    ///
78    ///
79    /// </details>
80    /// <details><summary><h4>SocketListener</h4></summary>
81    ///
82    ///
83    /// #### `event`
84    ///  Emitted when @listener's activity on @socket changes state.
85    /// Note that when @listener is used to listen on both IPv4 and
86    /// IPv6, a separate set of signals will be emitted for each, and
87    /// the order they happen in is undefined.
88    ///
89    ///
90    /// </details>
91    ///
92    /// # Implements
93    ///
94    /// [`ThreadedSocketServiceExt`][trait@crate::prelude::ThreadedSocketServiceExt], [`SocketServiceExt`][trait@crate::prelude::SocketServiceExt], [`SocketListenerExt`][trait@crate::prelude::SocketListenerExt], [`trait@glib::ObjectExt`], [`SocketListenerExtManual`][trait@crate::prelude::SocketListenerExtManual]
95    #[doc(alias = "GThreadedSocketService")]
96    pub struct ThreadedSocketService(Object<ffi::GThreadedSocketService, ffi::GThreadedSocketServiceClass>) @extends SocketService, SocketListener;
97
98    match fn {
99        type_ => || ffi::g_threaded_socket_service_get_type(),
100    }
101}
102
103impl ThreadedSocketService {
104    pub const NONE: Option<&'static ThreadedSocketService> = None;
105}
106
107mod sealed {
108    pub trait Sealed {}
109    impl<T: super::IsA<super::ThreadedSocketService>> Sealed for T {}
110}
111
112/// Trait containing all [`struct@ThreadedSocketService`] methods.
113///
114/// # Implementors
115///
116/// [`ThreadedSocketService`][struct@crate::ThreadedSocketService]
117pub trait ThreadedSocketServiceExt: IsA<ThreadedSocketService> + sealed::Sealed + 'static {
118    /// The maximum number of threads handling clients for this service.
119    #[doc(alias = "max-threads")]
120    fn max_threads(&self) -> i32 {
121        ObjectExt::property(self.as_ref(), "max-threads")
122    }
123
124    /// The ::run signal is emitted in a worker thread in response to an
125    /// incoming connection. This thread is dedicated to handling
126    /// @connection and may perform blocking IO. The signal handler need
127    /// not return until the connection is closed.
128    /// ## `connection`
129    /// a new #GSocketConnection object.
130    /// ## `source_object`
131    /// the source_object passed to g_socket_listener_add_address().
132    ///
133    /// # Returns
134    ///
135    /// [`true`] to stop further signal handlers from being called
136    #[doc(alias = "run")]
137    fn connect_run<F: Fn(&Self, &SocketConnection, Option<&glib::Object>) -> bool + 'static>(
138        &self,
139        f: F,
140    ) -> SignalHandlerId {
141        unsafe extern "C" fn run_trampoline<
142            P: IsA<ThreadedSocketService>,
143            F: Fn(&P, &SocketConnection, Option<&glib::Object>) -> bool + 'static,
144        >(
145            this: *mut ffi::GThreadedSocketService,
146            connection: *mut ffi::GSocketConnection,
147            source_object: *mut glib::gobject_ffi::GObject,
148            f: glib::ffi::gpointer,
149        ) -> glib::ffi::gboolean {
150            let f: &F = &*(f as *const F);
151            f(
152                ThreadedSocketService::from_glib_borrow(this).unsafe_cast_ref(),
153                &from_glib_borrow(connection),
154                Option::<glib::Object>::from_glib_borrow(source_object)
155                    .as_ref()
156                    .as_ref(),
157            )
158            .into_glib()
159        }
160        unsafe {
161            let f: Box_<F> = Box_::new(f);
162            connect_raw(
163                self.as_ptr() as *mut _,
164                b"run\0".as_ptr() as *const _,
165                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
166                    run_trampoline::<Self, F> as *const (),
167                )),
168                Box_::into_raw(f),
169            )
170        }
171    }
172}
173
174impl<O: IsA<ThreadedSocketService>> ThreadedSocketServiceExt for O {}