Skip to content

Commit b9d2746

Browse files
committed
gio: support sending/receiving socket control messages
1 parent aa75187 commit b9d2746

12 files changed

+1125
-2
lines changed

gio/Gir.toml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ generate = [
9191
"Gio.OutputStreamSpliceFlags",
9292
"Gio.PasswordSave",
9393
"Gio.Permission",
94+
"Gio.PollableReturn",
9495
"Gio.PropertyAction",
9596
"Gio.Proxy",
9697
"Gio.ProxyResolver",
@@ -151,8 +152,10 @@ ignore = [
151152
manual = [
152153
"Gio.ActionEntry",
153154
"Gio.FileAttributeInfo",
155+
"Gio.InputMessage",
154156
"Gio.IOExtension",
155157
"Gio.IOExtensionPoint",
158+
"Gio.OutputMessage",
156159
"Gio.Task",
157160
"GLib.ByteArray",
158161
"GLib.Bytes",
@@ -497,7 +500,6 @@ generate_builder = true
497500
#finish functions not needed
498501
manual = true
499502

500-
501503
[[object]]
502504
name = "Gio.DataOutputStream"
503505
status = "generate"
@@ -1187,6 +1189,22 @@ status = "generate"
11871189
[object.function.return]
11881190
nullable = true
11891191

1192+
[[object]]
1193+
name = "Gio.SocketControlMessage"
1194+
status = "generate"
1195+
manual_traits = ["SocketControlMessageExtManual"]
1196+
[[object.function]]
1197+
name = "deserialize"
1198+
# NULL indicates deserialization failure
1199+
# Glib MR: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3099
1200+
[object.function.return]
1201+
nullable = true
1202+
[[object.function]]
1203+
name = "serialize"
1204+
# writes to a void pointer
1205+
manual = true
1206+
doc_trait_name = "SocketControlMessageExtManual"
1207+
11901208
[[object]]
11911209
name = "Gio.Subprocess"
11921210
status = "generate"
@@ -1317,6 +1335,11 @@ status = "generate"
13171335
name = "set_value"
13181336
ignore = true
13191337

1338+
[[object]]
1339+
name = "Gio.UnixCredentialsMessage"
1340+
status = "generate"
1341+
cfg_condition = "unix"
1342+
13201343
[[object]]
13211344
name = "Gio.UnixFDList"
13221345
status = "generate"
@@ -1351,6 +1374,22 @@ manual_traits = ["UnixFDListExtManual"]
13511374
manual = true
13521375
doc_trait_name = "UnixFDListExtManual"
13531376

1377+
[[object]]
1378+
name = "Gio.UnixFDMessage"
1379+
status = "generate"
1380+
cfg_condition = "unix"
1381+
manual_traits = ["UnixFDMessageExtManual"]
1382+
[[object.function]]
1383+
name = "append_fd"
1384+
# has to use RawFd
1385+
manual = true
1386+
doc_trait_name = "UnixFDMessageExtManual"
1387+
[[object.function]]
1388+
name = "steal_fds"
1389+
# has to use RawFd
1390+
manual = true
1391+
doc_trait_name = "UnixFDMessageExtManual"
1392+
13541393
[[object]]
13551394
name = "Gio.UnixInputStream"
13561395
status = "generate"

gio/src/auto/enums.rs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,118 @@ impl From<PasswordSave> for glib::Value {
24092409
}
24102410
}
24112411

2412+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2413+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2414+
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
2415+
#[non_exhaustive]
2416+
#[doc(alias = "GPollableReturn")]
2417+
pub enum PollableReturn {
2418+
#[doc(alias = "G_POLLABLE_RETURN_FAILED")]
2419+
Failed,
2420+
#[doc(alias = "G_POLLABLE_RETURN_OK")]
2421+
Ok,
2422+
#[doc(alias = "G_POLLABLE_RETURN_WOULD_BLOCK")]
2423+
WouldBlock,
2424+
#[doc(hidden)]
2425+
__Unknown(i32),
2426+
}
2427+
2428+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2429+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2430+
impl fmt::Display for PollableReturn {
2431+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2432+
write!(
2433+
f,
2434+
"PollableReturn::{}",
2435+
match *self {
2436+
Self::Failed => "Failed",
2437+
Self::Ok => "Ok",
2438+
Self::WouldBlock => "WouldBlock",
2439+
_ => "Unknown",
2440+
}
2441+
)
2442+
}
2443+
}
2444+
2445+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2446+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2447+
#[doc(hidden)]
2448+
impl IntoGlib for PollableReturn {
2449+
type GlibType = ffi::GPollableReturn;
2450+
2451+
fn into_glib(self) -> ffi::GPollableReturn {
2452+
match self {
2453+
Self::Failed => ffi::G_POLLABLE_RETURN_FAILED,
2454+
Self::Ok => ffi::G_POLLABLE_RETURN_OK,
2455+
Self::WouldBlock => ffi::G_POLLABLE_RETURN_WOULD_BLOCK,
2456+
Self::__Unknown(value) => value,
2457+
}
2458+
}
2459+
}
2460+
2461+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2462+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2463+
#[doc(hidden)]
2464+
impl FromGlib<ffi::GPollableReturn> for PollableReturn {
2465+
unsafe fn from_glib(value: ffi::GPollableReturn) -> Self {
2466+
match value {
2467+
ffi::G_POLLABLE_RETURN_FAILED => Self::Failed,
2468+
ffi::G_POLLABLE_RETURN_OK => Self::Ok,
2469+
ffi::G_POLLABLE_RETURN_WOULD_BLOCK => Self::WouldBlock,
2470+
value => Self::__Unknown(value),
2471+
}
2472+
}
2473+
}
2474+
2475+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2476+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2477+
impl StaticType for PollableReturn {
2478+
fn static_type() -> Type {
2479+
unsafe { from_glib(ffi::g_pollable_return_get_type()) }
2480+
}
2481+
}
2482+
2483+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2484+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2485+
impl glib::value::ValueType for PollableReturn {
2486+
type Type = Self;
2487+
}
2488+
2489+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2490+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2491+
unsafe impl<'a> FromValue<'a> for PollableReturn {
2492+
type Checker = glib::value::GenericValueTypeChecker<Self>;
2493+
2494+
unsafe fn from_value(value: &'a glib::Value) -> Self {
2495+
from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
2496+
}
2497+
}
2498+
2499+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2500+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2501+
impl ToValue for PollableReturn {
2502+
fn to_value(&self) -> glib::Value {
2503+
let mut value = glib::Value::for_value_type::<Self>();
2504+
unsafe {
2505+
glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
2506+
}
2507+
value
2508+
}
2509+
2510+
fn value_type(&self) -> glib::Type {
2511+
Self::static_type()
2512+
}
2513+
}
2514+
2515+
#[cfg(any(feature = "v2_60", feature = "dox"))]
2516+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
2517+
impl From<PollableReturn> for glib::Value {
2518+
#[inline]
2519+
fn from(v: PollableReturn) -> Self {
2520+
ToValue::to_value(&v)
2521+
}
2522+
}
2523+
24122524
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
24132525
#[non_exhaustive]
24142526
#[doc(alias = "GResolverError")]

gio/src/auto/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ pub use self::socket_connectable::SocketConnectable;
316316
mod socket_connection;
317317
pub use self::socket_connection::SocketConnection;
318318

319+
mod socket_control_message;
320+
pub use self::socket_control_message::SocketControlMessage;
321+
319322
mod socket_listener;
320323
pub use self::socket_listener::SocketListener;
321324

@@ -364,13 +367,26 @@ pub use self::tls_password::TlsPassword;
364367
mod tls_server_connection;
365368
pub use self::tls_server_connection::TlsServerConnection;
366369

370+
#[cfg(any(unix, feature = "dox"))]
371+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
372+
mod unix_credentials_message;
373+
#[cfg(any(unix, feature = "dox"))]
374+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
375+
pub use self::unix_credentials_message::UnixCredentialsMessage;
376+
367377
#[cfg(any(unix, feature = "dox"))]
368378
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
369379
mod unix_fd_list;
370380
#[cfg(any(unix, feature = "dox"))]
371381
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
372382
pub use self::unix_fd_list::UnixFDList;
373383

384+
#[cfg(any(unix, feature = "dox"))]
385+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
386+
mod unix_fd_message;
387+
#[cfg(any(unix, feature = "dox"))]
388+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
389+
pub use self::unix_fd_message::UnixFDMessage;
374390
#[cfg(any(unix, feature = "dox"))]
375391
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
376392
mod unix_input_stream;
@@ -483,6 +499,9 @@ pub use self::enums::MountOperationResult;
483499
pub use self::enums::NetworkConnectivity;
484500
pub use self::enums::NotificationPriority;
485501
pub use self::enums::PasswordSave;
502+
#[cfg(any(feature = "v2_60", feature = "dox"))]
503+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
504+
pub use self::enums::PollableReturn;
486505
pub use self::enums::ResolverError;
487506
pub use self::enums::ResolverRecordType;
488507
pub use self::enums::ResourceError;
@@ -768,6 +787,7 @@ pub mod traits {
768787
pub use super::socket_client::SocketClientExt;
769788
pub use super::socket_connectable::SocketConnectableExt;
770789
pub use super::socket_connection::SocketConnectionExt;
790+
pub use super::socket_control_message::SocketControlMessageExt;
771791
pub use super::socket_listener::SocketListenerExt;
772792
pub use super::socket_service::SocketServiceExt;
773793
pub use super::tcp_connection::TcpConnectionExt;
@@ -783,9 +803,15 @@ pub mod traits {
783803
pub use super::tls_server_connection::TlsServerConnectionExt;
784804
#[cfg(any(unix, feature = "dox"))]
785805
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
806+
pub use super::unix_credentials_message::UnixCredentialsMessageExt;
807+
#[cfg(any(unix, feature = "dox"))]
808+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
786809
pub use super::unix_fd_list::UnixFDListExt;
787810
#[cfg(any(unix, feature = "dox"))]
788811
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
812+
pub use super::unix_fd_message::UnixFDMessageExt;
813+
#[cfg(any(unix, feature = "dox"))]
814+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
789815
pub use super::unix_input_stream::UnixInputStreamExt;
790816
#[cfg(any(unix, feature = "dox"))]
791817
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
5+
use glib::object::IsA;
6+
use glib::translate::*;
7+
use std::fmt;
8+
9+
glib::wrapper! {
10+
#[doc(alias = "GSocketControlMessage")]
11+
pub struct SocketControlMessage(Object<ffi::GSocketControlMessage, ffi::GSocketControlMessageClass>);
12+
13+
match fn {
14+
type_ => || ffi::g_socket_control_message_get_type(),
15+
}
16+
}
17+
18+
impl SocketControlMessage {
19+
pub const NONE: Option<&'static SocketControlMessage> = None;
20+
21+
#[doc(alias = "g_socket_control_message_deserialize")]
22+
pub fn deserialize(level: i32, type_: i32, data: &[u8]) -> Option<SocketControlMessage> {
23+
let size = data.len() as _;
24+
unsafe {
25+
from_glib_full(ffi::g_socket_control_message_deserialize(
26+
level,
27+
type_,
28+
size,
29+
data.to_glib_none().0 as glib::ffi::gpointer,
30+
))
31+
}
32+
}
33+
}
34+
35+
pub trait SocketControlMessageExt: 'static {
36+
#[doc(alias = "g_socket_control_message_get_level")]
37+
#[doc(alias = "get_level")]
38+
fn level(&self) -> i32;
39+
40+
#[doc(alias = "g_socket_control_message_get_msg_type")]
41+
#[doc(alias = "get_msg_type")]
42+
fn msg_type(&self) -> i32;
43+
44+
#[doc(alias = "g_socket_control_message_get_size")]
45+
#[doc(alias = "get_size")]
46+
fn size(&self) -> usize;
47+
}
48+
49+
impl<O: IsA<SocketControlMessage>> SocketControlMessageExt for O {
50+
fn level(&self) -> i32 {
51+
unsafe { ffi::g_socket_control_message_get_level(self.as_ref().to_glib_none().0) }
52+
}
53+
54+
fn msg_type(&self) -> i32 {
55+
unsafe { ffi::g_socket_control_message_get_msg_type(self.as_ref().to_glib_none().0) }
56+
}
57+
58+
fn size(&self) -> usize {
59+
unsafe { ffi::g_socket_control_message_get_size(self.as_ref().to_glib_none().0) }
60+
}
61+
}
62+
63+
impl fmt::Display for SocketControlMessage {
64+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65+
f.write_str("SocketControlMessage")
66+
}
67+
}

0 commit comments

Comments
 (0)