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 crate::Cancellable; 6 use crate::Credentials; 7 use crate::InetAddress; 8 use crate::Initable; 9 use crate::SocketAddress; 10 use crate::SocketConnection; 11 use crate::SocketFamily; 12 use crate::SocketProtocol; 13 use crate::SocketType; 14 use glib::object::Cast; 15 use glib::object::IsA; 16 use glib::signal::connect_raw; 17 use glib::signal::SignalHandlerId; 18 use glib::translate::*; 19 use glib::ObjectExt; 20 use glib::StaticType; 21 use std::boxed::Box as Box_; 22 use std::fmt; 23 use std::mem; 24 use std::mem::transmute; 25 use std::ptr; 26 27 glib::wrapper! { 28 #[doc(alias = "GSocket")] 29 pub struct Socket(Object<ffi::GSocket, ffi::GSocketClass>) @implements Initable; 30 31 match fn { 32 type_ => || ffi::g_socket_get_type(), 33 } 34 } 35 36 impl Socket { 37 #[doc(alias = "g_socket_new")] new( family: SocketFamily, type_: SocketType, protocol: SocketProtocol, ) -> Result<Socket, glib::Error>38 pub fn new( 39 family: SocketFamily, 40 type_: SocketType, 41 protocol: SocketProtocol, 42 ) -> Result<Socket, glib::Error> { 43 unsafe { 44 let mut error = ptr::null_mut(); 45 let ret = ffi::g_socket_new( 46 family.into_glib(), 47 type_.into_glib(), 48 protocol.into_glib(), 49 &mut error, 50 ); 51 if error.is_null() { 52 Ok(from_glib_full(ret)) 53 } else { 54 Err(from_glib_full(error)) 55 } 56 } 57 } 58 } 59 60 unsafe impl glib::SendUnique for Socket { is_unique(&self) -> bool61 fn is_unique(&self) -> bool { 62 self.ref_count() == 1 63 } 64 } 65 66 pub const NONE_SOCKET: Option<&Socket> = None; 67 68 pub trait SocketExt: 'static { 69 #[doc(alias = "g_socket_accept")] accept<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<Socket, glib::Error>70 fn accept<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<Socket, glib::Error>; 71 72 #[doc(alias = "g_socket_bind")] 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 79 #[doc(alias = "g_socket_check_connect_result")] check_connect_result(&self) -> Result<(), glib::Error>80 fn check_connect_result(&self) -> Result<(), glib::Error>; 81 82 #[doc(alias = "g_socket_close")] close(&self) -> Result<(), glib::Error>83 fn close(&self) -> Result<(), glib::Error>; 84 85 #[doc(alias = "g_socket_condition_check")] condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition86 fn condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition; 87 88 #[doc(alias = "g_socket_condition_timed_wait")] condition_timed_wait<P: IsA<Cancellable>>( &self, condition: glib::IOCondition, timeout_us: i64, cancellable: Option<&P>, ) -> Result<(), glib::Error>89 fn condition_timed_wait<P: IsA<Cancellable>>( 90 &self, 91 condition: glib::IOCondition, 92 timeout_us: i64, 93 cancellable: Option<&P>, 94 ) -> Result<(), glib::Error>; 95 96 #[doc(alias = "g_socket_condition_wait")] condition_wait<P: IsA<Cancellable>>( &self, condition: glib::IOCondition, cancellable: Option<&P>, ) -> Result<(), glib::Error>97 fn condition_wait<P: IsA<Cancellable>>( 98 &self, 99 condition: glib::IOCondition, 100 cancellable: Option<&P>, 101 ) -> Result<(), glib::Error>; 102 103 #[doc(alias = "g_socket_connect")] connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( &self, address: &P, cancellable: Option<&Q>, ) -> Result<(), glib::Error>104 fn connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( 105 &self, 106 address: &P, 107 cancellable: Option<&Q>, 108 ) -> Result<(), glib::Error>; 109 110 #[doc(alias = "g_socket_connection_factory_create_connection")] connection_factory_create_connection(&self) -> SocketConnection111 fn connection_factory_create_connection(&self) -> SocketConnection; 112 113 #[doc(alias = "g_socket_get_available_bytes")] 114 #[doc(alias = "get_available_bytes")] available_bytes(&self) -> isize115 fn available_bytes(&self) -> isize; 116 117 #[doc(alias = "g_socket_get_blocking")] 118 #[doc(alias = "get_blocking")] is_blocking(&self) -> bool119 fn is_blocking(&self) -> bool; 120 121 #[doc(alias = "g_socket_get_broadcast")] 122 #[doc(alias = "get_broadcast")] is_broadcast(&self) -> bool123 fn is_broadcast(&self) -> bool; 124 125 #[doc(alias = "g_socket_get_credentials")] 126 #[doc(alias = "get_credentials")] credentials(&self) -> Result<Credentials, glib::Error>127 fn credentials(&self) -> Result<Credentials, glib::Error>; 128 129 #[doc(alias = "g_socket_get_family")] 130 #[doc(alias = "get_family")] family(&self) -> SocketFamily131 fn family(&self) -> SocketFamily; 132 133 #[doc(alias = "g_socket_get_keepalive")] 134 #[doc(alias = "get_keepalive")] is_keepalive(&self) -> bool135 fn is_keepalive(&self) -> bool; 136 137 #[doc(alias = "g_socket_get_listen_backlog")] 138 #[doc(alias = "get_listen_backlog")] listen_backlog(&self) -> i32139 fn listen_backlog(&self) -> i32; 140 141 #[doc(alias = "g_socket_get_local_address")] 142 #[doc(alias = "get_local_address")] local_address(&self) -> Result<SocketAddress, glib::Error>143 fn local_address(&self) -> Result<SocketAddress, glib::Error>; 144 145 #[doc(alias = "g_socket_get_multicast_loopback")] 146 #[doc(alias = "get_multicast_loopback")] is_multicast_loopback(&self) -> bool147 fn is_multicast_loopback(&self) -> bool; 148 149 #[doc(alias = "g_socket_get_multicast_ttl")] 150 #[doc(alias = "get_multicast_ttl")] multicast_ttl(&self) -> u32151 fn multicast_ttl(&self) -> u32; 152 153 #[doc(alias = "g_socket_get_option")] 154 #[doc(alias = "get_option")] option(&self, level: i32, optname: i32) -> Result<i32, glib::Error>155 fn option(&self, level: i32, optname: i32) -> Result<i32, glib::Error>; 156 157 #[doc(alias = "g_socket_get_protocol")] 158 #[doc(alias = "get_protocol")] protocol(&self) -> SocketProtocol159 fn protocol(&self) -> SocketProtocol; 160 161 #[doc(alias = "g_socket_get_remote_address")] 162 #[doc(alias = "get_remote_address")] remote_address(&self) -> Result<SocketAddress, glib::Error>163 fn remote_address(&self) -> Result<SocketAddress, glib::Error>; 164 165 #[doc(alias = "g_socket_get_socket_type")] 166 #[doc(alias = "get_socket_type")] socket_type(&self) -> SocketType167 fn socket_type(&self) -> SocketType; 168 169 #[doc(alias = "g_socket_get_timeout")] 170 #[doc(alias = "get_timeout")] timeout(&self) -> u32171 fn timeout(&self) -> u32; 172 173 #[doc(alias = "g_socket_get_ttl")] 174 #[doc(alias = "get_ttl")] ttl(&self) -> u32175 fn ttl(&self) -> u32; 176 177 #[doc(alias = "g_socket_is_closed")] is_closed(&self) -> bool178 fn is_closed(&self) -> bool; 179 180 #[doc(alias = "g_socket_is_connected")] is_connected(&self) -> bool181 fn is_connected(&self) -> bool; 182 183 #[doc(alias = "g_socket_join_multicast_group")] join_multicast_group<P: IsA<InetAddress>>( &self, group: &P, source_specific: bool, iface: Option<&str>, ) -> Result<(), glib::Error>184 fn join_multicast_group<P: IsA<InetAddress>>( 185 &self, 186 group: &P, 187 source_specific: bool, 188 iface: Option<&str>, 189 ) -> Result<(), glib::Error>; 190 191 #[cfg(any(feature = "v2_56", feature = "dox"))] 192 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))] 193 #[doc(alias = "g_socket_join_multicast_group_ssm")] join_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( &self, group: &P, source_specific: Option<&Q>, iface: Option<&str>, ) -> Result<(), glib::Error>194 fn join_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( 195 &self, 196 group: &P, 197 source_specific: Option<&Q>, 198 iface: Option<&str>, 199 ) -> Result<(), glib::Error>; 200 201 #[doc(alias = "g_socket_leave_multicast_group")] leave_multicast_group<P: IsA<InetAddress>>( &self, group: &P, source_specific: bool, iface: Option<&str>, ) -> Result<(), glib::Error>202 fn leave_multicast_group<P: IsA<InetAddress>>( 203 &self, 204 group: &P, 205 source_specific: bool, 206 iface: Option<&str>, 207 ) -> Result<(), glib::Error>; 208 209 #[cfg(any(feature = "v2_56", feature = "dox"))] 210 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))] 211 #[doc(alias = "g_socket_leave_multicast_group_ssm")] leave_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( &self, group: &P, source_specific: Option<&Q>, iface: Option<&str>, ) -> Result<(), glib::Error>212 fn leave_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( 213 &self, 214 group: &P, 215 source_specific: Option<&Q>, 216 iface: Option<&str>, 217 ) -> Result<(), glib::Error>; 218 219 #[doc(alias = "g_socket_listen")] listen(&self) -> Result<(), glib::Error>220 fn listen(&self) -> Result<(), glib::Error>; 221 222 #[doc(alias = "g_socket_set_blocking")] set_blocking(&self, blocking: bool)223 fn set_blocking(&self, blocking: bool); 224 225 #[doc(alias = "g_socket_set_broadcast")] set_broadcast(&self, broadcast: bool)226 fn set_broadcast(&self, broadcast: bool); 227 228 #[doc(alias = "g_socket_set_keepalive")] set_keepalive(&self, keepalive: bool)229 fn set_keepalive(&self, keepalive: bool); 230 231 #[doc(alias = "g_socket_set_listen_backlog")] set_listen_backlog(&self, backlog: i32)232 fn set_listen_backlog(&self, backlog: i32); 233 234 #[doc(alias = "g_socket_set_multicast_loopback")] set_multicast_loopback(&self, loopback: bool)235 fn set_multicast_loopback(&self, loopback: bool); 236 237 #[doc(alias = "g_socket_set_multicast_ttl")] set_multicast_ttl(&self, ttl: u32)238 fn set_multicast_ttl(&self, ttl: u32); 239 240 #[doc(alias = "g_socket_set_option")] set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error>241 fn set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error>; 242 243 #[doc(alias = "g_socket_set_timeout")] set_timeout(&self, timeout: u32)244 fn set_timeout(&self, timeout: u32); 245 246 #[doc(alias = "g_socket_set_ttl")] set_ttl(&self, ttl: u32)247 fn set_ttl(&self, ttl: u32); 248 249 #[doc(alias = "g_socket_shutdown")] shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error>250 fn shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error>; 251 252 #[doc(alias = "g_socket_speaks_ipv4")] speaks_ipv4(&self) -> bool253 fn speaks_ipv4(&self) -> bool; 254 255 #[doc(alias = "type")] type_(&self) -> SocketType256 fn type_(&self) -> SocketType; 257 258 #[doc(alias = "blocking")] connect_blocking_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId259 fn connect_blocking_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId; 260 261 #[doc(alias = "broadcast")] connect_broadcast_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId262 fn connect_broadcast_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId; 263 264 #[doc(alias = "keepalive")] connect_keepalive_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId265 fn connect_keepalive_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId; 266 267 #[doc(alias = "listen-backlog")] connect_listen_backlog_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId268 fn connect_listen_backlog_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) 269 -> SignalHandlerId; 270 271 #[doc(alias = "local-address")] connect_local_address_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId272 fn connect_local_address_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId; 273 274 #[doc(alias = "multicast-loopback")] connect_multicast_loopback_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId275 fn connect_multicast_loopback_notify<F: Fn(&Self) + Send + 'static>( 276 &self, 277 f: F, 278 ) -> SignalHandlerId; 279 280 #[doc(alias = "multicast-ttl")] connect_multicast_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId281 fn connect_multicast_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId; 282 283 #[doc(alias = "remote-address")] connect_remote_address_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId284 fn connect_remote_address_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) 285 -> SignalHandlerId; 286 287 #[doc(alias = "timeout")] connect_timeout_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId288 fn connect_timeout_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId; 289 290 #[doc(alias = "ttl")] connect_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId291 fn connect_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId; 292 } 293 294 impl<O: IsA<Socket>> SocketExt for O { accept<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<Socket, glib::Error>295 fn accept<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<Socket, glib::Error> { 296 unsafe { 297 let mut error = ptr::null_mut(); 298 let ret = ffi::g_socket_accept( 299 self.as_ref().to_glib_none().0, 300 cancellable.map(|p| p.as_ref()).to_glib_none().0, 301 &mut error, 302 ); 303 if error.is_null() { 304 Ok(from_glib_full(ret)) 305 } else { 306 Err(from_glib_full(error)) 307 } 308 } 309 } 310 bind<P: IsA<SocketAddress>>( &self, address: &P, allow_reuse: bool, ) -> Result<(), glib::Error>311 fn bind<P: IsA<SocketAddress>>( 312 &self, 313 address: &P, 314 allow_reuse: bool, 315 ) -> Result<(), glib::Error> { 316 unsafe { 317 let mut error = ptr::null_mut(); 318 let _ = ffi::g_socket_bind( 319 self.as_ref().to_glib_none().0, 320 address.as_ref().to_glib_none().0, 321 allow_reuse.into_glib(), 322 &mut error, 323 ); 324 if error.is_null() { 325 Ok(()) 326 } else { 327 Err(from_glib_full(error)) 328 } 329 } 330 } 331 check_connect_result(&self) -> Result<(), glib::Error>332 fn check_connect_result(&self) -> Result<(), glib::Error> { 333 unsafe { 334 let mut error = ptr::null_mut(); 335 let _ = ffi::g_socket_check_connect_result(self.as_ref().to_glib_none().0, &mut error); 336 if error.is_null() { 337 Ok(()) 338 } else { 339 Err(from_glib_full(error)) 340 } 341 } 342 } 343 close(&self) -> Result<(), glib::Error>344 fn close(&self) -> Result<(), glib::Error> { 345 unsafe { 346 let mut error = ptr::null_mut(); 347 let _ = ffi::g_socket_close(self.as_ref().to_glib_none().0, &mut error); 348 if error.is_null() { 349 Ok(()) 350 } else { 351 Err(from_glib_full(error)) 352 } 353 } 354 } 355 condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition356 fn condition_check(&self, condition: glib::IOCondition) -> glib::IOCondition { 357 unsafe { 358 from_glib(ffi::g_socket_condition_check( 359 self.as_ref().to_glib_none().0, 360 condition.into_glib(), 361 )) 362 } 363 } 364 condition_timed_wait<P: IsA<Cancellable>>( &self, condition: glib::IOCondition, timeout_us: i64, cancellable: Option<&P>, ) -> Result<(), glib::Error>365 fn condition_timed_wait<P: IsA<Cancellable>>( 366 &self, 367 condition: glib::IOCondition, 368 timeout_us: i64, 369 cancellable: Option<&P>, 370 ) -> Result<(), glib::Error> { 371 unsafe { 372 let mut error = ptr::null_mut(); 373 let _ = ffi::g_socket_condition_timed_wait( 374 self.as_ref().to_glib_none().0, 375 condition.into_glib(), 376 timeout_us, 377 cancellable.map(|p| p.as_ref()).to_glib_none().0, 378 &mut error, 379 ); 380 if error.is_null() { 381 Ok(()) 382 } else { 383 Err(from_glib_full(error)) 384 } 385 } 386 } 387 condition_wait<P: IsA<Cancellable>>( &self, condition: glib::IOCondition, cancellable: Option<&P>, ) -> Result<(), glib::Error>388 fn condition_wait<P: IsA<Cancellable>>( 389 &self, 390 condition: glib::IOCondition, 391 cancellable: Option<&P>, 392 ) -> Result<(), glib::Error> { 393 unsafe { 394 let mut error = ptr::null_mut(); 395 let _ = ffi::g_socket_condition_wait( 396 self.as_ref().to_glib_none().0, 397 condition.into_glib(), 398 cancellable.map(|p| p.as_ref()).to_glib_none().0, 399 &mut error, 400 ); 401 if error.is_null() { 402 Ok(()) 403 } else { 404 Err(from_glib_full(error)) 405 } 406 } 407 } 408 connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( &self, address: &P, cancellable: Option<&Q>, ) -> Result<(), glib::Error>409 fn connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( 410 &self, 411 address: &P, 412 cancellable: Option<&Q>, 413 ) -> Result<(), glib::Error> { 414 unsafe { 415 let mut error = ptr::null_mut(); 416 let _ = ffi::g_socket_connect( 417 self.as_ref().to_glib_none().0, 418 address.as_ref().to_glib_none().0, 419 cancellable.map(|p| p.as_ref()).to_glib_none().0, 420 &mut error, 421 ); 422 if error.is_null() { 423 Ok(()) 424 } else { 425 Err(from_glib_full(error)) 426 } 427 } 428 } 429 connection_factory_create_connection(&self) -> SocketConnection430 fn connection_factory_create_connection(&self) -> SocketConnection { 431 unsafe { 432 from_glib_full(ffi::g_socket_connection_factory_create_connection( 433 self.as_ref().to_glib_none().0, 434 )) 435 } 436 } 437 available_bytes(&self) -> isize438 fn available_bytes(&self) -> isize { 439 unsafe { ffi::g_socket_get_available_bytes(self.as_ref().to_glib_none().0) } 440 } 441 is_blocking(&self) -> bool442 fn is_blocking(&self) -> bool { 443 unsafe { from_glib(ffi::g_socket_get_blocking(self.as_ref().to_glib_none().0)) } 444 } 445 is_broadcast(&self) -> bool446 fn is_broadcast(&self) -> bool { 447 unsafe { from_glib(ffi::g_socket_get_broadcast(self.as_ref().to_glib_none().0)) } 448 } 449 credentials(&self) -> Result<Credentials, glib::Error>450 fn credentials(&self) -> Result<Credentials, glib::Error> { 451 unsafe { 452 let mut error = ptr::null_mut(); 453 let ret = ffi::g_socket_get_credentials(self.as_ref().to_glib_none().0, &mut error); 454 if error.is_null() { 455 Ok(from_glib_full(ret)) 456 } else { 457 Err(from_glib_full(error)) 458 } 459 } 460 } 461 family(&self) -> SocketFamily462 fn family(&self) -> SocketFamily { 463 unsafe { from_glib(ffi::g_socket_get_family(self.as_ref().to_glib_none().0)) } 464 } 465 is_keepalive(&self) -> bool466 fn is_keepalive(&self) -> bool { 467 unsafe { from_glib(ffi::g_socket_get_keepalive(self.as_ref().to_glib_none().0)) } 468 } 469 listen_backlog(&self) -> i32470 fn listen_backlog(&self) -> i32 { 471 unsafe { ffi::g_socket_get_listen_backlog(self.as_ref().to_glib_none().0) } 472 } 473 local_address(&self) -> Result<SocketAddress, glib::Error>474 fn local_address(&self) -> Result<SocketAddress, glib::Error> { 475 unsafe { 476 let mut error = ptr::null_mut(); 477 let ret = ffi::g_socket_get_local_address(self.as_ref().to_glib_none().0, &mut error); 478 if error.is_null() { 479 Ok(from_glib_full(ret)) 480 } else { 481 Err(from_glib_full(error)) 482 } 483 } 484 } 485 is_multicast_loopback(&self) -> bool486 fn is_multicast_loopback(&self) -> bool { 487 unsafe { 488 from_glib(ffi::g_socket_get_multicast_loopback( 489 self.as_ref().to_glib_none().0, 490 )) 491 } 492 } 493 multicast_ttl(&self) -> u32494 fn multicast_ttl(&self) -> u32 { 495 unsafe { ffi::g_socket_get_multicast_ttl(self.as_ref().to_glib_none().0) } 496 } 497 option(&self, level: i32, optname: i32) -> Result<i32, glib::Error>498 fn option(&self, level: i32, optname: i32) -> Result<i32, glib::Error> { 499 unsafe { 500 let mut value = mem::MaybeUninit::uninit(); 501 let mut error = ptr::null_mut(); 502 let _ = ffi::g_socket_get_option( 503 self.as_ref().to_glib_none().0, 504 level, 505 optname, 506 value.as_mut_ptr(), 507 &mut error, 508 ); 509 let value = value.assume_init(); 510 if error.is_null() { 511 Ok(value) 512 } else { 513 Err(from_glib_full(error)) 514 } 515 } 516 } 517 protocol(&self) -> SocketProtocol518 fn protocol(&self) -> SocketProtocol { 519 unsafe { from_glib(ffi::g_socket_get_protocol(self.as_ref().to_glib_none().0)) } 520 } 521 remote_address(&self) -> Result<SocketAddress, glib::Error>522 fn remote_address(&self) -> Result<SocketAddress, glib::Error> { 523 unsafe { 524 let mut error = ptr::null_mut(); 525 let ret = ffi::g_socket_get_remote_address(self.as_ref().to_glib_none().0, &mut error); 526 if error.is_null() { 527 Ok(from_glib_full(ret)) 528 } else { 529 Err(from_glib_full(error)) 530 } 531 } 532 } 533 socket_type(&self) -> SocketType534 fn socket_type(&self) -> SocketType { 535 unsafe { 536 from_glib(ffi::g_socket_get_socket_type( 537 self.as_ref().to_glib_none().0, 538 )) 539 } 540 } 541 timeout(&self) -> u32542 fn timeout(&self) -> u32 { 543 unsafe { ffi::g_socket_get_timeout(self.as_ref().to_glib_none().0) } 544 } 545 ttl(&self) -> u32546 fn ttl(&self) -> u32 { 547 unsafe { ffi::g_socket_get_ttl(self.as_ref().to_glib_none().0) } 548 } 549 is_closed(&self) -> bool550 fn is_closed(&self) -> bool { 551 unsafe { from_glib(ffi::g_socket_is_closed(self.as_ref().to_glib_none().0)) } 552 } 553 is_connected(&self) -> bool554 fn is_connected(&self) -> bool { 555 unsafe { from_glib(ffi::g_socket_is_connected(self.as_ref().to_glib_none().0)) } 556 } 557 join_multicast_group<P: IsA<InetAddress>>( &self, group: &P, source_specific: bool, iface: Option<&str>, ) -> Result<(), glib::Error>558 fn join_multicast_group<P: IsA<InetAddress>>( 559 &self, 560 group: &P, 561 source_specific: bool, 562 iface: Option<&str>, 563 ) -> Result<(), glib::Error> { 564 unsafe { 565 let mut error = ptr::null_mut(); 566 let _ = ffi::g_socket_join_multicast_group( 567 self.as_ref().to_glib_none().0, 568 group.as_ref().to_glib_none().0, 569 source_specific.into_glib(), 570 iface.to_glib_none().0, 571 &mut error, 572 ); 573 if error.is_null() { 574 Ok(()) 575 } else { 576 Err(from_glib_full(error)) 577 } 578 } 579 } 580 581 #[cfg(any(feature = "v2_56", feature = "dox"))] 582 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))] join_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( &self, group: &P, source_specific: Option<&Q>, iface: Option<&str>, ) -> Result<(), glib::Error>583 fn join_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( 584 &self, 585 group: &P, 586 source_specific: Option<&Q>, 587 iface: Option<&str>, 588 ) -> Result<(), glib::Error> { 589 unsafe { 590 let mut error = ptr::null_mut(); 591 let _ = ffi::g_socket_join_multicast_group_ssm( 592 self.as_ref().to_glib_none().0, 593 group.as_ref().to_glib_none().0, 594 source_specific.map(|p| p.as_ref()).to_glib_none().0, 595 iface.to_glib_none().0, 596 &mut error, 597 ); 598 if error.is_null() { 599 Ok(()) 600 } else { 601 Err(from_glib_full(error)) 602 } 603 } 604 } 605 leave_multicast_group<P: IsA<InetAddress>>( &self, group: &P, source_specific: bool, iface: Option<&str>, ) -> Result<(), glib::Error>606 fn leave_multicast_group<P: IsA<InetAddress>>( 607 &self, 608 group: &P, 609 source_specific: bool, 610 iface: Option<&str>, 611 ) -> Result<(), glib::Error> { 612 unsafe { 613 let mut error = ptr::null_mut(); 614 let _ = ffi::g_socket_leave_multicast_group( 615 self.as_ref().to_glib_none().0, 616 group.as_ref().to_glib_none().0, 617 source_specific.into_glib(), 618 iface.to_glib_none().0, 619 &mut error, 620 ); 621 if error.is_null() { 622 Ok(()) 623 } else { 624 Err(from_glib_full(error)) 625 } 626 } 627 } 628 629 #[cfg(any(feature = "v2_56", feature = "dox"))] 630 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))] leave_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( &self, group: &P, source_specific: Option<&Q>, iface: Option<&str>, ) -> Result<(), glib::Error>631 fn leave_multicast_group_ssm<P: IsA<InetAddress>, Q: IsA<InetAddress>>( 632 &self, 633 group: &P, 634 source_specific: Option<&Q>, 635 iface: Option<&str>, 636 ) -> Result<(), glib::Error> { 637 unsafe { 638 let mut error = ptr::null_mut(); 639 let _ = ffi::g_socket_leave_multicast_group_ssm( 640 self.as_ref().to_glib_none().0, 641 group.as_ref().to_glib_none().0, 642 source_specific.map(|p| p.as_ref()).to_glib_none().0, 643 iface.to_glib_none().0, 644 &mut error, 645 ); 646 if error.is_null() { 647 Ok(()) 648 } else { 649 Err(from_glib_full(error)) 650 } 651 } 652 } 653 listen(&self) -> Result<(), glib::Error>654 fn listen(&self) -> Result<(), glib::Error> { 655 unsafe { 656 let mut error = ptr::null_mut(); 657 let _ = ffi::g_socket_listen(self.as_ref().to_glib_none().0, &mut error); 658 if error.is_null() { 659 Ok(()) 660 } else { 661 Err(from_glib_full(error)) 662 } 663 } 664 } 665 set_blocking(&self, blocking: bool)666 fn set_blocking(&self, blocking: bool) { 667 unsafe { 668 ffi::g_socket_set_blocking(self.as_ref().to_glib_none().0, blocking.into_glib()); 669 } 670 } 671 set_broadcast(&self, broadcast: bool)672 fn set_broadcast(&self, broadcast: bool) { 673 unsafe { 674 ffi::g_socket_set_broadcast(self.as_ref().to_glib_none().0, broadcast.into_glib()); 675 } 676 } 677 set_keepalive(&self, keepalive: bool)678 fn set_keepalive(&self, keepalive: bool) { 679 unsafe { 680 ffi::g_socket_set_keepalive(self.as_ref().to_glib_none().0, keepalive.into_glib()); 681 } 682 } 683 set_listen_backlog(&self, backlog: i32)684 fn set_listen_backlog(&self, backlog: i32) { 685 unsafe { 686 ffi::g_socket_set_listen_backlog(self.as_ref().to_glib_none().0, backlog); 687 } 688 } 689 set_multicast_loopback(&self, loopback: bool)690 fn set_multicast_loopback(&self, loopback: bool) { 691 unsafe { 692 ffi::g_socket_set_multicast_loopback( 693 self.as_ref().to_glib_none().0, 694 loopback.into_glib(), 695 ); 696 } 697 } 698 set_multicast_ttl(&self, ttl: u32)699 fn set_multicast_ttl(&self, ttl: u32) { 700 unsafe { 701 ffi::g_socket_set_multicast_ttl(self.as_ref().to_glib_none().0, ttl); 702 } 703 } 704 set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error>705 fn set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), glib::Error> { 706 unsafe { 707 let mut error = ptr::null_mut(); 708 let _ = ffi::g_socket_set_option( 709 self.as_ref().to_glib_none().0, 710 level, 711 optname, 712 value, 713 &mut error, 714 ); 715 if error.is_null() { 716 Ok(()) 717 } else { 718 Err(from_glib_full(error)) 719 } 720 } 721 } 722 set_timeout(&self, timeout: u32)723 fn set_timeout(&self, timeout: u32) { 724 unsafe { 725 ffi::g_socket_set_timeout(self.as_ref().to_glib_none().0, timeout); 726 } 727 } 728 set_ttl(&self, ttl: u32)729 fn set_ttl(&self, ttl: u32) { 730 unsafe { 731 ffi::g_socket_set_ttl(self.as_ref().to_glib_none().0, ttl); 732 } 733 } 734 shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error>735 fn shutdown(&self, shutdown_read: bool, shutdown_write: bool) -> Result<(), glib::Error> { 736 unsafe { 737 let mut error = ptr::null_mut(); 738 let _ = ffi::g_socket_shutdown( 739 self.as_ref().to_glib_none().0, 740 shutdown_read.into_glib(), 741 shutdown_write.into_glib(), 742 &mut error, 743 ); 744 if error.is_null() { 745 Ok(()) 746 } else { 747 Err(from_glib_full(error)) 748 } 749 } 750 } 751 speaks_ipv4(&self) -> bool752 fn speaks_ipv4(&self) -> bool { 753 unsafe { from_glib(ffi::g_socket_speaks_ipv4(self.as_ref().to_glib_none().0)) } 754 } 755 type_(&self) -> SocketType756 fn type_(&self) -> SocketType { 757 unsafe { 758 let mut value = glib::Value::from_type(<SocketType as StaticType>::static_type()); 759 glib::gobject_ffi::g_object_get_property( 760 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 761 b"type\0".as_ptr() as *const _, 762 value.to_glib_none_mut().0, 763 ); 764 value 765 .get() 766 .expect("Return Value for property `type` getter") 767 } 768 } 769 connect_blocking_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId770 fn connect_blocking_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId { 771 unsafe extern "C" fn notify_blocking_trampoline< 772 P: IsA<Socket>, 773 F: Fn(&P) + Send + 'static, 774 >( 775 this: *mut ffi::GSocket, 776 _param_spec: glib::ffi::gpointer, 777 f: glib::ffi::gpointer, 778 ) { 779 let f: &F = &*(f as *const F); 780 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 781 } 782 unsafe { 783 let f: Box_<F> = Box_::new(f); 784 connect_raw( 785 self.as_ptr() as *mut _, 786 b"notify::blocking\0".as_ptr() as *const _, 787 Some(transmute::<_, unsafe extern "C" fn()>( 788 notify_blocking_trampoline::<Self, F> as *const (), 789 )), 790 Box_::into_raw(f), 791 ) 792 } 793 } 794 connect_broadcast_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId795 fn connect_broadcast_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId { 796 unsafe extern "C" fn notify_broadcast_trampoline< 797 P: IsA<Socket>, 798 F: Fn(&P) + Send + 'static, 799 >( 800 this: *mut ffi::GSocket, 801 _param_spec: glib::ffi::gpointer, 802 f: glib::ffi::gpointer, 803 ) { 804 let f: &F = &*(f as *const F); 805 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 806 } 807 unsafe { 808 let f: Box_<F> = Box_::new(f); 809 connect_raw( 810 self.as_ptr() as *mut _, 811 b"notify::broadcast\0".as_ptr() as *const _, 812 Some(transmute::<_, unsafe extern "C" fn()>( 813 notify_broadcast_trampoline::<Self, F> as *const (), 814 )), 815 Box_::into_raw(f), 816 ) 817 } 818 } 819 connect_keepalive_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId820 fn connect_keepalive_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId { 821 unsafe extern "C" fn notify_keepalive_trampoline< 822 P: IsA<Socket>, 823 F: Fn(&P) + Send + 'static, 824 >( 825 this: *mut ffi::GSocket, 826 _param_spec: glib::ffi::gpointer, 827 f: glib::ffi::gpointer, 828 ) { 829 let f: &F = &*(f as *const F); 830 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 831 } 832 unsafe { 833 let f: Box_<F> = Box_::new(f); 834 connect_raw( 835 self.as_ptr() as *mut _, 836 b"notify::keepalive\0".as_ptr() as *const _, 837 Some(transmute::<_, unsafe extern "C" fn()>( 838 notify_keepalive_trampoline::<Self, F> as *const (), 839 )), 840 Box_::into_raw(f), 841 ) 842 } 843 } 844 connect_listen_backlog_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId845 fn connect_listen_backlog_notify<F: Fn(&Self) + Send + 'static>( 846 &self, 847 f: F, 848 ) -> SignalHandlerId { 849 unsafe extern "C" fn notify_listen_backlog_trampoline< 850 P: IsA<Socket>, 851 F: Fn(&P) + Send + 'static, 852 >( 853 this: *mut ffi::GSocket, 854 _param_spec: glib::ffi::gpointer, 855 f: glib::ffi::gpointer, 856 ) { 857 let f: &F = &*(f as *const F); 858 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 859 } 860 unsafe { 861 let f: Box_<F> = Box_::new(f); 862 connect_raw( 863 self.as_ptr() as *mut _, 864 b"notify::listen-backlog\0".as_ptr() as *const _, 865 Some(transmute::<_, unsafe extern "C" fn()>( 866 notify_listen_backlog_trampoline::<Self, F> as *const (), 867 )), 868 Box_::into_raw(f), 869 ) 870 } 871 } 872 connect_local_address_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId873 fn connect_local_address_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId { 874 unsafe extern "C" fn notify_local_address_trampoline< 875 P: IsA<Socket>, 876 F: Fn(&P) + Send + 'static, 877 >( 878 this: *mut ffi::GSocket, 879 _param_spec: glib::ffi::gpointer, 880 f: glib::ffi::gpointer, 881 ) { 882 let f: &F = &*(f as *const F); 883 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 884 } 885 unsafe { 886 let f: Box_<F> = Box_::new(f); 887 connect_raw( 888 self.as_ptr() as *mut _, 889 b"notify::local-address\0".as_ptr() as *const _, 890 Some(transmute::<_, unsafe extern "C" fn()>( 891 notify_local_address_trampoline::<Self, F> as *const (), 892 )), 893 Box_::into_raw(f), 894 ) 895 } 896 } 897 connect_multicast_loopback_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId898 fn connect_multicast_loopback_notify<F: Fn(&Self) + Send + 'static>( 899 &self, 900 f: F, 901 ) -> SignalHandlerId { 902 unsafe extern "C" fn notify_multicast_loopback_trampoline< 903 P: IsA<Socket>, 904 F: Fn(&P) + Send + 'static, 905 >( 906 this: *mut ffi::GSocket, 907 _param_spec: glib::ffi::gpointer, 908 f: glib::ffi::gpointer, 909 ) { 910 let f: &F = &*(f as *const F); 911 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 912 } 913 unsafe { 914 let f: Box_<F> = Box_::new(f); 915 connect_raw( 916 self.as_ptr() as *mut _, 917 b"notify::multicast-loopback\0".as_ptr() as *const _, 918 Some(transmute::<_, unsafe extern "C" fn()>( 919 notify_multicast_loopback_trampoline::<Self, F> as *const (), 920 )), 921 Box_::into_raw(f), 922 ) 923 } 924 } 925 connect_multicast_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId926 fn connect_multicast_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId { 927 unsafe extern "C" fn notify_multicast_ttl_trampoline< 928 P: IsA<Socket>, 929 F: Fn(&P) + Send + 'static, 930 >( 931 this: *mut ffi::GSocket, 932 _param_spec: glib::ffi::gpointer, 933 f: glib::ffi::gpointer, 934 ) { 935 let f: &F = &*(f as *const F); 936 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 937 } 938 unsafe { 939 let f: Box_<F> = Box_::new(f); 940 connect_raw( 941 self.as_ptr() as *mut _, 942 b"notify::multicast-ttl\0".as_ptr() as *const _, 943 Some(transmute::<_, unsafe extern "C" fn()>( 944 notify_multicast_ttl_trampoline::<Self, F> as *const (), 945 )), 946 Box_::into_raw(f), 947 ) 948 } 949 } 950 connect_remote_address_notify<F: Fn(&Self) + Send + 'static>( &self, f: F, ) -> SignalHandlerId951 fn connect_remote_address_notify<F: Fn(&Self) + Send + 'static>( 952 &self, 953 f: F, 954 ) -> SignalHandlerId { 955 unsafe extern "C" fn notify_remote_address_trampoline< 956 P: IsA<Socket>, 957 F: Fn(&P) + Send + 'static, 958 >( 959 this: *mut ffi::GSocket, 960 _param_spec: glib::ffi::gpointer, 961 f: glib::ffi::gpointer, 962 ) { 963 let f: &F = &*(f as *const F); 964 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 965 } 966 unsafe { 967 let f: Box_<F> = Box_::new(f); 968 connect_raw( 969 self.as_ptr() as *mut _, 970 b"notify::remote-address\0".as_ptr() as *const _, 971 Some(transmute::<_, unsafe extern "C" fn()>( 972 notify_remote_address_trampoline::<Self, F> as *const (), 973 )), 974 Box_::into_raw(f), 975 ) 976 } 977 } 978 connect_timeout_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId979 fn connect_timeout_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId { 980 unsafe extern "C" fn notify_timeout_trampoline< 981 P: IsA<Socket>, 982 F: Fn(&P) + Send + 'static, 983 >( 984 this: *mut ffi::GSocket, 985 _param_spec: glib::ffi::gpointer, 986 f: glib::ffi::gpointer, 987 ) { 988 let f: &F = &*(f as *const F); 989 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 990 } 991 unsafe { 992 let f: Box_<F> = Box_::new(f); 993 connect_raw( 994 self.as_ptr() as *mut _, 995 b"notify::timeout\0".as_ptr() as *const _, 996 Some(transmute::<_, unsafe extern "C" fn()>( 997 notify_timeout_trampoline::<Self, F> as *const (), 998 )), 999 Box_::into_raw(f), 1000 ) 1001 } 1002 } 1003 connect_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId1004 fn connect_ttl_notify<F: Fn(&Self) + Send + 'static>(&self, f: F) -> SignalHandlerId { 1005 unsafe extern "C" fn notify_ttl_trampoline<P: IsA<Socket>, F: Fn(&P) + Send + 'static>( 1006 this: *mut ffi::GSocket, 1007 _param_spec: glib::ffi::gpointer, 1008 f: glib::ffi::gpointer, 1009 ) { 1010 let f: &F = &*(f as *const F); 1011 f(Socket::from_glib_borrow(this).unsafe_cast_ref()) 1012 } 1013 unsafe { 1014 let f: Box_<F> = Box_::new(f); 1015 connect_raw( 1016 self.as_ptr() as *mut _, 1017 b"notify::ttl\0".as_ptr() as *const _, 1018 Some(transmute::<_, unsafe extern "C" fn()>( 1019 notify_ttl_trampoline::<Self, F> as *const (), 1020 )), 1021 Box_::into_raw(f), 1022 ) 1023 } 1024 } 1025 } 1026 1027 impl fmt::Display for Socket { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result1028 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 1029 f.write_str("Socket") 1030 } 1031 } 1032