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