gio/auto/
socket_control_message.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// A `GSocketControlMessage` is a special-purpose utility message that
10    /// can be sent to or received from a [`Socket`][crate::Socket]. These types of
11    /// messages are often called ‘ancillary data’.
12    ///
13    /// The message can represent some sort of special instruction to or
14    /// information from the socket or can represent a special kind of
15    /// transfer to the peer (for example, sending a file descriptor over
16    /// a UNIX socket).
17    ///
18    /// These messages are sent with [`SocketExtManual::send_message()`][crate::prelude::SocketExtManual::send_message()] and received
19    /// with [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()].
20    ///
21    /// To extend the set of control message that can be sent, subclass this
22    /// class and override the `get_size`, `get_level`, `get_type` and `serialize`
23    /// methods.
24    ///
25    /// To extend the set of control messages that can be received, subclass
26    /// this class and implement the `deserialize` method. Also, make sure your
27    /// class is registered with the [type@GObject.Type] type system before calling
28    /// [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()] to read such a message.
29    ///
30    /// This is an Abstract Base Class, you cannot instantiate it.
31    ///
32    /// # Implements
33    ///
34    /// [`SocketControlMessageExt`][trait@crate::prelude::SocketControlMessageExt], [`trait@glib::ObjectExt`], [`SocketControlMessageExtManual`][trait@crate::prelude::SocketControlMessageExtManual]
35    #[doc(alias = "GSocketControlMessage")]
36    pub struct SocketControlMessage(Object<ffi::GSocketControlMessage, ffi::GSocketControlMessageClass>);
37
38    match fn {
39        type_ => || ffi::g_socket_control_message_get_type(),
40    }
41}
42
43impl SocketControlMessage {
44    pub const NONE: Option<&'static SocketControlMessage> = None;
45
46    /// Tries to deserialize a socket control message of a given
47    /// @level and @type_. This will ask all known (to GType) subclasses
48    /// of #GSocketControlMessage if they can understand this kind
49    /// of message and if so deserialize it into a #GSocketControlMessage.
50    ///
51    /// If there is no implementation for this kind of control message, [`None`]
52    /// will be returned.
53    /// ## `level`
54    /// a socket level
55    /// ## `type_`
56    /// a socket control message type for the given @level
57    ///
58    /// # Returns
59    ///
60    /// the deserialized message or [`None`]
61    #[doc(alias = "g_socket_control_message_deserialize")]
62    pub fn deserialize(level: i32, type_: i32, data: &[u8]) -> Option<SocketControlMessage> {
63        let size = data.len() as _;
64        unsafe {
65            from_glib_full(ffi::g_socket_control_message_deserialize(
66                level,
67                type_,
68                size,
69                data.to_glib_none().0 as glib::ffi::gpointer,
70            ))
71        }
72    }
73}
74
75mod sealed {
76    pub trait Sealed {}
77    impl<T: super::IsA<super::SocketControlMessage>> Sealed for T {}
78}
79
80/// Trait containing all [`struct@SocketControlMessage`] methods.
81///
82/// # Implementors
83///
84/// [`SocketControlMessage`][struct@crate::SocketControlMessage], [`UnixCredentialsMessage`][struct@crate::UnixCredentialsMessage], [`UnixFDMessage`][struct@crate::UnixFDMessage]
85pub trait SocketControlMessageExt: IsA<SocketControlMessage> + sealed::Sealed + 'static {
86    /// Returns the "level" (i.e. the originating protocol) of the control message.
87    /// This is often SOL_SOCKET.
88    ///
89    /// # Returns
90    ///
91    /// an integer describing the level
92    #[doc(alias = "g_socket_control_message_get_level")]
93    #[doc(alias = "get_level")]
94    fn level(&self) -> i32 {
95        unsafe { ffi::g_socket_control_message_get_level(self.as_ref().to_glib_none().0) }
96    }
97
98    /// Returns the protocol specific type of the control message.
99    /// For instance, for UNIX fd passing this would be SCM_RIGHTS.
100    ///
101    /// # Returns
102    ///
103    /// an integer describing the type of control message
104    #[doc(alias = "g_socket_control_message_get_msg_type")]
105    #[doc(alias = "get_msg_type")]
106    fn msg_type(&self) -> i32 {
107        unsafe { ffi::g_socket_control_message_get_msg_type(self.as_ref().to_glib_none().0) }
108    }
109
110    /// Returns the space required for the control message, not including
111    /// headers or alignment.
112    ///
113    /// # Returns
114    ///
115    /// The number of bytes required.
116    #[doc(alias = "g_socket_control_message_get_size")]
117    #[doc(alias = "get_size")]
118    fn size(&self) -> usize {
119        unsafe { ffi::g_socket_control_message_get_size(self.as_ref().to_glib_none().0) }
120    }
121}
122
123impl<O: IsA<SocketControlMessage>> SocketControlMessageExt for O {}