1use crate::{
6 ffi, Cancellable, Credentials, DatagramBased, InetAddress, Initable, SocketAddress,
7 SocketConnection, SocketFamily, SocketProtocol, SocketType,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 #[doc(alias = "GSocket")]
18 pub struct Socket(Object<ffi::GSocket, ffi::GSocketClass>) @implements DatagramBased, Initable;
19
20 match fn {
21 type_ => || ffi::g_socket_get_type(),
22 }
23}
24
25impl Socket {
26 pub const NONE: Option<&'static Socket> = None;
27
28 #[doc(alias = "g_socket_new")]
29 pub fn new(
30 family: SocketFamily,
31 type_: SocketType,
32 protocol: SocketProtocol,
33 ) -> Result<Socket, glib::Error> {
34 unsafe {
35 let mut error = std::ptr::null_mut();
36 let ret = ffi::g_socket_new(
37 family.into_glib(),
38 type_.into_glib(),
39 protocol.into_glib(),
40 &mut error,
41 );
42 if error.is_null() {
43 Ok(from_glib_full(ret))
44 } else {
45 Err(from_glib_full(error))
46 }
47 }
48 }
49}
50
51mod sealed {
52 pub trait Sealed {}
53 impl<T: super::IsA<super::Socket>> Sealed for T {}
54}
55
56pub trait SocketExt: IsA<Socket> + sealed::Sealed + 'static {
57 #[doc(alias = "g_socket_accept")]
58 fn accept(&self, cancellable: Option<&impl IsA<Cancellable>>) -> Result<Socket, glib::Error> {
59 unsafe {
60 let mut error = std::ptr::null_mut();
61 let ret = ffi::g_socket_accept(
62 self.as_ref().to_glib_none().0,
63 cancellable.map(|p| p.as_ref()).to_glib_none().0,
64 &mut error,
65 );
66 if error.is_null() {
67 Ok(from_glib_full(ret))
68 } else {
69 Err(from_glib_full(error))
70 }
71 }
72 }
73
74 #[doc(alias = "g_socket_bind")]
75 fn bind(
76 &self,
77 address: &impl IsA<SocketAddress>,
78 allow_reuse: bool,
79 ) -> Result<(), glib::Error> {
80 unsafe {
81 let mut error = std::ptr::null_mut();
82 let is_ok = ffi::g_socket_bind(
83 self.as_ref().to_glib_none().0,
84 address.as_ref().to_glib_none().0,
85 allow_reuse.into_glib(),
86 &mut error,
87 );
88 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
89 if error.is_null() {
90 Ok(())
91 } else {
92 Err(from_glib_full(error))
93 }
94 }
95 }
96
97 #[doc(alias = "g_socket_check_connect_result")]
98 fn check_connect_result(&self) -> Result<(), glib::Error> {
99 unsafe {
100 let mut error = std::ptr::null_mut();
101 let is_ok =
102 ffi::g_socket_check_connect_result(self.as_ref().to_glib_none().0, &mut error);
103 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
104 if error.is_null() {
105 Ok(())
106 } else {
107 Err(from_glib_full(error))
108 }
109 }
110 }
111
112 #[doc(alias = "g_socket_close")]
113 fn close(&self) -> Result<(), glib::Error> {
114 unsafe {
115 let mut error = std::ptr::null_mut();
116 let is_ok = ffi::g_socket_close(self.as_ref().to_glib_none().0, &mut error);
117 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
118 if error.is_null() {
119 Ok(())
120 } else {
121 Err(from_glib_full(error))
122 }
123 }
124 }
125
126 #[doc(alias = "g_socket_condition_check")]
127 fn condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition {
128 unsafe {
129 from_glib(ffi::g_socket_condition_check(
130 self.as_ref().to_glib_none().0,
131 condition.into_glib(),
132 ))
133 }
134 }
135
136 #[doc(alias = "g_socket_condition_timed_wait")]
137 fn condition_timed_wait(
138 &self,
139 condition: glib::IOCondition,
140 timeout_us: i64,
141 cancellable: Option<&impl IsA<Cancellable>>,
142 ) -> Result<(), glib::Error> {
143 unsafe {
144 let mut error = std::ptr::null_mut();
145 let is_ok = ffi::g_socket_condition_timed_wait(
146 self.as_ref().to_glib_none().0,
147 condition.into_glib(),
148 timeout_us,
149 cancellable.map(|p| p.as_ref()).to_glib_none().0,
150 &mut error,
151 );
152 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
153 if error.is_null() {
154 Ok(())
155 } else {
156 Err(from_glib_full(error))
157 }
158 }
159 }
160
161 #[doc(alias = "g_socket_condition_wait")]
162 fn condition_wait(
163 &self,
164 condition: glib::IOCondition,
165 cancellable: Option<&impl IsA<Cancellable>>,
166 ) -> Result<(), glib::Error> {
167 unsafe {
168 let mut error = std::ptr::null_mut();
169 let is_ok = ffi::g_socket_condition_wait(
170 self.as_ref().to_glib_none().0,
171 condition.into_glib(),
172 cancellable.map(|p| p.as_ref()).to_glib_none().0,
173 &mut error,
174 );
175 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
176 if error.is_null() {
177 Ok(())
178 } else {
179 Err(from_glib_full(error))
180 }
181 }
182 }
183
184 #[doc(alias = "g_socket_connect")]
185 fn connect(
186 &self,
187 address: &impl IsA<SocketAddress>,
188 cancellable: Option<&impl IsA<Cancellable>>,
189 ) -> Result<(), glib::Error> {
190 unsafe {
191 let mut error = std::ptr::null_mut();
192 let is_ok = ffi::g_socket_connect(
193 self.as_ref().to_glib_none().0,
194 address.as_ref().to_glib_none().0,
195 cancellable.map(|p| p.as_ref()).to_glib_none().0,
196 &mut error,
197 );
198 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
199 if error.is_null() {
200 Ok(())
201 } else {
202 Err(from_glib_full(error))
203 }
204 }
205 }
206
207 #[doc(alias = "g_socket_connection_factory_create_connection")]
208 fn connection_factory_create_connection(&self) -> SocketConnection {
209 unsafe {
210 from_glib_full(ffi::g_socket_connection_factory_create_connection(
211 self.as_ref().to_glib_none().0,
212 ))
213 }
214 }
215
216 #[doc(alias = "g_socket_get_available_bytes")]
217 #[doc(alias = "get_available_bytes")]
218 fn available_bytes(&self) -> isize {
219 unsafe { ffi::g_socket_get_available_bytes(self.as_ref().to_glib_none().0) }
220 }
221
222 #[doc(alias = "g_socket_get_blocking")]
223 #[doc(alias = "get_blocking")]
224 #[doc(alias = "blocking")]
225 fn is_blocking(&self) -> bool {
226 unsafe { from_glib(ffi::g_socket_get_blocking(self.as_ref().to_glib_none().0)) }
227 }
228
229 #[doc(alias = "g_socket_get_broadcast")]
230 #[doc(alias = "get_broadcast")]
231 #[doc(alias = "broadcast")]
232 fn is_broadcast(&self) -> bool {
233 unsafe { from_glib(ffi::g_socket_get_broadcast(self.as_ref().to_glib_none().0)) }
234 }
235
236 #[doc(alias = "g_socket_get_credentials")]
237 #[doc(alias = "get_credentials")]
238 fn credentials(&self) -> Result<Credentials, glib::Error> {
239 unsafe {
240 let mut error = std::ptr::null_mut();
241 let ret = ffi::g_socket_get_credentials(self.as_ref().to_glib_none().0, &mut error);
242 if error.is_null() {
243 Ok(from_glib_full(ret))
244 } else {
245 Err(from_glib_full(error))
246 }
247 }
248 }
249
250 #[doc(alias = "g_socket_get_family")]
251 #[doc(alias = "get_family")]
252 fn family(&self) -> SocketFamily {
253 unsafe { from_glib(ffi::g_socket_get_family(self.as_ref().to_glib_none().0)) }
254 }
255
256 #[doc(alias = "g_socket_get_keepalive")]
257 #[doc(alias = "get_keepalive")]
258 #[doc(alias = "keepalive")]
259 fn is_keepalive(&self) -> bool {
260 unsafe { from_glib(ffi::g_socket_get_keepalive(self.as_ref().to_glib_none().0)) }
261 }
262
263 #[doc(alias = "g_socket_get_listen_backlog")]
264 #[doc(alias = "get_listen_backlog")]
265 #[doc(alias = "listen-backlog")]
266 fn listen_backlog(&self) -> i32 {
267 unsafe { ffi::g_socket_get_listen_backlog(self.as_ref().to_glib_none().0) }
268 }
269
270 #[doc(alias = "g_socket_get_local_address")]
271 #[doc(alias = "get_local_address")]
272 #[doc(alias = "local-address")]
273 fn local_address(&self) -> Result<SocketAddress, glib::Error> {
274 unsafe {
275 let mut error = std::ptr::null_mut();
276 let ret = ffi::g_socket_get_local_address(self.as_ref().to_glib_none().0, &mut error);
277 if error.is_null() {
278 Ok(from_glib_full(ret))
279 } else {
280 Err(from_glib_full(error))
281 }
282 }
283 }
284
285 #[doc(alias = "g_socket_get_multicast_loopback")]
286 #[doc(alias = "get_multicast_loopback")]
287 #[doc(alias = "multicast-loopback")]
288 fn is_multicast_loopback(&self) -> bool {
289 unsafe {
290 from_glib(ffi::g_socket_get_multicast_loopback(
291 self.as_ref().to_glib_none().0,
292 ))
293 }
294 }
295
296 #[doc(alias = "g_socket_get_multicast_ttl")]
297 #[doc(alias = "get_multicast_ttl")]
298 #[doc(alias = "multicast-ttl")]
299 fn multicast_ttl(&self) -> u32 {
300 unsafe { ffi::g_socket_get_multicast_ttl(self.as_ref().to_glib_none().0) }
301 }
302
303 #[doc(alias = "g_socket_get_option")]
304 #[doc(alias = "get_option")]
305 fn option(&self, level: i32, optname: i32) -> Result<i32, glib::Error> {
306 unsafe {
307 let mut value = std::mem::MaybeUninit::uninit();
308 let mut error = std::ptr::null_mut();
309 let is_ok = ffi::g_socket_get_option(
310 self.as_ref().to_glib_none().0,
311 level,
312 optname,
313 value.as_mut_ptr(),
314 &mut error,
315 );
316 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
317 if error.is_null() {
318 Ok(value.assume_init())
319 } else {
320 Err(from_glib_full(error))
321 }
322 }
323 }
324
325 #[doc(alias = "g_socket_get_protocol")]
326 #[doc(alias = "get_protocol")]
327 fn protocol(&self) -> SocketProtocol {
328 unsafe { from_glib(ffi::g_socket_get_protocol(self.as_ref().to_glib_none().0)) }
329 }
330
331 #[doc(alias = "g_socket_get_remote_address")]
332 #[doc(alias = "get_remote_address")]
333 #[doc(alias = "remote-address")]
334 fn remote_address(&self) -> Result<SocketAddress, glib::Error> {
335 unsafe {
336 let mut error = std::ptr::null_mut();
337 let ret = ffi::g_socket_get_remote_address(self.as_ref().to_glib_none().0, &mut error);
338 if error.is_null() {
339 Ok(from_glib_full(ret))
340 } else {
341 Err(from_glib_full(error))
342 }
343 }
344 }
345
346 #[doc(alias = "g_socket_get_socket_type")]
347 #[doc(alias = "get_socket_type")]
348 fn socket_type(&self) -> SocketType {
349 unsafe {
350 from_glib(ffi::g_socket_get_socket_type(
351 self.as_ref().to_glib_none().0,
352 ))
353 }
354 }
355
356 #[doc(alias = "g_socket_get_timeout")]
357 #[doc(alias = "get_timeout")]
358 fn timeout(&self) -> u32 {
359 unsafe { ffi::g_socket_get_timeout(self.as_ref().to_glib_none().0) }
360 }
361
362 #[doc(alias = "g_socket_get_ttl")]
363 #[doc(alias = "get_ttl")]
364 fn ttl(&self) -> u32 {
365 unsafe { ffi::g_socket_get_ttl(self.as_ref().to_glib_none().0) }
366 }
367
368 #[doc(alias = "g_socket_is_closed")]
369 fn is_closed(&self) -> bool {
370 unsafe { from_glib(ffi::g_socket_is_closed(self.as_ref().to_glib_none().0)) }
371 }
372
373 #[doc(alias = "g_socket_is_connected")]
374 fn is_connected(&self) -> bool {
375 unsafe { from_glib(ffi::g_socket_is_connected(self.as_ref().to_glib_none().0)) }
376 }
377
378 #[doc(alias = "g_socket_join_multicast_group")]
379 fn join_multicast_group(
380 &self,
381 group: &impl IsA<InetAddress>,
382 source_specific: bool,
383 iface: Option<&str>,
384 ) -> Result<(), glib::Error> {
385 unsafe {
386 let mut error = std::ptr::null_mut();
387 let is_ok = ffi::g_socket_join_multicast_group(
388 self.as_ref().to_glib_none().0,
389 group.as_ref().to_glib_none().0,
390 source_specific.into_glib(),
391 iface.to_glib_none().0,
392 &mut error,
393 );
394 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
395 if error.is_null() {
396 Ok(())
397 } else {
398 Err(from_glib_full(error))
399 }
400 }
401 }
402
403 #[doc(alias = "g_socket_join_multicast_group_ssm")]
404 fn join_multicast_group_ssm(
405 &self,
406 group: &impl IsA<InetAddress>,
407 source_specific: Option<&impl IsA<InetAddress>>,
408 iface: Option<&str>,
409 ) -> Result<(), glib::Error> {
410 unsafe {
411 let mut error = std::ptr::null_mut();
412 let is_ok = ffi::g_socket_join_multicast_group_ssm(
413 self.as_ref().to_glib_none().0,
414 group.as_ref().to_glib_none().0,
415 source_specific.map(|p| p.as_ref()).to_glib_none().0,
416 iface.to_glib_none().0,
417 &mut error,
418 );
419 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
420 if error.is_null() {
421 Ok(())
422 } else {
423 Err(from_glib_full(error))
424 }
425 }
426 }
427
428 #[doc(alias = "g_socket_leave_multicast_group")]
429 fn leave_multicast_group(
430 &self,
431 group: &impl IsA<InetAddress>,
432 source_specific: bool,
433 iface: Option<&str>,
434 ) -> Result<(), glib::Error> {
435 unsafe {
436 let mut error = std::ptr::null_mut();
437 let is_ok = ffi::g_socket_leave_multicast_group(
438 self.as_ref().to_glib_none().0,
439 group.as_ref().to_glib_none().0,
440 source_specific.into_glib(),
441 iface.to_glib_none().0,
442 &mut error,
443 );
444 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
445 if error.is_null() {
446 Ok(())
447 } else {
448 Err(from_glib_full(error))
449 }
450 }
451 }
452
453 #[doc(alias = "g_socket_leave_multicast_group_ssm")]
454 fn leave_multicast_group_ssm(
455 &self,
456 group: &impl IsA<InetAddress>,
457 source_specific: Option<&impl IsA<InetAddress>>,
458 iface: Option<&str>,
459 ) -> Result<(), glib::Error> {
460 unsafe {
461 let mut error = std::ptr::null_mut();
462 let is_ok = ffi::g_socket_leave_multicast_group_ssm(
463 self.as_ref().to_glib_none().0,
464 group.as_ref().to_glib_none().0,
465 source_specific.map(|p| p.as_ref()).to_glib_none().0,
466 iface.to_glib_none().0,
467 &mut error,
468 );
469 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
470 if error.is_null() {
471 Ok(())
472 } else {
473 Err(from_glib_full(error))
474 }
475 }
476 }
477
478 #[doc(alias = "g_socket_listen")]
479 fn listen(&self) -> Result<(), glib::Error> {
480 unsafe {
481 let mut error = std::ptr::null_mut();
482 let is_ok = ffi::g_socket_listen(self.as_ref().to_glib_none().0, &mut error);
483 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
484 if error.is_null() {
485 Ok(())
486 } else {
487 Err(from_glib_full(error))
488 }
489 }
490 }
491
492 #[doc(alias = "g_socket_set_blocking")]
493 #[doc(alias = "blocking")]
494 fn set_blocking(&self, blocking: bool) {
495 unsafe {
496 ffi::g_socket_set_blocking(self.as_ref().to_glib_none().0, blocking.into_glib());
497 }
498 }
499
500 #[doc(alias = "g_socket_set_broadcast")]
501 #[doc(alias = "broadcast")]
502 fn set_broadcast(&self, broadcast: bool) {
503 unsafe {
504 ffi::g_socket_set_broadcast(self.as_ref().to_glib_none().0, broadcast.into_glib());
505 }
506 }
507
508 #[doc(alias = "g_socket_set_keepalive")]
509 #[doc(alias = "keepalive")]
510 fn set_keepalive(&self, keepalive: bool) {
511 unsafe {
512 ffi::g_socket_set_keepalive(self.as_ref().to_glib_none().0, keepalive.into_glib());
513 }
514 }
515
516 #[doc(alias = "g_socket_set_listen_backlog")]
517 #[doc(alias = "listen-backlog")]
518 fn set_listen_backlog(&self, backlog: i32) {
519 unsafe {
520 ffi::g_socket_set_listen_backlog(self.as_ref().to_glib_none().0, backlog);
521 }
522 }
523
524 #[doc(alias = "g_socket_set_multicast_loopback")]
525 #[doc(alias = "multicast-loopback")]
526 fn set_multicast_loopback(&self, loopback: bool) {
527 unsafe {
528 ffi::g_socket_set_multicast_loopback(
529 self.as_ref().to_glib_none().0,
530 loopback.into_glib(),
531 );
532 }
533 }
534
535 #[doc(alias = "g_socket_set_multicast_ttl")]
536 #[doc(alias = "multicast-ttl")]
537 fn set_multicast_ttl(&self, ttl: u32) {
538 unsafe {
539 ffi::g_socket_set_multicast_ttl(self.as_ref().to_glib_none().0, ttl);
540 }
541 }
542
543 #[doc(alias = "g_socket_set_option")]
544 fn set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error> {
545 unsafe {
546 let mut error = std::ptr::null_mut();
547 let is_ok = ffi::g_socket_set_option(
548 self.as_ref().to_glib_none().0,
549 level,
550 optname,
551 value,
552 &mut error,
553 );
554 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
555 if error.is_null() {
556 Ok(())
557 } else {
558 Err(from_glib_full(error))
559 }
560 }
561 }
562
563 #[doc(alias = "g_socket_set_timeout")]
564 #[doc(alias = "timeout")]
565 fn set_timeout(&self, timeout: u32) {
566 unsafe {
567 ffi::g_socket_set_timeout(self.as_ref().to_glib_none().0, timeout);
568 }
569 }
570
571 #[doc(alias = "g_socket_set_ttl")]
572 #[doc(alias = "ttl")]
573 fn set_ttl(&self, ttl: u32) {
574 unsafe {
575 ffi::g_socket_set_ttl(self.as_ref().to_glib_none().0, ttl);
576 }
577 }
578
579 #[doc(alias = "g_socket_shutdown")]
580 fn shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error> {
581 unsafe {
582 let mut error = std::ptr::null_mut();
583 let is_ok = ffi::g_socket_shutdown(
584 self.as_ref().to_glib_none().0,
585 shutdown_read.into_glib(),
586 shutdown_write.into_glib(),
587 &mut error,
588 );
589 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
590 if error.is_null() {
591 Ok(())
592 } else {
593 Err(from_glib_full(error))
594 }
595 }
596 }
597
598 #[doc(alias = "g_socket_speaks_ipv4")]
599 fn speaks_ipv4(&self) -> bool {
600 unsafe { from_glib(ffi::g_socket_speaks_ipv4(self.as_ref().to_glib_none().0)) }
601 }
602
603 #[doc(alias = "type")]
604 fn type_(&self) -> SocketType {
605 ObjectExt::property(self.as_ref(), "type")
606 }
607
608 #[doc(alias = "blocking")]
609 fn connect_blocking_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
610 unsafe extern "C" fn notify_blocking_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
611 this: *mut ffi::GSocket,
612 _param_spec: glib::ffi::gpointer,
613 f: glib::ffi::gpointer,
614 ) {
615 let f: &F = &*(f as *const F);
616 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
617 }
618 unsafe {
619 let f: Box_<F> = Box_::new(f);
620 connect_raw(
621 self.as_ptr() as *mut _,
622 b"notify::blocking\0".as_ptr() as *const _,
623 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
624 notify_blocking_trampoline::<Self, F> as *const (),
625 )),
626 Box_::into_raw(f),
627 )
628 }
629 }
630
631 #[doc(alias = "broadcast")]
632 fn connect_broadcast_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
633 unsafe extern "C" fn notify_broadcast_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
634 this: *mut ffi::GSocket,
635 _param_spec: glib::ffi::gpointer,
636 f: glib::ffi::gpointer,
637 ) {
638 let f: &F = &*(f as *const F);
639 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
640 }
641 unsafe {
642 let f: Box_<F> = Box_::new(f);
643 connect_raw(
644 self.as_ptr() as *mut _,
645 b"notify::broadcast\0".as_ptr() as *const _,
646 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
647 notify_broadcast_trampoline::<Self, F> as *const (),
648 )),
649 Box_::into_raw(f),
650 )
651 }
652 }
653
654 #[doc(alias = "keepalive")]
655 fn connect_keepalive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
656 unsafe extern "C" fn notify_keepalive_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
657 this: *mut ffi::GSocket,
658 _param_spec: glib::ffi::gpointer,
659 f: glib::ffi::gpointer,
660 ) {
661 let f: &F = &*(f as *const F);
662 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
663 }
664 unsafe {
665 let f: Box_<F> = Box_::new(f);
666 connect_raw(
667 self.as_ptr() as *mut _,
668 b"notify::keepalive\0".as_ptr() as *const _,
669 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
670 notify_keepalive_trampoline::<Self, F> as *const (),
671 )),
672 Box_::into_raw(f),
673 )
674 }
675 }
676
677 #[doc(alias = "listen-backlog")]
678 fn connect_listen_backlog_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
679 unsafe extern "C" fn notify_listen_backlog_trampoline<
680 P: IsA<Socket>,
681 F: Fn(&P) + 'static,
682 >(
683 this: *mut ffi::GSocket,
684 _param_spec: glib::ffi::gpointer,
685 f: glib::ffi::gpointer,
686 ) {
687 let f: &F = &*(f as *const F);
688 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
689 }
690 unsafe {
691 let f: Box_<F> = Box_::new(f);
692 connect_raw(
693 self.as_ptr() as *mut _,
694 b"notify::listen-backlog\0".as_ptr() as *const _,
695 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
696 notify_listen_backlog_trampoline::<Self, F> as *const (),
697 )),
698 Box_::into_raw(f),
699 )
700 }
701 }
702
703 #[doc(alias = "local-address")]
704 fn connect_local_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
705 unsafe extern "C" fn notify_local_address_trampoline<
706 P: IsA<Socket>,
707 F: Fn(&P) + 'static,
708 >(
709 this: *mut ffi::GSocket,
710 _param_spec: glib::ffi::gpointer,
711 f: glib::ffi::gpointer,
712 ) {
713 let f: &F = &*(f as *const F);
714 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
715 }
716 unsafe {
717 let f: Box_<F> = Box_::new(f);
718 connect_raw(
719 self.as_ptr() as *mut _,
720 b"notify::local-address\0".as_ptr() as *const _,
721 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
722 notify_local_address_trampoline::<Self, F> as *const (),
723 )),
724 Box_::into_raw(f),
725 )
726 }
727 }
728
729 #[doc(alias = "multicast-loopback")]
730 fn connect_multicast_loopback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
731 unsafe extern "C" fn notify_multicast_loopback_trampoline<
732 P: IsA<Socket>,
733 F: Fn(&P) + 'static,
734 >(
735 this: *mut ffi::GSocket,
736 _param_spec: glib::ffi::gpointer,
737 f: glib::ffi::gpointer,
738 ) {
739 let f: &F = &*(f as *const F);
740 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
741 }
742 unsafe {
743 let f: Box_<F> = Box_::new(f);
744 connect_raw(
745 self.as_ptr() as *mut _,
746 b"notify::multicast-loopback\0".as_ptr() as *const _,
747 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
748 notify_multicast_loopback_trampoline::<Self, F> as *const (),
749 )),
750 Box_::into_raw(f),
751 )
752 }
753 }
754
755 #[doc(alias = "multicast-ttl")]
756 fn connect_multicast_ttl_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
757 unsafe extern "C" fn notify_multicast_ttl_trampoline<
758 P: IsA<Socket>,
759 F: Fn(&P) + 'static,
760 >(
761 this: *mut ffi::GSocket,
762 _param_spec: glib::ffi::gpointer,
763 f: glib::ffi::gpointer,
764 ) {
765 let f: &F = &*(f as *const F);
766 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
767 }
768 unsafe {
769 let f: Box_<F> = Box_::new(f);
770 connect_raw(
771 self.as_ptr() as *mut _,
772 b"notify::multicast-ttl\0".as_ptr() as *const _,
773 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
774 notify_multicast_ttl_trampoline::<Self, F> as *const (),
775 )),
776 Box_::into_raw(f),
777 )
778 }
779 }
780
781 #[doc(alias = "remote-address")]
782 fn connect_remote_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
783 unsafe extern "C" fn notify_remote_address_trampoline<
784 P: IsA<Socket>,
785 F: Fn(&P) + 'static,
786 >(
787 this: *mut ffi::GSocket,
788 _param_spec: glib::ffi::gpointer,
789 f: glib::ffi::gpointer,
790 ) {
791 let f: &F = &*(f as *const F);
792 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
793 }
794 unsafe {
795 let f: Box_<F> = Box_::new(f);
796 connect_raw(
797 self.as_ptr() as *mut _,
798 b"notify::remote-address\0".as_ptr() as *const _,
799 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
800 notify_remote_address_trampoline::<Self, F> as *const (),
801 )),
802 Box_::into_raw(f),
803 )
804 }
805 }
806
807 #[doc(alias = "timeout")]
808 fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
809 unsafe extern "C" fn notify_timeout_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
810 this: *mut ffi::GSocket,
811 _param_spec: glib::ffi::gpointer,
812 f: glib::ffi::gpointer,
813 ) {
814 let f: &F = &*(f as *const F);
815 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
816 }
817 unsafe {
818 let f: Box_<F> = Box_::new(f);
819 connect_raw(
820 self.as_ptr() as *mut _,
821 b"notify::timeout\0".as_ptr() as *const _,
822 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
823 notify_timeout_trampoline::<Self, F> as *const (),
824 )),
825 Box_::into_raw(f),
826 )
827 }
828 }
829
830 #[doc(alias = "ttl")]
831 fn connect_ttl_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
832 unsafe extern "C" fn notify_ttl_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
833 this: *mut ffi::GSocket,
834 _param_spec: glib::ffi::gpointer,
835 f: glib::ffi::gpointer,
836 ) {
837 let f: &F = &*(f as *const F);
838 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
839 }
840 unsafe {
841 let f: Box_<F> = Box_::new(f);
842 connect_raw(
843 self.as_ptr() as *mut _,
844 b"notify::ttl\0".as_ptr() as *const _,
845 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
846 notify_ttl_trampoline::<Self, F> as *const (),
847 )),
848 Box_::into_raw(f),
849 )
850 }
851 }
852}
853
854impl<O: IsA<Socket>> SocketExt for O {}