gio/auto/
socket_control_message.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::ffi;
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// A `GSocketControlMessage` is a special-purpose utility message that
    /// can be sent to or received from a [`Socket`][crate::Socket]. These types of
    /// messages are often called ‘ancillary data’.
    ///
    /// The message can represent some sort of special instruction to or
    /// information from the socket or can represent a special kind of
    /// transfer to the peer (for example, sending a file descriptor over
    /// a UNIX socket).
    ///
    /// These messages are sent with [`SocketExtManual::send_message()`][crate::prelude::SocketExtManual::send_message()] and received
    /// with [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()].
    ///
    /// To extend the set of control message that can be sent, subclass this
    /// class and override the `get_size`, `get_level`, `get_type` and `serialize`
    /// methods.
    ///
    /// To extend the set of control messages that can be received, subclass
    /// this class and implement the `deserialize` method. Also, make sure your
    /// class is registered with the [type@GObject.Type] type system before calling
    /// [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()] to read such a message.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`SocketControlMessageExt`][trait@crate::prelude::SocketControlMessageExt], [`trait@glib::ObjectExt`], [`SocketControlMessageExtManual`][trait@crate::prelude::SocketControlMessageExtManual]
    #[doc(alias = "GSocketControlMessage")]
    pub struct SocketControlMessage(Object<ffi::GSocketControlMessage, ffi::GSocketControlMessageClass>);

    match fn {
        type_ => || ffi::g_socket_control_message_get_type(),
    }
}

impl SocketControlMessage {
    pub const NONE: Option<&'static SocketControlMessage> = None;

    /// Tries to deserialize a socket control message of a given
    /// @level and @type_. This will ask all known (to GType) subclasses
    /// of #GSocketControlMessage if they can understand this kind
    /// of message and if so deserialize it into a #GSocketControlMessage.
    ///
    /// If there is no implementation for this kind of control message, [`None`]
    /// will be returned.
    /// ## `level`
    /// a socket level
    /// ## `type_`
    /// a socket control message type for the given @level
    ///
    /// # Returns
    ///
    /// the deserialized message or [`None`]
    #[doc(alias = "g_socket_control_message_deserialize")]
    pub fn deserialize(level: i32, type_: i32, data: &[u8]) -> Option<SocketControlMessage> {
        let size = data.len() as _;
        unsafe {
            from_glib_full(ffi::g_socket_control_message_deserialize(
                level,
                type_,
                size,
                data.to_glib_none().0 as glib::ffi::gpointer,
            ))
        }
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::SocketControlMessage>> Sealed for T {}
}

/// Trait containing all [`struct@SocketControlMessage`] methods.
///
/// # Implementors
///
/// [`SocketControlMessage`][struct@crate::SocketControlMessage], [`UnixCredentialsMessage`][struct@crate::UnixCredentialsMessage], [`UnixFDMessage`][struct@crate::UnixFDMessage]
pub trait SocketControlMessageExt: IsA<SocketControlMessage> + sealed::Sealed + 'static {
    /// Returns the "level" (i.e. the originating protocol) of the control message.
    /// This is often SOL_SOCKET.
    ///
    /// # Returns
    ///
    /// an integer describing the level
    #[doc(alias = "g_socket_control_message_get_level")]
    #[doc(alias = "get_level")]
    fn level(&self) -> i32 {
        unsafe { ffi::g_socket_control_message_get_level(self.as_ref().to_glib_none().0) }
    }

    /// Returns the protocol specific type of the control message.
    /// For instance, for UNIX fd passing this would be SCM_RIGHTS.
    ///
    /// # Returns
    ///
    /// an integer describing the type of control message
    #[doc(alias = "g_socket_control_message_get_msg_type")]
    #[doc(alias = "get_msg_type")]
    fn msg_type(&self) -> i32 {
        unsafe { ffi::g_socket_control_message_get_msg_type(self.as_ref().to_glib_none().0) }
    }

    /// Returns the space required for the control message, not including
    /// headers or alignment.
    ///
    /// # Returns
    ///
    /// The number of bytes required.
    #[doc(alias = "g_socket_control_message_get_size")]
    #[doc(alias = "get_size")]
    fn size(&self) -> usize {
        unsafe { ffi::g_socket_control_message_get_size(self.as_ref().to_glib_none().0) }
    }
}

impl<O: IsA<SocketControlMessage>> SocketControlMessageExt for O {}