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
107/// Trait containing all [`struct@ThreadedSocketService`] methods.
108///
109/// # Implementors
110///
111/// [`ThreadedSocketService`][struct@crate::ThreadedSocketService]
112pub trait ThreadedSocketServiceExt: IsA<ThreadedSocketService> + 'static {
113 /// The maximum number of threads handling clients for this service.
114 #[doc(alias = "max-threads")]
115 fn max_threads(&self) -> i32 {
116 ObjectExt::property(self.as_ref(), "max-threads")
117 }
118
119 /// The ::run signal is emitted in a worker thread in response to an
120 /// incoming connection. This thread is dedicated to handling
121 /// @connection and may perform blocking IO. The signal handler need
122 /// not return until the connection is closed.
123 /// ## `connection`
124 /// a new #GSocketConnection object.
125 /// ## `source_object`
126 /// the source_object passed to g_socket_listener_add_address().
127 ///
128 /// # Returns
129 ///
130 /// [`true`] to stop further signal handlers from being called
131 #[doc(alias = "run")]
132 fn connect_run<F: Fn(&Self, &SocketConnection, Option<&glib::Object>) -> bool + 'static>(
133 &self,
134 f: F,
135 ) -> SignalHandlerId {
136 unsafe extern "C" fn run_trampoline<
137 P: IsA<ThreadedSocketService>,
138 F: Fn(&P, &SocketConnection, Option<&glib::Object>) -> bool + 'static,
139 >(
140 this: *mut ffi::GThreadedSocketService,
141 connection: *mut ffi::GSocketConnection,
142 source_object: *mut glib::gobject_ffi::GObject,
143 f: glib::ffi::gpointer,
144 ) -> glib::ffi::gboolean {
145 let f: &F = &*(f as *const F);
146 f(
147 ThreadedSocketService::from_glib_borrow(this).unsafe_cast_ref(),
148 &from_glib_borrow(connection),
149 Option::<glib::Object>::from_glib_borrow(source_object)
150 .as_ref()
151 .as_ref(),
152 )
153 .into_glib()
154 }
155 unsafe {
156 let f: Box_<F> = Box_::new(f);
157 connect_raw(
158 self.as_ptr() as *mut _,
159 c"run".as_ptr() as *const _,
160 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
161 run_trampoline::<Self, F> as *const (),
162 )),
163 Box_::into_raw(f),
164 )
165 }
166 }
167}
168
169impl<O: IsA<ThreadedSocketService>> ThreadedSocketServiceExt for O {}