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 AsyncResult, Cancellable, IOStream, ProxyResolver, SocketAddress, SocketClientEvent,
8 SocketConnectable, SocketConnection, SocketFamily, SocketProtocol, SocketType,
9 TlsCertificateFlags, ffi,
10};
11use glib::{
12 object::ObjectType as _,
13 prelude::*,
14 signal::{SignalHandlerId, connect_raw},
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 unsafe {
325 let mut error = std::ptr::null_mut();
326 let ret =
327 ffi::g_socket_client_connect_finish(_source_object as *mut _, res, &mut error);
328 let result = if error.is_null() {
329 Ok(from_glib_full(ret))
330 } else {
331 Err(from_glib_full(error))
332 };
333 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
334 Box_::from_raw(user_data as *mut _);
335 let callback: P = callback.into_inner();
336 callback(result);
337 }
338 }
339 let callback = connect_async_trampoline::<P>;
340 unsafe {
341 ffi::g_socket_client_connect_async(
342 self.as_ref().to_glib_none().0,
343 connectable.as_ref().to_glib_none().0,
344 cancellable.map(|p| p.as_ref()).to_glib_none().0,
345 Some(callback),
346 Box_::into_raw(user_data) as *mut _,
347 );
348 }
349 }
350
351 fn connect_future(
352 &self,
353 connectable: &(impl IsA<SocketConnectable> + Clone + 'static),
354 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
355 {
356 let connectable = connectable.clone();
357 Box_::pin(crate::GioFuture::new(
358 self,
359 move |obj, cancellable, send| {
360 obj.connect_async(&connectable, Some(cancellable), move |res| {
361 send.resolve(res);
362 });
363 },
364 ))
365 }
366
367 /// This is a helper function for g_socket_client_connect().
368 ///
369 /// Attempts to create a TCP connection to the named host.
370 ///
371 /// @host_and_port may be in any of a number of recognized formats; an IPv6
372 /// address, an IPv4 address, or a domain name (in which case a DNS
373 /// lookup is performed). Quoting with [] is supported for all address
374 /// types. A port override may be specified in the usual way with a
375 /// colon. Ports may be given as decimal numbers or symbolic names (in
376 /// which case an /etc/services lookup is performed).
377 ///
378 /// If no port override is given in @host_and_port then @default_port will be
379 /// used as the port number to connect to.
380 ///
381 /// In general, @host_and_port is expected to be provided by the user (allowing
382 /// them to give the hostname, and a port override if necessary) and
383 /// @default_port is expected to be provided by the application.
384 ///
385 /// In the case that an IP address is given, a single connection
386 /// attempt is made. In the case that a name is given, multiple
387 /// connection attempts may be made, in turn and according to the
388 /// number of address records in DNS, until a connection succeeds.
389 ///
390 /// Upon a successful connection, a new #GSocketConnection is constructed
391 /// and returned. The caller owns this new object and must drop their
392 /// reference to it when finished with it.
393 ///
394 /// In the event of any failure (DNS error, service not found, no hosts
395 /// connectable) [`None`] is returned and @error (if non-[`None`]) is set
396 /// accordingly.
397 /// ## `host_and_port`
398 /// the name and optionally port of the host to connect to
399 /// ## `default_port`
400 /// the default port to connect to
401 /// ## `cancellable`
402 /// a #GCancellable, or [`None`]
403 ///
404 /// # Returns
405 ///
406 /// a #GSocketConnection on success, [`None`] on error.
407 #[doc(alias = "g_socket_client_connect_to_host")]
408 fn connect_to_host(
409 &self,
410 host_and_port: &str,
411 default_port: u16,
412 cancellable: Option<&impl IsA<Cancellable>>,
413 ) -> Result<SocketConnection, glib::Error> {
414 unsafe {
415 let mut error = std::ptr::null_mut();
416 let ret = ffi::g_socket_client_connect_to_host(
417 self.as_ref().to_glib_none().0,
418 host_and_port.to_glib_none().0,
419 default_port,
420 cancellable.map(|p| p.as_ref()).to_glib_none().0,
421 &mut error,
422 );
423 if error.is_null() {
424 Ok(from_glib_full(ret))
425 } else {
426 Err(from_glib_full(error))
427 }
428 }
429 }
430
431 /// This is the asynchronous version of g_socket_client_connect_to_host().
432 ///
433 /// When the operation is finished @callback will be
434 /// called. You can then call g_socket_client_connect_to_host_finish() to get
435 /// the result of the operation.
436 /// ## `host_and_port`
437 /// the name and optionally the port of the host to connect to
438 /// ## `default_port`
439 /// the default port to connect to
440 /// ## `cancellable`
441 /// a #GCancellable, or [`None`]
442 /// ## `callback`
443 /// a #GAsyncReadyCallback
444 #[doc(alias = "g_socket_client_connect_to_host_async")]
445 fn connect_to_host_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
446 &self,
447 host_and_port: &str,
448 default_port: u16,
449 cancellable: Option<&impl IsA<Cancellable>>,
450 callback: P,
451 ) {
452 let main_context = glib::MainContext::ref_thread_default();
453 let is_main_context_owner = main_context.is_owner();
454 let has_acquired_main_context = (!is_main_context_owner)
455 .then(|| main_context.acquire().ok())
456 .flatten();
457 assert!(
458 is_main_context_owner || has_acquired_main_context.is_some(),
459 "Async operations only allowed if the thread is owning the MainContext"
460 );
461
462 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
463 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
464 unsafe extern "C" fn connect_to_host_async_trampoline<
465 P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
466 >(
467 _source_object: *mut glib::gobject_ffi::GObject,
468 res: *mut crate::ffi::GAsyncResult,
469 user_data: glib::ffi::gpointer,
470 ) {
471 unsafe {
472 let mut error = std::ptr::null_mut();
473 let ret = ffi::g_socket_client_connect_to_host_finish(
474 _source_object as *mut _,
475 res,
476 &mut error,
477 );
478 let result = if error.is_null() {
479 Ok(from_glib_full(ret))
480 } else {
481 Err(from_glib_full(error))
482 };
483 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
484 Box_::from_raw(user_data as *mut _);
485 let callback: P = callback.into_inner();
486 callback(result);
487 }
488 }
489 let callback = connect_to_host_async_trampoline::<P>;
490 unsafe {
491 ffi::g_socket_client_connect_to_host_async(
492 self.as_ref().to_glib_none().0,
493 host_and_port.to_glib_none().0,
494 default_port,
495 cancellable.map(|p| p.as_ref()).to_glib_none().0,
496 Some(callback),
497 Box_::into_raw(user_data) as *mut _,
498 );
499 }
500 }
501
502 fn connect_to_host_future(
503 &self,
504 host_and_port: &str,
505 default_port: u16,
506 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
507 {
508 let host_and_port = String::from(host_and_port);
509 Box_::pin(crate::GioFuture::new(
510 self,
511 move |obj, cancellable, send| {
512 obj.connect_to_host_async(
513 &host_and_port,
514 default_port,
515 Some(cancellable),
516 move |res| {
517 send.resolve(res);
518 },
519 );
520 },
521 ))
522 }
523
524 /// Attempts to create a TCP connection to a service.
525 ///
526 /// This call looks up the SRV record for @service at @domain for the
527 /// "tcp" protocol. It then attempts to connect, in turn, to each of
528 /// the hosts providing the service until either a connection succeeds
529 /// or there are no hosts remaining.
530 ///
531 /// Upon a successful connection, a new #GSocketConnection is constructed
532 /// and returned. The caller owns this new object and must drop their
533 /// reference to it when finished with it.
534 ///
535 /// In the event of any failure (DNS error, service not found, no hosts
536 /// connectable) [`None`] is returned and @error (if non-[`None`]) is set
537 /// accordingly.
538 /// ## `domain`
539 /// a domain name
540 /// ## `service`
541 /// the name of the service to connect to
542 /// ## `cancellable`
543 /// a #GCancellable, or [`None`]
544 ///
545 /// # Returns
546 ///
547 /// a #GSocketConnection if successful, or [`None`] on error
548 #[doc(alias = "g_socket_client_connect_to_service")]
549 fn connect_to_service(
550 &self,
551 domain: &str,
552 service: &str,
553 cancellable: Option<&impl IsA<Cancellable>>,
554 ) -> Result<SocketConnection, glib::Error> {
555 unsafe {
556 let mut error = std::ptr::null_mut();
557 let ret = ffi::g_socket_client_connect_to_service(
558 self.as_ref().to_glib_none().0,
559 domain.to_glib_none().0,
560 service.to_glib_none().0,
561 cancellable.map(|p| p.as_ref()).to_glib_none().0,
562 &mut error,
563 );
564 if error.is_null() {
565 Ok(from_glib_full(ret))
566 } else {
567 Err(from_glib_full(error))
568 }
569 }
570 }
571
572 /// This is the asynchronous version of
573 /// g_socket_client_connect_to_service().
574 /// ## `domain`
575 /// a domain name
576 /// ## `service`
577 /// the name of the service to connect to
578 /// ## `cancellable`
579 /// a #GCancellable, or [`None`]
580 /// ## `callback`
581 /// a #GAsyncReadyCallback
582 #[doc(alias = "g_socket_client_connect_to_service_async")]
583 fn connect_to_service_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
584 &self,
585 domain: &str,
586 service: &str,
587 cancellable: Option<&impl IsA<Cancellable>>,
588 callback: P,
589 ) {
590 let main_context = glib::MainContext::ref_thread_default();
591 let is_main_context_owner = main_context.is_owner();
592 let has_acquired_main_context = (!is_main_context_owner)
593 .then(|| main_context.acquire().ok())
594 .flatten();
595 assert!(
596 is_main_context_owner || has_acquired_main_context.is_some(),
597 "Async operations only allowed if the thread is owning the MainContext"
598 );
599
600 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
601 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
602 unsafe extern "C" fn connect_to_service_async_trampoline<
603 P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
604 >(
605 _source_object: *mut glib::gobject_ffi::GObject,
606 res: *mut crate::ffi::GAsyncResult,
607 user_data: glib::ffi::gpointer,
608 ) {
609 unsafe {
610 let mut error = std::ptr::null_mut();
611 let ret = ffi::g_socket_client_connect_to_service_finish(
612 _source_object as *mut _,
613 res,
614 &mut error,
615 );
616 let result = if error.is_null() {
617 Ok(from_glib_full(ret))
618 } else {
619 Err(from_glib_full(error))
620 };
621 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
622 Box_::from_raw(user_data as *mut _);
623 let callback: P = callback.into_inner();
624 callback(result);
625 }
626 }
627 let callback = connect_to_service_async_trampoline::<P>;
628 unsafe {
629 ffi::g_socket_client_connect_to_service_async(
630 self.as_ref().to_glib_none().0,
631 domain.to_glib_none().0,
632 service.to_glib_none().0,
633 cancellable.map(|p| p.as_ref()).to_glib_none().0,
634 Some(callback),
635 Box_::into_raw(user_data) as *mut _,
636 );
637 }
638 }
639
640 fn connect_to_service_future(
641 &self,
642 domain: &str,
643 service: &str,
644 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
645 {
646 let domain = String::from(domain);
647 let service = String::from(service);
648 Box_::pin(crate::GioFuture::new(
649 self,
650 move |obj, cancellable, send| {
651 obj.connect_to_service_async(&domain, &service, Some(cancellable), move |res| {
652 send.resolve(res);
653 });
654 },
655 ))
656 }
657
658 /// This is a helper function for g_socket_client_connect().
659 ///
660 /// Attempts to create a TCP connection with a network URI.
661 ///
662 /// @uri may be any valid URI containing an "authority" (hostname/port)
663 /// component. If a port is not specified in the URI, @default_port
664 /// will be used. TLS will be negotiated if #GSocketClient:tls is [`true`].
665 /// (#GSocketClient does not know to automatically assume TLS for
666 /// certain URI schemes.)
667 ///
668 /// Using this rather than g_socket_client_connect() or
669 /// g_socket_client_connect_to_host() allows #GSocketClient to
670 /// determine when to use application-specific proxy protocols.
671 ///
672 /// Upon a successful connection, a new #GSocketConnection is constructed
673 /// and returned. The caller owns this new object and must drop their
674 /// reference to it when finished with it.
675 ///
676 /// In the event of any failure (DNS error, service not found, no hosts
677 /// connectable) [`None`] is returned and @error (if non-[`None`]) is set
678 /// accordingly.
679 /// ## `uri`
680 /// A network URI
681 /// ## `default_port`
682 /// the default port to connect to
683 /// ## `cancellable`
684 /// a #GCancellable, or [`None`]
685 ///
686 /// # Returns
687 ///
688 /// a #GSocketConnection on success, [`None`] on error.
689 #[doc(alias = "g_socket_client_connect_to_uri")]
690 fn connect_to_uri(
691 &self,
692 uri: &str,
693 default_port: u16,
694 cancellable: Option<&impl IsA<Cancellable>>,
695 ) -> Result<SocketConnection, glib::Error> {
696 unsafe {
697 let mut error = std::ptr::null_mut();
698 let ret = ffi::g_socket_client_connect_to_uri(
699 self.as_ref().to_glib_none().0,
700 uri.to_glib_none().0,
701 default_port,
702 cancellable.map(|p| p.as_ref()).to_glib_none().0,
703 &mut error,
704 );
705 if error.is_null() {
706 Ok(from_glib_full(ret))
707 } else {
708 Err(from_glib_full(error))
709 }
710 }
711 }
712
713 /// This is the asynchronous version of g_socket_client_connect_to_uri().
714 ///
715 /// When the operation is finished @callback will be
716 /// called. You can then call g_socket_client_connect_to_uri_finish() to get
717 /// the result of the operation.
718 /// ## `uri`
719 /// a network uri
720 /// ## `default_port`
721 /// the default port to connect to
722 /// ## `cancellable`
723 /// a #GCancellable, or [`None`]
724 /// ## `callback`
725 /// a #GAsyncReadyCallback
726 #[doc(alias = "g_socket_client_connect_to_uri_async")]
727 fn connect_to_uri_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
728 &self,
729 uri: &str,
730 default_port: u16,
731 cancellable: Option<&impl IsA<Cancellable>>,
732 callback: P,
733 ) {
734 let main_context = glib::MainContext::ref_thread_default();
735 let is_main_context_owner = main_context.is_owner();
736 let has_acquired_main_context = (!is_main_context_owner)
737 .then(|| main_context.acquire().ok())
738 .flatten();
739 assert!(
740 is_main_context_owner || has_acquired_main_context.is_some(),
741 "Async operations only allowed if the thread is owning the MainContext"
742 );
743
744 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
745 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
746 unsafe extern "C" fn connect_to_uri_async_trampoline<
747 P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
748 >(
749 _source_object: *mut glib::gobject_ffi::GObject,
750 res: *mut crate::ffi::GAsyncResult,
751 user_data: glib::ffi::gpointer,
752 ) {
753 unsafe {
754 let mut error = std::ptr::null_mut();
755 let ret = ffi::g_socket_client_connect_to_uri_finish(
756 _source_object as *mut _,
757 res,
758 &mut error,
759 );
760 let result = if error.is_null() {
761 Ok(from_glib_full(ret))
762 } else {
763 Err(from_glib_full(error))
764 };
765 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
766 Box_::from_raw(user_data as *mut _);
767 let callback: P = callback.into_inner();
768 callback(result);
769 }
770 }
771 let callback = connect_to_uri_async_trampoline::<P>;
772 unsafe {
773 ffi::g_socket_client_connect_to_uri_async(
774 self.as_ref().to_glib_none().0,
775 uri.to_glib_none().0,
776 default_port,
777 cancellable.map(|p| p.as_ref()).to_glib_none().0,
778 Some(callback),
779 Box_::into_raw(user_data) as *mut _,
780 );
781 }
782 }
783
784 fn connect_to_uri_future(
785 &self,
786 uri: &str,
787 default_port: u16,
788 ) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
789 {
790 let uri = String::from(uri);
791 Box_::pin(crate::GioFuture::new(
792 self,
793 move |obj, cancellable, send| {
794 obj.connect_to_uri_async(&uri, default_port, Some(cancellable), move |res| {
795 send.resolve(res);
796 });
797 },
798 ))
799 }
800
801 /// Gets the proxy enable state; see g_socket_client_set_enable_proxy()
802 ///
803 /// # Returns
804 ///
805 /// whether proxying is enabled
806 #[doc(alias = "g_socket_client_get_enable_proxy")]
807 #[doc(alias = "get_enable_proxy")]
808 #[doc(alias = "enable-proxy")]
809 fn enables_proxy(&self) -> bool {
810 unsafe {
811 from_glib(ffi::g_socket_client_get_enable_proxy(
812 self.as_ref().to_glib_none().0,
813 ))
814 }
815 }
816
817 /// Gets the socket family of the socket client.
818 ///
819 /// See g_socket_client_set_family() for details.
820 ///
821 /// # Returns
822 ///
823 /// a #GSocketFamily
824 #[doc(alias = "g_socket_client_get_family")]
825 #[doc(alias = "get_family")]
826 fn family(&self) -> SocketFamily {
827 unsafe {
828 from_glib(ffi::g_socket_client_get_family(
829 self.as_ref().to_glib_none().0,
830 ))
831 }
832 }
833
834 /// Gets the local address of the socket client.
835 ///
836 /// See g_socket_client_set_local_address() for details.
837 ///
838 /// # Returns
839 ///
840 /// a #GSocketAddress or [`None`]. Do not free.
841 #[doc(alias = "g_socket_client_get_local_address")]
842 #[doc(alias = "get_local_address")]
843 #[doc(alias = "local-address")]
844 fn local_address(&self) -> Option<SocketAddress> {
845 unsafe {
846 from_glib_none(ffi::g_socket_client_get_local_address(
847 self.as_ref().to_glib_none().0,
848 ))
849 }
850 }
851
852 /// Gets the protocol name type of the socket client.
853 ///
854 /// See g_socket_client_set_protocol() for details.
855 ///
856 /// # Returns
857 ///
858 /// a #GSocketProtocol
859 #[doc(alias = "g_socket_client_get_protocol")]
860 #[doc(alias = "get_protocol")]
861 fn protocol(&self) -> SocketProtocol {
862 unsafe {
863 from_glib(ffi::g_socket_client_get_protocol(
864 self.as_ref().to_glib_none().0,
865 ))
866 }
867 }
868
869 /// Gets the #GProxyResolver being used by @self. Normally, this will
870 /// be the resolver returned by g_proxy_resolver_get_default(), but you
871 /// can override it with g_socket_client_set_proxy_resolver().
872 ///
873 /// # Returns
874 ///
875 /// The #GProxyResolver being used by
876 /// @self.
877 #[doc(alias = "g_socket_client_get_proxy_resolver")]
878 #[doc(alias = "get_proxy_resolver")]
879 #[doc(alias = "proxy-resolver")]
880 fn proxy_resolver(&self) -> ProxyResolver {
881 unsafe {
882 from_glib_none(ffi::g_socket_client_get_proxy_resolver(
883 self.as_ref().to_glib_none().0,
884 ))
885 }
886 }
887
888 /// Gets the socket type of the socket client.
889 ///
890 /// See g_socket_client_set_socket_type() for details.
891 ///
892 /// # Returns
893 ///
894 /// a #GSocketFamily
895 #[doc(alias = "g_socket_client_get_socket_type")]
896 #[doc(alias = "get_socket_type")]
897 fn socket_type(&self) -> SocketType {
898 unsafe {
899 from_glib(ffi::g_socket_client_get_socket_type(
900 self.as_ref().to_glib_none().0,
901 ))
902 }
903 }
904
905 /// Gets the I/O timeout time for sockets created by @self.
906 ///
907 /// See g_socket_client_set_timeout() for details.
908 ///
909 /// # Returns
910 ///
911 /// the timeout in seconds
912 #[doc(alias = "g_socket_client_get_timeout")]
913 #[doc(alias = "get_timeout")]
914 fn timeout(&self) -> u32 {
915 unsafe { ffi::g_socket_client_get_timeout(self.as_ref().to_glib_none().0) }
916 }
917
918 /// Gets whether @self creates TLS connections. See
919 /// g_socket_client_set_tls() for details.
920 ///
921 /// # Returns
922 ///
923 /// whether @self uses TLS
924 #[doc(alias = "g_socket_client_get_tls")]
925 #[doc(alias = "get_tls")]
926 #[doc(alias = "tls")]
927 fn is_tls(&self) -> bool {
928 unsafe { from_glib(ffi::g_socket_client_get_tls(self.as_ref().to_glib_none().0)) }
929 }
930
931 /// Gets the TLS validation flags used creating TLS connections via
932 /// @self.
933 ///
934 /// This function does not work as originally designed and is impossible
935 /// to use correctly. See #GSocketClient:tls-validation-flags for more
936 /// information.
937 ///
938 /// # Deprecated since 2.72
939 ///
940 /// Do not attempt to ignore validation errors.
941 ///
942 /// # Returns
943 ///
944 /// the TLS validation flags
945 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
946 #[allow(deprecated)]
947 #[doc(alias = "g_socket_client_get_tls_validation_flags")]
948 #[doc(alias = "get_tls_validation_flags")]
949 #[doc(alias = "tls-validation-flags")]
950 fn tls_validation_flags(&self) -> TlsCertificateFlags {
951 unsafe {
952 from_glib(ffi::g_socket_client_get_tls_validation_flags(
953 self.as_ref().to_glib_none().0,
954 ))
955 }
956 }
957
958 /// Sets whether or not @self attempts to make connections via a
959 /// proxy server. When enabled (the default), #GSocketClient will use a
960 /// #GProxyResolver to determine if a proxy protocol such as SOCKS is
961 /// needed, and automatically do the necessary proxy negotiation.
962 ///
963 /// See also g_socket_client_set_proxy_resolver().
964 /// ## `enable`
965 /// whether to enable proxies
966 #[doc(alias = "g_socket_client_set_enable_proxy")]
967 #[doc(alias = "enable-proxy")]
968 fn set_enable_proxy(&self, enable: bool) {
969 unsafe {
970 ffi::g_socket_client_set_enable_proxy(
971 self.as_ref().to_glib_none().0,
972 enable.into_glib(),
973 );
974 }
975 }
976
977 /// Sets the socket family of the socket client.
978 /// If this is set to something other than [`SocketFamily::Invalid`][crate::SocketFamily::Invalid]
979 /// then the sockets created by this object will be of the specified
980 /// family.
981 ///
982 /// This might be useful for instance if you want to force the local
983 /// connection to be an ipv4 socket, even though the address might
984 /// be an ipv6 mapped to ipv4 address.
985 /// ## `family`
986 /// a #GSocketFamily
987 #[doc(alias = "g_socket_client_set_family")]
988 #[doc(alias = "family")]
989 fn set_family(&self, family: SocketFamily) {
990 unsafe {
991 ffi::g_socket_client_set_family(self.as_ref().to_glib_none().0, family.into_glib());
992 }
993 }
994
995 /// Sets the local address of the socket client.
996 /// The sockets created by this object will bound to the
997 /// specified address (if not [`None`]) before connecting.
998 ///
999 /// This is useful if you want to ensure that the local
1000 /// side of the connection is on a specific port, or on
1001 /// a specific interface.
1002 /// ## `address`
1003 /// a #GSocketAddress, or [`None`]
1004 #[doc(alias = "g_socket_client_set_local_address")]
1005 #[doc(alias = "local-address")]
1006 fn set_local_address(&self, address: Option<&impl IsA<SocketAddress>>) {
1007 unsafe {
1008 ffi::g_socket_client_set_local_address(
1009 self.as_ref().to_glib_none().0,
1010 address.map(|p| p.as_ref()).to_glib_none().0,
1011 );
1012 }
1013 }
1014
1015 /// Sets the protocol of the socket client.
1016 /// The sockets created by this object will use of the specified
1017 /// protocol.
1018 ///
1019 /// If @protocol is [`SocketProtocol::Default`][crate::SocketProtocol::Default] that means to use the default
1020 /// protocol for the socket family and type.
1021 /// ## `protocol`
1022 /// a #GSocketProtocol
1023 #[doc(alias = "g_socket_client_set_protocol")]
1024 #[doc(alias = "protocol")]
1025 fn set_protocol(&self, protocol: SocketProtocol) {
1026 unsafe {
1027 ffi::g_socket_client_set_protocol(self.as_ref().to_glib_none().0, protocol.into_glib());
1028 }
1029 }
1030
1031 /// Overrides the #GProxyResolver used by @self. You can call this if
1032 /// you want to use specific proxies, rather than using the system
1033 /// default proxy settings.
1034 ///
1035 /// Note that whether or not the proxy resolver is actually used
1036 /// depends on the setting of #GSocketClient:enable-proxy, which is not
1037 /// changed by this function (but which is [`true`] by default)
1038 /// ## `proxy_resolver`
1039 /// a #GProxyResolver, or [`None`] for the
1040 /// default.
1041 #[doc(alias = "g_socket_client_set_proxy_resolver")]
1042 #[doc(alias = "proxy-resolver")]
1043 fn set_proxy_resolver(&self, proxy_resolver: Option<&impl IsA<ProxyResolver>>) {
1044 unsafe {
1045 ffi::g_socket_client_set_proxy_resolver(
1046 self.as_ref().to_glib_none().0,
1047 proxy_resolver.map(|p| p.as_ref()).to_glib_none().0,
1048 );
1049 }
1050 }
1051
1052 /// Sets the socket type of the socket client.
1053 /// The sockets created by this object will be of the specified
1054 /// type.
1055 ///
1056 /// It doesn't make sense to specify a type of [`SocketType::Datagram`][crate::SocketType::Datagram],
1057 /// as GSocketClient is used for connection oriented services.
1058 /// ## `type_`
1059 /// a #GSocketType
1060 #[doc(alias = "g_socket_client_set_socket_type")]
1061 fn set_socket_type(&self, type_: SocketType) {
1062 unsafe {
1063 ffi::g_socket_client_set_socket_type(self.as_ref().to_glib_none().0, type_.into_glib());
1064 }
1065 }
1066
1067 /// Sets the I/O timeout for sockets created by @self. @timeout is a
1068 /// time in seconds, or 0 for no timeout (the default).
1069 ///
1070 /// The timeout value affects the initial connection attempt as well,
1071 /// so setting this may cause calls to g_socket_client_connect(), etc,
1072 /// to fail with [`IOErrorEnum::TimedOut`][crate::IOErrorEnum::TimedOut].
1073 /// ## `timeout`
1074 /// the timeout
1075 #[doc(alias = "g_socket_client_set_timeout")]
1076 #[doc(alias = "timeout")]
1077 fn set_timeout(&self, timeout: u32) {
1078 unsafe {
1079 ffi::g_socket_client_set_timeout(self.as_ref().to_glib_none().0, timeout);
1080 }
1081 }
1082
1083 /// Sets whether @self creates TLS (aka SSL) connections. If @tls is
1084 /// [`true`], @self will wrap its connections in a #GTlsClientConnection
1085 /// and perform a TLS handshake when connecting.
1086 ///
1087 /// Note that since #GSocketClient must return a #GSocketConnection,
1088 /// but #GTlsClientConnection is not a #GSocketConnection, this
1089 /// actually wraps the resulting #GTlsClientConnection in a
1090 /// #GTcpWrapperConnection when returning it. You can use
1091 /// g_tcp_wrapper_connection_get_base_io_stream() on the return value
1092 /// to extract the #GTlsClientConnection.
1093 ///
1094 /// If you need to modify the behavior of the TLS handshake (eg, by
1095 /// setting a client-side certificate to use, or connecting to the
1096 /// #GTlsConnection::accept-certificate signal), you can connect to
1097 /// @self's #GSocketClient::event signal and wait for it to be
1098 /// emitted with [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking], which will give you
1099 /// a chance to see the #GTlsClientConnection before the handshake
1100 /// starts.
1101 /// ## `tls`
1102 /// whether to use TLS
1103 #[doc(alias = "g_socket_client_set_tls")]
1104 #[doc(alias = "tls")]
1105 fn set_tls(&self, tls: bool) {
1106 unsafe {
1107 ffi::g_socket_client_set_tls(self.as_ref().to_glib_none().0, tls.into_glib());
1108 }
1109 }
1110
1111 /// Sets the TLS validation flags used when creating TLS connections
1112 /// via @self. The default value is [`TlsCertificateFlags::VALIDATE_ALL`][crate::TlsCertificateFlags::VALIDATE_ALL].
1113 ///
1114 /// This function does not work as originally designed and is impossible
1115 /// to use correctly. See #GSocketClient:tls-validation-flags for more
1116 /// information.
1117 ///
1118 /// # Deprecated since 2.72
1119 ///
1120 /// Do not attempt to ignore validation errors.
1121 /// ## `flags`
1122 /// the validation flags
1123 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
1124 #[allow(deprecated)]
1125 #[doc(alias = "g_socket_client_set_tls_validation_flags")]
1126 #[doc(alias = "tls-validation-flags")]
1127 fn set_tls_validation_flags(&self, flags: TlsCertificateFlags) {
1128 unsafe {
1129 ffi::g_socket_client_set_tls_validation_flags(
1130 self.as_ref().to_glib_none().0,
1131 flags.into_glib(),
1132 );
1133 }
1134 }
1135
1136 /// The type to use for socket construction.
1137 #[doc(alias = "type")]
1138 fn type_(&self) -> SocketType {
1139 ObjectExt::property(self.as_ref(), "type")
1140 }
1141
1142 /// The type to use for socket construction.
1143 #[doc(alias = "type")]
1144 fn set_type(&self, type_: SocketType) {
1145 ObjectExt::set_property(self.as_ref(), "type", type_)
1146 }
1147
1148 /// Emitted when @client's activity on @connectable changes state.
1149 /// Among other things, this can be used to provide progress
1150 /// information about a network connection in the UI. The meanings of
1151 /// the different @event values are as follows:
1152 ///
1153 /// - [`SocketClientEvent::Resolving`][crate::SocketClientEvent::Resolving]: @client is about to look up @connectable
1154 /// in DNS. @connection will be [`None`].
1155 ///
1156 /// - [`SocketClientEvent::Resolved`][crate::SocketClientEvent::Resolved]: @client has successfully resolved
1157 /// @connectable in DNS. @connection will be [`None`].
1158 ///
1159 /// - [`SocketClientEvent::Connecting`][crate::SocketClientEvent::Connecting]: @client is about to make a connection
1160 /// to a remote host; either a proxy server or the destination server
1161 /// itself. @connection is the #GSocketConnection, which is not yet
1162 /// connected. Since GLib 2.40, you can access the remote
1163 /// address via g_socket_connection_get_remote_address().
1164 ///
1165 /// - [`SocketClientEvent::Connected`][crate::SocketClientEvent::Connected]: @client has successfully connected
1166 /// to a remote host. @connection is the connected #GSocketConnection.
1167 ///
1168 /// - [`SocketClientEvent::ProxyNegotiating`][crate::SocketClientEvent::ProxyNegotiating]: @client is about to negotiate
1169 /// with a proxy to get it to connect to @connectable. @connection is
1170 /// the #GSocketConnection to the proxy server.
1171 ///
1172 /// - [`SocketClientEvent::ProxyNegotiated`][crate::SocketClientEvent::ProxyNegotiated]: @client has negotiated a
1173 /// connection to @connectable through a proxy server. @connection is
1174 /// the stream returned from g_proxy_connect(), which may or may not
1175 /// be a #GSocketConnection.
1176 ///
1177 /// - [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking]: @client is about to begin a TLS
1178 /// handshake. @connection is a #GTlsClientConnection.
1179 ///
1180 /// - [`SocketClientEvent::TlsHandshaked`][crate::SocketClientEvent::TlsHandshaked]: @client has successfully completed
1181 /// the TLS handshake. @connection is a #GTlsClientConnection.
1182 ///
1183 /// - [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete]: @client has either successfully connected
1184 /// to @connectable (in which case @connection is the #GSocketConnection
1185 /// that it will be returning to the caller) or has failed (in which
1186 /// case @connection is [`None`] and the client is about to return an error).
1187 ///
1188 /// Each event except [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] may be emitted
1189 /// multiple times (or not at all) for a given connectable (in
1190 /// particular, if @client ends up attempting to connect to more than
1191 /// one address). However, if @client emits the #GSocketClient::event
1192 /// signal at all for a given connectable, then it will always emit
1193 /// it with [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] when it is done.
1194 ///
1195 /// Note that there may be additional #GSocketClientEvent values in
1196 /// the future; unrecognized @event values should be ignored.
1197 /// ## `event`
1198 /// the event that is occurring
1199 /// ## `connectable`
1200 /// the #GSocketConnectable that @event is occurring on
1201 /// ## `connection`
1202 /// the current representation of the connection
1203 #[doc(alias = "event")]
1204 fn connect_event<
1205 F: Fn(&Self, SocketClientEvent, &SocketConnectable, Option<&IOStream>) + 'static,
1206 >(
1207 &self,
1208 f: F,
1209 ) -> SignalHandlerId {
1210 unsafe extern "C" fn event_trampoline<
1211 P: IsA<SocketClient>,
1212 F: Fn(&P, SocketClientEvent, &SocketConnectable, Option<&IOStream>) + 'static,
1213 >(
1214 this: *mut ffi::GSocketClient,
1215 event: ffi::GSocketClientEvent,
1216 connectable: *mut ffi::GSocketConnectable,
1217 connection: *mut ffi::GIOStream,
1218 f: glib::ffi::gpointer,
1219 ) {
1220 unsafe {
1221 let f: &F = &*(f as *const F);
1222 f(
1223 SocketClient::from_glib_borrow(this).unsafe_cast_ref(),
1224 from_glib(event),
1225 &from_glib_borrow(connectable),
1226 Option::<IOStream>::from_glib_borrow(connection)
1227 .as_ref()
1228 .as_ref(),
1229 )
1230 }
1231 }
1232 unsafe {
1233 let f: Box_<F> = Box_::new(f);
1234 connect_raw(
1235 self.as_ptr() as *mut _,
1236 c"event".as_ptr() as *const _,
1237 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1238 event_trampoline::<Self, F> as *const (),
1239 )),
1240 Box_::into_raw(f),
1241 )
1242 }
1243 }
1244
1245 #[doc(alias = "enable-proxy")]
1246 fn connect_enable_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1247 unsafe extern "C" fn notify_enable_proxy_trampoline<
1248 P: IsA<SocketClient>,
1249 F: Fn(&P) + 'static,
1250 >(
1251 this: *mut ffi::GSocketClient,
1252 _param_spec: glib::ffi::gpointer,
1253 f: glib::ffi::gpointer,
1254 ) {
1255 unsafe {
1256 let f: &F = &*(f as *const F);
1257 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1258 }
1259 }
1260 unsafe {
1261 let f: Box_<F> = Box_::new(f);
1262 connect_raw(
1263 self.as_ptr() as *mut _,
1264 c"notify::enable-proxy".as_ptr() as *const _,
1265 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1266 notify_enable_proxy_trampoline::<Self, F> as *const (),
1267 )),
1268 Box_::into_raw(f),
1269 )
1270 }
1271 }
1272
1273 #[doc(alias = "family")]
1274 fn connect_family_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1275 unsafe extern "C" fn notify_family_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
1276 this: *mut ffi::GSocketClient,
1277 _param_spec: glib::ffi::gpointer,
1278 f: glib::ffi::gpointer,
1279 ) {
1280 unsafe {
1281 let f: &F = &*(f as *const F);
1282 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1283 }
1284 }
1285 unsafe {
1286 let f: Box_<F> = Box_::new(f);
1287 connect_raw(
1288 self.as_ptr() as *mut _,
1289 c"notify::family".as_ptr() as *const _,
1290 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1291 notify_family_trampoline::<Self, F> as *const (),
1292 )),
1293 Box_::into_raw(f),
1294 )
1295 }
1296 }
1297
1298 #[doc(alias = "local-address")]
1299 fn connect_local_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1300 unsafe extern "C" fn notify_local_address_trampoline<
1301 P: IsA<SocketClient>,
1302 F: Fn(&P) + 'static,
1303 >(
1304 this: *mut ffi::GSocketClient,
1305 _param_spec: glib::ffi::gpointer,
1306 f: glib::ffi::gpointer,
1307 ) {
1308 unsafe {
1309 let f: &F = &*(f as *const F);
1310 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1311 }
1312 }
1313 unsafe {
1314 let f: Box_<F> = Box_::new(f);
1315 connect_raw(
1316 self.as_ptr() as *mut _,
1317 c"notify::local-address".as_ptr() as *const _,
1318 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1319 notify_local_address_trampoline::<Self, F> as *const (),
1320 )),
1321 Box_::into_raw(f),
1322 )
1323 }
1324 }
1325
1326 #[doc(alias = "protocol")]
1327 fn connect_protocol_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1328 unsafe extern "C" fn notify_protocol_trampoline<
1329 P: IsA<SocketClient>,
1330 F: Fn(&P) + 'static,
1331 >(
1332 this: *mut ffi::GSocketClient,
1333 _param_spec: glib::ffi::gpointer,
1334 f: glib::ffi::gpointer,
1335 ) {
1336 unsafe {
1337 let f: &F = &*(f as *const F);
1338 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1339 }
1340 }
1341 unsafe {
1342 let f: Box_<F> = Box_::new(f);
1343 connect_raw(
1344 self.as_ptr() as *mut _,
1345 c"notify::protocol".as_ptr() as *const _,
1346 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1347 notify_protocol_trampoline::<Self, F> as *const (),
1348 )),
1349 Box_::into_raw(f),
1350 )
1351 }
1352 }
1353
1354 #[doc(alias = "proxy-resolver")]
1355 fn connect_proxy_resolver_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1356 unsafe extern "C" fn notify_proxy_resolver_trampoline<
1357 P: IsA<SocketClient>,
1358 F: Fn(&P) + 'static,
1359 >(
1360 this: *mut ffi::GSocketClient,
1361 _param_spec: glib::ffi::gpointer,
1362 f: glib::ffi::gpointer,
1363 ) {
1364 unsafe {
1365 let f: &F = &*(f as *const F);
1366 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1367 }
1368 }
1369 unsafe {
1370 let f: Box_<F> = Box_::new(f);
1371 connect_raw(
1372 self.as_ptr() as *mut _,
1373 c"notify::proxy-resolver".as_ptr() as *const _,
1374 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1375 notify_proxy_resolver_trampoline::<Self, F> as *const (),
1376 )),
1377 Box_::into_raw(f),
1378 )
1379 }
1380 }
1381
1382 #[doc(alias = "timeout")]
1383 fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1384 unsafe extern "C" fn notify_timeout_trampoline<
1385 P: IsA<SocketClient>,
1386 F: Fn(&P) + 'static,
1387 >(
1388 this: *mut ffi::GSocketClient,
1389 _param_spec: glib::ffi::gpointer,
1390 f: glib::ffi::gpointer,
1391 ) {
1392 unsafe {
1393 let f: &F = &*(f as *const F);
1394 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1395 }
1396 }
1397 unsafe {
1398 let f: Box_<F> = Box_::new(f);
1399 connect_raw(
1400 self.as_ptr() as *mut _,
1401 c"notify::timeout".as_ptr() as *const _,
1402 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1403 notify_timeout_trampoline::<Self, F> as *const (),
1404 )),
1405 Box_::into_raw(f),
1406 )
1407 }
1408 }
1409
1410 #[doc(alias = "tls")]
1411 fn connect_tls_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1412 unsafe extern "C" fn notify_tls_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
1413 this: *mut ffi::GSocketClient,
1414 _param_spec: glib::ffi::gpointer,
1415 f: glib::ffi::gpointer,
1416 ) {
1417 unsafe {
1418 let f: &F = &*(f as *const F);
1419 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1420 }
1421 }
1422 unsafe {
1423 let f: Box_<F> = Box_::new(f);
1424 connect_raw(
1425 self.as_ptr() as *mut _,
1426 c"notify::tls".as_ptr() as *const _,
1427 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1428 notify_tls_trampoline::<Self, F> as *const (),
1429 )),
1430 Box_::into_raw(f),
1431 )
1432 }
1433 }
1434
1435 #[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
1436 #[doc(alias = "tls-validation-flags")]
1437 fn connect_tls_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1438 unsafe extern "C" fn notify_tls_validation_flags_trampoline<
1439 P: IsA<SocketClient>,
1440 F: Fn(&P) + 'static,
1441 >(
1442 this: *mut ffi::GSocketClient,
1443 _param_spec: glib::ffi::gpointer,
1444 f: glib::ffi::gpointer,
1445 ) {
1446 unsafe {
1447 let f: &F = &*(f as *const F);
1448 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1449 }
1450 }
1451 unsafe {
1452 let f: Box_<F> = Box_::new(f);
1453 connect_raw(
1454 self.as_ptr() as *mut _,
1455 c"notify::tls-validation-flags".as_ptr() as *const _,
1456 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1457 notify_tls_validation_flags_trampoline::<Self, F> as *const (),
1458 )),
1459 Box_::into_raw(f),
1460 )
1461 }
1462 }
1463
1464 #[doc(alias = "type")]
1465 fn connect_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1466 unsafe extern "C" fn notify_type_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
1467 this: *mut ffi::GSocketClient,
1468 _param_spec: glib::ffi::gpointer,
1469 f: glib::ffi::gpointer,
1470 ) {
1471 unsafe {
1472 let f: &F = &*(f as *const F);
1473 f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
1474 }
1475 }
1476 unsafe {
1477 let f: Box_<F> = Box_::new(f);
1478 connect_raw(
1479 self.as_ptr() as *mut _,
1480 c"notify::type".as_ptr() as *const _,
1481 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1482 notify_type_trampoline::<Self, F> as *const (),
1483 )),
1484 Box_::into_raw(f),
1485 )
1486 }
1487 }
1488}
1489
1490impl<O: IsA<SocketClient>> SocketClientExt for O {}