gio/auto/socket_client.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#![allow(deprecated)]
5
6use crate::{
7 ffi, AsyncResult, Cancellable, IOStream, ProxyResolver, SocketAddress, SocketClientEvent,
8 SocketConnectable, SocketConnection, SocketFamily, SocketProtocol, SocketType,
9 TlsCertificateFlags,
10};
11use glib::{
12 object::ObjectType as _,
13 prelude::*,
14 signal::{connect_raw, SignalHandlerId},
15 translate::*,
16};
17use std::{boxed::Box as Box_, pin::Pin};
18
19glib::wrapper! {
20 /// `GSocketClient` is a lightweight high-level utility class for connecting to
21 /// a network host using a connection oriented socket type.
22 ///
23 /// You create a `GSocketClient` object, set any options you want, and then
24 /// call a sync or async connect operation, which returns a
25 /// [`SocketConnection`][crate::SocketConnection] subclass on success.
26 ///
27 /// The type of the [`SocketConnection`][crate::SocketConnection] object returned depends on the
28 /// type of the underlying socket that is in use. For instance, for a TCP/IP
29 /// connection it will be a [`TcpConnection`][crate::TcpConnection].
30 ///
31 /// As `GSocketClient` is a lightweight object, you don't need to cache it. You
32 /// can just create a new one any time you need one.
33 ///
34 /// ## Properties
35 ///
36 ///
37 /// #### `enable-proxy`
38 /// Enable proxy support.
39 ///
40 /// Readable | Writeable | Construct
41 ///
42 ///
43 /// #### `family`
44 /// The address family to use for socket construction.
45 ///
46 /// Readable | Writeable | Construct
47 ///
48 ///
49 /// #### `local-address`
50 /// The local address constructed sockets will be bound to.
51 ///
52 /// Readable | Writeable | Construct
53 ///
54 ///
55 /// #### `protocol`
56 /// The protocol to use for socket construction, or `0` for default.
57 ///
58 /// Readable | Writeable | Construct
59 ///
60 ///
61 /// #### `proxy-resolver`
62 /// The proxy resolver to use
63 ///
64 /// Readable | Writeable | Construct
65 ///
66 ///
67 /// #### `timeout`
68 /// The I/O timeout for sockets, in seconds, or `0` for none.
69 ///
70 /// Readable | Writeable | Construct
71 ///
72 ///
73 /// #### `tls`
74 /// Whether to create TLS connections.
75 ///
76 /// Readable | Writeable | Construct
77 ///
78 ///
79 /// #### `tls-validation-flags`
80 /// The TLS validation flags used when creating TLS connections. The
81 /// default value is [`TlsCertificateFlags::VALIDATE_ALL`][crate::TlsCertificateFlags::VALIDATE_ALL].
82 ///
83 /// GLib guarantees that if certificate verification fails, at least one
84 /// flag will be set, but it does not guarantee that all possible flags
85 /// will be set. Accordingly, you may not safely decide to ignore any
86 /// particular type of error. For example, it would be incorrect to mask
87 /// [`TlsCertificateFlags::EXPIRED`][crate::TlsCertificateFlags::EXPIRED] if you want to allow expired certificates,
88 /// because this could potentially be the only error flag set even if
89 /// other problems exist with the certificate. Therefore, there is no
90 /// safe way to use this property. This is not a horrible problem,
91 /// though, because you should not be attempting to ignore validation
92 /// errors anyway. If you really must ignore TLS certificate errors,
93 /// connect to the #GSocketClient::event signal, wait for it to be
94 /// emitted with [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking], and use that to
95 /// connect to #GTlsConnection::accept-certificate.
96 ///
97 /// Readable | Writeable | Construct
98 ///
99 ///
100 /// #### `type`
101 /// The type to use for socket construction.
102 ///
103 /// Readable | Writeable | Construct
104 ///
105 /// ## Signals
106 ///
107 ///
108 /// #### `event`
109 /// Emitted when @client's activity on @connectable changes state.
110 /// Among other things, this can be used to provide progress
111 /// information about a network connection in the UI. The meanings of
112 /// the different @event values are as follows:
113 ///
114 /// - [`SocketClientEvent::Resolving`][crate::SocketClientEvent::Resolving]: @client is about to look up @connectable
115 /// in DNS. @connection will be [`None`].
116 ///
117 /// - [`SocketClientEvent::Resolved`][crate::SocketClientEvent::Resolved]: @client has successfully resolved
118 /// @connectable in DNS. @connection will be [`None`].
119 ///
120 /// - [`SocketClientEvent::Connecting`][crate::SocketClientEvent::Connecting]: @client is about to make a connection
121 /// to a remote host; either a proxy server or the destination server
122 /// itself. @connection is the #GSocketConnection, which is not yet
123 /// connected. Since GLib 2.40, you can access the remote
124 /// address via g_socket_connection_get_remote_address().
125 ///
126 /// - [`SocketClientEvent::Connected`][crate::SocketClientEvent::Connected]: @client has successfully connected
127 /// to a remote host. @connection is the connected #GSocketConnection.
128 ///
129 /// - [`SocketClientEvent::ProxyNegotiating`][crate::SocketClientEvent::ProxyNegotiating]: @client is about to negotiate
130 /// with a proxy to get it to connect to @connectable. @connection is
131 /// the #GSocketConnection to the proxy server.
132 ///
133 /// - [`SocketClientEvent::ProxyNegotiated`][crate::SocketClientEvent::ProxyNegotiated]: @client has negotiated a
134 /// connection to @connectable through a proxy server. @connection is
135 /// the stream returned from g_proxy_connect(), which may or may not
136 /// be a #GSocketConnection.
137 ///
138 /// - [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking]: @client is about to begin a TLS
139 /// handshake. @connection is a #GTlsClientConnection.
140 ///
141 /// - [`SocketClientEvent::TlsHandshaked`][crate::SocketClientEvent::TlsHandshaked]: @client has successfully completed
142 /// the TLS handshake. @connection is a #GTlsClientConnection.
143 ///
144 /// - [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete]: @client has either successfully connected
145 /// to @connectable (in which case @connection is the #GSocketConnection
146 /// that it will be returning to the caller) or has failed (in which
147 /// case @connection is [`None`] and the client is about to return an error).
148 ///
149 /// Each event except [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] may be emitted
150 /// multiple times (or not at all) for a given connectable (in
151 /// particular, if @client ends up attempting to connect to more than
152 /// one address). However, if @client emits the #GSocketClient::event
153 /// signal at all for a given connectable, then it will always emit
154 /// it with [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] when it is done.
155 ///
156 /// Note that there may be additional #GSocketClientEvent values in
157 /// the future; unrecognized @event values should be ignored.
158 ///
159 ///
160 ///
161 /// # Implements
162 ///
163 /// [`SocketClientExt`][trait@crate::prelude::SocketClientExt], [`trait@glib::ObjectExt`]
164 #[doc(alias = "GSocketClient")]
165 pub struct SocketClient(Object<ffi::GSocketClient, ffi::GSocketClientClass>);
166
167 match fn {
168 type_ => || ffi::g_socket_client_get_type(),
169 }
170}
171
172impl SocketClient {
173 pub const NONE: Option<&'static SocketClient> = None;
174
175 /// Creates a new #GSocketClient with the default options.
176 ///
177 /// # Returns
178 ///
179 /// a #GSocketClient.
180 /// Free the returned object with g_object_unref().
181 #[doc(alias = "g_socket_client_new")]
182 pub fn new() -> SocketClient {
183 unsafe { from_glib_full(ffi::g_socket_client_new()) }
184 }
185}
186
187impl Default for SocketClient {
188 fn default() -> Self {
189 Self::new()
190 }
191}
192
193/// Trait containing all [`struct@SocketClient`] methods.
194///
195/// # Implementors
196///
197/// [`SocketClient`][struct@crate::SocketClient]
198pub trait SocketClientExt: IsA<SocketClient> + 'static {
199 /// Enable proxy protocols to be handled by the application. When the
200 /// indicated proxy protocol is returned by the #GProxyResolver,
201 /// #GSocketClient will consider this protocol as supported but will
202 /// not try to find a #GProxy instance to handle handshaking. The
203 /// application must check for this case by calling
204 /// g_socket_connection_get_remote_address() on the returned
205 /// #GSocketConnection, and seeing if it's a #GProxyAddress of the
206 /// appropriate type, to determine whether or not it needs to handle
207 /// the proxy handshaking itself.
208 ///
209 /// This should be used for proxy protocols that are dialects of
210 /// another protocol such as HTTP proxy. It also allows cohabitation of
211 /// proxy protocols that are reused between protocols. A good example
212 /// is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also
213 /// be use as generic socket proxy through the HTTP CONNECT method.
214 ///
215 /// When the proxy is detected as being an application proxy, TLS handshake
216 /// will be skipped. This is required to let the application do the proxy
217 /// specific handshake.
218 /// ## `protocol`
219 /// The proxy protocol
220 #[doc(alias = "g_socket_client_add_application_proxy")]
221 fn add_application_proxy(&self, protocol: &str) {
222 unsafe {
223 ffi::g_socket_client_add_application_proxy(
224 self.as_ref().to_glib_none().0,
225 protocol.to_glib_none().0,
226 );
227 }
228 }
229
230 /// Tries to resolve the @connectable and make a network connection to it.
231 ///
232 /// Upon a successful connection, a new #GSocketConnection is constructed
233 /// and returned. The caller owns this new object and must drop their
234 /// reference to it when finished with it.
235 ///
236 /// The type of the #GSocketConnection object returned depends on the type of
237 /// the underlying socket that is used. For instance, for a TCP/IP connection
238 /// it will be a #GTcpConnection.
239 ///
240 /// The socket created will be the same family as the address that the
241 /// @connectable resolves to, unless family is set with g_socket_client_set_family()
242 /// or indirectly via g_socket_client_set_local_address(). The socket type
243 /// defaults to [`SocketType::Stream`][crate::SocketType::Stream] but can be set with
244 /// g_socket_client_set_socket_type().
245 ///
246 /// If a local address is specified with g_socket_client_set_local_address() the
247 /// socket will be bound to this address before connecting.
248 /// ## `connectable`
249 /// a #GSocketConnectable specifying the remote address.
250 /// ## `cancellable`
251 /// optional #GCancellable object, [`None`] to ignore.
252 ///
253 /// # Returns
254 ///
255 /// a #GSocketConnection on success, [`None`] on error.
256 #[doc(alias = "g_socket_client_connect")]
257 fn connect(
258 &self,
259 connectable: &impl IsA<SocketConnectable>,
260 cancellable: Option<&impl IsA<Cancellable>>,
261 ) -> Result<SocketConnection, glib::Error> {
262 unsafe {
263 let mut error = std::ptr::null_mut();
264 let ret = ffi::g_socket_client_connect(
265 self.as_ref().to_glib_none().0,
266 connectable.as_ref().to_glib_none().0,
267 cancellable.map(|p| p.as_ref()).to_glib_none().0,
268 &mut error,
269 );
270 if error.is_null() {
271 Ok(from_glib_full(ret))
272 } else {
273 Err(from_glib_full(error))
274 }
275 }
276 }
277
278 /// This is the asynchronous version of g_socket_client_connect().
279 ///
280 /// You may wish to prefer the asynchronous version even in synchronous
281 /// command line programs because, since 2.60, it implements
282 /// [RFC 8305](https://tools.ietf.org/html/rfc8305) "Happy Eyeballs"
283 /// recommendations to work around long connection timeouts in networks
284 /// where IPv6 is broken by performing an IPv4 connection simultaneously
285 /// without waiting for IPv6 to time out, which is not supported by the
286 /// synchronous call. (This is not an API guarantee, and may change in
287 /// the future.)
288 ///
289 /// When the operation is finished @callback will be
290 /// called. You can then call g_socket_client_connect_finish() to get
291 /// the result of the operation.
292 /// ## `connectable`
293 /// a #GSocketConnectable specifying the remote address.
294 /// ## `cancellable`
295 /// a #GCancellable, or [`None`]
296 /// ## `callback`
297 /// a #GAsyncReadyCallback
298 #[doc(alias = "g_socket_client_connect_async")]
299 fn connect_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
300 &self,
301 connectable: &impl IsA<SocketConnectable>,
302 cancellable: Option<&impl IsA<Cancellable>>,
303 callback: P,
304 ) {
305 let main_context = glib::MainContext::ref_thread_default();
306 let is_main_context_owner = main_context.is_owner();
307 let has_acquired_main_context = (!is_main_context_owner)
308 .then(|| main_context.acquire().ok())
309 .flatten();
310 assert!(
311 is_main_context_owner || has_acquired_main_context.is_some(),
312 "Async operations only allowed if the thread is owning the MainContext"
313 );
314
315 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
316 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
317 unsafe extern "C" fn connect_async_trampoline<
318 P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
319 >(
320 _source_object: *mut glib::gobject_ffi::GObject,
321 res: *mut crate::ffi::GAsyncResult,
322 user_data: glib::ffi::gpointer,
323 ) {
324 let mut error = std::ptr::null_mut();
325 let ret =
326 ffi::g_socket_client_connect_finish(_source_object as *mut _, res, &mut error);
327 let result = if error.is_null() {
328 Ok(from_glib_full(ret))
329 } else {
330 Err(from_glib_full(error))
331 };
332 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
333 Box_::from_raw(user_data as *mut _);
334 let callback: P = callback.into_inner();
335 callback(result);
336 }
337 let callback = connect_async_trampoline::<P>;
338 unsafe {
339 ffi::g_socket_client_connect_async(
340 self.as_ref().to_glib_none().0,
341 connectable.as_ref().to_glib_none().0,
342 cancellable.map(|p| p.as_ref()).to_glib_none().0,
343 Some(callback),
344 Box_::into_raw(user_data) as *mut _,
345 );
346 }
347 }
348
349 fn connect_future(
350 &self,
351 connectable: &(impl IsA<SocketConnectable> + Clone + 'static),
352 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
353 {
354 let connectable = connectable.clone();
355 Box_::pin(crate::GioFuture::new(
356 self,
357 move |obj, cancellable, send| {
358 obj.connect_async(&connectable, Some(cancellable), move |res| {
359 send.resolve(res);
360 });
361 },
362 ))
363 }
364
365 /// This is a helper function for g_socket_client_connect().
366 ///
367 /// Attempts to create a TCP connection to the named host.
368 ///
369 /// @host_and_port may be in any of a number of recognized formats; an IPv6
370 /// address, an IPv4 address, or a domain name (in which case a DNS
371 /// lookup is performed). Quoting with [] is supported for all address
372 /// types. A port override may be specified in the usual way with a
373 /// colon. Ports may be given as decimal numbers or symbolic names (in
374 /// which case an /etc/services lookup is performed).
375 ///
376 /// If no port override is given in @host_and_port then @default_port will be
377 /// used as the port number to connect to.
378 ///
379 /// In general, @host_and_port is expected to be provided by the user (allowing
380 /// them to give the hostname, and a port override if necessary) and
381 /// @default_port is expected to be provided by the application.
382 ///
383 /// In the case that an IP address is given, a single connection
384 /// attempt is made. In the case that a name is given, multiple
385 /// connection attempts may be made, in turn and according to the
386 /// number of address records in DNS, until a connection succeeds.
387 ///
388 /// Upon a successful connection, a new #GSocketConnection is constructed
389 /// and returned. The caller owns this new object and must drop their
390 /// reference to it when finished with it.
391 ///
392 /// In the event of any failure (DNS error, service not found, no hosts
393 /// connectable) [`None`] is returned and @error (if non-[`None`]) is set
394 /// accordingly.
395 /// ## `host_and_port`
396 /// the name and optionally port of the host to connect to
397 /// ## `default_port`
398 /// the default port to connect to
399 /// ## `cancellable`
400 /// a #GCancellable, or [`None`]
401 ///
402 /// # Returns
403 ///
404 /// a #GSocketConnection on success, [`None`] on error.
405 #[doc(alias = "g_socket_client_connect_to_host")]
406 fn connect_to_host(
407 &self,
408 host_and_port: &str,
409 default_port: u16,
410 cancellable: Option<&impl IsA<Cancellable>>,
411 ) -> Result<SocketConnection, glib::Error> {
412 unsafe {
413 let mut error = std::ptr::null_mut();
414 let ret = ffi::g_socket_client_connect_to_host(
415 self.as_ref().to_glib_none().0,
416 host_and_port.to_glib_none().0,
417 default_port,
418 cancellable.map(|p| p.as_ref()).to_glib_none().0,
419 &mut error,
420 );
421 if error.is_null() {
422 Ok(from_glib_full(ret))
423 } else {
424 Err(from_glib_full(error))
425 }
426 }
427 }
428
429 /// This is the asynchronous version of g_socket_client_connect_to_host().
430 ///
431 /// When the operation is finished @callback will be
432 /// called. You can then call g_socket_client_connect_to_host_finish() to get
433 /// the result of the operation.
434 /// ## `host_and_port`
435 /// the name and optionally the port of the host to connect to
436 /// ## `default_port`
437 /// the default port to connect to
438 /// ## `cancellable`
439 /// a #GCancellable, or [`None`]
440 /// ## `callback`
441 /// a #GAsyncReadyCallback
442 #[doc(alias = "g_socket_client_connect_to_host_async")]
443 fn connect_to_host_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
444 &self,
445 host_and_port: &str,
446 default_port: u16,
447 cancellable: Option<&impl IsA<Cancellable>>,
448 callback: P,
449 ) {
450 let main_context = glib::MainContext::ref_thread_default();
451 let is_main_context_owner = main_context.is_owner();
452 let has_acquired_main_context = (!is_main_context_owner)
453 .then(|| main_context.acquire().ok())
454 .flatten();
455 assert!(
456 is_main_context_owner || has_acquired_main_context.is_some(),
457 "Async operations only allowed if the thread is owning the MainContext"
458 );
459
460 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
461 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
462 unsafe extern "C" fn connect_to_host_async_trampoline<
463 P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
464 >(
465 _source_object: *mut glib::gobject_ffi::GObject,
466 res: *mut crate::ffi::GAsyncResult,
467 user_data: glib::ffi::gpointer,
468 ) {
469 let mut error = std::ptr::null_mut();
470 let ret = ffi::g_socket_client_connect_to_host_finish(
471 _source_object as *mut _,
472 res,
473 &mut error,
474 );
475 let result = if error.is_null() {
476 Ok(from_glib_full(ret))
477 } else {
478 Err(from_glib_full(error))
479 };
480 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
481 Box_::from_raw(user_data as *mut _);
482 let callback: P = callback.into_inner();
483 callback(result);
484 }
485 let callback = connect_to_host_async_trampoline::<P>;
486 unsafe {
487 ffi::g_socket_client_connect_to_host_async(
488 self.as_ref().to_glib_none().0,
489 host_and_port.to_glib_none().0,
490 default_port,
491 cancellable.map(|p| p.as_ref()).to_glib_none().0,
492 Some(callback),
493 Box_::into_raw(user_data) as *mut _,
494 );
495 }
496 }
497
498 fn connect_to_host_future(
499 &self,
500 host_and_port: &str,
501 default_port: u16,
502 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
503 {
504 let host_and_port = String::from(host_and_port);
505 Box_::pin(crate::GioFuture::new(
506 self,
507 move |obj, cancellable, send| {
508 obj.connect_to_host_async(
509 &host_and_port,
510 default_port,
511 Some(cancellable),
512 move |res| {
513 send.resolve(res);
514 },
515 );
516 },
517 ))
518 }
519
520 /// Attempts to create a TCP connection to a service.
521 ///
522 /// This call looks up the SRV record for @service at @domain for the
523 /// "tcp" protocol. It then attempts to connect, in turn, to each of
524 /// the hosts providing the service until either a connection succeeds
525 /// or there are no hosts remaining.
526 ///
527 /// Upon a successful connection, a new #GSocketConnection is constructed
528 /// and returned. The caller owns this new object and must drop their
529 /// reference to it when finished with it.
530 ///
531 /// In the event of any failure (DNS error, service not found, no hosts
532 /// connectable) [`None`] is returned and @error (if non-[`None`]) is set
533 /// accordingly.
534 /// ## `domain`
535 /// a domain name
536 /// ## `service`
537 /// the name of the service to connect to
538 /// ## `cancellable`
539 /// a #GCancellable, or [`None`]
540 ///
541 /// # Returns
542 ///
543 /// a #GSocketConnection if successful, or [`None`] on error
544 #[doc(alias = "g_socket_client_connect_to_service")]
545 fn connect_to_service(
546 &self,
547 domain: &str,
548 service: &str,
549 cancellable: Option<&impl IsA<Cancellable>>,
550 ) -> Result<SocketConnection, glib::Error> {
551 unsafe {
552 let mut error = std::ptr::null_mut();
553 let ret = ffi::g_socket_client_connect_to_service(
554 self.as_ref().to_glib_none().0,
555 domain.to_glib_none().0,
556 service.to_glib_none().0,
557 cancellable.map(|p| p.as_ref()).to_glib_none().0,
558 &mut error,
559 );
560 if error.is_null() {
561 Ok(from_glib_full(ret))
562 } else {
563 Err(from_glib_full(error))
564 }
565 }
566 }
567
568 /// This is the asynchronous version of
569 /// g_socket_client_connect_to_service().
570 /// ## `domain`
571 /// a domain name
572 /// ## `service`
573 /// the name of the service to connect to
574 /// ## `cancellable`
575 /// a #GCancellable, or [`None`]
576 /// ## `callback`
577 /// a #GAsyncReadyCallback
578 #[doc(alias = "g_socket_client_connect_to_service_async")]
579 fn connect_to_service_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
580 &self,
581 domain: &str,
582 service: &str,
583 cancellable: Option<&impl IsA<Cancellable>>,
584 callback: P,
585 ) {
586 let main_context = glib::MainContext::ref_thread_default();
587 let is_main_context_owner = main_context.is_owner();
588 let has_acquired_main_context = (!is_main_context_owner)
589 .then(|| main_context.acquire().ok())
590 .flatten();
591 assert!(
592 is_main_context_owner || has_acquired_main_context.is_some(),
593 "Async operations only allowed if the thread is owning the MainContext"
594 );
595
596 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
597 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
598 unsafe extern "C" fn connect_to_service_async_trampoline<
599 P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
600 >(
601 _source_object: *mut glib::gobject_ffi::GObject,
602 res: *mut crate::ffi::GAsyncResult,
603 user_data: glib::ffi::gpointer,
604 ) {
605 let mut error = std::ptr::null_mut();
606 let ret = ffi::g_socket_client_connect_to_service_finish(
607 _source_object as *mut _,
608 res,
609 &mut error,
610 );
611 let result = if error.is_null() {
612 Ok(from_glib_full(ret))
613 } else {
614 Err(from_glib_full(error))
615 };
616 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
617 Box_::from_raw(user_data as *mut _);
618 let callback: P = callback.into_inner();
619 callback(result);
620 }
621 let callback = connect_to_service_async_trampoline::<P>;
622 unsafe {
623 ffi::g_socket_client_connect_to_service_async(
624 self.as_ref().to_glib_none().0,
625 domain.to_glib_none().0,
626 service.to_glib_none().0,
627 cancellable.map(|p| p.as_ref()).to_glib_none().0,
628 Some(callback),
629 Box_::into_raw(user_data) as *mut _,
630 );
631 }
632 }
633
634 fn connect_to_service_future(
635 &self,
636 domain: &str,
637 service: &str,
638 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
639 {
640 let domain = String::from(domain);
641 let service = String::from(service);
642 Box_::pin(crate::GioFuture::new(
643 self,
644 move |obj, cancellable, send| {
645 obj.connect_to_service_async(&domain, &service, Some(cancellable), move |res| {
646 send.resolve(res);
647 });
648 },
649 ))
650 }
651
652 /// This is a helper function for g_socket_client_connect().
653 ///
654 /// Attempts to create a TCP connection with a network URI.
655 ///
656 /// @uri may be any valid URI containing an "authority" (hostname/port)
657 /// component. If a port is not specified in the URI, @default_port
658 /// will be used. TLS will be negotiated if #GSocketClient:tls is [`true`].
659 /// (#GSocketClient does not know to automatically assume TLS for
660 /// certain URI schemes.)
661 ///
662 /// Using this rather than g_socket_client_connect() or
663 /// g_socket_client_connect_to_host() allows #GSocketClient to
664 /// determine when to use application-specific proxy protocols.
665 ///
666 /// Upon a successful connection, a new #GSocketConnection is constructed
667 /// and returned. The caller owns this new object and must drop their
668 /// reference to it when finished with it.
669 ///
670 /// In the event of any failure (DNS error, service not found, no hosts
671 /// connectable) [`None`] is returned and @error (if non-[`None`]) is set
672 /// accordingly.
673 /// ## `uri`
674 /// A network URI
675 /// ## `default_port`
676 /// the default port to connect to
677 /// ## `cancellable`
678 /// a #GCancellable, or [`None`]
679 ///
680 /// # Returns
681 ///
682 /// a #GSocketConnection on success, [`None`] on error.
683 #[doc(alias = "g_socket_client_connect_to_uri")]
684 fn connect_to_uri(
685 &self,
686 uri: &str,
687 default_port: u16,
688 cancellable: Option<&impl IsA<Cancellable>>,
689 ) -> Result<SocketConnection, glib::Error> {
690 unsafe {
691 let mut error = std::ptr::null_mut();
692 let ret = ffi::g_socket_client_connect_to_uri(
693 self.as_ref().to_glib_none().0,
694 uri.to_glib_none().0,
695 default_port,
696 cancellable.map(|p| p.as_ref()).to_glib_none().0,
697 &mut error,
698 );
699 if error.is_null() {
700 Ok(from_glib_full(ret))
701 } else {
702 Err(from_glib_full(error))
703 }
704 }
705 }
706
707 /// This is the asynchronous version of g_socket_client_connect_to_uri().
708 ///
709 /// When the operation is finished @callback will be
710 /// called. You can then call g_socket_client_connect_to_uri_finish() to get
711 /// the result of the operation.
712 /// ## `uri`
713 /// a network uri
714 /// ## `default_port`
715 /// the default port to connect to
716 /// ## `cancellable`
717 /// a #GCancellable, or [`None`]
718 /// ## `callback`
719 /// a #GAsyncReadyCallback
720 #[doc(alias = "g_socket_client_connect_to_uri_async")]
721 fn connect_to_uri_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
722 &self,
723 uri: &str,
724 default_port: u16,
725 cancellable: Option<&impl IsA<Cancellable>>,
726 callback: P,
727 ) {
728 let main_context = glib::MainContext::ref_thread_default();
729 let is_main_context_owner = main_context.is_owner();
730 let has_acquired_main_context = (!is_main_context_owner)
731 .then(|| main_context.acquire().ok())
732 .flatten();
733 assert!(
734 is_main_context_owner || has_acquired_main_context.is_some(),
735 "Async operations only allowed if the thread is owning the MainContext"
736 );
737
738 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
739 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
740 unsafe extern "C" fn connect_to_uri_async_trampoline<
741 P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
742 >(
743 _source_object: *mut glib::gobject_ffi::GObject,
744 res: *mut crate::ffi::GAsyncResult,
745 user_data: glib::ffi::gpointer,
746 ) {
747 let mut error = std::ptr::null_mut();
748 let ret = ffi::g_socket_client_connect_to_uri_finish(
749 _source_object as *mut _,
750 res,
751 &mut error,
752 );
753 let result = if error.is_null() {
754 Ok(from_glib_full(ret))
755 } else {
756 Err(from_glib_full(error))
757 };
758 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
759 Box_::from_raw(user_data as *mut _);
760 let callback: P = callback.into_inner();
761 callback(result);
762 }
763 let callback = connect_to_uri_async_trampoline::<P>;
764 unsafe {
765 ffi::g_socket_client_connect_to_uri_async(
766 self.as_ref().to_glib_none().0,
767 uri.to_glib_none().0,
768 default_port,
769 cancellable.map(|p| p.as_ref()).to_glib_none().0,
770 Some(callback),
771 Box_::into_raw(user_data) as *mut _,
772 );
773 }
774 }
775
776 fn connect_to_uri_future(
777 &self,
778 uri: &str,
779 default_port: u16,
780 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
781 {
782 let uri = String::from(uri);
783 Box_::pin(crate::GioFuture::new(
784 self,
785 move |obj, cancellable, send| {
786 obj.connect_to_uri_async(&uri, default_port, Some(cancellable), move |res| {
787 send.resolve(res);
788 });
789 },
790 ))
791 }
792
793 /// Gets the proxy enable state; see g_socket_client_set_enable_proxy()
794 ///
795 /// # Returns
796 ///
797 /// whether proxying is enabled
798 #[doc(alias = "g_socket_client_get_enable_proxy")]
799 #[doc(alias = "get_enable_proxy")]
800 #[doc(alias = "enable-proxy")]
801 fn enables_proxy(&self) -> bool {
802 unsafe {
803 from_glib(ffi::g_socket_client_get_enable_proxy(
804 self.as_ref().to_glib_none().0,
805 ))
806 }
807 }
808
809 /// Gets the socket family of the socket client.
810 ///
811 /// See g_socket_client_set_family() for details.
812 ///
813 /// # Returns
814 ///
815 /// a #GSocketFamily
816 #[doc(alias = "g_socket_client_get_family")]
817 #[doc(alias = "get_family")]
818 fn family(&self) -> SocketFamily {
819 unsafe {
820 from_glib(ffi::g_socket_client_get_family(
821 self.as_ref().to_glib_none().0,
822 ))
823 }
824 }
825
826 /// Gets the local address of the socket client.
827 ///
828 /// See g_socket_client_set_local_address() for details.
829 ///
830 /// # Returns
831 ///
832 /// a #GSocketAddress or [`None`]. Do not free.
833 #[doc(alias = "g_socket_client_get_local_address")]
834 #[doc(alias = "get_local_address")]
835 #[doc(alias = "local-address")]
836 fn local_address(&self) -> Option<SocketAddress> {
837 unsafe {
838 from_glib_none(ffi::g_socket_client_get_local_address(
839 self.as_ref().to_glib_none().0,
840 ))
841 }
842 }
843
844 /// Gets the protocol name type of the socket client.
845 ///
846 /// See g_socket_client_set_protocol() for details.
847 ///
848 /// # Returns
849 ///
850 /// a #GSocketProtocol
851 #[doc(alias = "g_socket_client_get_protocol")]
852 #[doc(alias = "get_protocol")]
853 fn protocol(&self) -> SocketProtocol {
854 unsafe {
855 from_glib(ffi::g_socket_client_get_protocol(
856 self.as_ref().to_glib_none().0,
857 ))
858 }
859 }
860
861 /// Gets the #GProxyResolver being used by @self. Normally, this will
862 /// be the resolver returned by g_proxy_resolver_get_default(), but you
863 /// can override it with g_socket_client_set_proxy_resolver().
864 ///
865 /// # Returns
866 ///
867 /// The #GProxyResolver being used by
868 /// @self.
869 #[doc(alias = "g_socket_client_get_proxy_resolver")]
870 #[doc(alias = "get_proxy_resolver")]
871 #[doc(alias = "proxy-resolver")]
872 fn proxy_resolver(&self) -> ProxyResolver {
873 unsafe {
874 from_glib_none(ffi::g_socket_client_get_proxy_resolver(
875 self.as_ref().to_glib_none().0,
876 ))
877 }
878 }
879
880 /// Gets the socket type of the socket client.
881 ///
882 /// See g_socket_client_set_socket_type() for details.
883 ///
884 /// # Returns
885 ///
886 /// a #GSocketFamily
887 #[doc(alias = "g_socket_client_get_socket_type")]
888 #[doc(alias = "get_socket_type")]
889 fn socket_type(&self) -> SocketType {
890 unsafe {
891 from_glib(ffi::g_socket_client_get_socket_type(
892 self.as_ref().to_glib_none().0,
893 ))
894 }
895 }
896
897 /// Gets the I/O timeout time for sockets created by @self.
898 ///
899 /// See g_socket_client_set_timeout() for details.
900 ///
901 /// # Returns
902 ///
903 /// the timeout in seconds
904 #[doc(alias = "g_socket_client_get_timeout")]
905 #[doc(alias = "get_timeout")]
906 fn timeout(&self) -> u32 {
907 unsafe { ffi::g_socket_client_get_timeout(self.as_ref().to_glib_none().0) }
908 }
909
910 /// Gets whether @self creates TLS connections. See
911 /// g_socket_client_set_tls() for details.
912 ///
913 /// # Returns
914 ///
915 /// whether @self uses TLS
916 #[doc(alias = "g_socket_client_get_tls")]
917 #[doc(alias = "get_tls")]
918 #[doc(alias = "tls")]
919 fn is_tls(&self) -> bool {
920 unsafe { from_glib(ffi::g_socket_client_get_tls(self.as_ref().to_glib_none().0)) }
921 }
922
923 /// Gets the TLS validation flags used creating TLS connections via
924 /// @self.
925 ///
926 /// This function does not work as originally designed and is impossible
927 /// to use correctly. See #GSocketClient:tls-validation-flags for more
928 /// information.
929 ///
930 /// # Deprecated since 2.72
931 ///
932 /// Do not attempt to ignore validation errors.
933 ///
934 /// # Returns
935 ///
936 /// the TLS validation flags
937 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
938 #[allow(deprecated)]
939 #[doc(alias = "g_socket_client_get_tls_validation_flags")]
940 #[doc(alias = "get_tls_validation_flags")]
941 #[doc(alias = "tls-validation-flags")]
942 fn tls_validation_flags(&self) -> TlsCertificateFlags {
943 unsafe {
944 from_glib(ffi::g_socket_client_get_tls_validation_flags(
945 self.as_ref().to_glib_none().0,
946 ))
947 }
948 }
949
950 /// Sets whether or not @self attempts to make connections via a
951 /// proxy server. When enabled (the default), #GSocketClient will use a
952 /// #GProxyResolver to determine if a proxy protocol such as SOCKS is
953 /// needed, and automatically do the necessary proxy negotiation.
954 ///
955 /// See also g_socket_client_set_proxy_resolver().
956 /// ## `enable`
957 /// whether to enable proxies
958 #[doc(alias = "g_socket_client_set_enable_proxy")]
959 #[doc(alias = "enable-proxy")]
960 fn set_enable_proxy(&self, enable: bool) {
961 unsafe {
962 ffi::g_socket_client_set_enable_proxy(
963 self.as_ref().to_glib_none().0,
964 enable.into_glib(),
965 );
966 }
967 }
968
969 /// Sets the socket family of the socket client.
970 /// If this is set to something other than [`SocketFamily::Invalid`][crate::SocketFamily::Invalid]
971 /// then the sockets created by this object will be of the specified
972 /// family.
973 ///
974 /// This might be useful for instance if you want to force the local
975 /// connection to be an ipv4 socket, even though the address might
976 /// be an ipv6 mapped to ipv4 address.
977 /// ## `family`
978 /// a #GSocketFamily
979 #[doc(alias = "g_socket_client_set_family")]
980 #[doc(alias = "family")]
981 fn set_family(&self, family: SocketFamily) {
982 unsafe {
983 ffi::g_socket_client_set_family(self.as_ref().to_glib_none().0, family.into_glib());
984 }
985 }
986
987 /// Sets the local address of the socket client.
988 /// The sockets created by this object will bound to the
989 /// specified address (if not [`None`]) before connecting.
990 ///
991 /// This is useful if you want to ensure that the local
992 /// side of the connection is on a specific port, or on
993 /// a specific interface.
994 /// ## `address`
995 /// a #GSocketAddress, or [`None`]
996 #[doc(alias = "g_socket_client_set_local_address")]
997 #[doc(alias = "local-address")]
998 fn set_local_address(&self, address: Option<&impl IsA<SocketAddress>>) {
999 unsafe {
1000 ffi::g_socket_client_set_local_address(
1001 self.as_ref().to_glib_none().0,
1002 address.map(|p| p.as_ref()).to_glib_none().0,
1003 );
1004 }
1005 }
1006
1007 /// Sets the protocol of the socket client.
1008 /// The sockets created by this object will use of the specified
1009 /// protocol.
1010 ///
1011 /// If @protocol is [`SocketProtocol::Default`][crate::SocketProtocol::Default] that means to use the default
1012 /// protocol for the socket family and type.
1013 /// ## `protocol`
1014 /// a #GSocketProtocol
1015 #[doc(alias = "g_socket_client_set_protocol")]
1016 #[doc(alias = "protocol")]
1017 fn set_protocol(&self, protocol: SocketProtocol) {
1018 unsafe {
1019 ffi::g_socket_client_set_protocol(self.as_ref().to_glib_none().0, protocol.into_glib());
1020 }
1021 }
1022
1023 /// Overrides the #GProxyResolver used by @self. You can call this if
1024 /// you want to use specific proxies, rather than using the system
1025 /// default proxy settings.
1026 ///
1027 /// Note that whether or not the proxy resolver is actually used
1028 /// depends on the setting of #GSocketClient:enable-proxy, which is not
1029 /// changed by this function (but which is [`true`] by default)
1030 /// ## `proxy_resolver`
1031 /// a #GProxyResolver, or [`None`] for the
1032 /// default.
1033 #[doc(alias = "g_socket_client_set_proxy_resolver")]
1034 #[doc(alias = "proxy-resolver")]
1035 fn set_proxy_resolver(&self, proxy_resolver: Option<&impl IsA<ProxyResolver>>) {
1036 unsafe {
1037 ffi::g_socket_client_set_proxy_resolver(
1038 self.as_ref().to_glib_none().0,
1039 proxy_resolver.map(|p| p.as_ref()).to_glib_none().0,
1040 );
1041 }
1042 }
1043
1044 /// Sets the socket type of the socket client.
1045 /// The sockets created by this object will be of the specified
1046 /// type.
1047 ///
1048 /// It doesn't make sense to specify a type of [`SocketType::Datagram`][crate::SocketType::Datagram],
1049 /// as GSocketClient is used for connection oriented services.
1050 /// ## `type_`
1051 /// a #GSocketType
1052 #[doc(alias = "g_socket_client_set_socket_type")]
1053 fn set_socket_type(&self, type_: SocketType) {
1054 unsafe {
1055 ffi::g_socket_client_set_socket_type(self.as_ref().to_glib_none().0, type_.into_glib());
1056 }
1057 }
1058
1059 /// Sets the I/O timeout for sockets created by @self. @timeout is a
1060 /// time in seconds, or 0 for no timeout (the default).
1061 ///
1062 /// The timeout value affects the initial connection attempt as well,
1063 /// so setting this may cause calls to g_socket_client_connect(), etc,
1064 /// to fail with [`IOErrorEnum::TimedOut`][crate::IOErrorEnum::TimedOut].
1065 /// ## `timeout`
1066 /// the timeout
1067 #[doc(alias = "g_socket_client_set_timeout")]
1068 #[doc(alias = "timeout")]
1069 fn set_timeout(&self, timeout: u32) {
1070 unsafe {
1071 ffi::g_socket_client_set_timeout(self.as_ref().to_glib_none().0, timeout);
1072 }
1073 }
1074
1075 /// Sets whether @self creates TLS (aka SSL) connections. If @tls is
1076 /// [`true`], @self will wrap its connections in a #GTlsClientConnection
1077 /// and perform a TLS handshake when connecting.
1078 ///
1079 /// Note that since #GSocketClient must return a #GSocketConnection,
1080 /// but #GTlsClientConnection is not a #GSocketConnection, this
1081 /// actually wraps the resulting #GTlsClientConnection in a
1082 /// #GTcpWrapperConnection when returning it. You can use
1083 /// g_tcp_wrapper_connection_get_base_io_stream() on the return value
1084 /// to extract the #GTlsClientConnection.
1085 ///
1086 /// If you need to modify the behavior of the TLS handshake (eg, by
1087 /// setting a client-side certificate to use, or connecting to the
1088 /// #GTlsConnection::accept-certificate signal), you can connect to
1089 /// @self's #GSocketClient::event signal and wait for it to be
1090 /// emitted with [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking], which will give you
1091 /// a chance to see the #GTlsClientConnection before the handshake
1092 /// starts.
1093 /// ## `tls`
1094 /// whether to use TLS
1095 #[doc(alias = "g_socket_client_set_tls")]
1096 #[doc(alias = "tls")]
1097 fn set_tls(&self, tls: bool) {
1098 unsafe {
1099 ffi::g_socket_client_set_tls(self.as_ref().to_glib_none().0, tls.into_glib());
1100 }
1101 }
1102
1103 /// Sets the TLS validation flags used when creating TLS connections
1104 /// via @self. The default value is [`TlsCertificateFlags::VALIDATE_ALL`][crate::TlsCertificateFlags::VALIDATE_ALL].
1105 ///
1106 /// This function does not work as originally designed and is impossible
1107 /// to use correctly. See #GSocketClient:tls-validation-flags for more
1108 /// information.
1109 ///
1110 /// # Deprecated since 2.72
1111 ///
1112 /// Do not attempt to ignore validation errors.
1113 /// ## `flags`
1114 /// the validation flags
1115 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
1116 #[allow(deprecated)]
1117 #[doc(alias = "g_socket_client_set_tls_validation_flags")]
1118 #[doc(alias = "tls-validation-flags")]
1119 fn set_tls_validation_flags(&self, flags: TlsCertificateFlags) {
1120 unsafe {
1121 ffi::g_socket_client_set_tls_validation_flags(
1122 self.as_ref().to_glib_none().0,
1123 flags.into_glib(),
1124 );
1125 }
1126 }
1127
1128 /// The type to use for socket construction.
1129 #[doc(alias = "type")]
1130 fn type_(&self) -> SocketType {
1131 ObjectExt::property(self.as_ref(), "type")
1132 }
1133
1134 /// The type to use for socket construction.
1135 #[doc(alias = "type")]
1136 fn set_type(&self, type_: SocketType) {
1137 ObjectExt::set_property(self.as_ref(), "type", type_)
1138 }
1139
1140 /// Emitted when @client's activity on @connectable changes state.
1141 /// Among other things, this can be used to provide progress
1142 /// information about a network connection in the UI. The meanings of
1143 /// the different @event values are as follows:
1144 ///
1145 /// - [`SocketClientEvent::Resolving`][crate::SocketClientEvent::Resolving]: @client is about to look up @connectable
1146 /// in DNS. @connection will be [`None`].
1147 ///
1148 /// - [`SocketClientEvent::Resolved`][crate::SocketClientEvent::Resolved]: @client has successfully resolved
1149 /// @connectable in DNS. @connection will be [`None`].
1150 ///
1151 /// - [`SocketClientEvent::Connecting`][crate::SocketClientEvent::Connecting]: @client is about to make a connection
1152 /// to a remote host; either a proxy server or the destination server
1153 /// itself. @connection is the #GSocketConnection, which is not yet
1154 /// connected. Since GLib 2.40, you can access the remote
1155 /// address via g_socket_connection_get_remote_address().
1156 ///
1157 /// - [`SocketClientEvent::Connected`][crate::SocketClientEvent::Connected]: @client has successfully connected
1158 /// to a remote host. @connection is the connected #GSocketConnection.
1159 ///
1160 /// - [`SocketClientEvent::ProxyNegotiating`][crate::SocketClientEvent::ProxyNegotiating]: @client is about to negotiate
1161 /// with a proxy to get it to connect to @connectable. @connection is
1162 /// the #GSocketConnection to the proxy server.
1163 ///
1164 /// - [`SocketClientEvent::ProxyNegotiated`][crate::SocketClientEvent::ProxyNegotiated]: @client has negotiated a
1165 /// connection to @connectable through a proxy server. @connection is
1166 /// the stream returned from g_proxy_connect(), which may or may not
1167 /// be a #GSocketConnection.
1168 ///
1169 /// - [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking]: @client is about to begin a TLS
1170 /// handshake. @connection is a #GTlsClientConnection.
1171 ///
1172 /// - [`SocketClientEvent::TlsHandshaked`][crate::SocketClientEvent::TlsHandshaked]: @client has successfully completed
1173 /// the TLS handshake. @connection is a #GTlsClientConnection.
1174 ///
1175 /// - [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete]: @client has either successfully connected
1176 /// to @connectable (in which case @connection is the #GSocketConnection
1177 /// that it will be returning to the caller) or has failed (in which
1178 /// case @connection is [`None`] and the client is about to return an error).
1179 ///
1180 /// Each event except [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] may be emitted
1181 /// multiple times (or not at all) for a given connectable (in
1182 /// particular, if @client ends up attempting to connect to more than
1183 /// one address). However, if @client emits the #GSocketClient::event
1184 /// signal at all for a given connectable, then it will always emit
1185 /// it with [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] when it is done.
1186 ///
1187 /// Note that there may be additional #GSocketClientEvent values in
1188 /// the future; unrecognized @event values should be ignored.
1189 /// ## `event`
1190 /// the event that is occurring
1191 /// ## `connectable`
1192 /// the #GSocketConnectable that @event is occurring on
1193 /// ## `connection`
1194 /// the current representation of the connection
1195 #[doc(alias = "event")]
1196 fn connect_event<
1197 F: Fn(&Self, SocketClientEvent, &SocketConnectable, Option<&IOStream>) + 'static,
1198 >(
1199 &self,
1200 f: F,
1201 ) -> SignalHandlerId {
1202 unsafe extern "C" fn event_trampoline<
1203 P: IsA<SocketClient>,
1204 F: Fn(&P, SocketClientEvent, &SocketConnectable, Option<&IOStream>) + 'static,
1205 >(
1206 this: *mut ffi::GSocketClient,
1207 event: ffi::GSocketClientEvent,
1208 connectable: *mut ffi::GSocketConnectable,
1209 connection: *mut ffi::GIOStream,
1210 f: glib::ffi::gpointer,
1211 ) {
1212 let f: &F = &*(f as *const F);
1213 f(
1214 SocketClient::from_glib_borrow(this).unsafe_cast_ref(),
1215 from_glib(event),
1216 &from_glib_borrow(connectable),
1217 Option::<IOStream>::from_glib_borrow(connection)
1218 .as_ref()
1219 .as_ref(),
1220 )
1221 }
1222 unsafe {
1223 let f: Box_<F> = Box_::new(f);
1224 connect_raw(
1225 self.as_ptr() as *mut _,
1226 c"event".as_ptr() as *const _,
1227 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1228 event_trampoline::<Self, F> as *const (),
1229 )),
1230 Box_::into_raw(f),
1231 )
1232 }
1233 }
1234
1235 #[doc(alias = "enable-proxy")]
1236 fn connect_enable_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1237 unsafe extern "C" fn notify_enable_proxy_trampoline<
1238 P: IsA<SocketClient>,
1239 F: Fn(&P) + 'static,
1240 >(
1241 this: *mut ffi::GSocketClient,
1242 _param_spec: glib::ffi::gpointer,
1243 f: glib::ffi::gpointer,
1244 ) {
1245 let f: &F = &*(f as *const F);
1246 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1247 }
1248 unsafe {
1249 let f: Box_<F> = Box_::new(f);
1250 connect_raw(
1251 self.as_ptr() as *mut _,
1252 c"notify::enable-proxy".as_ptr() as *const _,
1253 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1254 notify_enable_proxy_trampoline::<Self, F> as *const (),
1255 )),
1256 Box_::into_raw(f),
1257 )
1258 }
1259 }
1260
1261 #[doc(alias = "family")]
1262 fn connect_family_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1263 unsafe extern "C" fn notify_family_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
1264 this: *mut ffi::GSocketClient,
1265 _param_spec: glib::ffi::gpointer,
1266 f: glib::ffi::gpointer,
1267 ) {
1268 let f: &F = &*(f as *const F);
1269 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1270 }
1271 unsafe {
1272 let f: Box_<F> = Box_::new(f);
1273 connect_raw(
1274 self.as_ptr() as *mut _,
1275 c"notify::family".as_ptr() as *const _,
1276 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1277 notify_family_trampoline::<Self, F> as *const (),
1278 )),
1279 Box_::into_raw(f),
1280 )
1281 }
1282 }
1283
1284 #[doc(alias = "local-address")]
1285 fn connect_local_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1286 unsafe extern "C" fn notify_local_address_trampoline<
1287 P: IsA<SocketClient>,
1288 F: Fn(&P) + 'static,
1289 >(
1290 this: *mut ffi::GSocketClient,
1291 _param_spec: glib::ffi::gpointer,
1292 f: glib::ffi::gpointer,
1293 ) {
1294 let f: &F = &*(f as *const F);
1295 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1296 }
1297 unsafe {
1298 let f: Box_<F> = Box_::new(f);
1299 connect_raw(
1300 self.as_ptr() as *mut _,
1301 c"notify::local-address".as_ptr() as *const _,
1302 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1303 notify_local_address_trampoline::<Self, F> as *const (),
1304 )),
1305 Box_::into_raw(f),
1306 )
1307 }
1308 }
1309
1310 #[doc(alias = "protocol")]
1311 fn connect_protocol_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1312 unsafe extern "C" fn notify_protocol_trampoline<
1313 P: IsA<SocketClient>,
1314 F: Fn(&P) + 'static,
1315 >(
1316 this: *mut ffi::GSocketClient,
1317 _param_spec: glib::ffi::gpointer,
1318 f: glib::ffi::gpointer,
1319 ) {
1320 let f: &F = &*(f as *const F);
1321 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1322 }
1323 unsafe {
1324 let f: Box_<F> = Box_::new(f);
1325 connect_raw(
1326 self.as_ptr() as *mut _,
1327 c"notify::protocol".as_ptr() as *const _,
1328 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1329 notify_protocol_trampoline::<Self, F> as *const (),
1330 )),
1331 Box_::into_raw(f),
1332 )
1333 }
1334 }
1335
1336 #[doc(alias = "proxy-resolver")]
1337 fn connect_proxy_resolver_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1338 unsafe extern "C" fn notify_proxy_resolver_trampoline<
1339 P: IsA<SocketClient>,
1340 F: Fn(&P) + 'static,
1341 >(
1342 this: *mut ffi::GSocketClient,
1343 _param_spec: glib::ffi::gpointer,
1344 f: glib::ffi::gpointer,
1345 ) {
1346 let f: &F = &*(f as *const F);
1347 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1348 }
1349 unsafe {
1350 let f: Box_<F> = Box_::new(f);
1351 connect_raw(
1352 self.as_ptr() as *mut _,
1353 c"notify::proxy-resolver".as_ptr() as *const _,
1354 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1355 notify_proxy_resolver_trampoline::<Self, F> as *const (),
1356 )),
1357 Box_::into_raw(f),
1358 )
1359 }
1360 }
1361
1362 #[doc(alias = "timeout")]
1363 fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1364 unsafe extern "C" fn notify_timeout_trampoline<
1365 P: IsA<SocketClient>,
1366 F: Fn(&P) + 'static,
1367 >(
1368 this: *mut ffi::GSocketClient,
1369 _param_spec: glib::ffi::gpointer,
1370 f: glib::ffi::gpointer,
1371 ) {
1372 let f: &F = &*(f as *const F);
1373 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1374 }
1375 unsafe {
1376 let f: Box_<F> = Box_::new(f);
1377 connect_raw(
1378 self.as_ptr() as *mut _,
1379 c"notify::timeout".as_ptr() as *const _,
1380 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1381 notify_timeout_trampoline::<Self, F> as *const (),
1382 )),
1383 Box_::into_raw(f),
1384 )
1385 }
1386 }
1387
1388 #[doc(alias = "tls")]
1389 fn connect_tls_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1390 unsafe extern "C" fn notify_tls_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
1391 this: *mut ffi::GSocketClient,
1392 _param_spec: glib::ffi::gpointer,
1393 f: glib::ffi::gpointer,
1394 ) {
1395 let f: &F = &*(f as *const F);
1396 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1397 }
1398 unsafe {
1399 let f: Box_<F> = Box_::new(f);
1400 connect_raw(
1401 self.as_ptr() as *mut _,
1402 c"notify::tls".as_ptr() as *const _,
1403 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1404 notify_tls_trampoline::<Self, F> as *const (),
1405 )),
1406 Box_::into_raw(f),
1407 )
1408 }
1409 }
1410
1411 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
1412 #[doc(alias = "tls-validation-flags")]
1413 fn connect_tls_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1414 unsafe extern "C" fn notify_tls_validation_flags_trampoline<
1415 P: IsA<SocketClient>,
1416 F: Fn(&P) + 'static,
1417 >(
1418 this: *mut ffi::GSocketClient,
1419 _param_spec: glib::ffi::gpointer,
1420 f: glib::ffi::gpointer,
1421 ) {
1422 let f: &F = &*(f as *const F);
1423 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1424 }
1425 unsafe {
1426 let f: Box_<F> = Box_::new(f);
1427 connect_raw(
1428 self.as_ptr() as *mut _,
1429 c"notify::tls-validation-flags".as_ptr() as *const _,
1430 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1431 notify_tls_validation_flags_trampoline::<Self, F> as *const (),
1432 )),
1433 Box_::into_raw(f),
1434 )
1435 }
1436 }
1437
1438 #[doc(alias = "type")]
1439 fn connect_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1440 unsafe extern "C" fn notify_type_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
1441 this: *mut ffi::GSocketClient,
1442 _param_spec: glib::ffi::gpointer,
1443 f: glib::ffi::gpointer,
1444 ) {
1445 let f: &F = &*(f as *const F);
1446 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1447 }
1448 unsafe {
1449 let f: Box_<F> = Box_::new(f);
1450 connect_raw(
1451 self.as_ptr() as *mut _,
1452 c"notify::type".as_ptr() as *const _,
1453 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1454 notify_type_trampoline::<Self, F> as *const (),
1455 )),
1456 Box_::into_raw(f),
1457 )
1458 }
1459 }
1460}
1461
1462impl<O: IsA<SocketClient>> SocketClientExt for O {}