gio/auto/socket_client.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
#![allow(deprecated)]
use crate::{
ffi, AsyncResult, Cancellable, IOStream, ProxyResolver, SocketAddress, SocketClientEvent,
SocketConnectable, SocketConnection, SocketFamily, SocketProtocol, SocketType,
TlsCertificateFlags,
};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, pin::Pin};
glib::wrapper! {
/// `GSocketClient` is a lightweight high-level utility class for connecting to
/// a network host using a connection oriented socket type.
///
/// You create a `GSocketClient` object, set any options you want, and then
/// call a sync or async connect operation, which returns a
/// [`SocketConnection`][crate::SocketConnection] subclass on success.
///
/// The type of the [`SocketConnection`][crate::SocketConnection] object returned depends on the
/// type of the underlying socket that is in use. For instance, for a TCP/IP
/// connection it will be a [`TcpConnection`][crate::TcpConnection].
///
/// As `GSocketClient` is a lightweight object, you don't need to cache it. You
/// can just create a new one any time you need one.
///
/// ## Properties
///
///
/// #### `enable-proxy`
/// Enable proxy support.
///
/// Readable | Writeable | Construct
///
///
/// #### `family`
/// The address family to use for socket construction.
///
/// Readable | Writeable | Construct
///
///
/// #### `local-address`
/// The local address constructed sockets will be bound to.
///
/// Readable | Writeable | Construct
///
///
/// #### `protocol`
/// The protocol to use for socket construction, or `0` for default.
///
/// Readable | Writeable | Construct
///
///
/// #### `proxy-resolver`
/// The proxy resolver to use
///
/// Readable | Writeable | Construct
///
///
/// #### `timeout`
/// The I/O timeout for sockets, in seconds, or `0` for none.
///
/// Readable | Writeable | Construct
///
///
/// #### `tls`
/// Whether to create TLS connections.
///
/// Readable | Writeable | Construct
///
///
/// #### `tls-validation-flags`
/// The TLS validation flags used when creating TLS connections. The
/// default value is [`TlsCertificateFlags::VALIDATE_ALL`][crate::TlsCertificateFlags::VALIDATE_ALL].
///
/// GLib guarantees that if certificate verification fails, at least one
/// flag will be set, but it does not guarantee that all possible flags
/// will be set. Accordingly, you may not safely decide to ignore any
/// particular type of error. For example, it would be incorrect to mask
/// [`TlsCertificateFlags::EXPIRED`][crate::TlsCertificateFlags::EXPIRED] if you want to allow expired certificates,
/// because this could potentially be the only error flag set even if
/// other problems exist with the certificate. Therefore, there is no
/// safe way to use this property. This is not a horrible problem,
/// though, because you should not be attempting to ignore validation
/// errors anyway. If you really must ignore TLS certificate errors,
/// connect to the #GSocketClient::event signal, wait for it to be
/// emitted with [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking], and use that to
/// connect to #GTlsConnection::accept-certificate.
///
/// Readable | Writeable | Construct
///
///
/// #### `type`
/// The type to use for socket construction.
///
/// Readable | Writeable | Construct
///
/// ## Signals
///
///
/// #### `event`
/// Emitted when @client's activity on @connectable changes state.
/// Among other things, this can be used to provide progress
/// information about a network connection in the UI. The meanings of
/// the different @event values are as follows:
///
/// - [`SocketClientEvent::Resolving`][crate::SocketClientEvent::Resolving]: @client is about to look up @connectable
/// in DNS. @connection will be [`None`].
///
/// - [`SocketClientEvent::Resolved`][crate::SocketClientEvent::Resolved]: @client has successfully resolved
/// @connectable in DNS. @connection will be [`None`].
///
/// - [`SocketClientEvent::Connecting`][crate::SocketClientEvent::Connecting]: @client is about to make a connection
/// to a remote host; either a proxy server or the destination server
/// itself. @connection is the #GSocketConnection, which is not yet
/// connected. Since GLib 2.40, you can access the remote
/// address via g_socket_connection_get_remote_address().
///
/// - [`SocketClientEvent::Connected`][crate::SocketClientEvent::Connected]: @client has successfully connected
/// to a remote host. @connection is the connected #GSocketConnection.
///
/// - [`SocketClientEvent::ProxyNegotiating`][crate::SocketClientEvent::ProxyNegotiating]: @client is about to negotiate
/// with a proxy to get it to connect to @connectable. @connection is
/// the #GSocketConnection to the proxy server.
///
/// - [`SocketClientEvent::ProxyNegotiated`][crate::SocketClientEvent::ProxyNegotiated]: @client has negotiated a
/// connection to @connectable through a proxy server. @connection is
/// the stream returned from g_proxy_connect(), which may or may not
/// be a #GSocketConnection.
///
/// - [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking]: @client is about to begin a TLS
/// handshake. @connection is a #GTlsClientConnection.
///
/// - [`SocketClientEvent::TlsHandshaked`][crate::SocketClientEvent::TlsHandshaked]: @client has successfully completed
/// the TLS handshake. @connection is a #GTlsClientConnection.
///
/// - [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete]: @client has either successfully connected
/// to @connectable (in which case @connection is the #GSocketConnection
/// that it will be returning to the caller) or has failed (in which
/// case @connection is [`None`] and the client is about to return an error).
///
/// Each event except [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] may be emitted
/// multiple times (or not at all) for a given connectable (in
/// particular, if @client ends up attempting to connect to more than
/// one address). However, if @client emits the #GSocketClient::event
/// signal at all for a given connectable, then it will always emit
/// it with [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] when it is done.
///
/// Note that there may be additional #GSocketClientEvent values in
/// the future; unrecognized @event values should be ignored.
///
///
///
/// # Implements
///
/// [`SocketClientExt`][trait@crate::prelude::SocketClientExt], [`trait@glib::ObjectExt`]
#[doc(alias = "GSocketClient")]
pub struct SocketClient(Object<ffi::GSocketClient, ffi::GSocketClientClass>);
match fn {
type_ => || ffi::g_socket_client_get_type(),
}
}
impl SocketClient {
pub const NONE: Option<&'static SocketClient> = None;
/// Creates a new #GSocketClient with the default options.
///
/// # Returns
///
/// a #GSocketClient.
/// Free the returned object with g_object_unref().
#[doc(alias = "g_socket_client_new")]
pub fn new() -> SocketClient {
unsafe { from_glib_full(ffi::g_socket_client_new()) }
}
}
impl Default for SocketClient {
fn default() -> Self {
Self::new()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::SocketClient>> Sealed for T {}
}
/// Trait containing all [`struct@SocketClient`] methods.
///
/// # Implementors
///
/// [`SocketClient`][struct@crate::SocketClient]
pub trait SocketClientExt: IsA<SocketClient> + sealed::Sealed + 'static {
/// Enable proxy protocols to be handled by the application. When the
/// indicated proxy protocol is returned by the #GProxyResolver,
/// #GSocketClient will consider this protocol as supported but will
/// not try to find a #GProxy instance to handle handshaking. The
/// application must check for this case by calling
/// g_socket_connection_get_remote_address() on the returned
/// #GSocketConnection, and seeing if it's a #GProxyAddress of the
/// appropriate type, to determine whether or not it needs to handle
/// the proxy handshaking itself.
///
/// This should be used for proxy protocols that are dialects of
/// another protocol such as HTTP proxy. It also allows cohabitation of
/// proxy protocols that are reused between protocols. A good example
/// is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also
/// be use as generic socket proxy through the HTTP CONNECT method.
///
/// When the proxy is detected as being an application proxy, TLS handshake
/// will be skipped. This is required to let the application do the proxy
/// specific handshake.
/// ## `protocol`
/// The proxy protocol
#[doc(alias = "g_socket_client_add_application_proxy")]
fn add_application_proxy(&self, protocol: &str) {
unsafe {
ffi::g_socket_client_add_application_proxy(
self.as_ref().to_glib_none().0,
protocol.to_glib_none().0,
);
}
}
/// Tries to resolve the @connectable and make a network connection to it.
///
/// Upon a successful connection, a new #GSocketConnection is constructed
/// and returned. The caller owns this new object and must drop their
/// reference to it when finished with it.
///
/// The type of the #GSocketConnection object returned depends on the type of
/// the underlying socket that is used. For instance, for a TCP/IP connection
/// it will be a #GTcpConnection.
///
/// The socket created will be the same family as the address that the
/// @connectable resolves to, unless family is set with g_socket_client_set_family()
/// or indirectly via g_socket_client_set_local_address(). The socket type
/// defaults to [`SocketType::Stream`][crate::SocketType::Stream] but can be set with
/// g_socket_client_set_socket_type().
///
/// If a local address is specified with g_socket_client_set_local_address() the
/// socket will be bound to this address before connecting.
/// ## `connectable`
/// a #GSocketConnectable specifying the remote address.
/// ## `cancellable`
/// optional #GCancellable object, [`None`] to ignore.
///
/// # Returns
///
/// a #GSocketConnection on success, [`None`] on error.
#[doc(alias = "g_socket_client_connect")]
fn connect(
&self,
connectable: &impl IsA<SocketConnectable>,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<SocketConnection, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::g_socket_client_connect(
self.as_ref().to_glib_none().0,
connectable.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// This is the asynchronous version of g_socket_client_connect().
///
/// You may wish to prefer the asynchronous version even in synchronous
/// command line programs because, since 2.60, it implements
/// [RFC 8305](https://tools.ietf.org/html/rfc8305) "Happy Eyeballs"
/// recommendations to work around long connection timeouts in networks
/// where IPv6 is broken by performing an IPv4 connection simultaneously
/// without waiting for IPv6 to time out, which is not supported by the
/// synchronous call. (This is not an API guarantee, and may change in
/// the future.)
///
/// When the operation is finished @callback will be
/// called. You can then call g_socket_client_connect_finish() to get
/// the result of the operation.
/// ## `connectable`
/// a #GSocketConnectable specifying the remote address.
/// ## `cancellable`
/// a #GCancellable, or [`None`]
/// ## `callback`
/// a #GAsyncReadyCallback
#[doc(alias = "g_socket_client_connect_async")]
fn connect_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
&self,
connectable: &impl IsA<SocketConnectable>,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn connect_async_trampoline<
P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut crate::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let ret =
ffi::g_socket_client_connect_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = connect_async_trampoline::<P>;
unsafe {
ffi::g_socket_client_connect_async(
self.as_ref().to_glib_none().0,
connectable.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
fn connect_future(
&self,
connectable: &(impl IsA<SocketConnectable> + Clone + 'static),
) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
{
let connectable = connectable.clone();
Box_::pin(crate::GioFuture::new(
self,
move |obj, cancellable, send| {
obj.connect_async(&connectable, Some(cancellable), move |res| {
send.resolve(res);
});
},
))
}
/// This is a helper function for g_socket_client_connect().
///
/// Attempts to create a TCP connection to the named host.
///
/// @host_and_port may be in any of a number of recognized formats; an IPv6
/// address, an IPv4 address, or a domain name (in which case a DNS
/// lookup is performed). Quoting with [] is supported for all address
/// types. A port override may be specified in the usual way with a
/// colon. Ports may be given as decimal numbers or symbolic names (in
/// which case an /etc/services lookup is performed).
///
/// If no port override is given in @host_and_port then @default_port will be
/// used as the port number to connect to.
///
/// In general, @host_and_port is expected to be provided by the user (allowing
/// them to give the hostname, and a port override if necessary) and
/// @default_port is expected to be provided by the application.
///
/// In the case that an IP address is given, a single connection
/// attempt is made. In the case that a name is given, multiple
/// connection attempts may be made, in turn and according to the
/// number of address records in DNS, until a connection succeeds.
///
/// Upon a successful connection, a new #GSocketConnection is constructed
/// and returned. The caller owns this new object and must drop their
/// reference to it when finished with it.
///
/// In the event of any failure (DNS error, service not found, no hosts
/// connectable) [`None`] is returned and @error (if non-[`None`]) is set
/// accordingly.
/// ## `host_and_port`
/// the name and optionally port of the host to connect to
/// ## `default_port`
/// the default port to connect to
/// ## `cancellable`
/// a #GCancellable, or [`None`]
///
/// # Returns
///
/// a #GSocketConnection on success, [`None`] on error.
#[doc(alias = "g_socket_client_connect_to_host")]
fn connect_to_host(
&self,
host_and_port: &str,
default_port: u16,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<SocketConnection, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::g_socket_client_connect_to_host(
self.as_ref().to_glib_none().0,
host_and_port.to_glib_none().0,
default_port,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// This is the asynchronous version of g_socket_client_connect_to_host().
///
/// When the operation is finished @callback will be
/// called. You can then call g_socket_client_connect_to_host_finish() to get
/// the result of the operation.
/// ## `host_and_port`
/// the name and optionally the port of the host to connect to
/// ## `default_port`
/// the default port to connect to
/// ## `cancellable`
/// a #GCancellable, or [`None`]
/// ## `callback`
/// a #GAsyncReadyCallback
#[doc(alias = "g_socket_client_connect_to_host_async")]
fn connect_to_host_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
&self,
host_and_port: &str,
default_port: u16,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn connect_to_host_async_trampoline<
P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut crate::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let ret = ffi::g_socket_client_connect_to_host_finish(
_source_object as *mut _,
res,
&mut error,
);
let result = if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = connect_to_host_async_trampoline::<P>;
unsafe {
ffi::g_socket_client_connect_to_host_async(
self.as_ref().to_glib_none().0,
host_and_port.to_glib_none().0,
default_port,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
fn connect_to_host_future(
&self,
host_and_port: &str,
default_port: u16,
) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
{
let host_and_port = String::from(host_and_port);
Box_::pin(crate::GioFuture::new(
self,
move |obj, cancellable, send| {
obj.connect_to_host_async(
&host_and_port,
default_port,
Some(cancellable),
move |res| {
send.resolve(res);
},
);
},
))
}
/// Attempts to create a TCP connection to a service.
///
/// This call looks up the SRV record for @service at @domain for the
/// "tcp" protocol. It then attempts to connect, in turn, to each of
/// the hosts providing the service until either a connection succeeds
/// or there are no hosts remaining.
///
/// Upon a successful connection, a new #GSocketConnection is constructed
/// and returned. The caller owns this new object and must drop their
/// reference to it when finished with it.
///
/// In the event of any failure (DNS error, service not found, no hosts
/// connectable) [`None`] is returned and @error (if non-[`None`]) is set
/// accordingly.
/// ## `domain`
/// a domain name
/// ## `service`
/// the name of the service to connect to
/// ## `cancellable`
/// a #GCancellable, or [`None`]
///
/// # Returns
///
/// a #GSocketConnection if successful, or [`None`] on error
#[doc(alias = "g_socket_client_connect_to_service")]
fn connect_to_service(
&self,
domain: &str,
service: &str,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<SocketConnection, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::g_socket_client_connect_to_service(
self.as_ref().to_glib_none().0,
domain.to_glib_none().0,
service.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// This is the asynchronous version of
/// g_socket_client_connect_to_service().
/// ## `domain`
/// a domain name
/// ## `service`
/// the name of the service to connect to
/// ## `cancellable`
/// a #GCancellable, or [`None`]
/// ## `callback`
/// a #GAsyncReadyCallback
#[doc(alias = "g_socket_client_connect_to_service_async")]
fn connect_to_service_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
&self,
domain: &str,
service: &str,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn connect_to_service_async_trampoline<
P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut crate::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let ret = ffi::g_socket_client_connect_to_service_finish(
_source_object as *mut _,
res,
&mut error,
);
let result = if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = connect_to_service_async_trampoline::<P>;
unsafe {
ffi::g_socket_client_connect_to_service_async(
self.as_ref().to_glib_none().0,
domain.to_glib_none().0,
service.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
fn connect_to_service_future(
&self,
domain: &str,
service: &str,
) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
{
let domain = String::from(domain);
let service = String::from(service);
Box_::pin(crate::GioFuture::new(
self,
move |obj, cancellable, send| {
obj.connect_to_service_async(&domain, &service, Some(cancellable), move |res| {
send.resolve(res);
});
},
))
}
/// This is a helper function for g_socket_client_connect().
///
/// Attempts to create a TCP connection with a network URI.
///
/// @uri may be any valid URI containing an "authority" (hostname/port)
/// component. If a port is not specified in the URI, @default_port
/// will be used. TLS will be negotiated if #GSocketClient:tls is [`true`].
/// (#GSocketClient does not know to automatically assume TLS for
/// certain URI schemes.)
///
/// Using this rather than g_socket_client_connect() or
/// g_socket_client_connect_to_host() allows #GSocketClient to
/// determine when to use application-specific proxy protocols.
///
/// Upon a successful connection, a new #GSocketConnection is constructed
/// and returned. The caller owns this new object and must drop their
/// reference to it when finished with it.
///
/// In the event of any failure (DNS error, service not found, no hosts
/// connectable) [`None`] is returned and @error (if non-[`None`]) is set
/// accordingly.
/// ## `uri`
/// A network URI
/// ## `default_port`
/// the default port to connect to
/// ## `cancellable`
/// a #GCancellable, or [`None`]
///
/// # Returns
///
/// a #GSocketConnection on success, [`None`] on error.
#[doc(alias = "g_socket_client_connect_to_uri")]
fn connect_to_uri(
&self,
uri: &str,
default_port: u16,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<SocketConnection, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::g_socket_client_connect_to_uri(
self.as_ref().to_glib_none().0,
uri.to_glib_none().0,
default_port,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// This is the asynchronous version of g_socket_client_connect_to_uri().
///
/// When the operation is finished @callback will be
/// called. You can then call g_socket_client_connect_to_uri_finish() to get
/// the result of the operation.
/// ## `uri`
/// a network uri
/// ## `default_port`
/// the default port to connect to
/// ## `cancellable`
/// a #GCancellable, or [`None`]
/// ## `callback`
/// a #GAsyncReadyCallback
#[doc(alias = "g_socket_client_connect_to_uri_async")]
fn connect_to_uri_async<P: FnOnce(Result<SocketConnection, glib::Error>) + 'static>(
&self,
uri: &str,
default_port: u16,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn connect_to_uri_async_trampoline<
P: FnOnce(Result<SocketConnection, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut crate::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let ret = ffi::g_socket_client_connect_to_uri_finish(
_source_object as *mut _,
res,
&mut error,
);
let result = if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = connect_to_uri_async_trampoline::<P>;
unsafe {
ffi::g_socket_client_connect_to_uri_async(
self.as_ref().to_glib_none().0,
uri.to_glib_none().0,
default_port,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
fn connect_to_uri_future(
&self,
uri: &str,
default_port: u16,
) -> Pin<Box_<dyn std::future::Future<Output = Result<SocketConnection, glib::Error>> + 'static>>
{
let uri = String::from(uri);
Box_::pin(crate::GioFuture::new(
self,
move |obj, cancellable, send| {
obj.connect_to_uri_async(&uri, default_port, Some(cancellable), move |res| {
send.resolve(res);
});
},
))
}
/// Gets the proxy enable state; see g_socket_client_set_enable_proxy()
///
/// # Returns
///
/// whether proxying is enabled
#[doc(alias = "g_socket_client_get_enable_proxy")]
#[doc(alias = "get_enable_proxy")]
#[doc(alias = "enable-proxy")]
fn enables_proxy(&self) -> bool {
unsafe {
from_glib(ffi::g_socket_client_get_enable_proxy(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the socket family of the socket client.
///
/// See g_socket_client_set_family() for details.
///
/// # Returns
///
/// a #GSocketFamily
#[doc(alias = "g_socket_client_get_family")]
#[doc(alias = "get_family")]
fn family(&self) -> SocketFamily {
unsafe {
from_glib(ffi::g_socket_client_get_family(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the local address of the socket client.
///
/// See g_socket_client_set_local_address() for details.
///
/// # Returns
///
/// a #GSocketAddress or [`None`]. Do not free.
#[doc(alias = "g_socket_client_get_local_address")]
#[doc(alias = "get_local_address")]
#[doc(alias = "local-address")]
fn local_address(&self) -> Option<SocketAddress> {
unsafe {
from_glib_none(ffi::g_socket_client_get_local_address(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the protocol name type of the socket client.
///
/// See g_socket_client_set_protocol() for details.
///
/// # Returns
///
/// a #GSocketProtocol
#[doc(alias = "g_socket_client_get_protocol")]
#[doc(alias = "get_protocol")]
fn protocol(&self) -> SocketProtocol {
unsafe {
from_glib(ffi::g_socket_client_get_protocol(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the #GProxyResolver being used by @self. Normally, this will
/// be the resolver returned by g_proxy_resolver_get_default(), but you
/// can override it with g_socket_client_set_proxy_resolver().
///
/// # Returns
///
/// The #GProxyResolver being used by
/// @self.
#[doc(alias = "g_socket_client_get_proxy_resolver")]
#[doc(alias = "get_proxy_resolver")]
#[doc(alias = "proxy-resolver")]
fn proxy_resolver(&self) -> ProxyResolver {
unsafe {
from_glib_none(ffi::g_socket_client_get_proxy_resolver(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the socket type of the socket client.
///
/// See g_socket_client_set_socket_type() for details.
///
/// # Returns
///
/// a #GSocketFamily
#[doc(alias = "g_socket_client_get_socket_type")]
#[doc(alias = "get_socket_type")]
fn socket_type(&self) -> SocketType {
unsafe {
from_glib(ffi::g_socket_client_get_socket_type(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the I/O timeout time for sockets created by @self.
///
/// See g_socket_client_set_timeout() for details.
///
/// # Returns
///
/// the timeout in seconds
#[doc(alias = "g_socket_client_get_timeout")]
#[doc(alias = "get_timeout")]
fn timeout(&self) -> u32 {
unsafe { ffi::g_socket_client_get_timeout(self.as_ref().to_glib_none().0) }
}
/// Gets whether @self creates TLS connections. See
/// g_socket_client_set_tls() for details.
///
/// # Returns
///
/// whether @self uses TLS
#[doc(alias = "g_socket_client_get_tls")]
#[doc(alias = "get_tls")]
#[doc(alias = "tls")]
fn is_tls(&self) -> bool {
unsafe { from_glib(ffi::g_socket_client_get_tls(self.as_ref().to_glib_none().0)) }
}
/// Gets the TLS validation flags used creating TLS connections via
/// @self.
///
/// This function does not work as originally designed and is impossible
/// to use correctly. See #GSocketClient:tls-validation-flags for more
/// information.
///
/// # Deprecated since 2.72
///
/// Do not attempt to ignore validation errors.
///
/// # Returns
///
/// the TLS validation flags
#[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
#[allow(deprecated)]
#[doc(alias = "g_socket_client_get_tls_validation_flags")]
#[doc(alias = "get_tls_validation_flags")]
#[doc(alias = "tls-validation-flags")]
fn tls_validation_flags(&self) -> TlsCertificateFlags {
unsafe {
from_glib(ffi::g_socket_client_get_tls_validation_flags(
self.as_ref().to_glib_none().0,
))
}
}
/// Sets whether or not @self attempts to make connections via a
/// proxy server. When enabled (the default), #GSocketClient will use a
/// #GProxyResolver to determine if a proxy protocol such as SOCKS is
/// needed, and automatically do the necessary proxy negotiation.
///
/// See also g_socket_client_set_proxy_resolver().
/// ## `enable`
/// whether to enable proxies
#[doc(alias = "g_socket_client_set_enable_proxy")]
#[doc(alias = "enable-proxy")]
fn set_enable_proxy(&self, enable: bool) {
unsafe {
ffi::g_socket_client_set_enable_proxy(
self.as_ref().to_glib_none().0,
enable.into_glib(),
);
}
}
/// Sets the socket family of the socket client.
/// If this is set to something other than [`SocketFamily::Invalid`][crate::SocketFamily::Invalid]
/// then the sockets created by this object will be of the specified
/// family.
///
/// This might be useful for instance if you want to force the local
/// connection to be an ipv4 socket, even though the address might
/// be an ipv6 mapped to ipv4 address.
/// ## `family`
/// a #GSocketFamily
#[doc(alias = "g_socket_client_set_family")]
#[doc(alias = "family")]
fn set_family(&self, family: SocketFamily) {
unsafe {
ffi::g_socket_client_set_family(self.as_ref().to_glib_none().0, family.into_glib());
}
}
/// Sets the local address of the socket client.
/// The sockets created by this object will bound to the
/// specified address (if not [`None`]) before connecting.
///
/// This is useful if you want to ensure that the local
/// side of the connection is on a specific port, or on
/// a specific interface.
/// ## `address`
/// a #GSocketAddress, or [`None`]
#[doc(alias = "g_socket_client_set_local_address")]
#[doc(alias = "local-address")]
fn set_local_address(&self, address: Option<&impl IsA<SocketAddress>>) {
unsafe {
ffi::g_socket_client_set_local_address(
self.as_ref().to_glib_none().0,
address.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Sets the protocol of the socket client.
/// The sockets created by this object will use of the specified
/// protocol.
///
/// If @protocol is [`SocketProtocol::Default`][crate::SocketProtocol::Default] that means to use the default
/// protocol for the socket family and type.
/// ## `protocol`
/// a #GSocketProtocol
#[doc(alias = "g_socket_client_set_protocol")]
#[doc(alias = "protocol")]
fn set_protocol(&self, protocol: SocketProtocol) {
unsafe {
ffi::g_socket_client_set_protocol(self.as_ref().to_glib_none().0, protocol.into_glib());
}
}
/// Overrides the #GProxyResolver used by @self. You can call this if
/// you want to use specific proxies, rather than using the system
/// default proxy settings.
///
/// Note that whether or not the proxy resolver is actually used
/// depends on the setting of #GSocketClient:enable-proxy, which is not
/// changed by this function (but which is [`true`] by default)
/// ## `proxy_resolver`
/// a #GProxyResolver, or [`None`] for the
/// default.
#[doc(alias = "g_socket_client_set_proxy_resolver")]
#[doc(alias = "proxy-resolver")]
fn set_proxy_resolver(&self, proxy_resolver: Option<&impl IsA<ProxyResolver>>) {
unsafe {
ffi::g_socket_client_set_proxy_resolver(
self.as_ref().to_glib_none().0,
proxy_resolver.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Sets the socket type of the socket client.
/// The sockets created by this object will be of the specified
/// type.
///
/// It doesn't make sense to specify a type of [`SocketType::Datagram`][crate::SocketType::Datagram],
/// as GSocketClient is used for connection oriented services.
/// ## `type_`
/// a #GSocketType
#[doc(alias = "g_socket_client_set_socket_type")]
fn set_socket_type(&self, type_: SocketType) {
unsafe {
ffi::g_socket_client_set_socket_type(self.as_ref().to_glib_none().0, type_.into_glib());
}
}
/// Sets the I/O timeout for sockets created by @self. @timeout is a
/// time in seconds, or 0 for no timeout (the default).
///
/// The timeout value affects the initial connection attempt as well,
/// so setting this may cause calls to g_socket_client_connect(), etc,
/// to fail with [`IOErrorEnum::TimedOut`][crate::IOErrorEnum::TimedOut].
/// ## `timeout`
/// the timeout
#[doc(alias = "g_socket_client_set_timeout")]
#[doc(alias = "timeout")]
fn set_timeout(&self, timeout: u32) {
unsafe {
ffi::g_socket_client_set_timeout(self.as_ref().to_glib_none().0, timeout);
}
}
/// Sets whether @self creates TLS (aka SSL) connections. If @tls is
/// [`true`], @self will wrap its connections in a #GTlsClientConnection
/// and perform a TLS handshake when connecting.
///
/// Note that since #GSocketClient must return a #GSocketConnection,
/// but #GTlsClientConnection is not a #GSocketConnection, this
/// actually wraps the resulting #GTlsClientConnection in a
/// #GTcpWrapperConnection when returning it. You can use
/// g_tcp_wrapper_connection_get_base_io_stream() on the return value
/// to extract the #GTlsClientConnection.
///
/// If you need to modify the behavior of the TLS handshake (eg, by
/// setting a client-side certificate to use, or connecting to the
/// #GTlsConnection::accept-certificate signal), you can connect to
/// @self's #GSocketClient::event signal and wait for it to be
/// emitted with [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking], which will give you
/// a chance to see the #GTlsClientConnection before the handshake
/// starts.
/// ## `tls`
/// whether to use TLS
#[doc(alias = "g_socket_client_set_tls")]
#[doc(alias = "tls")]
fn set_tls(&self, tls: bool) {
unsafe {
ffi::g_socket_client_set_tls(self.as_ref().to_glib_none().0, tls.into_glib());
}
}
/// Sets the TLS validation flags used when creating TLS connections
/// via @self. The default value is [`TlsCertificateFlags::VALIDATE_ALL`][crate::TlsCertificateFlags::VALIDATE_ALL].
///
/// This function does not work as originally designed and is impossible
/// to use correctly. See #GSocketClient:tls-validation-flags for more
/// information.
///
/// # Deprecated since 2.72
///
/// Do not attempt to ignore validation errors.
/// ## `flags`
/// the validation flags
#[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
#[allow(deprecated)]
#[doc(alias = "g_socket_client_set_tls_validation_flags")]
#[doc(alias = "tls-validation-flags")]
fn set_tls_validation_flags(&self, flags: TlsCertificateFlags) {
unsafe {
ffi::g_socket_client_set_tls_validation_flags(
self.as_ref().to_glib_none().0,
flags.into_glib(),
);
}
}
/// The type to use for socket construction.
#[doc(alias = "type")]
fn type_(&self) -> SocketType {
ObjectExt::property(self.as_ref(), "type")
}
/// The type to use for socket construction.
#[doc(alias = "type")]
fn set_type(&self, type_: SocketType) {
ObjectExt::set_property(self.as_ref(), "type", type_)
}
/// Emitted when @client's activity on @connectable changes state.
/// Among other things, this can be used to provide progress
/// information about a network connection in the UI. The meanings of
/// the different @event values are as follows:
///
/// - [`SocketClientEvent::Resolving`][crate::SocketClientEvent::Resolving]: @client is about to look up @connectable
/// in DNS. @connection will be [`None`].
///
/// - [`SocketClientEvent::Resolved`][crate::SocketClientEvent::Resolved]: @client has successfully resolved
/// @connectable in DNS. @connection will be [`None`].
///
/// - [`SocketClientEvent::Connecting`][crate::SocketClientEvent::Connecting]: @client is about to make a connection
/// to a remote host; either a proxy server or the destination server
/// itself. @connection is the #GSocketConnection, which is not yet
/// connected. Since GLib 2.40, you can access the remote
/// address via g_socket_connection_get_remote_address().
///
/// - [`SocketClientEvent::Connected`][crate::SocketClientEvent::Connected]: @client has successfully connected
/// to a remote host. @connection is the connected #GSocketConnection.
///
/// - [`SocketClientEvent::ProxyNegotiating`][crate::SocketClientEvent::ProxyNegotiating]: @client is about to negotiate
/// with a proxy to get it to connect to @connectable. @connection is
/// the #GSocketConnection to the proxy server.
///
/// - [`SocketClientEvent::ProxyNegotiated`][crate::SocketClientEvent::ProxyNegotiated]: @client has negotiated a
/// connection to @connectable through a proxy server. @connection is
/// the stream returned from g_proxy_connect(), which may or may not
/// be a #GSocketConnection.
///
/// - [`SocketClientEvent::TlsHandshaking`][crate::SocketClientEvent::TlsHandshaking]: @client is about to begin a TLS
/// handshake. @connection is a #GTlsClientConnection.
///
/// - [`SocketClientEvent::TlsHandshaked`][crate::SocketClientEvent::TlsHandshaked]: @client has successfully completed
/// the TLS handshake. @connection is a #GTlsClientConnection.
///
/// - [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete]: @client has either successfully connected
/// to @connectable (in which case @connection is the #GSocketConnection
/// that it will be returning to the caller) or has failed (in which
/// case @connection is [`None`] and the client is about to return an error).
///
/// Each event except [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] may be emitted
/// multiple times (or not at all) for a given connectable (in
/// particular, if @client ends up attempting to connect to more than
/// one address). However, if @client emits the #GSocketClient::event
/// signal at all for a given connectable, then it will always emit
/// it with [`SocketClientEvent::Complete`][crate::SocketClientEvent::Complete] when it is done.
///
/// Note that there may be additional #GSocketClientEvent values in
/// the future; unrecognized @event values should be ignored.
/// ## `event`
/// the event that is occurring
/// ## `connectable`
/// the #GSocketConnectable that @event is occurring on
/// ## `connection`
/// the current representation of the connection
#[doc(alias = "event")]
fn connect_event<
F: Fn(&Self, SocketClientEvent, &SocketConnectable, Option<&IOStream>) + 'static,
>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn event_trampoline<
P: IsA<SocketClient>,
F: Fn(&P, SocketClientEvent, &SocketConnectable, Option<&IOStream>) + 'static,
>(
this: *mut ffi::GSocketClient,
event: ffi::GSocketClientEvent,
connectable: *mut ffi::GSocketConnectable,
connection: *mut ffi::GIOStream,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
SocketClient::from_glib_borrow(this).unsafe_cast_ref(),
from_glib(event),
&from_glib_borrow(connectable),
Option::<IOStream>::from_glib_borrow(connection)
.as_ref()
.as_ref(),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"event\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
event_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "enable-proxy")]
fn connect_enable_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_enable_proxy_trampoline<
P: IsA<SocketClient>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::enable-proxy\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_enable_proxy_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "family")]
fn connect_family_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_family_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::family\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_family_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "local-address")]
fn connect_local_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_local_address_trampoline<
P: IsA<SocketClient>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::local-address\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_local_address_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "protocol")]
fn connect_protocol_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_protocol_trampoline<
P: IsA<SocketClient>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::protocol\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_protocol_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "proxy-resolver")]
fn connect_proxy_resolver_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_proxy_resolver_trampoline<
P: IsA<SocketClient>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::proxy-resolver\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_proxy_resolver_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "timeout")]
fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_timeout_trampoline<
P: IsA<SocketClient>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::timeout\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_timeout_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "tls")]
fn connect_tls_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_tls_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::tls\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_tls_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg_attr(feature = "v2_72", deprecated = "Since 2.72")]
#[doc(alias = "tls-validation-flags")]
fn connect_tls_validation_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_tls_validation_flags_trampoline<
P: IsA<SocketClient>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::tls-validation-flags\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_tls_validation_flags_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "type")]
fn connect_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_type_trampoline<P: IsA<SocketClient>, F: Fn(&P) + 'static>(
this: *mut ffi::GSocketClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SocketClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::type\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_type_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<SocketClient>> SocketClientExt for O {}