Skip to main content

gio/auto/
socket.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    Cancellable, Credentials, DatagramBased, InetAddress, Initable, SocketAddress,
7    SocketConnection, SocketFamily, SocketProtocol, SocketType, ffi,
8};
9use glib::{
10    prelude::*,
11    signal::{SignalHandlerId, connect_raw},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    /// local_error);
18    ///     // handle error if needed
19    ///   }
20    /// ```text
21    ///
22    ///
23    /// ## Properties
24    ///
25    ///
26    /// #### `blocking`
27    ///  Whether I/O on this socket is blocking.
28    ///
29    /// Readable | Writable
30    ///
31    ///
32    /// #### `broadcast`
33    ///  Whether the socket should allow sending to broadcast addresses.
34    ///
35    /// Readable | Writable
36    ///
37    ///
38    /// #### `family`
39    ///  s address family.
40    ///
41    /// Readable | Writable | Construct Only
42    ///
43    ///
44    /// #### `fd`
45    ///  s file descriptor.
46    ///
47    /// Readable | Writable | Construct Only
48    ///
49    ///
50    /// #### `keepalive`
51    ///  Whether to keep the connection alive by sending periodic pings.
52    ///
53    /// Readable | Writable
54    ///
55    ///
56    /// #### `listen-backlog`
57    ///  The number of outstanding connections in the listen queue.
58    ///
59    /// Readable | Writable
60    ///
61    ///
62    /// #### `local-address`
63    ///  The local address the socket is bound to.
64    ///
65    /// Readable
66    ///
67    ///
68    /// #### `multicast-loopback`
69    ///  Whether outgoing multicast packets loop back to the local host.
70    ///
71    /// Readable | Writable
72    ///
73    ///
74    /// #### `multicast-ttl`
75    ///  Time-to-live out outgoing multicast packets
76    ///
77    /// Readable | Writable
78    ///
79    ///
80    /// #### `protocol`
81    ///  The ID of the protocol to use, or `-1` for unknown.
82    ///
83    /// Readable | Writable | Construct Only
84    ///
85    ///
86    /// #### `remote-address`
87    ///  The remote address the socket is connected to.
88    ///
89    /// Readable
90    ///
91    ///
92    /// #### `timeout`
93    ///  The timeout in seconds on socket I/O
94    ///
95    /// Readable | Writable
96    ///
97    ///
98    /// #### `ttl`
99    ///  Time-to-live for outgoing unicast packets
100    ///
101    /// Readable | Writable
102    ///
103    ///
104    /// #### `type`
105    ///  s type.
106    ///
107    /// Readable | Writable | Construct Only
108    ///
109    /// # Implements
110    ///
111    /// [`SocketExt`][trait@crate::prelude::SocketExt], [`trait@glib::ObjectExt`], [`DatagramBasedExt`][trait@crate::prelude::DatagramBasedExt], [`InitableExt`][trait@crate::prelude::InitableExt], [`SocketExtManual`][trait@crate::prelude::SocketExtManual], [`DatagramBasedExtManual`][trait@crate::prelude::DatagramBasedExtManual]
112    #[doc(alias = "GSocket")]
113    pub struct Socket(Object<ffi::GSocket, ffi::GSocketClass>) @implements DatagramBased, Initable;
114
115    match fn {
116        type_ => || ffi::g_socket_get_type(),
117    }
118}
119
120impl Socket {
121    pub const NONE: Option<&'static Socket> = None;
122
123    /// Creates a new #GSocket with the defined family, type and protocol.
124    /// If @protocol is 0 ([`SocketProtocol::Default`][crate::SocketProtocol::Default]) the default protocol type
125    /// for the family and type is used.
126    ///
127    /// The @protocol is a family and type specific int that specifies what
128    /// kind of protocol to use. #GSocketProtocol lists several common ones.
129    /// Many families only support one protocol, and use 0 for this, others
130    /// support several and using 0 means to use the default protocol for
131    /// the family and type.
132    ///
133    /// The protocol id is passed directly to the operating
134    /// system, so you can use protocols not listed in #GSocketProtocol if you
135    /// know the protocol number used for it.
136    /// ## `family`
137    /// the socket family to use, e.g. [`SocketFamily::Ipv4`][crate::SocketFamily::Ipv4].
138    /// ## `type_`
139    /// the socket type to use.
140    /// ## `protocol`
141    /// the id of the protocol to use, or 0 for default.
142    ///
143    /// # Returns
144    ///
145    /// a #GSocket or [`None`] on error.
146    ///     Free the returned object with g_object_unref().
147    #[doc(alias = "g_socket_new")]
148    pub fn new(
149        family: SocketFamily,
150        type_: SocketType,
151        protocol: SocketProtocol,
152    ) -> Result<Socket, glib::Error> {
153        unsafe {
154            let mut error = std::ptr::null_mut();
155            let ret = ffi::g_socket_new(
156                family.into_glib(),
157                type_.into_glib(),
158                protocol.into_glib(),
159                &mut error,
160            );
161            if error.is_null() {
162                Ok(from_glib_full(ret))
163            } else {
164                Err(from_glib_full(error))
165            }
166        }
167    }
168}
169
170/// Trait containing all [`struct@Socket`] methods.
171///
172/// # Implementors
173///
174/// [`Socket`][struct@crate::Socket]
175pub trait SocketExt: IsA<Socket> + 'static {
176    /// Accept incoming connections on a connection-based socket. This removes
177    /// the first outstanding connection request from the listening socket and
178    /// creates a #GSocket object for it.
179    ///
180    /// The @self must be bound to a local address with g_socket_bind() and
181    /// must be listening for incoming connections (g_socket_listen()).
182    ///
183    /// If there are no outstanding connections then the operation will block
184    /// or return [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock] if non-blocking I/O is enabled.
185    /// To be notified of an incoming connection, wait for the [`glib::IOCondition::IN`][crate::glib::IOCondition::IN] condition.
186    /// ## `cancellable`
187    /// a `GCancellable` or [`None`]
188    ///
189    /// # Returns
190    ///
191    /// a new #GSocket, or [`None`] on error.
192    ///     Free the returned object with g_object_unref().
193    #[doc(alias = "g_socket_accept")]
194    fn accept(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<Socket, glib::Error> {
195        unsafe {
196            let mut error = std::ptr::null_mut();
197            let ret = ffi::g_socket_accept(
198                self.as_ref().to_glib_none().0,
199                cancellable.map(|p| p.as_ref()).to_glib_none().0,
200                &mut error,
201            );
202            if error.is_null() {
203                Ok(from_glib_full(ret))
204            } else {
205                Err(from_glib_full(error))
206            }
207        }
208    }
209
210    /// When a socket is created it is attached to an address family, but it
211    /// doesn't have an address in this family. g_socket_bind() assigns the
212    /// address (sometimes called name) of the socket.
213    ///
214    /// It is generally required to bind to a local address before you can
215    /// receive connections. (See g_socket_listen() and g_socket_accept() ).
216    /// In certain situations, you may also want to bind a socket that will be
217    /// used to initiate connections, though this is not normally required.
218    ///
219    /// If @self is a TCP socket, then @allow_reuse controls the setting
220    /// of the `SO_REUSEADDR` socket option; normally it should be [`true`] for
221    /// server sockets (sockets that you will eventually call
222    /// g_socket_accept() on), and [`false`] for client sockets. (Failing to
223    /// set this flag on a server socket may cause g_socket_bind() to return
224    /// [`IOErrorEnum::AddressInUse`][crate::IOErrorEnum::AddressInUse] if the server program is stopped and then
225    /// immediately restarted.)
226    ///
227    /// If @self is a UDP socket, then @allow_reuse determines whether or
228    /// not other UDP sockets can be bound to the same address at the same
229    /// time. In particular, you can have several UDP sockets bound to the
230    /// same address, and they will all receive all of the multicast and
231    /// broadcast packets sent to that address. (The behavior of unicast
232    /// UDP packets to an address with multiple listeners is not defined.)
233    /// ## `address`
234    /// a #GSocketAddress specifying the local address.
235    /// ## `allow_reuse`
236    /// whether to allow reusing this address
237    ///
238    /// # Returns
239    ///
240    /// [`true`] on success, [`false`] on error.
241    #[doc(alias = "g_socket_bind")]
242    fn bind(
243        &self,
244        address: &impl IsA<SocketAddress>,
245        allow_reuse: bool,
246    ) -> Result<(), glib::Error> {
247        unsafe {
248            let mut error = std::ptr::null_mut();
249            let is_ok = ffi::g_socket_bind(
250                self.as_ref().to_glib_none().0,
251                address.as_ref().to_glib_none().0,
252                allow_reuse.into_glib(),
253                &mut error,
254            );
255            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
256            if error.is_null() {
257                Ok(())
258            } else {
259                Err(from_glib_full(error))
260            }
261        }
262    }
263
264    /// Checks and resets the pending connect error for the socket.
265    /// This is used to check for errors when g_socket_connect() is
266    /// used in non-blocking mode.
267    ///
268    /// # Returns
269    ///
270    /// [`true`] if no error, [`false`] otherwise, setting @error to the error
271    #[doc(alias = "g_socket_check_connect_result")]
272    fn check_connect_result(&self) -> Result<(), glib::Error> {
273        unsafe {
274            let mut error = std::ptr::null_mut();
275            let is_ok =
276                ffi::g_socket_check_connect_result(self.as_ref().to_glib_none().0, &mut error);
277            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
278            if error.is_null() {
279                Ok(())
280            } else {
281                Err(from_glib_full(error))
282            }
283        }
284    }
285
286    /// Closes the socket, shutting down any active connection.
287    ///
288    /// Closing a socket does not wait for all outstanding I/O operations
289    /// to finish, so the caller should not rely on them to be guaranteed
290    /// to complete even if the close returns with no error.
291    ///
292    /// Once the socket is closed, all other operations will return
293    /// [`IOErrorEnum::Closed`][crate::IOErrorEnum::Closed]. Closing a socket multiple times will not
294    /// return an error.
295    ///
296    /// Sockets will be automatically closed when the last reference
297    /// is dropped, but you might want to call this function to make sure
298    /// resources are released as early as possible.
299    ///
300    /// Beware that due to the way that TCP works, it is possible for
301    /// recently-sent data to be lost if either you close a socket while the
302    /// [`glib::IOCondition::IN`][crate::glib::IOCondition::IN] condition is set, or else if the remote connection tries to
303    /// send something to you after you close the socket but before it has
304    /// finished reading all of the data you sent. There is no easy generic
305    /// way to avoid this problem; the easiest fix is to design the network
306    /// protocol such that the client will never send data "out of turn".
307    /// Another solution is for the server to half-close the connection by
308    /// calling g_socket_shutdown() with only the @shutdown_write flag set,
309    /// and then wait for the client to notice this and close its side of the
310    /// connection, after which the server can safely call g_socket_close().
311    /// (This is what #GTcpConnection does if you call
312    /// g_tcp_connection_set_graceful_disconnect(). But of course, this
313    /// only works if the client will close its connection after the server
314    /// does.)
315    ///
316    /// # Returns
317    ///
318    /// [`true`] on success, [`false`] on error
319    #[doc(alias = "g_socket_close")]
320    fn close(&self) -> Result<(), glib::Error> {
321        unsafe {
322            let mut error = std::ptr::null_mut();
323            let is_ok = ffi::g_socket_close(self.as_ref().to_glib_none().0, &mut error);
324            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
325            if error.is_null() {
326                Ok(())
327            } else {
328                Err(from_glib_full(error))
329            }
330        }
331    }
332
333    /// Checks on the readiness of @self to perform operations.
334    /// The operations specified in @condition are checked for and masked
335    /// against the currently-satisfied conditions on @self. The result
336    /// is returned.
337    ///
338    /// Note that on Windows, it is possible for an operation to return
339    /// [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock] even immediately after
340    /// g_socket_condition_check() has claimed that the socket is ready for
341    /// writing. Rather than calling g_socket_condition_check() and then
342    /// writing to the socket if it succeeds, it is generally better to
343    /// simply try writing to the socket right away, and try again later if
344    /// the initial attempt returns [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock].
345    ///
346    /// It is meaningless to specify [`glib::IOCondition::ERR`][crate::glib::IOCondition::ERR] or [`glib::IOCondition::HUP`][crate::glib::IOCondition::HUP] in condition;
347    /// these conditions will always be set in the output if they are true.
348    ///
349    /// This call never blocks.
350    /// ## `condition`
351    /// a #GIOCondition mask to check
352    ///
353    /// # Returns
354    ///
355    /// the @GIOCondition mask of the current state
356    #[doc(alias = "g_socket_condition_check")]
357    fn condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition {
358        unsafe {
359            from_glib(ffi::g_socket_condition_check(
360                self.as_ref().to_glib_none().0,
361                condition.into_glib(),
362            ))
363        }
364    }
365
366    /// Waits for up to @timeout_us microseconds for @condition to become true
367    /// on @self. If the condition is met, [`true`] is returned.
368    ///
369    /// If @cancellable is cancelled before the condition is met, or if
370    /// @timeout_us (or the socket's #GSocket:timeout) is reached before the
371    /// condition is met, then [`false`] is returned and @error, if non-[`None`],
372    /// is set to the appropriate value ([`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] or
373    /// [`IOErrorEnum::TimedOut`][crate::IOErrorEnum::TimedOut]).
374    ///
375    /// If you don't want a timeout, use g_socket_condition_wait().
376    /// (Alternatively, you can pass -1 for @timeout_us.)
377    ///
378    /// Note that although @timeout_us is in microseconds for consistency with
379    /// other GLib APIs, this function actually only has millisecond
380    /// resolution, and the behavior is undefined if @timeout_us is not an
381    /// exact number of milliseconds.
382    /// ## `condition`
383    /// a #GIOCondition mask to wait for
384    /// ## `timeout_us`
385    /// the maximum time (in microseconds) to wait, or -1
386    /// ## `cancellable`
387    /// a #GCancellable, or [`None`]
388    ///
389    /// # Returns
390    ///
391    /// [`true`] if the condition was met, [`false`] otherwise
392    #[doc(alias = "g_socket_condition_timed_wait")]
393    fn condition_timed_wait(
394        &self,
395        condition: glib::IOCondition,
396        timeout_us: i64,
397        cancellable: Option<&impl IsA<Cancellable>>,
398    ) -> Result<(), glib::Error> {
399        unsafe {
400            let mut error = std::ptr::null_mut();
401            let is_ok = ffi::g_socket_condition_timed_wait(
402                self.as_ref().to_glib_none().0,
403                condition.into_glib(),
404                timeout_us,
405                cancellable.map(|p| p.as_ref()).to_glib_none().0,
406                &mut error,
407            );
408            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
409            if error.is_null() {
410                Ok(())
411            } else {
412                Err(from_glib_full(error))
413            }
414        }
415    }
416
417    /// Waits for @condition to become true on @self. When the condition
418    /// is met, [`true`] is returned.
419    ///
420    /// If @cancellable is cancelled before the condition is met, or if the
421    /// socket has a timeout set and it is reached before the condition is
422    /// met, then [`false`] is returned and @error, if non-[`None`], is set to
423    /// the appropriate value ([`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled] or
424    /// [`IOErrorEnum::TimedOut`][crate::IOErrorEnum::TimedOut]).
425    ///
426    /// See also g_socket_condition_timed_wait().
427    /// ## `condition`
428    /// a #GIOCondition mask to wait for
429    /// ## `cancellable`
430    /// a #GCancellable, or [`None`]
431    ///
432    /// # Returns
433    ///
434    /// [`true`] if the condition was met, [`false`] otherwise
435    #[doc(alias = "g_socket_condition_wait")]
436    fn condition_wait(
437        &self,
438        condition: glib::IOCondition,
439        cancellable: Option<&impl IsA<Cancellable>>,
440    ) -> Result<(), glib::Error> {
441        unsafe {
442            let mut error = std::ptr::null_mut();
443            let is_ok = ffi::g_socket_condition_wait(
444                self.as_ref().to_glib_none().0,
445                condition.into_glib(),
446                cancellable.map(|p| p.as_ref()).to_glib_none().0,
447                &mut error,
448            );
449            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
450            if error.is_null() {
451                Ok(())
452            } else {
453                Err(from_glib_full(error))
454            }
455        }
456    }
457
458    /// Connect the socket to the specified remote address.
459    ///
460    /// For connection oriented socket this generally means we attempt to make
461    /// a connection to the @address. For a connection-less socket it sets
462    /// the default address for g_socket_send() and discards all incoming datagrams
463    /// from other sources.
464    ///
465    /// Generally connection oriented sockets can only connect once, but
466    /// connection-less sockets can connect multiple times to change the
467    /// default address.
468    ///
469    /// If the connect call needs to do network I/O it will block, unless
470    /// non-blocking I/O is enabled. Then [`IOErrorEnum::Pending`][crate::IOErrorEnum::Pending] is returned
471    /// and the user can be notified of the connection finishing by waiting
472    /// for the G_IO_OUT condition. The result of the connection must then be
473    /// checked with g_socket_check_connect_result().
474    /// ## `address`
475    /// a #GSocketAddress specifying the remote address.
476    /// ## `cancellable`
477    /// a `GCancellable` or [`None`]
478    ///
479    /// # Returns
480    ///
481    /// [`true`] if connected, [`false`] on error.
482    #[doc(alias = "g_socket_connect")]
483    fn connect(
484        &self,
485        address: &impl IsA<SocketAddress>,
486        cancellable: Option<&impl IsA<Cancellable>>,
487    ) -> Result<(), glib::Error> {
488        unsafe {
489            let mut error = std::ptr::null_mut();
490            let is_ok = ffi::g_socket_connect(
491                self.as_ref().to_glib_none().0,
492                address.as_ref().to_glib_none().0,
493                cancellable.map(|p| p.as_ref()).to_glib_none().0,
494                &mut error,
495            );
496            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
497            if error.is_null() {
498                Ok(())
499            } else {
500                Err(from_glib_full(error))
501            }
502        }
503    }
504
505    /// Creates a #GSocketConnection subclass of the right type for
506    /// @self.
507    ///
508    /// # Returns
509    ///
510    /// a #GSocketConnection
511    #[doc(alias = "g_socket_connection_factory_create_connection")]
512    fn connection_factory_create_connection(&self) -> SocketConnection {
513        unsafe {
514            from_glib_full(ffi::g_socket_connection_factory_create_connection(
515                self.as_ref().to_glib_none().0,
516            ))
517        }
518    }
519
520    /// Get the amount of data pending in the OS input buffer, without blocking.
521    ///
522    /// If @self is a UDP or SCTP socket, this will return the size of
523    /// just the next packet, even if additional packets are buffered after
524    /// that one.
525    ///
526    /// Note that on Windows, this function is rather inefficient in the
527    /// UDP case, and so if you know any plausible upper bound on the size
528    /// of the incoming packet, it is better to just do a
529    /// g_socket_receive() with a buffer of that size, rather than calling
530    /// g_socket_get_available_bytes() first and then doing a receive of
531    /// exactly the right size.
532    ///
533    /// # Returns
534    ///
535    /// the number of bytes that can be read from the socket
536    /// without blocking or truncating, or -1 on error.
537    #[doc(alias = "g_socket_get_available_bytes")]
538    #[doc(alias = "get_available_bytes")]
539    fn available_bytes(&self) -> isize {
540        unsafe { ffi::g_socket_get_available_bytes(self.as_ref().to_glib_none().0) }
541    }
542
543    /// Gets the blocking mode of the socket. For details on blocking I/O,
544    /// see g_socket_set_blocking().
545    ///
546    /// # Returns
547    ///
548    /// [`true`] if blocking I/O is used, [`false`] otherwise.
549    #[doc(alias = "g_socket_get_blocking")]
550    #[doc(alias = "get_blocking")]
551    #[doc(alias = "blocking")]
552    fn is_blocking(&self) -> bool {
553        unsafe { from_glib(ffi::g_socket_get_blocking(self.as_ref().to_glib_none().0)) }
554    }
555
556    /// Gets the broadcast setting on @self; if [`true`],
557    /// it is possible to send packets to broadcast
558    /// addresses.
559    ///
560    /// # Returns
561    ///
562    /// the broadcast setting on @self
563    #[doc(alias = "g_socket_get_broadcast")]
564    #[doc(alias = "get_broadcast")]
565    #[doc(alias = "broadcast")]
566    fn is_broadcast(&self) -> bool {
567        unsafe { from_glib(ffi::g_socket_get_broadcast(self.as_ref().to_glib_none().0)) }
568    }
569
570    /// Returns the credentials of the foreign process connected to this
571    /// socket, if any (e.g. it is only supported for [`SocketFamily::Unix`][crate::SocketFamily::Unix]
572    /// sockets).
573    ///
574    /// If this operation isn't supported on the OS, the method fails with
575    /// the [`IOErrorEnum::NotSupported`][crate::IOErrorEnum::NotSupported] error. On Linux this is implemented
576    /// by reading the `SO_PEERCRED` option on the underlying socket.
577    ///
578    /// This method can be expected to be available on the following platforms:
579    ///
580    /// - Linux since GLib 2.26
581    /// - OpenBSD since GLib 2.30
582    /// - Solaris, Illumos and OpenSolaris since GLib 2.40
583    /// - NetBSD since GLib 2.42
584    /// - macOS, tvOS, iOS since GLib 2.66
585    ///
586    /// Other ways to obtain credentials from a foreign peer includes the
587    /// #GUnixCredentialsMessage type and
588    /// g_unix_connection_send_credentials() /
589    /// g_unix_connection_receive_credentials() functions.
590    ///
591    /// # Returns
592    ///
593    /// [`None`] if @error is set, otherwise a #GCredentials object
594    /// that must be freed with g_object_unref().
595    #[doc(alias = "g_socket_get_credentials")]
596    #[doc(alias = "get_credentials")]
597    fn credentials(&self) -> Result<Credentials, glib::Error> {
598        unsafe {
599            let mut error = std::ptr::null_mut();
600            let ret = ffi::g_socket_get_credentials(self.as_ref().to_glib_none().0, &mut error);
601            if error.is_null() {
602                Ok(from_glib_full(ret))
603            } else {
604                Err(from_glib_full(error))
605            }
606        }
607    }
608
609    /// Gets the socket family of the socket.
610    ///
611    /// # Returns
612    ///
613    /// a #GSocketFamily
614    #[doc(alias = "g_socket_get_family")]
615    #[doc(alias = "get_family")]
616    fn family(&self) -> SocketFamily {
617        unsafe { from_glib(ffi::g_socket_get_family(self.as_ref().to_glib_none().0)) }
618    }
619
620    /// Gets the keepalive mode of the socket. For details on this,
621    /// see g_socket_set_keepalive().
622    ///
623    /// # Returns
624    ///
625    /// [`true`] if keepalive is active, [`false`] otherwise.
626    #[doc(alias = "g_socket_get_keepalive")]
627    #[doc(alias = "get_keepalive")]
628    #[doc(alias = "keepalive")]
629    fn is_keepalive(&self) -> bool {
630        unsafe { from_glib(ffi::g_socket_get_keepalive(self.as_ref().to_glib_none().0)) }
631    }
632
633    /// Gets the listen backlog setting of the socket. For details on this,
634    /// see g_socket_set_listen_backlog().
635    ///
636    /// # Returns
637    ///
638    /// the maximum number of pending connections.
639    #[doc(alias = "g_socket_get_listen_backlog")]
640    #[doc(alias = "get_listen_backlog")]
641    #[doc(alias = "listen-backlog")]
642    fn listen_backlog(&self) -> i32 {
643        unsafe { ffi::g_socket_get_listen_backlog(self.as_ref().to_glib_none().0) }
644    }
645
646    /// Try to get the local address of a bound socket. This is only
647    /// useful if the socket has been bound to a local address,
648    /// either explicitly or implicitly when connecting.
649    ///
650    /// # Returns
651    ///
652    /// a #GSocketAddress or [`None`] on error.
653    ///     Free the returned object with g_object_unref().
654    #[doc(alias = "g_socket_get_local_address")]
655    #[doc(alias = "get_local_address")]
656    #[doc(alias = "local-address")]
657    fn local_address(&self) -> Result<SocketAddress, glib::Error> {
658        unsafe {
659            let mut error = std::ptr::null_mut();
660            let ret = ffi::g_socket_get_local_address(self.as_ref().to_glib_none().0, &mut error);
661            if error.is_null() {
662                Ok(from_glib_full(ret))
663            } else {
664                Err(from_glib_full(error))
665            }
666        }
667    }
668
669    /// Gets the multicast loopback setting on @self; if [`true`] (the
670    /// default), outgoing multicast packets will be looped back to
671    /// multicast listeners on the same host.
672    ///
673    /// # Returns
674    ///
675    /// the multicast loopback setting on @self
676    #[doc(alias = "g_socket_get_multicast_loopback")]
677    #[doc(alias = "get_multicast_loopback")]
678    #[doc(alias = "multicast-loopback")]
679    fn is_multicast_loopback(&self) -> bool {
680        unsafe {
681            from_glib(ffi::g_socket_get_multicast_loopback(
682                self.as_ref().to_glib_none().0,
683            ))
684        }
685    }
686
687    /// Gets the multicast time-to-live setting on @self; see
688    /// g_socket_set_multicast_ttl() for more details.
689    ///
690    /// # Returns
691    ///
692    /// the multicast time-to-live setting on @self
693    #[doc(alias = "g_socket_get_multicast_ttl")]
694    #[doc(alias = "get_multicast_ttl")]
695    #[doc(alias = "multicast-ttl")]
696    fn multicast_ttl(&self) -> u32 {
697        unsafe { ffi::g_socket_get_multicast_ttl(self.as_ref().to_glib_none().0) }
698    }
699
700    /// `](networking.html)
701    /// header pulls in system headers that will define most of the
702    /// standard/portable socket options. For unusual socket protocols or
703    /// platform-dependent options, you may need to include additional
704    /// headers.
705    ///
706    /// Note that even for socket options that are a single byte in size,
707    /// @value is still a pointer to a #gint variable, not a #guchar;
708    /// g_socket_get_option() will handle the conversion internally.
709    /// ## `level`
710    /// the "API level" of the option (eg, `SOL_SOCKET`)
711    /// ## `optname`
712    /// the "name" of the option (eg, `SO_BROADCAST`)
713    ///
714    /// # Returns
715    ///
716    /// success or failure. On failure, @error will be set, and
717    ///   the system error value (`errno` or WSAGetLastError()) will still
718    ///   be set to the result of the getsockopt() call.
719    ///
720    /// ## `value`
721    /// return location for the option value
722    #[doc(alias = "g_socket_get_option")]
723    #[doc(alias = "get_option")]
724    fn option(&self, level: i32, optname: i32) -> Result<i32, glib::Error> {
725        unsafe {
726            let mut value = std::mem::MaybeUninit::uninit();
727            let mut error = std::ptr::null_mut();
728            let is_ok = ffi::g_socket_get_option(
729                self.as_ref().to_glib_none().0,
730                level,
731                optname,
732                value.as_mut_ptr(),
733                &mut error,
734            );
735            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
736            if error.is_null() {
737                Ok(value.assume_init())
738            } else {
739                Err(from_glib_full(error))
740            }
741        }
742    }
743
744    /// Gets the socket protocol id the socket was created with.
745    /// In case the protocol is unknown, -1 is returned.
746    ///
747    /// # Returns
748    ///
749    /// a protocol id, or -1 if unknown
750    #[doc(alias = "g_socket_get_protocol")]
751    #[doc(alias = "get_protocol")]
752    fn protocol(&self) -> SocketProtocol {
753        unsafe { from_glib(ffi::g_socket_get_protocol(self.as_ref().to_glib_none().0)) }
754    }
755
756    /// Try to get the remote address of a connected socket. This is only
757    /// useful for connection oriented sockets that have been connected.
758    ///
759    /// # Returns
760    ///
761    /// a #GSocketAddress or [`None`] on error.
762    ///     Free the returned object with g_object_unref().
763    #[doc(alias = "g_socket_get_remote_address")]
764    #[doc(alias = "get_remote_address")]
765    #[doc(alias = "remote-address")]
766    fn remote_address(&self) -> Result<SocketAddress, glib::Error> {
767        unsafe {
768            let mut error = std::ptr::null_mut();
769            let ret = ffi::g_socket_get_remote_address(self.as_ref().to_glib_none().0, &mut error);
770            if error.is_null() {
771                Ok(from_glib_full(ret))
772            } else {
773                Err(from_glib_full(error))
774            }
775        }
776    }
777
778    /// Gets the socket type of the socket.
779    ///
780    /// # Returns
781    ///
782    /// a #GSocketType
783    #[doc(alias = "g_socket_get_socket_type")]
784    #[doc(alias = "get_socket_type")]
785    fn socket_type(&self) -> SocketType {
786        unsafe {
787            from_glib(ffi::g_socket_get_socket_type(
788                self.as_ref().to_glib_none().0,
789            ))
790        }
791    }
792
793    /// Gets the timeout setting of the socket. For details on this, see
794    /// g_socket_set_timeout().
795    ///
796    /// # Returns
797    ///
798    /// the timeout in seconds
799    #[doc(alias = "g_socket_get_timeout")]
800    #[doc(alias = "get_timeout")]
801    fn timeout(&self) -> u32 {
802        unsafe { ffi::g_socket_get_timeout(self.as_ref().to_glib_none().0) }
803    }
804
805    /// Gets the unicast time-to-live setting on @self; see
806    /// g_socket_set_ttl() for more details.
807    ///
808    /// # Returns
809    ///
810    /// the time-to-live setting on @self
811    #[doc(alias = "g_socket_get_ttl")]
812    #[doc(alias = "get_ttl")]
813    fn ttl(&self) -> u32 {
814        unsafe { ffi::g_socket_get_ttl(self.as_ref().to_glib_none().0) }
815    }
816
817    /// Checks whether a socket is closed.
818    ///
819    /// # Returns
820    ///
821    /// [`true`] if socket is closed, [`false`] otherwise
822    #[doc(alias = "g_socket_is_closed")]
823    fn is_closed(&self) -> bool {
824        unsafe { from_glib(ffi::g_socket_is_closed(self.as_ref().to_glib_none().0)) }
825    }
826
827    /// Check whether the socket is connected. This is only useful for
828    /// connection-oriented sockets.
829    ///
830    /// If using g_socket_shutdown(), this function will return [`true`] until the
831    /// socket has been shut down for reading and writing. If you do a non-blocking
832    /// connect, this function will not return [`true`] until after you call
833    /// g_socket_check_connect_result().
834    ///
835    /// # Returns
836    ///
837    /// [`true`] if socket is connected, [`false`] otherwise.
838    #[doc(alias = "g_socket_is_connected")]
839    fn is_connected(&self) -> bool {
840        unsafe { from_glib(ffi::g_socket_is_connected(self.as_ref().to_glib_none().0)) }
841    }
842
843    /// Registers @self to receive multicast messages sent to @group.
844    /// @self must be a [`SocketType::Datagram`][crate::SocketType::Datagram] socket, and must have
845    /// been bound to an appropriate interface and port with
846    /// g_socket_bind().
847    ///
848    /// If @iface is [`None`], the system will automatically pick an interface
849    /// to bind to based on @group.
850    ///
851    /// If @source_specific is [`true`], source-specific multicast as defined
852    /// in RFC 4604 is used. Note that on older platforms this may fail
853    /// with a [`IOErrorEnum::NotSupported`][crate::IOErrorEnum::NotSupported] error.
854    ///
855    /// To bind to a given source-specific multicast address, use
856    /// g_socket_join_multicast_group_ssm() instead.
857    /// ## `group`
858    /// a #GInetAddress specifying the group address to join.
859    /// ## `source_specific`
860    /// [`true`] if source-specific multicast should be used
861    /// ## `iface`
862    /// Name of the interface to use, or [`None`]
863    ///
864    /// # Returns
865    ///
866    /// [`true`] on success, [`false`] on error.
867    #[doc(alias = "g_socket_join_multicast_group")]
868    fn join_multicast_group(
869        &self,
870        group: &impl IsA<InetAddress>,
871        source_specific: bool,
872        iface: Option<&str>,
873    ) -> Result<(), glib::Error> {
874        unsafe {
875            let mut error = std::ptr::null_mut();
876            let is_ok = ffi::g_socket_join_multicast_group(
877                self.as_ref().to_glib_none().0,
878                group.as_ref().to_glib_none().0,
879                source_specific.into_glib(),
880                iface.to_glib_none().0,
881                &mut error,
882            );
883            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
884            if error.is_null() {
885                Ok(())
886            } else {
887                Err(from_glib_full(error))
888            }
889        }
890    }
891
892    /// Registers @self to receive multicast messages sent to @group.
893    /// @self must be a [`SocketType::Datagram`][crate::SocketType::Datagram] socket, and must have
894    /// been bound to an appropriate interface and port with
895    /// g_socket_bind().
896    ///
897    /// If @iface is [`None`], the system will automatically pick an interface
898    /// to bind to based on @group.
899    ///
900    /// If @source_specific is not [`None`], use source-specific multicast as
901    /// defined in RFC 4604. Note that on older platforms this may fail
902    /// with a [`IOErrorEnum::NotSupported`][crate::IOErrorEnum::NotSupported] error.
903    ///
904    /// Note that this function can be called multiple times for the same
905    /// @group with different @source_specific in order to receive multicast
906    /// packets from more than one source.
907    /// ## `group`
908    /// a #GInetAddress specifying the group address to join.
909    /// ## `source_specific`
910    /// a #GInetAddress specifying the
911    /// source-specific multicast address or [`None`] to ignore.
912    /// ## `iface`
913    /// Name of the interface to use, or [`None`]
914    ///
915    /// # Returns
916    ///
917    /// [`true`] on success, [`false`] on error.
918    #[doc(alias = "g_socket_join_multicast_group_ssm")]
919    fn join_multicast_group_ssm(
920        &self,
921        group: &impl IsA<InetAddress>,
922        source_specific: Option<&impl IsA<InetAddress>>,
923        iface: Option<&str>,
924    ) -> Result<(), glib::Error> {
925        unsafe {
926            let mut error = std::ptr::null_mut();
927            let is_ok = ffi::g_socket_join_multicast_group_ssm(
928                self.as_ref().to_glib_none().0,
929                group.as_ref().to_glib_none().0,
930                source_specific.map(|p| p.as_ref()).to_glib_none().0,
931                iface.to_glib_none().0,
932                &mut error,
933            );
934            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
935            if error.is_null() {
936                Ok(())
937            } else {
938                Err(from_glib_full(error))
939            }
940        }
941    }
942
943    /// Removes @self from the multicast group defined by @group, @iface,
944    /// and @source_specific (which must all have the same values they had
945    /// when you joined the group).
946    ///
947    /// @self remains bound to its address and port, and can still receive
948    /// unicast messages after calling this.
949    ///
950    /// To unbind to a given source-specific multicast address, use
951    /// g_socket_leave_multicast_group_ssm() instead.
952    /// ## `group`
953    /// a #GInetAddress specifying the group address to leave.
954    /// ## `source_specific`
955    /// [`true`] if source-specific multicast was used
956    /// ## `iface`
957    /// Interface used
958    ///
959    /// # Returns
960    ///
961    /// [`true`] on success, [`false`] on error.
962    #[doc(alias = "g_socket_leave_multicast_group")]
963    fn leave_multicast_group(
964        &self,
965        group: &impl IsA<InetAddress>,
966        source_specific: bool,
967        iface: Option<&str>,
968    ) -> Result<(), glib::Error> {
969        unsafe {
970            let mut error = std::ptr::null_mut();
971            let is_ok = ffi::g_socket_leave_multicast_group(
972                self.as_ref().to_glib_none().0,
973                group.as_ref().to_glib_none().0,
974                source_specific.into_glib(),
975                iface.to_glib_none().0,
976                &mut error,
977            );
978            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
979            if error.is_null() {
980                Ok(())
981            } else {
982                Err(from_glib_full(error))
983            }
984        }
985    }
986
987    /// Removes @self from the multicast group defined by @group, @iface,
988    /// and @source_specific (which must all have the same values they had
989    /// when you joined the group).
990    ///
991    /// @self remains bound to its address and port, and can still receive
992    /// unicast messages after calling this.
993    /// ## `group`
994    /// a #GInetAddress specifying the group address to leave.
995    /// ## `source_specific`
996    /// a #GInetAddress specifying the
997    /// source-specific multicast address or [`None`] to ignore.
998    /// ## `iface`
999    /// Name of the interface to use, or [`None`]
1000    ///
1001    /// # Returns
1002    ///
1003    /// [`true`] on success, [`false`] on error.
1004    #[doc(alias = "g_socket_leave_multicast_group_ssm")]
1005    fn leave_multicast_group_ssm(
1006        &self,
1007        group: &impl IsA<InetAddress>,
1008        source_specific: Option<&impl IsA<InetAddress>>,
1009        iface: Option<&str>,
1010    ) -> Result<(), glib::Error> {
1011        unsafe {
1012            let mut error = std::ptr::null_mut();
1013            let is_ok = ffi::g_socket_leave_multicast_group_ssm(
1014                self.as_ref().to_glib_none().0,
1015                group.as_ref().to_glib_none().0,
1016                source_specific.map(|p| p.as_ref()).to_glib_none().0,
1017                iface.to_glib_none().0,
1018                &mut error,
1019            );
1020            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1021            if error.is_null() {
1022                Ok(())
1023            } else {
1024                Err(from_glib_full(error))
1025            }
1026        }
1027    }
1028
1029    /// Marks the socket as a server socket, i.e. a socket that is used
1030    /// to accept incoming requests using g_socket_accept().
1031    ///
1032    /// Before calling this the socket must be bound to a local address using
1033    /// g_socket_bind().
1034    ///
1035    /// To set the maximum amount of outstanding clients, use
1036    /// g_socket_set_listen_backlog().
1037    ///
1038    /// # Returns
1039    ///
1040    /// [`true`] on success, [`false`] on error.
1041    #[doc(alias = "g_socket_listen")]
1042    fn listen(&self) -> Result<(), glib::Error> {
1043        unsafe {
1044            let mut error = std::ptr::null_mut();
1045            let is_ok = ffi::g_socket_listen(self.as_ref().to_glib_none().0, &mut error);
1046            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1047            if error.is_null() {
1048                Ok(())
1049            } else {
1050                Err(from_glib_full(error))
1051            }
1052        }
1053    }
1054
1055    /// t take an explicit blocking parameter) block until
1056    /// they succeed or there is an error. In
1057    /// non-blocking mode all functions return results immediately or
1058    /// with a [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock] error.
1059    ///
1060    /// All sockets are created in blocking mode. However, note that the
1061    /// platform level socket is always non-blocking, and blocking mode
1062    /// is a GSocket level feature.
1063    /// ## `blocking`
1064    /// Whether to use blocking I/O or not.
1065    #[doc(alias = "g_socket_set_blocking")]
1066    #[doc(alias = "blocking")]
1067    fn set_blocking(&self, blocking: bool) {
1068        unsafe {
1069            ffi::g_socket_set_blocking(self.as_ref().to_glib_none().0, blocking.into_glib());
1070        }
1071    }
1072
1073    /// Sets whether @self should allow sending to broadcast addresses.
1074    /// This is [`false`] by default.
1075    /// ## `broadcast`
1076    /// whether @self should allow sending to broadcast
1077    ///     addresses
1078    #[doc(alias = "g_socket_set_broadcast")]
1079    #[doc(alias = "broadcast")]
1080    fn set_broadcast(&self, broadcast: bool) {
1081        unsafe {
1082            ffi::g_socket_set_broadcast(self.as_ref().to_glib_none().0, broadcast.into_glib());
1083        }
1084    }
1085
1086    /// Sets or unsets the `SO_KEEPALIVE` flag on the underlying socket. When
1087    /// this flag is set on a socket, the system will attempt to verify that the
1088    /// remote socket endpoint is still present if a sufficiently long period of
1089    /// time passes with no data being exchanged. If the system is unable to
1090    /// verify the presence of the remote endpoint, it will automatically close
1091    /// the connection.
1092    ///
1093    /// This option is only functional on certain kinds of sockets. (Notably,
1094    /// [`SocketProtocol::Tcp`][crate::SocketProtocol::Tcp] sockets.)
1095    ///
1096    /// The exact time between pings is system- and protocol-dependent, but will
1097    /// normally be at least two hours. Most commonly, you would set this flag
1098    /// on a server socket if you want to allow clients to remain idle for long
1099    /// periods of time, but also want to ensure that connections are eventually
1100    /// garbage-collected if clients crash or become unreachable.
1101    /// ## `keepalive`
1102    /// Value for the keepalive flag
1103    #[doc(alias = "g_socket_set_keepalive")]
1104    #[doc(alias = "keepalive")]
1105    fn set_keepalive(&self, keepalive: bool) {
1106        unsafe {
1107            ffi::g_socket_set_keepalive(self.as_ref().to_glib_none().0, keepalive.into_glib());
1108        }
1109    }
1110
1111    /// Sets the maximum number of outstanding connections allowed
1112    /// when listening on this socket. If more clients than this are
1113    /// connecting to the socket and the application is not handling them
1114    /// on time then the new connections will be refused.
1115    ///
1116    /// Note that this must be called before g_socket_listen() and has no
1117    /// effect if called after that.
1118    /// ## `backlog`
1119    /// the maximum number of pending connections.
1120    #[doc(alias = "g_socket_set_listen_backlog")]
1121    #[doc(alias = "listen-backlog")]
1122    fn set_listen_backlog(&self, backlog: i32) {
1123        unsafe {
1124            ffi::g_socket_set_listen_backlog(self.as_ref().to_glib_none().0, backlog);
1125        }
1126    }
1127
1128    /// Sets whether outgoing multicast packets will be received by sockets
1129    /// listening on that multicast address on the same host. This is [`true`]
1130    /// by default.
1131    /// ## `loopback`
1132    /// whether @self should receive messages sent to its
1133    ///   multicast groups from the local host
1134    #[doc(alias = "g_socket_set_multicast_loopback")]
1135    #[doc(alias = "multicast-loopback")]
1136    fn set_multicast_loopback(&self, loopback: bool) {
1137        unsafe {
1138            ffi::g_socket_set_multicast_loopback(
1139                self.as_ref().to_glib_none().0,
1140                loopback.into_glib(),
1141            );
1142        }
1143    }
1144
1145    /// Sets the time-to-live for outgoing multicast datagrams on @self.
1146    /// By default, this is 1, meaning that multicast packets will not leave
1147    /// the local network.
1148    /// ## `ttl`
1149    /// the time-to-live value for all multicast datagrams on @self
1150    #[doc(alias = "g_socket_set_multicast_ttl")]
1151    #[doc(alias = "multicast-ttl")]
1152    fn set_multicast_ttl(&self, ttl: u32) {
1153        unsafe {
1154            ffi::g_socket_set_multicast_ttl(self.as_ref().to_glib_none().0, ttl);
1155        }
1156    }
1157
1158    /// `](networking.html)
1159    /// header pulls in system headers that will define most of the
1160    /// standard/portable socket options. For unusual socket protocols or
1161    /// platform-dependent options, you may need to include additional
1162    /// headers.
1163    /// ## `level`
1164    /// the "API level" of the option (eg, `SOL_SOCKET`)
1165    /// ## `optname`
1166    /// the "name" of the option (eg, `SO_BROADCAST`)
1167    /// ## `value`
1168    /// the value to set the option to
1169    ///
1170    /// # Returns
1171    ///
1172    /// success or failure. On failure, @error will be set, and
1173    ///   the system error value (`errno` or WSAGetLastError()) will still
1174    ///   be set to the result of the setsockopt() call.
1175    #[doc(alias = "g_socket_set_option")]
1176    fn set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error> {
1177        unsafe {
1178            let mut error = std::ptr::null_mut();
1179            let is_ok = ffi::g_socket_set_option(
1180                self.as_ref().to_glib_none().0,
1181                level,
1182                optname,
1183                value,
1184                &mut error,
1185            );
1186            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1187            if error.is_null() {
1188                Ok(())
1189            } else {
1190                Err(from_glib_full(error))
1191            }
1192        }
1193    }
1194
1195    /// Sets the time in seconds after which I/O operations on @self will
1196    /// time out if they have not yet completed.
1197    ///
1198    /// On a blocking socket, this means that any blocking #GSocket
1199    /// operation will time out after @timeout seconds of inactivity,
1200    /// returning [`IOErrorEnum::TimedOut`][crate::IOErrorEnum::TimedOut].
1201    ///
1202    /// On a non-blocking socket, calls to g_socket_condition_wait() will
1203    /// also fail with [`IOErrorEnum::TimedOut`][crate::IOErrorEnum::TimedOut] after the given time. Sources
1204    /// created with g_socket_create_source() will trigger after
1205    /// @timeout seconds of inactivity, with the requested condition
1206    /// set, at which point calling g_socket_receive(), g_socket_send(),
1207    /// g_socket_check_connect_result(), etc, will fail with
1208    /// [`IOErrorEnum::TimedOut`][crate::IOErrorEnum::TimedOut].
1209    ///
1210    /// If @timeout is 0 (the default), operations will never time out
1211    /// on their own.
1212    ///
1213    /// Note that if an I/O operation is interrupted by a signal, this may
1214    /// cause the timeout to be reset.
1215    /// ## `timeout`
1216    /// the timeout for @self, in seconds, or 0 for none
1217    #[doc(alias = "g_socket_set_timeout")]
1218    #[doc(alias = "timeout")]
1219    fn set_timeout(&self, timeout: u32) {
1220        unsafe {
1221            ffi::g_socket_set_timeout(self.as_ref().to_glib_none().0, timeout);
1222        }
1223    }
1224
1225    /// Sets the time-to-live for outgoing unicast packets on @self.
1226    /// By default the platform-specific default value is used.
1227    /// ## `ttl`
1228    /// the time-to-live value for all unicast packets on @self
1229    #[doc(alias = "g_socket_set_ttl")]
1230    #[doc(alias = "ttl")]
1231    fn set_ttl(&self, ttl: u32) {
1232        unsafe {
1233            ffi::g_socket_set_ttl(self.as_ref().to_glib_none().0, ttl);
1234        }
1235    }
1236
1237    /// Shut down part or all of a full-duplex connection.
1238    ///
1239    /// If @shutdown_read is [`true`] then the receiving side of the connection
1240    /// is shut down, and further reading is disallowed.
1241    ///
1242    /// If @shutdown_write is [`true`] then the sending side of the connection
1243    /// is shut down, and further writing is disallowed.
1244    ///
1245    /// It is allowed for both @shutdown_read and @shutdown_write to be [`true`].
1246    ///
1247    /// One example where it is useful to shut down only one side of a connection is
1248    /// graceful disconnect for TCP connections where you close the sending side,
1249    /// then wait for the other side to close the connection, thus ensuring that the
1250    /// other side saw all sent data.
1251    /// ## `shutdown_read`
1252    /// whether to shut down the read side
1253    /// ## `shutdown_write`
1254    /// whether to shut down the write side
1255    ///
1256    /// # Returns
1257    ///
1258    /// [`true`] on success, [`false`] on error
1259    #[doc(alias = "g_socket_shutdown")]
1260    fn shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error> {
1261        unsafe {
1262            let mut error = std::ptr::null_mut();
1263            let is_ok = ffi::g_socket_shutdown(
1264                self.as_ref().to_glib_none().0,
1265                shutdown_read.into_glib(),
1266                shutdown_write.into_glib(),
1267                &mut error,
1268            );
1269            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1270            if error.is_null() {
1271                Ok(())
1272            } else {
1273                Err(from_glib_full(error))
1274            }
1275        }
1276    }
1277
1278    /// Checks if a socket is capable of speaking IPv4.
1279    ///
1280    /// IPv4 sockets are capable of speaking IPv4.  On some operating systems
1281    /// and under some combinations of circumstances IPv6 sockets are also
1282    /// capable of speaking IPv4.  See RFC 3493 section 3.7 for more
1283    /// information.
1284    ///
1285    /// No other types of sockets are currently considered as being capable
1286    /// of speaking IPv4.
1287    ///
1288    /// # Returns
1289    ///
1290    /// [`true`] if this socket can be used with IPv4.
1291    #[doc(alias = "g_socket_speaks_ipv4")]
1292    fn speaks_ipv4(&self) -> bool {
1293        unsafe { from_glib(ffi::g_socket_speaks_ipv4(self.as_ref().to_glib_none().0)) }
1294    }
1295
1296    /// s type.
1297    #[doc(alias = "type")]
1298    fn type_(&self) -> SocketType {
1299        ObjectExt::property(self.as_ref(), "type")
1300    }
1301
1302    #[doc(alias = "blocking")]
1303    fn connect_blocking_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1304        unsafe extern "C" fn notify_blocking_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
1305            this: *mut ffi::GSocket,
1306            _param_spec: glib::ffi::gpointer,
1307            f: glib::ffi::gpointer,
1308        ) {
1309            unsafe {
1310                let f: &F = &*(f as *const F);
1311                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1312            }
1313        }
1314        unsafe {
1315            let f: Box_<F> = Box_::new(f);
1316            connect_raw(
1317                self.as_ptr() as *mut _,
1318                c"notify::blocking".as_ptr(),
1319                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1320                    notify_blocking_trampoline::<Self, F> as *const (),
1321                )),
1322                Box_::into_raw(f),
1323            )
1324        }
1325    }
1326
1327    #[doc(alias = "broadcast")]
1328    fn connect_broadcast_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1329        unsafe extern "C" fn notify_broadcast_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
1330            this: *mut ffi::GSocket,
1331            _param_spec: glib::ffi::gpointer,
1332            f: glib::ffi::gpointer,
1333        ) {
1334            unsafe {
1335                let f: &F = &*(f as *const F);
1336                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1337            }
1338        }
1339        unsafe {
1340            let f: Box_<F> = Box_::new(f);
1341            connect_raw(
1342                self.as_ptr() as *mut _,
1343                c"notify::broadcast".as_ptr(),
1344                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1345                    notify_broadcast_trampoline::<Self, F> as *const (),
1346                )),
1347                Box_::into_raw(f),
1348            )
1349        }
1350    }
1351
1352    #[doc(alias = "keepalive")]
1353    fn connect_keepalive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1354        unsafe extern "C" fn notify_keepalive_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
1355            this: *mut ffi::GSocket,
1356            _param_spec: glib::ffi::gpointer,
1357            f: glib::ffi::gpointer,
1358        ) {
1359            unsafe {
1360                let f: &F = &*(f as *const F);
1361                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1362            }
1363        }
1364        unsafe {
1365            let f: Box_<F> = Box_::new(f);
1366            connect_raw(
1367                self.as_ptr() as *mut _,
1368                c"notify::keepalive".as_ptr(),
1369                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1370                    notify_keepalive_trampoline::<Self, F> as *const (),
1371                )),
1372                Box_::into_raw(f),
1373            )
1374        }
1375    }
1376
1377    #[doc(alias = "listen-backlog")]
1378    fn connect_listen_backlog_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1379        unsafe extern "C" fn notify_listen_backlog_trampoline<
1380            P: IsA<Socket>,
1381            F: Fn(&P) + 'static,
1382        >(
1383            this: *mut ffi::GSocket,
1384            _param_spec: glib::ffi::gpointer,
1385            f: glib::ffi::gpointer,
1386        ) {
1387            unsafe {
1388                let f: &F = &*(f as *const F);
1389                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1390            }
1391        }
1392        unsafe {
1393            let f: Box_<F> = Box_::new(f);
1394            connect_raw(
1395                self.as_ptr() as *mut _,
1396                c"notify::listen-backlog".as_ptr(),
1397                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1398                    notify_listen_backlog_trampoline::<Self, F> as *const (),
1399                )),
1400                Box_::into_raw(f),
1401            )
1402        }
1403    }
1404
1405    #[doc(alias = "local-address")]
1406    fn connect_local_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1407        unsafe extern "C" fn notify_local_address_trampoline<
1408            P: IsA<Socket>,
1409            F: Fn(&P) + 'static,
1410        >(
1411            this: *mut ffi::GSocket,
1412            _param_spec: glib::ffi::gpointer,
1413            f: glib::ffi::gpointer,
1414        ) {
1415            unsafe {
1416                let f: &F = &*(f as *const F);
1417                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1418            }
1419        }
1420        unsafe {
1421            let f: Box_<F> = Box_::new(f);
1422            connect_raw(
1423                self.as_ptr() as *mut _,
1424                c"notify::local-address".as_ptr(),
1425                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1426                    notify_local_address_trampoline::<Self, F> as *const (),
1427                )),
1428                Box_::into_raw(f),
1429            )
1430        }
1431    }
1432
1433    #[doc(alias = "multicast-loopback")]
1434    fn connect_multicast_loopback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1435        unsafe extern "C" fn notify_multicast_loopback_trampoline<
1436            P: IsA<Socket>,
1437            F: Fn(&P) + 'static,
1438        >(
1439            this: *mut ffi::GSocket,
1440            _param_spec: glib::ffi::gpointer,
1441            f: glib::ffi::gpointer,
1442        ) {
1443            unsafe {
1444                let f: &F = &*(f as *const F);
1445                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1446            }
1447        }
1448        unsafe {
1449            let f: Box_<F> = Box_::new(f);
1450            connect_raw(
1451                self.as_ptr() as *mut _,
1452                c"notify::multicast-loopback".as_ptr(),
1453                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1454                    notify_multicast_loopback_trampoline::<Self, F> as *const (),
1455                )),
1456                Box_::into_raw(f),
1457            )
1458        }
1459    }
1460
1461    #[doc(alias = "multicast-ttl")]
1462    fn connect_multicast_ttl_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1463        unsafe extern "C" fn notify_multicast_ttl_trampoline<
1464            P: IsA<Socket>,
1465            F: Fn(&P) + 'static,
1466        >(
1467            this: *mut ffi::GSocket,
1468            _param_spec: glib::ffi::gpointer,
1469            f: glib::ffi::gpointer,
1470        ) {
1471            unsafe {
1472                let f: &F = &*(f as *const F);
1473                f(Socket::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::multicast-ttl".as_ptr(),
1481                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1482                    notify_multicast_ttl_trampoline::<Self, F> as *const (),
1483                )),
1484                Box_::into_raw(f),
1485            )
1486        }
1487    }
1488
1489    #[doc(alias = "remote-address")]
1490    fn connect_remote_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1491        unsafe extern "C" fn notify_remote_address_trampoline<
1492            P: IsA<Socket>,
1493            F: Fn(&P) + 'static,
1494        >(
1495            this: *mut ffi::GSocket,
1496            _param_spec: glib::ffi::gpointer,
1497            f: glib::ffi::gpointer,
1498        ) {
1499            unsafe {
1500                let f: &F = &*(f as *const F);
1501                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1502            }
1503        }
1504        unsafe {
1505            let f: Box_<F> = Box_::new(f);
1506            connect_raw(
1507                self.as_ptr() as *mut _,
1508                c"notify::remote-address".as_ptr(),
1509                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1510                    notify_remote_address_trampoline::<Self, F> as *const (),
1511                )),
1512                Box_::into_raw(f),
1513            )
1514        }
1515    }
1516
1517    #[doc(alias = "timeout")]
1518    fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1519        unsafe extern "C" fn notify_timeout_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
1520            this: *mut ffi::GSocket,
1521            _param_spec: glib::ffi::gpointer,
1522            f: glib::ffi::gpointer,
1523        ) {
1524            unsafe {
1525                let f: &F = &*(f as *const F);
1526                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1527            }
1528        }
1529        unsafe {
1530            let f: Box_<F> = Box_::new(f);
1531            connect_raw(
1532                self.as_ptr() as *mut _,
1533                c"notify::timeout".as_ptr(),
1534                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1535                    notify_timeout_trampoline::<Self, F> as *const (),
1536                )),
1537                Box_::into_raw(f),
1538            )
1539        }
1540    }
1541
1542    #[doc(alias = "ttl")]
1543    fn connect_ttl_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1544        unsafe extern "C" fn notify_ttl_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
1545            this: *mut ffi::GSocket,
1546            _param_spec: glib::ffi::gpointer,
1547            f: glib::ffi::gpointer,
1548        ) {
1549            unsafe {
1550                let f: &F = &*(f as *const F);
1551                f(Socket::from_glib_borrow(this).unsafe_cast_ref())
1552            }
1553        }
1554        unsafe {
1555            let f: Box_<F> = Box_::new(f);
1556            connect_raw(
1557                self.as_ptr() as *mut _,
1558                c"notify::ttl".as_ptr(),
1559                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1560                    notify_ttl_trampoline::<Self, F> as *const (),
1561                )),
1562                Box_::into_raw(f),
1563            )
1564        }
1565    }
1566}
1567
1568impl<O: IsA<Socket>> SocketExt for O {}