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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// 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 glib::{prelude::*, translate::*};

glib::wrapper! {
    /// Interface for socket-like objects with datagram semantics.
    ///
    /// A `GDatagramBased` is a networking interface for representing datagram-based
    /// communications. It is a more or less direct mapping of the core parts of the
    /// BSD socket API in a portable GObject interface. It is implemented by
    /// [`Socket`][crate::Socket], which wraps the UNIX socket API on UNIX and winsock2 on Windows.
    ///
    /// `GDatagramBased` is entirely platform independent, and is intended to be used
    /// alongside higher-level networking APIs such as [`IOStream`][crate::IOStream].
    ///
    /// It uses vectored scatter/gather I/O by default, allowing for many messages
    /// to be sent or received in a single call. Where possible, implementations of
    /// the interface should take advantage of vectored I/O to minimise processing
    /// or system calls. For example, `GSocket` uses `recvmmsg()` and `sendmmsg()`
    /// where possible. Callers should take advantage of scatter/gather I/O (the use of
    /// multiple buffers per message) to avoid unnecessary copying of data to
    /// assemble or disassemble a message.
    ///
    /// Each `GDatagramBased` operation has a timeout parameter which may be negative
    /// for blocking behaviour, zero for non-blocking behaviour, or positive for
    /// timeout behaviour. A blocking operation blocks until finished or there is an
    /// error. A non-blocking operation will return immediately with a
    /// `G_IO_ERROR_WOULD_BLOCK` error if it cannot make progress. A timeout operation
    /// will block until the operation is complete or the timeout expires; if the
    /// timeout expires it will return what progress it made, or
    /// `G_IO_ERROR_TIMED_OUT` if no progress was made. To know when a call would
    /// successfully run you can call [`DatagramBasedExt::condition_check()`][crate::prelude::DatagramBasedExt::condition_check()] or
    /// [`DatagramBasedExtManual::condition_wait()`][crate::prelude::DatagramBasedExtManual::condition_wait()]. You can also use
    /// [`DatagramBasedExtManual::create_source()`][crate::prelude::DatagramBasedExtManual::create_source()] and attach it to a [`glib::MainContext`][crate::glib::MainContext]
    /// to get callbacks when I/O is possible.
    ///
    /// When running a non-blocking operation applications should always be able to
    /// handle getting a `G_IO_ERROR_WOULD_BLOCK` error even when some other function
    /// said that I/O was possible. This can easily happen in case of a race
    /// condition in the application, but it can also happen for other reasons. For
    /// instance, on Windows a socket is always seen as writable until a write
    /// returns `G_IO_ERROR_WOULD_BLOCK`.
    ///
    /// As with `GSocket`, `GDatagramBased`s can be either connection oriented (for
    /// example, SCTP) or connectionless (for example, UDP). `GDatagramBased`s must be
    /// datagram-based, not stream-based. The interface does not cover connection
    /// establishment — use methods on the underlying type to establish a connection
    /// before sending and receiving data through the `GDatagramBased` API. For
    /// connectionless socket types the target/source address is specified or
    /// received in each I/O operation.
    ///
    /// Like most other APIs in GLib, `GDatagramBased` is not inherently thread safe.
    /// To use a `GDatagramBased` concurrently from multiple threads, you must
    /// implement your own locking.
    ///
    /// # Implements
    ///
    /// [`DatagramBasedExt`][trait@crate::prelude::DatagramBasedExt], [`DatagramBasedExtManual`][trait@crate::prelude::DatagramBasedExtManual]
    #[doc(alias = "GDatagramBased")]
    pub struct DatagramBased(Interface<ffi::GDatagramBased, ffi::GDatagramBasedInterface>);

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

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

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

/// Trait containing all [`struct@DatagramBased`] methods.
///
/// # Implementors
///
/// [`DatagramBased`][struct@crate::DatagramBased], [`Socket`][struct@crate::Socket]
pub trait DatagramBasedExt: IsA<DatagramBased> + sealed::Sealed + 'static {
    /// Checks on the readiness of @self to perform operations. The
    /// operations specified in @condition are checked for and masked against the
    /// currently-satisfied conditions on @self. The result is returned.
    ///
    /// [`glib::IOCondition::IN`][crate::glib::IOCondition::IN] will be set in the return value if data is available to read with
    /// g_datagram_based_receive_messages(), or if the connection is closed remotely
    /// (EOS); and if the datagram_based has not been closed locally using some
    /// implementation-specific method (such as g_socket_close() or
    /// g_socket_shutdown() with @shutdown_read set, if it’s a #GSocket).
    ///
    /// If the connection is shut down or closed (by calling g_socket_close() or
    /// g_socket_shutdown() with @shutdown_read set, if it’s a #GSocket, for
    /// example), all calls to this function will return [`IOErrorEnum::Closed`][crate::IOErrorEnum::Closed].
    ///
    /// [`glib::IOCondition::OUT`][crate::glib::IOCondition::OUT] will be set if it is expected that at least one byte can be sent
    /// using g_datagram_based_send_messages() without blocking. It will not be set
    /// if the datagram_based has been closed locally.
    ///
    /// [`glib::IOCondition::HUP`][crate::glib::IOCondition::HUP] will be set if the connection has been closed locally.
    ///
    /// [`glib::IOCondition::ERR`][crate::glib::IOCondition::ERR] will be set if there was an asynchronous error in transmitting data
    /// previously enqueued using g_datagram_based_send_messages().
    ///
    /// Note that on Windows, it is possible for an operation to return
    /// [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock] even immediately after
    /// g_datagram_based_condition_check() has claimed that the #GDatagramBased is
    /// ready for writing. Rather than calling g_datagram_based_condition_check() and
    /// then writing to the #GDatagramBased if it succeeds, it is generally better to
    /// simply try writing right away, and try again later if the initial attempt
    /// returns [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock].
    ///
    /// It is meaningless to specify [`glib::IOCondition::ERR`][crate::glib::IOCondition::ERR] or [`glib::IOCondition::HUP`][crate::glib::IOCondition::HUP] in @condition; these
    /// conditions will always be set in the output if they are true. Apart from
    /// these flags, the output is guaranteed to be masked by @condition.
    ///
    /// This call never blocks.
    /// ## `condition`
    /// a #GIOCondition mask to check
    ///
    /// # Returns
    ///
    /// the #GIOCondition mask of the current state
    #[doc(alias = "g_datagram_based_condition_check")]
    fn condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition {
        unsafe {
            from_glib(ffi::g_datagram_based_condition_check(
                self.as_ref().to_glib_none().0,
                condition.into_glib(),
            ))
        }
    }
}

impl<O: IsA<DatagramBased>> DatagramBasedExt for O {}