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
75/// Trait containing all [`struct@SocketControlMessage`] methods.
76///
77/// # Implementors
78///
79/// [`SocketControlMessage`][struct@crate::SocketControlMessage], [`UnixCredentialsMessage`][struct@crate::UnixCredentialsMessage], [`UnixFDMessage`][struct@crate::UnixFDMessage]
80pub trait SocketControlMessageExt: IsA<SocketControlMessage> + 'static {
81 /// Returns the "level" (i.e. the originating protocol) of the control message.
82 /// This is often SOL_SOCKET.
83 ///
84 /// # Returns
85 ///
86 /// an integer describing the level
87 #[doc(alias = "g_socket_control_message_get_level")]
88 #[doc(alias = "get_level")]
89 fn level(&self) -> i32 {
90 unsafe { ffi::g_socket_control_message_get_level(self.as_ref().to_glib_none().0) }
91 }
92
93 /// Returns the protocol specific type of the control message.
94 /// For instance, for UNIX fd passing this would be SCM_RIGHTS.
95 ///
96 /// # Returns
97 ///
98 /// an integer describing the type of control message
99 #[doc(alias = "g_socket_control_message_get_msg_type")]
100 #[doc(alias = "get_msg_type")]
101 fn msg_type(&self) -> i32 {
102 unsafe { ffi::g_socket_control_message_get_msg_type(self.as_ref().to_glib_none().0) }
103 }
104
105 /// Returns the space required for the control message, not including
106 /// headers or alignment.
107 ///
108 /// # Returns
109 ///
110 /// The number of bytes required.
111 #[doc(alias = "g_socket_control_message_get_size")]
112 #[doc(alias = "get_size")]
113 fn size(&self) -> usize {
114 unsafe { ffi::g_socket_control_message_get_size(self.as_ref().to_glib_none().0) }
115 }
116}
117
118impl<O: IsA<SocketControlMessage>> SocketControlMessageExt for O {}