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
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 let f: &F = &*(f as *const F);
611 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
612 }
613 unsafe {
614 let f: Box_<F> = Box_::new(f);
615 connect_raw(
616 self.as_ptr() as *mut _,
617 c"notify::blocking".as_ptr() as *const _,
618 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
619 notify_blocking_trampoline::<Self, F> as *const (),
620 )),
621 Box_::into_raw(f),
622 )
623 }
624 }
625
626 #[doc(alias = "broadcast")]
627 fn connect_broadcast_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
628 unsafe extern "C" fn notify_broadcast_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
629 this: *mut ffi::GSocket,
630 _param_spec: glib::ffi::gpointer,
631 f: glib::ffi::gpointer,
632 ) {
633 let f: &F = &*(f as *const F);
634 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
635 }
636 unsafe {
637 let f: Box_<F> = Box_::new(f);
638 connect_raw(
639 self.as_ptr() as *mut _,
640 c"notify::broadcast".as_ptr() as *const _,
641 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
642 notify_broadcast_trampoline::<Self, F> as *const (),
643 )),
644 Box_::into_raw(f),
645 )
646 }
647 }
648
649 #[doc(alias = "keepalive")]
650 fn connect_keepalive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
651 unsafe extern "C" fn notify_keepalive_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
652 this: *mut ffi::GSocket,
653 _param_spec: glib::ffi::gpointer,
654 f: glib::ffi::gpointer,
655 ) {
656 let f: &F = &*(f as *const F);
657 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
658 }
659 unsafe {
660 let f: Box_<F> = Box_::new(f);
661 connect_raw(
662 self.as_ptr() as *mut _,
663 c"notify::keepalive".as_ptr() as *const _,
664 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
665 notify_keepalive_trampoline::<Self, F> as *const (),
666 )),
667 Box_::into_raw(f),
668 )
669 }
670 }
671
672 #[doc(alias = "listen-backlog")]
673 fn connect_listen_backlog_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
674 unsafe extern "C" fn notify_listen_backlog_trampoline<
675 P: IsA<Socket>,
676 F: Fn(&P) + 'static,
677 >(
678 this: *mut ffi::GSocket,
679 _param_spec: glib::ffi::gpointer,
680 f: glib::ffi::gpointer,
681 ) {
682 let f: &F = &*(f as *const F);
683 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
684 }
685 unsafe {
686 let f: Box_<F> = Box_::new(f);
687 connect_raw(
688 self.as_ptr() as *mut _,
689 c"notify::listen-backlog".as_ptr() as *const _,
690 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
691 notify_listen_backlog_trampoline::<Self, F> as *const (),
692 )),
693 Box_::into_raw(f),
694 )
695 }
696 }
697
698 #[doc(alias = "local-address")]
699 fn connect_local_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
700 unsafe extern "C" fn notify_local_address_trampoline<
701 P: IsA<Socket>,
702 F: Fn(&P) + 'static,
703 >(
704 this: *mut ffi::GSocket,
705 _param_spec: glib::ffi::gpointer,
706 f: glib::ffi::gpointer,
707 ) {
708 let f: &F = &*(f as *const F);
709 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
710 }
711 unsafe {
712 let f: Box_<F> = Box_::new(f);
713 connect_raw(
714 self.as_ptr() as *mut _,
715 c"notify::local-address".as_ptr() as *const _,
716 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
717 notify_local_address_trampoline::<Self, F> as *const (),
718 )),
719 Box_::into_raw(f),
720 )
721 }
722 }
723
724 #[doc(alias = "multicast-loopback")]
725 fn connect_multicast_loopback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
726 unsafe extern "C" fn notify_multicast_loopback_trampoline<
727 P: IsA<Socket>,
728 F: Fn(&P) + 'static,
729 >(
730 this: *mut ffi::GSocket,
731 _param_spec: glib::ffi::gpointer,
732 f: glib::ffi::gpointer,
733 ) {
734 let f: &F = &*(f as *const F);
735 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
736 }
737 unsafe {
738 let f: Box_<F> = Box_::new(f);
739 connect_raw(
740 self.as_ptr() as *mut _,
741 c"notify::multicast-loopback".as_ptr() as *const _,
742 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
743 notify_multicast_loopback_trampoline::<Self, F> as *const (),
744 )),
745 Box_::into_raw(f),
746 )
747 }
748 }
749
750 #[doc(alias = "multicast-ttl")]
751 fn connect_multicast_ttl_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
752 unsafe extern "C" fn notify_multicast_ttl_trampoline<
753 P: IsA<Socket>,
754 F: Fn(&P) + 'static,
755 >(
756 this: *mut ffi::GSocket,
757 _param_spec: glib::ffi::gpointer,
758 f: glib::ffi::gpointer,
759 ) {
760 let f: &F = &*(f as *const F);
761 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
762 }
763 unsafe {
764 let f: Box_<F> = Box_::new(f);
765 connect_raw(
766 self.as_ptr() as *mut _,
767 c"notify::multicast-ttl".as_ptr() as *const _,
768 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
769 notify_multicast_ttl_trampoline::<Self, F> as *const (),
770 )),
771 Box_::into_raw(f),
772 )
773 }
774 }
775
776 #[doc(alias = "remote-address")]
777 fn connect_remote_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
778 unsafe extern "C" fn notify_remote_address_trampoline<
779 P: IsA<Socket>,
780 F: Fn(&P) + 'static,
781 >(
782 this: *mut ffi::GSocket,
783 _param_spec: glib::ffi::gpointer,
784 f: glib::ffi::gpointer,
785 ) {
786 let f: &F = &*(f as *const F);
787 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
788 }
789 unsafe {
790 let f: Box_<F> = Box_::new(f);
791 connect_raw(
792 self.as_ptr() as *mut _,
793 c"notify::remote-address".as_ptr() as *const _,
794 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
795 notify_remote_address_trampoline::<Self, F> as *const (),
796 )),
797 Box_::into_raw(f),
798 )
799 }
800 }
801
802 #[doc(alias = "timeout")]
803 fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
804 unsafe extern "C" fn notify_timeout_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
805 this: *mut ffi::GSocket,
806 _param_spec: glib::ffi::gpointer,
807 f: glib::ffi::gpointer,
808 ) {
809 let f: &F = &*(f as *const F);
810 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
811 }
812 unsafe {
813 let f: Box_<F> = Box_::new(f);
814 connect_raw(
815 self.as_ptr() as *mut _,
816 c"notify::timeout".as_ptr() as *const _,
817 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
818 notify_timeout_trampoline::<Self, F> as *const (),
819 )),
820 Box_::into_raw(f),
821 )
822 }
823 }
824
825 #[doc(alias = "ttl")]
826 fn connect_ttl_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
827 unsafe extern "C" fn notify_ttl_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
828 this: *mut ffi::GSocket,
829 _param_spec: glib::ffi::gpointer,
830 f: glib::ffi::gpointer,
831 ) {
832 let f: &F = &*(f as *const F);
833 f(Socket::from_glib_borrow(this).unsafe_cast_ref())
834 }
835 unsafe {
836 let f: Box_<F> = Box_::new(f);
837 connect_raw(
838 self.as_ptr() as *mut _,
839 c"notify::ttl".as_ptr() as *const _,
840 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
841 notify_ttl_trampoline::<Self, F> as *const (),
842 )),
843 Box_::into_raw(f),
844 )
845 }
846 }
847}
848
849impl<O: IsA<Socket>> SocketExt for O {}