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 gio_sys;
6 use glib;
7 use glib::object::Cast;
8 use glib::object::IsA;
9 use glib::signal::connect_raw;
10 use glib::signal::SignalHandlerId;
11 use glib::translate::*;
12 use glib::ObjectExt;
13 use glib::StaticType;
14 use glib::Value;
15 use glib_sys;
16 use gobject_sys;
17 use std::boxed::Box as Box_;
18 use std::fmt;
19 use std::mem;
20 use std::mem::transmute;
21 use std::ptr;
22 use Cancellable;
23 use Credentials;
24 use InetAddress;
25 use SocketAddress;
26 use SocketConnection;
27 use SocketFamily;
28 use SocketProtocol;
29 use SocketType;
30 
31 glib_wrapper! {
32     pub struct Socket(Object<gio_sys::GSocket, gio_sys::GSocketClass, SocketClass>);
33 
34     match fn {
35         get_type => || gio_sys::g_socket_get_type(),
36     }
37 }
38 
39 impl Socket {
new( family: SocketFamily, type_: SocketType, protocol: SocketProtocol, ) -> Result<Socket, glib::Error>40     pub fn new(
41         family: SocketFamily,
42         type_: SocketType,
43         protocol: SocketProtocol,
44     ) -> Result<Socket, glib::Error> {
45         unsafe {
46             let mut error = ptr::null_mut();
47             let ret = gio_sys::g_socket_new(
48                 family.to_glib(),
49                 type_.to_glib(),
50                 protocol.to_glib(),
51                 &mut error,
52             );
53             if error.is_null() {
54                 Ok(from_glib_full(ret))
55             } else {
56                 Err(from_glib_full(error))
57             }
58         }
59     }
60 }
61 
62 unsafe impl glib::SendUnique for Socket {
is_unique(&self) -> bool63     fn is_unique(&self) -> bool {
64         self.ref_count() == 1
65     }
66 }
67 
68 pub const NONE_SOCKET: Option<&Socket> = None;
69 
70 pub trait SocketExt: 'static {
accept<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<Socket, glib::Error>71     fn accept<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<Socket, glib::Error>;
72 
bind<P: IsA<SocketAddress>>( &self, address: &P, allow_reuse: bool, ) -> Result<(), glib::Error>73     fn bind<P: IsA<SocketAddress>>(
74         &self,
75         address: &P,
76         allow_reuse: bool,
77     ) -> Result<(), glib::Error>;
78 
check_connect_result(&self) -> Result<(), glib::Error>79     fn check_connect_result(&self) -> Result<(), glib::Error>;
80 
close(&self) -> Result<(), glib::Error>81     fn close(&self) -> Result<(), glib::Error>;
82 
condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition83     fn condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition;
84 
condition_timed_wait<P: IsA<Cancellable>>( &self, condition: glib::IOCondition, timeout_us: i64, cancellable: Option<&P>, ) -> Result<(), glib::Error>85     fn condition_timed_wait<P: IsA<Cancellable>>(
86         &self,
87         condition: glib::IOCondition,
88         timeout_us: i64,
89         cancellable: Option<&P>,
90     ) -> Result<(), glib::Error>;
91 
condition_wait<P: IsA<Cancellable>>( &self, condition: glib::IOCondition, cancellable: Option<&P>, ) -> Result<(), glib::Error>92     fn condition_wait<P: IsA<Cancellable>>(
93         &self,
94         condition: glib::IOCondition,
95         cancellable: Option<&P>,
96     ) -> Result<(), glib::Error>;
97 
connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( &self, address: &P, cancellable: Option<&Q>, ) -> Result<(), glib::Error>98     fn connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>(
99         &self,
100         address: &P,
101         cancellable: Option<&Q>,
102     ) -> Result<(), glib::Error>;
103 
connection_factory_create_connection(&self) -> Option<SocketConnection>104     fn connection_factory_create_connection(&self) -> Option<SocketConnection>;
105 
get_available_bytes(&self) -> isize106     fn get_available_bytes(&self) -> isize;
107 
get_blocking(&self) -> bool108     fn get_blocking(&self) -> bool;
109 
get_broadcast(&self) -> bool110     fn get_broadcast(&self) -> bool;
111 
get_credentials(&self) -> Result<Credentials, glib::Error>112     fn get_credentials(&self) -> Result<Credentials, glib::Error>;
113 
get_family(&self) -> SocketFamily114     fn get_family(&self) -> SocketFamily;
115 
get_keepalive(&self) -> bool116     fn get_keepalive(&self) -> bool;
117 
get_listen_backlog(&self) -> i32118     fn get_listen_backlog(&self) -> i32;
119 
get_local_address(&self) -> Result<SocketAddress, glib::Error>120     fn get_local_address(&self) -> Result<SocketAddress, glib::Error>;
121 
get_multicast_loopback(&self) -> bool122     fn get_multicast_loopback(&self) -> bool;
123 
get_multicast_ttl(&self) -> u32124     fn get_multicast_ttl(&self) -> u32;
125 
get_option(&self, level: i32, optname: i32) -> Result<i32, glib::Error>126     fn get_option(&self, level: i32, optname: i32) -> Result<i32, glib::Error>;
127 
get_protocol(&self) -> SocketProtocol128     fn get_protocol(&self) -> SocketProtocol;
129 
get_remote_address(&self) -> Result<SocketAddress, glib::Error>130     fn get_remote_address(&self) -> Result<SocketAddress, glib::Error>;
131 
get_socket_type(&self) -> SocketType132     fn get_socket_type(&self) -> SocketType;
133 
get_timeout(&self) -> u32134     fn get_timeout(&self) -> u32;
135 
get_ttl(&self) -> u32136     fn get_ttl(&self) -> u32;
137 
is_closed(&self) -> bool138     fn is_closed(&self) -> bool;
139 
is_connected(&self) -> bool140     fn is_connected(&self) -> bool;
141 
join_multicast_group<P: IsA<InetAddress>>( &self, group: &P, source_specific: bool, iface: Option<&str>, ) -> Result<(), glib::Error>142     fn join_multicast_group<P: IsA<InetAddress>>(
143         &self,
144         group: &P,
145         source_specific: bool,
146         iface: Option<&str>,
147     ) -> Result<(), glib::Error>;
148 
149     #[cfg(any(feature = "v2_56", feature = "dox"))]
join_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( &self, group: &P, source_specific: Option<&Q>, iface: Option<&str>, ) -> Result<(), glib::Error>150     fn join_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>(
151         &self,
152         group: &P,
153         source_specific: Option<&Q>,
154         iface: Option<&str>,
155     ) -> Result<(), glib::Error>;
156 
leave_multicast_group<P: IsA<InetAddress>>( &self, group: &P, source_specific: bool, iface: Option<&str>, ) -> Result<(), glib::Error>157     fn leave_multicast_group<P: IsA<InetAddress>>(
158         &self,
159         group: &P,
160         source_specific: bool,
161         iface: Option<&str>,
162     ) -> Result<(), glib::Error>;
163 
164     #[cfg(any(feature = "v2_56", feature = "dox"))]
leave_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( &self, group: &P, source_specific: Option<&Q>, iface: Option<&str>, ) -> Result<(), glib::Error>165     fn leave_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>(
166         &self,
167         group: &P,
168         source_specific: Option<&Q>,
169         iface: Option<&str>,
170     ) -> Result<(), glib::Error>;
171 
listen(&self) -> Result<(), glib::Error>172     fn listen(&self) -> Result<(), glib::Error>;
173 
set_blocking(&self, blocking: bool)174     fn set_blocking(&self, blocking: bool);
175 
set_broadcast(&self, broadcast: bool)176     fn set_broadcast(&self, broadcast: bool);
177 
set_keepalive(&self, keepalive: bool)178     fn set_keepalive(&self, keepalive: bool);
179 
set_listen_backlog(&self, backlog: i32)180     fn set_listen_backlog(&self, backlog: i32);
181 
set_multicast_loopback(&self, loopback: bool)182     fn set_multicast_loopback(&self, loopback: bool);
183 
set_multicast_ttl(&self, ttl: u32)184     fn set_multicast_ttl(&self, ttl: u32);
185 
set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error>186     fn set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error>;
187 
set_timeout(&self, timeout: u32)188     fn set_timeout(&self, timeout: u32);
189 
set_ttl(&self, ttl: u32)190     fn set_ttl(&self, ttl: u32);
191 
shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error>192     fn shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error>;
193 
speaks_ipv4(&self) -> bool194     fn speaks_ipv4(&self) -> bool;
195 
get_property_type(&self) -> SocketType196     fn get_property_type(&self) -> SocketType;
197 
connect_property_blocking_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId198     fn connect_property_blocking_notify<F: Fn(&Self) + Send + 'static>(
199         &self,
200         f: F,
201     ) -> SignalHandlerId;
202 
connect_property_broadcast_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId203     fn connect_property_broadcast_notify<F: Fn(&Self) + Send + 'static>(
204         &self,
205         f: F,
206     ) -> SignalHandlerId;
207 
connect_property_keepalive_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId208     fn connect_property_keepalive_notify<F: Fn(&Self) + Send + 'static>(
209         &self,
210         f: F,
211     ) -> SignalHandlerId;
212 
connect_property_listen_backlog_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId213     fn connect_property_listen_backlog_notify<F: Fn(&Self) + Send + 'static>(
214         &self,
215         f: F,
216     ) -> SignalHandlerId;
217 
connect_property_local_address_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId218     fn connect_property_local_address_notify<F: Fn(&Self) + Send + 'static>(
219         &self,
220         f: F,
221     ) -> SignalHandlerId;
222 
connect_property_multicast_loopback_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId223     fn connect_property_multicast_loopback_notify<F: Fn(&Self) + Send + 'static>(
224         &self,
225         f: F,
226     ) -> SignalHandlerId;
227 
connect_property_multicast_ttl_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId228     fn connect_property_multicast_ttl_notify<F: Fn(&Self) + Send + 'static>(
229         &self,
230         f: F,
231     ) -> SignalHandlerId;
232 
connect_property_remote_address_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId233     fn connect_property_remote_address_notify<F: Fn(&Self) + Send + 'static>(
234         &self,
235         f: F,
236     ) -> SignalHandlerId;
237 
connect_property_timeout_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId238     fn connect_property_timeout_notify<F: Fn(&Self) + Send + 'static>(
239         &self,
240         f: F,
241     ) -> SignalHandlerId;
242 
connect_property_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId243     fn connect_property_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId;
244 }
245 
246 impl<O: IsA<Socket>> SocketExt for O {
accept<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<Socket, glib::Error>247     fn accept<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<Socket, glib::Error> {
248         unsafe {
249             let mut error = ptr::null_mut();
250             let ret = gio_sys::g_socket_accept(
251                 self.as_ref().to_glib_none().0,
252                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
253                 &mut error,
254             );
255             if error.is_null() {
256                 Ok(from_glib_full(ret))
257             } else {
258                 Err(from_glib_full(error))
259             }
260         }
261     }
262 
bind<P: IsA<SocketAddress>>( &self, address: &P, allow_reuse: bool, ) -> Result<(), glib::Error>263     fn bind<P: IsA<SocketAddress>>(
264         &self,
265         address: &P,
266         allow_reuse: bool,
267     ) -> Result<(), glib::Error> {
268         unsafe {
269             let mut error = ptr::null_mut();
270             let _ = gio_sys::g_socket_bind(
271                 self.as_ref().to_glib_none().0,
272                 address.as_ref().to_glib_none().0,
273                 allow_reuse.to_glib(),
274                 &mut error,
275             );
276             if error.is_null() {
277                 Ok(())
278             } else {
279                 Err(from_glib_full(error))
280             }
281         }
282     }
283 
check_connect_result(&self) -> Result<(), glib::Error>284     fn check_connect_result(&self) -> Result<(), glib::Error> {
285         unsafe {
286             let mut error = ptr::null_mut();
287             let _ =
288                 gio_sys::g_socket_check_connect_result(self.as_ref().to_glib_none().0, &mut error);
289             if error.is_null() {
290                 Ok(())
291             } else {
292                 Err(from_glib_full(error))
293             }
294         }
295     }
296 
close(&self) -> Result<(), glib::Error>297     fn close(&self) -> Result<(), glib::Error> {
298         unsafe {
299             let mut error = ptr::null_mut();
300             let _ = gio_sys::g_socket_close(self.as_ref().to_glib_none().0, &mut error);
301             if error.is_null() {
302                 Ok(())
303             } else {
304                 Err(from_glib_full(error))
305             }
306         }
307     }
308 
condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition309     fn condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition {
310         unsafe {
311             from_glib(gio_sys::g_socket_condition_check(
312                 self.as_ref().to_glib_none().0,
313                 condition.to_glib(),
314             ))
315         }
316     }
317 
condition_timed_wait<P: IsA<Cancellable>>( &self, condition: glib::IOCondition, timeout_us: i64, cancellable: Option<&P>, ) -> Result<(), glib::Error>318     fn condition_timed_wait<P: IsA<Cancellable>>(
319         &self,
320         condition: glib::IOCondition,
321         timeout_us: i64,
322         cancellable: Option<&P>,
323     ) -> Result<(), glib::Error> {
324         unsafe {
325             let mut error = ptr::null_mut();
326             let _ = gio_sys::g_socket_condition_timed_wait(
327                 self.as_ref().to_glib_none().0,
328                 condition.to_glib(),
329                 timeout_us,
330                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
331                 &mut error,
332             );
333             if error.is_null() {
334                 Ok(())
335             } else {
336                 Err(from_glib_full(error))
337             }
338         }
339     }
340 
condition_wait<P: IsA<Cancellable>>( &self, condition: glib::IOCondition, cancellable: Option<&P>, ) -> Result<(), glib::Error>341     fn condition_wait<P: IsA<Cancellable>>(
342         &self,
343         condition: glib::IOCondition,
344         cancellable: Option<&P>,
345     ) -> Result<(), glib::Error> {
346         unsafe {
347             let mut error = ptr::null_mut();
348             let _ = gio_sys::g_socket_condition_wait(
349                 self.as_ref().to_glib_none().0,
350                 condition.to_glib(),
351                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
352                 &mut error,
353             );
354             if error.is_null() {
355                 Ok(())
356             } else {
357                 Err(from_glib_full(error))
358             }
359         }
360     }
361 
connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( &self, address: &P, cancellable: Option<&Q>, ) -> Result<(), glib::Error>362     fn connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>(
363         &self,
364         address: &P,
365         cancellable: Option<&Q>,
366     ) -> Result<(), glib::Error> {
367         unsafe {
368             let mut error = ptr::null_mut();
369             let _ = gio_sys::g_socket_connect(
370                 self.as_ref().to_glib_none().0,
371                 address.as_ref().to_glib_none().0,
372                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
373                 &mut error,
374             );
375             if error.is_null() {
376                 Ok(())
377             } else {
378                 Err(from_glib_full(error))
379             }
380         }
381     }
382 
connection_factory_create_connection(&self) -> Option<SocketConnection>383     fn connection_factory_create_connection(&self) -> Option<SocketConnection> {
384         unsafe {
385             from_glib_full(gio_sys::g_socket_connection_factory_create_connection(
386                 self.as_ref().to_glib_none().0,
387             ))
388         }
389     }
390 
get_available_bytes(&self) -> isize391     fn get_available_bytes(&self) -> isize {
392         unsafe { gio_sys::g_socket_get_available_bytes(self.as_ref().to_glib_none().0) }
393     }
394 
get_blocking(&self) -> bool395     fn get_blocking(&self) -> bool {
396         unsafe {
397             from_glib(gio_sys::g_socket_get_blocking(
398                 self.as_ref().to_glib_none().0,
399             ))
400         }
401     }
402 
get_broadcast(&self) -> bool403     fn get_broadcast(&self) -> bool {
404         unsafe {
405             from_glib(gio_sys::g_socket_get_broadcast(
406                 self.as_ref().to_glib_none().0,
407             ))
408         }
409     }
410 
get_credentials(&self) -> Result<Credentials, glib::Error>411     fn get_credentials(&self) -> Result<Credentials, glib::Error> {
412         unsafe {
413             let mut error = ptr::null_mut();
414             let ret = gio_sys::g_socket_get_credentials(self.as_ref().to_glib_none().0, &mut error);
415             if error.is_null() {
416                 Ok(from_glib_full(ret))
417             } else {
418                 Err(from_glib_full(error))
419             }
420         }
421     }
422 
get_family(&self) -> SocketFamily423     fn get_family(&self) -> SocketFamily {
424         unsafe { from_glib(gio_sys::g_socket_get_family(self.as_ref().to_glib_none().0)) }
425     }
426 
get_keepalive(&self) -> bool427     fn get_keepalive(&self) -> bool {
428         unsafe {
429             from_glib(gio_sys::g_socket_get_keepalive(
430                 self.as_ref().to_glib_none().0,
431             ))
432         }
433     }
434 
get_listen_backlog(&self) -> i32435     fn get_listen_backlog(&self) -> i32 {
436         unsafe { gio_sys::g_socket_get_listen_backlog(self.as_ref().to_glib_none().0) }
437     }
438 
get_local_address(&self) -> Result<SocketAddress, glib::Error>439     fn get_local_address(&self) -> Result<SocketAddress, glib::Error> {
440         unsafe {
441             let mut error = ptr::null_mut();
442             let ret =
443                 gio_sys::g_socket_get_local_address(self.as_ref().to_glib_none().0, &mut error);
444             if error.is_null() {
445                 Ok(from_glib_full(ret))
446             } else {
447                 Err(from_glib_full(error))
448             }
449         }
450     }
451 
get_multicast_loopback(&self) -> bool452     fn get_multicast_loopback(&self) -> bool {
453         unsafe {
454             from_glib(gio_sys::g_socket_get_multicast_loopback(
455                 self.as_ref().to_glib_none().0,
456             ))
457         }
458     }
459 
get_multicast_ttl(&self) -> u32460     fn get_multicast_ttl(&self) -> u32 {
461         unsafe { gio_sys::g_socket_get_multicast_ttl(self.as_ref().to_glib_none().0) }
462     }
463 
get_option(&self, level: i32, optname: i32) -> Result<i32, glib::Error>464     fn get_option(&self, level: i32, optname: i32) -> Result<i32, glib::Error> {
465         unsafe {
466             let mut value = mem::MaybeUninit::uninit();
467             let mut error = ptr::null_mut();
468             let _ = gio_sys::g_socket_get_option(
469                 self.as_ref().to_glib_none().0,
470                 level,
471                 optname,
472                 value.as_mut_ptr(),
473                 &mut error,
474             );
475             let value = value.assume_init();
476             if error.is_null() {
477                 Ok(value)
478             } else {
479                 Err(from_glib_full(error))
480             }
481         }
482     }
483 
get_protocol(&self) -> SocketProtocol484     fn get_protocol(&self) -> SocketProtocol {
485         unsafe {
486             from_glib(gio_sys::g_socket_get_protocol(
487                 self.as_ref().to_glib_none().0,
488             ))
489         }
490     }
491 
get_remote_address(&self) -> Result<SocketAddress, glib::Error>492     fn get_remote_address(&self) -> Result<SocketAddress, glib::Error> {
493         unsafe {
494             let mut error = ptr::null_mut();
495             let ret =
496                 gio_sys::g_socket_get_remote_address(self.as_ref().to_glib_none().0, &mut error);
497             if error.is_null() {
498                 Ok(from_glib_full(ret))
499             } else {
500                 Err(from_glib_full(error))
501             }
502         }
503     }
504 
get_socket_type(&self) -> SocketType505     fn get_socket_type(&self) -> SocketType {
506         unsafe {
507             from_glib(gio_sys::g_socket_get_socket_type(
508                 self.as_ref().to_glib_none().0,
509             ))
510         }
511     }
512 
get_timeout(&self) -> u32513     fn get_timeout(&self) -> u32 {
514         unsafe { gio_sys::g_socket_get_timeout(self.as_ref().to_glib_none().0) }
515     }
516 
get_ttl(&self) -> u32517     fn get_ttl(&self) -> u32 {
518         unsafe { gio_sys::g_socket_get_ttl(self.as_ref().to_glib_none().0) }
519     }
520 
is_closed(&self) -> bool521     fn is_closed(&self) -> bool {
522         unsafe { from_glib(gio_sys::g_socket_is_closed(self.as_ref().to_glib_none().0)) }
523     }
524 
is_connected(&self) -> bool525     fn is_connected(&self) -> bool {
526         unsafe {
527             from_glib(gio_sys::g_socket_is_connected(
528                 self.as_ref().to_glib_none().0,
529             ))
530         }
531     }
532 
join_multicast_group<P: IsA<InetAddress>>( &self, group: &P, source_specific: bool, iface: Option<&str>, ) -> Result<(), glib::Error>533     fn join_multicast_group<P: IsA<InetAddress>>(
534         &self,
535         group: &P,
536         source_specific: bool,
537         iface: Option<&str>,
538     ) -> Result<(), glib::Error> {
539         unsafe {
540             let mut error = ptr::null_mut();
541             let _ = gio_sys::g_socket_join_multicast_group(
542                 self.as_ref().to_glib_none().0,
543                 group.as_ref().to_glib_none().0,
544                 source_specific.to_glib(),
545                 iface.to_glib_none().0,
546                 &mut error,
547             );
548             if error.is_null() {
549                 Ok(())
550             } else {
551                 Err(from_glib_full(error))
552             }
553         }
554     }
555 
556     #[cfg(any(feature = "v2_56", feature = "dox"))]
join_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( &self, group: &P, source_specific: Option<&Q>, iface: Option<&str>, ) -> Result<(), glib::Error>557     fn join_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>(
558         &self,
559         group: &P,
560         source_specific: Option<&Q>,
561         iface: Option<&str>,
562     ) -> Result<(), glib::Error> {
563         unsafe {
564             let mut error = ptr::null_mut();
565             let _ = gio_sys::g_socket_join_multicast_group_ssm(
566                 self.as_ref().to_glib_none().0,
567                 group.as_ref().to_glib_none().0,
568                 source_specific.map(|p| p.as_ref()).to_glib_none().0,
569                 iface.to_glib_none().0,
570                 &mut error,
571             );
572             if error.is_null() {
573                 Ok(())
574             } else {
575                 Err(from_glib_full(error))
576             }
577         }
578     }
579 
leave_multicast_group<P: IsA<InetAddress>>( &self, group: &P, source_specific: bool, iface: Option<&str>, ) -> Result<(), glib::Error>580     fn leave_multicast_group<P: IsA<InetAddress>>(
581         &self,
582         group: &P,
583         source_specific: bool,
584         iface: Option<&str>,
585     ) -> Result<(), glib::Error> {
586         unsafe {
587             let mut error = ptr::null_mut();
588             let _ = gio_sys::g_socket_leave_multicast_group(
589                 self.as_ref().to_glib_none().0,
590                 group.as_ref().to_glib_none().0,
591                 source_specific.to_glib(),
592                 iface.to_glib_none().0,
593                 &mut error,
594             );
595             if error.is_null() {
596                 Ok(())
597             } else {
598                 Err(from_glib_full(error))
599             }
600         }
601     }
602 
603     #[cfg(any(feature = "v2_56", feature = "dox"))]
leave_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( &self, group: &P, source_specific: Option<&Q>, iface: Option<&str>, ) -> Result<(), glib::Error>604     fn leave_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>(
605         &self,
606         group: &P,
607         source_specific: Option<&Q>,
608         iface: Option<&str>,
609     ) -> Result<(), glib::Error> {
610         unsafe {
611             let mut error = ptr::null_mut();
612             let _ = gio_sys::g_socket_leave_multicast_group_ssm(
613                 self.as_ref().to_glib_none().0,
614                 group.as_ref().to_glib_none().0,
615                 source_specific.map(|p| p.as_ref()).to_glib_none().0,
616                 iface.to_glib_none().0,
617                 &mut error,
618             );
619             if error.is_null() {
620                 Ok(())
621             } else {
622                 Err(from_glib_full(error))
623             }
624         }
625     }
626 
listen(&self) -> Result<(), glib::Error>627     fn listen(&self) -> Result<(), glib::Error> {
628         unsafe {
629             let mut error = ptr::null_mut();
630             let _ = gio_sys::g_socket_listen(self.as_ref().to_glib_none().0, &mut error);
631             if error.is_null() {
632                 Ok(())
633             } else {
634                 Err(from_glib_full(error))
635             }
636         }
637     }
638 
set_blocking(&self, blocking: bool)639     fn set_blocking(&self, blocking: bool) {
640         unsafe {
641             gio_sys::g_socket_set_blocking(self.as_ref().to_glib_none().0, blocking.to_glib());
642         }
643     }
644 
set_broadcast(&self, broadcast: bool)645     fn set_broadcast(&self, broadcast: bool) {
646         unsafe {
647             gio_sys::g_socket_set_broadcast(self.as_ref().to_glib_none().0, broadcast.to_glib());
648         }
649     }
650 
set_keepalive(&self, keepalive: bool)651     fn set_keepalive(&self, keepalive: bool) {
652         unsafe {
653             gio_sys::g_socket_set_keepalive(self.as_ref().to_glib_none().0, keepalive.to_glib());
654         }
655     }
656 
set_listen_backlog(&self, backlog: i32)657     fn set_listen_backlog(&self, backlog: i32) {
658         unsafe {
659             gio_sys::g_socket_set_listen_backlog(self.as_ref().to_glib_none().0, backlog);
660         }
661     }
662 
set_multicast_loopback(&self, loopback: bool)663     fn set_multicast_loopback(&self, loopback: bool) {
664         unsafe {
665             gio_sys::g_socket_set_multicast_loopback(
666                 self.as_ref().to_glib_none().0,
667                 loopback.to_glib(),
668             );
669         }
670     }
671 
set_multicast_ttl(&self, ttl: u32)672     fn set_multicast_ttl(&self, ttl: u32) {
673         unsafe {
674             gio_sys::g_socket_set_multicast_ttl(self.as_ref().to_glib_none().0, ttl);
675         }
676     }
677 
set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error>678     fn set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error> {
679         unsafe {
680             let mut error = ptr::null_mut();
681             let _ = gio_sys::g_socket_set_option(
682                 self.as_ref().to_glib_none().0,
683                 level,
684                 optname,
685                 value,
686                 &mut error,
687             );
688             if error.is_null() {
689                 Ok(())
690             } else {
691                 Err(from_glib_full(error))
692             }
693         }
694     }
695 
set_timeout(&self, timeout: u32)696     fn set_timeout(&self, timeout: u32) {
697         unsafe {
698             gio_sys::g_socket_set_timeout(self.as_ref().to_glib_none().0, timeout);
699         }
700     }
701 
set_ttl(&self, ttl: u32)702     fn set_ttl(&self, ttl: u32) {
703         unsafe {
704             gio_sys::g_socket_set_ttl(self.as_ref().to_glib_none().0, ttl);
705         }
706     }
707 
shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error>708     fn shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error> {
709         unsafe {
710             let mut error = ptr::null_mut();
711             let _ = gio_sys::g_socket_shutdown(
712                 self.as_ref().to_glib_none().0,
713                 shutdown_read.to_glib(),
714                 shutdown_write.to_glib(),
715                 &mut error,
716             );
717             if error.is_null() {
718                 Ok(())
719             } else {
720                 Err(from_glib_full(error))
721             }
722         }
723     }
724 
speaks_ipv4(&self) -> bool725     fn speaks_ipv4(&self) -> bool {
726         unsafe {
727             from_glib(gio_sys::g_socket_speaks_ipv4(
728                 self.as_ref().to_glib_none().0,
729             ))
730         }
731     }
732 
get_property_type(&self) -> SocketType733     fn get_property_type(&self) -> SocketType {
734         unsafe {
735             let mut value = Value::from_type(<SocketType as StaticType>::static_type());
736             gobject_sys::g_object_get_property(
737                 self.to_glib_none().0 as *mut gobject_sys::GObject,
738                 b"type\0".as_ptr() as *const _,
739                 value.to_glib_none_mut().0,
740             );
741             value
742                 .get()
743                 .expect("Return Value for property `type` getter")
744                 .unwrap()
745         }
746     }
747 
connect_property_blocking_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId748     fn connect_property_blocking_notify<F: Fn(&Self) + Send + 'static>(
749         &self,
750         f: F,
751     ) -> SignalHandlerId {
752         unsafe extern "C" fn notify_blocking_trampoline<P, F: Fn(&P) + Send + 'static>(
753             this: *mut gio_sys::GSocket,
754             _param_spec: glib_sys::gpointer,
755             f: glib_sys::gpointer,
756         ) where
757             P: IsA<Socket>,
758         {
759             let f: &F = &*(f as *const F);
760             f(&Socket::from_glib_borrow(this).unsafe_cast())
761         }
762         unsafe {
763             let f: Box_<F> = Box_::new(f);
764             connect_raw(
765                 self.as_ptr() as *mut _,
766                 b"notify::blocking\0".as_ptr() as *const _,
767                 Some(transmute(notify_blocking_trampoline::<Self, F> as usize)),
768                 Box_::into_raw(f),
769             )
770         }
771     }
772 
connect_property_broadcast_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId773     fn connect_property_broadcast_notify<F: Fn(&Self) + Send + 'static>(
774         &self,
775         f: F,
776     ) -> SignalHandlerId {
777         unsafe extern "C" fn notify_broadcast_trampoline<P, F: Fn(&P) + Send + 'static>(
778             this: *mut gio_sys::GSocket,
779             _param_spec: glib_sys::gpointer,
780             f: glib_sys::gpointer,
781         ) where
782             P: IsA<Socket>,
783         {
784             let f: &F = &*(f as *const F);
785             f(&Socket::from_glib_borrow(this).unsafe_cast())
786         }
787         unsafe {
788             let f: Box_<F> = Box_::new(f);
789             connect_raw(
790                 self.as_ptr() as *mut _,
791                 b"notify::broadcast\0".as_ptr() as *const _,
792                 Some(transmute(notify_broadcast_trampoline::<Self, F> as usize)),
793                 Box_::into_raw(f),
794             )
795         }
796     }
797 
connect_property_keepalive_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId798     fn connect_property_keepalive_notify<F: Fn(&Self) + Send + 'static>(
799         &self,
800         f: F,
801     ) -> SignalHandlerId {
802         unsafe extern "C" fn notify_keepalive_trampoline<P, F: Fn(&P) + Send + 'static>(
803             this: *mut gio_sys::GSocket,
804             _param_spec: glib_sys::gpointer,
805             f: glib_sys::gpointer,
806         ) where
807             P: IsA<Socket>,
808         {
809             let f: &F = &*(f as *const F);
810             f(&Socket::from_glib_borrow(this).unsafe_cast())
811         }
812         unsafe {
813             let f: Box_<F> = Box_::new(f);
814             connect_raw(
815                 self.as_ptr() as *mut _,
816                 b"notify::keepalive\0".as_ptr() as *const _,
817                 Some(transmute(notify_keepalive_trampoline::<Self, F> as usize)),
818                 Box_::into_raw(f),
819             )
820         }
821     }
822 
connect_property_listen_backlog_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId823     fn connect_property_listen_backlog_notify<F: Fn(&Self) + Send + 'static>(
824         &self,
825         f: F,
826     ) -> SignalHandlerId {
827         unsafe extern "C" fn notify_listen_backlog_trampoline<P, F: Fn(&P) + Send + 'static>(
828             this: *mut gio_sys::GSocket,
829             _param_spec: glib_sys::gpointer,
830             f: glib_sys::gpointer,
831         ) where
832             P: IsA<Socket>,
833         {
834             let f: &F = &*(f as *const F);
835             f(&Socket::from_glib_borrow(this).unsafe_cast())
836         }
837         unsafe {
838             let f: Box_<F> = Box_::new(f);
839             connect_raw(
840                 self.as_ptr() as *mut _,
841                 b"notify::listen-backlog\0".as_ptr() as *const _,
842                 Some(transmute(
843                     notify_listen_backlog_trampoline::<Self, F> as usize,
844                 )),
845                 Box_::into_raw(f),
846             )
847         }
848     }
849 
connect_property_local_address_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId850     fn connect_property_local_address_notify<F: Fn(&Self) + Send + 'static>(
851         &self,
852         f: F,
853     ) -> SignalHandlerId {
854         unsafe extern "C" fn notify_local_address_trampoline<P, F: Fn(&P) + Send + 'static>(
855             this: *mut gio_sys::GSocket,
856             _param_spec: glib_sys::gpointer,
857             f: glib_sys::gpointer,
858         ) where
859             P: IsA<Socket>,
860         {
861             let f: &F = &*(f as *const F);
862             f(&Socket::from_glib_borrow(this).unsafe_cast())
863         }
864         unsafe {
865             let f: Box_<F> = Box_::new(f);
866             connect_raw(
867                 self.as_ptr() as *mut _,
868                 b"notify::local-address\0".as_ptr() as *const _,
869                 Some(transmute(
870                     notify_local_address_trampoline::<Self, F> as usize,
871                 )),
872                 Box_::into_raw(f),
873             )
874         }
875     }
876 
connect_property_multicast_loopback_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId877     fn connect_property_multicast_loopback_notify<F: Fn(&Self) + Send + 'static>(
878         &self,
879         f: F,
880     ) -> SignalHandlerId {
881         unsafe extern "C" fn notify_multicast_loopback_trampoline<P, F: Fn(&P) + Send + 'static>(
882             this: *mut gio_sys::GSocket,
883             _param_spec: glib_sys::gpointer,
884             f: glib_sys::gpointer,
885         ) where
886             P: IsA<Socket>,
887         {
888             let f: &F = &*(f as *const F);
889             f(&Socket::from_glib_borrow(this).unsafe_cast())
890         }
891         unsafe {
892             let f: Box_<F> = Box_::new(f);
893             connect_raw(
894                 self.as_ptr() as *mut _,
895                 b"notify::multicast-loopback\0".as_ptr() as *const _,
896                 Some(transmute(
897                     notify_multicast_loopback_trampoline::<Self, F> as usize,
898                 )),
899                 Box_::into_raw(f),
900             )
901         }
902     }
903 
connect_property_multicast_ttl_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId904     fn connect_property_multicast_ttl_notify<F: Fn(&Self) + Send + 'static>(
905         &self,
906         f: F,
907     ) -> SignalHandlerId {
908         unsafe extern "C" fn notify_multicast_ttl_trampoline<P, F: Fn(&P) + Send + 'static>(
909             this: *mut gio_sys::GSocket,
910             _param_spec: glib_sys::gpointer,
911             f: glib_sys::gpointer,
912         ) where
913             P: IsA<Socket>,
914         {
915             let f: &F = &*(f as *const F);
916             f(&Socket::from_glib_borrow(this).unsafe_cast())
917         }
918         unsafe {
919             let f: Box_<F> = Box_::new(f);
920             connect_raw(
921                 self.as_ptr() as *mut _,
922                 b"notify::multicast-ttl\0".as_ptr() as *const _,
923                 Some(transmute(
924                     notify_multicast_ttl_trampoline::<Self, F> as usize,
925                 )),
926                 Box_::into_raw(f),
927             )
928         }
929     }
930 
connect_property_remote_address_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId931     fn connect_property_remote_address_notify<F: Fn(&Self) + Send + 'static>(
932         &self,
933         f: F,
934     ) -> SignalHandlerId {
935         unsafe extern "C" fn notify_remote_address_trampoline<P, F: Fn(&P) + Send + 'static>(
936             this: *mut gio_sys::GSocket,
937             _param_spec: glib_sys::gpointer,
938             f: glib_sys::gpointer,
939         ) where
940             P: IsA<Socket>,
941         {
942             let f: &F = &*(f as *const F);
943             f(&Socket::from_glib_borrow(this).unsafe_cast())
944         }
945         unsafe {
946             let f: Box_<F> = Box_::new(f);
947             connect_raw(
948                 self.as_ptr() as *mut _,
949                 b"notify::remote-address\0".as_ptr() as *const _,
950                 Some(transmute(
951                     notify_remote_address_trampoline::<Self, F> as usize,
952                 )),
953                 Box_::into_raw(f),
954             )
955         }
956     }
957 
connect_property_timeout_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId958     fn connect_property_timeout_notify<F: Fn(&Self) + Send + 'static>(
959         &self,
960         f: F,
961     ) -> SignalHandlerId {
962         unsafe extern "C" fn notify_timeout_trampoline<P, F: Fn(&P) + Send + 'static>(
963             this: *mut gio_sys::GSocket,
964             _param_spec: glib_sys::gpointer,
965             f: glib_sys::gpointer,
966         ) where
967             P: IsA<Socket>,
968         {
969             let f: &F = &*(f as *const F);
970             f(&Socket::from_glib_borrow(this).unsafe_cast())
971         }
972         unsafe {
973             let f: Box_<F> = Box_::new(f);
974             connect_raw(
975                 self.as_ptr() as *mut _,
976                 b"notify::timeout\0".as_ptr() as *const _,
977                 Some(transmute(notify_timeout_trampoline::<Self, F> as usize)),
978                 Box_::into_raw(f),
979             )
980         }
981     }
982 
connect_property_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId983     fn connect_property_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId {
984         unsafe extern "C" fn notify_ttl_trampoline<P, F: Fn(&P) + Send + 'static>(
985             this: *mut gio_sys::GSocket,
986             _param_spec: glib_sys::gpointer,
987             f: glib_sys::gpointer,
988         ) where
989             P: IsA<Socket>,
990         {
991             let f: &F = &*(f as *const F);
992             f(&Socket::from_glib_borrow(this).unsafe_cast())
993         }
994         unsafe {
995             let f: Box_<F> = Box_::new(f);
996             connect_raw(
997                 self.as_ptr() as *mut _,
998                 b"notify::ttl\0".as_ptr() as *const _,
999                 Some(transmute(notify_ttl_trampoline::<Self, F> as usize)),
1000                 Box_::into_raw(f),
1001             )
1002         }
1003     }
1004 }
1005 
1006 impl fmt::Display for Socket {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result1007     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1008         write!(f, "Socket")
1009     }
1010 }
1011