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