1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.SocketClient; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.IOStream; 30 private import gio.ProxyResolverIF; 31 private import gio.SocketAddress; 32 private import gio.SocketConnectableIF; 33 private import gio.SocketConnection; 34 private import gio.c.functions; 35 public import gio.c.types; 36 private import glib.ConstructionException; 37 private import glib.ErrorG; 38 private import glib.GException; 39 private import glib.Str; 40 private import gobject.ObjectG; 41 private import gobject.Signals; 42 private import std.algorithm; 43 44 45 /** 46 * #GSocketClient is a lightweight high-level utility class for connecting to 47 * a network host using a connection oriented socket type. 48 * 49 * You create a #GSocketClient object, set any options you want, and then 50 * call a sync or async connect operation, which returns a #GSocketConnection 51 * subclass on success. 52 * 53 * The type of the #GSocketConnection object returned depends on the type of 54 * the underlying socket that is in use. For instance, for a TCP/IP connection 55 * it will be a #GTcpConnection. 56 * 57 * As #GSocketClient is a lightweight object, you don't need to cache it. You 58 * can just create a new one any time you need one. 59 * 60 * Since: 2.22 61 */ 62 public class SocketClient : ObjectG 63 { 64 /** the main Gtk struct */ 65 protected GSocketClient* gSocketClient; 66 67 /** Get the main Gtk struct */ 68 public GSocketClient* getSocketClientStruct(bool transferOwnership = false) 69 { 70 if (transferOwnership) 71 ownedRef = false; 72 return gSocketClient; 73 } 74 75 /** the main Gtk struct as a void* */ 76 protected override void* getStruct() 77 { 78 return cast(void*)gSocketClient; 79 } 80 81 /** 82 * Sets our main struct and passes it to the parent class. 83 */ 84 public this (GSocketClient* gSocketClient, bool ownedRef = false) 85 { 86 this.gSocketClient = gSocketClient; 87 super(cast(GObject*)gSocketClient, ownedRef); 88 } 89 90 91 /** */ 92 public static GType getType() 93 { 94 return g_socket_client_get_type(); 95 } 96 97 /** 98 * Creates a new #GSocketClient with the default options. 99 * 100 * Returns: a #GSocketClient. 101 * Free the returned object with g_object_unref(). 102 * 103 * Since: 2.22 104 * 105 * Throws: ConstructionException GTK+ fails to create the object. 106 */ 107 public this() 108 { 109 auto __p = g_socket_client_new(); 110 111 if(__p is null) 112 { 113 throw new ConstructionException("null returned by new"); 114 } 115 116 this(cast(GSocketClient*) __p, true); 117 } 118 119 /** 120 * Enable proxy protocols to be handled by the application. When the 121 * indicated proxy protocol is returned by the #GProxyResolver, 122 * #GSocketClient will consider this protocol as supported but will 123 * not try to find a #GProxy instance to handle handshaking. The 124 * application must check for this case by calling 125 * g_socket_connection_get_remote_address() on the returned 126 * #GSocketConnection, and seeing if it's a #GProxyAddress of the 127 * appropriate type, to determine whether or not it needs to handle 128 * the proxy handshaking itself. 129 * 130 * This should be used for proxy protocols that are dialects of 131 * another protocol such as HTTP proxy. It also allows cohabitation of 132 * proxy protocols that are reused between protocols. A good example 133 * is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also 134 * be use as generic socket proxy through the HTTP CONNECT method. 135 * 136 * When the proxy is detected as being an application proxy, TLS handshake 137 * will be skipped. This is required to let the application do the proxy 138 * specific handshake. 139 * 140 * Params: 141 * protocol = The proxy protocol 142 */ 143 public void addApplicationProxy(string protocol) 144 { 145 g_socket_client_add_application_proxy(gSocketClient, Str.toStringz(protocol)); 146 } 147 148 /** 149 * Tries to resolve the @connectable and make a network connection to it. 150 * 151 * Upon a successful connection, a new #GSocketConnection is constructed 152 * and returned. The caller owns this new object and must drop their 153 * reference to it when finished with it. 154 * 155 * The type of the #GSocketConnection object returned depends on the type of 156 * the underlying socket that is used. For instance, for a TCP/IP connection 157 * it will be a #GTcpConnection. 158 * 159 * The socket created will be the same family as the address that the 160 * @connectable resolves to, unless family is set with g_socket_client_set_family() 161 * or indirectly via g_socket_client_set_local_address(). The socket type 162 * defaults to %G_SOCKET_TYPE_STREAM but can be set with 163 * g_socket_client_set_socket_type(). 164 * 165 * If a local address is specified with g_socket_client_set_local_address() the 166 * socket will be bound to this address before connecting. 167 * 168 * Params: 169 * connectable = a #GSocketConnectable specifying the remote address. 170 * cancellable = optional #GCancellable object, %NULL to ignore. 171 * 172 * Returns: a #GSocketConnection on success, %NULL on error. 173 * 174 * Since: 2.22 175 * 176 * Throws: GException on failure. 177 */ 178 public SocketConnection connect(SocketConnectableIF connectable, Cancellable cancellable) 179 { 180 GError* err = null; 181 182 auto __p = g_socket_client_connect(gSocketClient, (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 183 184 if (err !is null) 185 { 186 throw new GException( new ErrorG(err) ); 187 } 188 189 if(__p is null) 190 { 191 return null; 192 } 193 194 return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) __p, true); 195 } 196 197 /** 198 * This is the asynchronous version of g_socket_client_connect(). 199 * 200 * You may wish to prefer the asynchronous version even in synchronous 201 * command line programs because, since 2.60, it implements 202 * [RFC 8305](https://tools.ietf.org/html/rfc8305) "Happy Eyeballs" 203 * recommendations to work around long connection timeouts in networks 204 * where IPv6 is broken by performing an IPv4 connection simultaneously 205 * without waiting for IPv6 to time out, which is not supported by the 206 * synchronous call. (This is not an API guarantee, and may change in 207 * the future.) 208 * 209 * When the operation is finished @callback will be 210 * called. You can then call g_socket_client_connect_finish() to get 211 * the result of the operation. 212 * 213 * Params: 214 * connectable = a #GSocketConnectable specifying the remote address. 215 * cancellable = a #GCancellable, or %NULL 216 * callback = a #GAsyncReadyCallback 217 * userData = user data for the callback 218 * 219 * Since: 2.22 220 */ 221 public void connectAsync(SocketConnectableIF connectable, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 222 { 223 g_socket_client_connect_async(gSocketClient, (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 224 } 225 226 /** 227 * Finishes an async connect operation. See g_socket_client_connect_async() 228 * 229 * Params: 230 * result = a #GAsyncResult. 231 * 232 * Returns: a #GSocketConnection on success, %NULL on error. 233 * 234 * Since: 2.22 235 * 236 * Throws: GException on failure. 237 */ 238 public SocketConnection connectFinish(AsyncResultIF result) 239 { 240 GError* err = null; 241 242 auto __p = g_socket_client_connect_finish(gSocketClient, (result is null) ? null : result.getAsyncResultStruct(), &err); 243 244 if (err !is null) 245 { 246 throw new GException( new ErrorG(err) ); 247 } 248 249 if(__p is null) 250 { 251 return null; 252 } 253 254 return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) __p, true); 255 } 256 257 /** 258 * This is a helper function for g_socket_client_connect(). 259 * 260 * Attempts to create a TCP connection to the named host. 261 * 262 * @host_and_port may be in any of a number of recognized formats; an IPv6 263 * address, an IPv4 address, or a domain name (in which case a DNS 264 * lookup is performed). Quoting with [] is supported for all address 265 * types. A port override may be specified in the usual way with a 266 * colon. Ports may be given as decimal numbers or symbolic names (in 267 * which case an /etc/services lookup is performed). 268 * 269 * If no port override is given in @host_and_port then @default_port will be 270 * used as the port number to connect to. 271 * 272 * In general, @host_and_port is expected to be provided by the user (allowing 273 * them to give the hostname, and a port override if necessary) and 274 * @default_port is expected to be provided by the application. 275 * 276 * In the case that an IP address is given, a single connection 277 * attempt is made. In the case that a name is given, multiple 278 * connection attempts may be made, in turn and according to the 279 * number of address records in DNS, until a connection succeeds. 280 * 281 * Upon a successful connection, a new #GSocketConnection is constructed 282 * and returned. The caller owns this new object and must drop their 283 * reference to it when finished with it. 284 * 285 * In the event of any failure (DNS error, service not found, no hosts 286 * connectable) %NULL is returned and @error (if non-%NULL) is set 287 * accordingly. 288 * 289 * Params: 290 * hostAndPort = the name and optionally port of the host to connect to 291 * defaultPort = the default port to connect to 292 * cancellable = a #GCancellable, or %NULL 293 * 294 * Returns: a #GSocketConnection on success, %NULL on error. 295 * 296 * Since: 2.22 297 * 298 * Throws: GException on failure. 299 */ 300 public SocketConnection connectToHost(string hostAndPort, ushort defaultPort, Cancellable cancellable) 301 { 302 GError* err = null; 303 304 auto __p = g_socket_client_connect_to_host(gSocketClient, Str.toStringz(hostAndPort), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 305 306 if (err !is null) 307 { 308 throw new GException( new ErrorG(err) ); 309 } 310 311 if(__p is null) 312 { 313 return null; 314 } 315 316 return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) __p, true); 317 } 318 319 /** 320 * This is the asynchronous version of g_socket_client_connect_to_host(). 321 * 322 * When the operation is finished @callback will be 323 * called. You can then call g_socket_client_connect_to_host_finish() to get 324 * the result of the operation. 325 * 326 * Params: 327 * hostAndPort = the name and optionally the port of the host to connect to 328 * defaultPort = the default port to connect to 329 * cancellable = a #GCancellable, or %NULL 330 * callback = a #GAsyncReadyCallback 331 * userData = user data for the callback 332 * 333 * Since: 2.22 334 */ 335 public void connectToHostAsync(string hostAndPort, ushort defaultPort, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 336 { 337 g_socket_client_connect_to_host_async(gSocketClient, Str.toStringz(hostAndPort), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 338 } 339 340 /** 341 * Finishes an async connect operation. See g_socket_client_connect_to_host_async() 342 * 343 * Params: 344 * result = a #GAsyncResult. 345 * 346 * Returns: a #GSocketConnection on success, %NULL on error. 347 * 348 * Since: 2.22 349 * 350 * Throws: GException on failure. 351 */ 352 public SocketConnection connectToHostFinish(AsyncResultIF result) 353 { 354 GError* err = null; 355 356 auto __p = g_socket_client_connect_to_host_finish(gSocketClient, (result is null) ? null : result.getAsyncResultStruct(), &err); 357 358 if (err !is null) 359 { 360 throw new GException( new ErrorG(err) ); 361 } 362 363 if(__p is null) 364 { 365 return null; 366 } 367 368 return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) __p, true); 369 } 370 371 /** 372 * Attempts to create a TCP connection to a service. 373 * 374 * This call looks up the SRV record for @service at @domain for the 375 * "tcp" protocol. It then attempts to connect, in turn, to each of 376 * the hosts providing the service until either a connection succeeds 377 * or there are no hosts remaining. 378 * 379 * Upon a successful connection, a new #GSocketConnection is constructed 380 * and returned. The caller owns this new object and must drop their 381 * reference to it when finished with it. 382 * 383 * In the event of any failure (DNS error, service not found, no hosts 384 * connectable) %NULL is returned and @error (if non-%NULL) is set 385 * accordingly. 386 * 387 * Params: 388 * domain = a domain name 389 * service = the name of the service to connect to 390 * cancellable = a #GCancellable, or %NULL 391 * 392 * Returns: a #GSocketConnection if successful, or %NULL on error 393 * 394 * Throws: GException on failure. 395 */ 396 public SocketConnection connectToService(string domain, string service, Cancellable cancellable) 397 { 398 GError* err = null; 399 400 auto __p = g_socket_client_connect_to_service(gSocketClient, Str.toStringz(domain), Str.toStringz(service), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 401 402 if (err !is null) 403 { 404 throw new GException( new ErrorG(err) ); 405 } 406 407 if(__p is null) 408 { 409 return null; 410 } 411 412 return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) __p, true); 413 } 414 415 /** 416 * This is the asynchronous version of 417 * g_socket_client_connect_to_service(). 418 * 419 * Params: 420 * domain = a domain name 421 * service = the name of the service to connect to 422 * cancellable = a #GCancellable, or %NULL 423 * callback = a #GAsyncReadyCallback 424 * userData = user data for the callback 425 * 426 * Since: 2.22 427 */ 428 public void connectToServiceAsync(string domain, string service, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 429 { 430 g_socket_client_connect_to_service_async(gSocketClient, Str.toStringz(domain), Str.toStringz(service), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 431 } 432 433 /** 434 * Finishes an async connect operation. See g_socket_client_connect_to_service_async() 435 * 436 * Params: 437 * result = a #GAsyncResult. 438 * 439 * Returns: a #GSocketConnection on success, %NULL on error. 440 * 441 * Since: 2.22 442 * 443 * Throws: GException on failure. 444 */ 445 public SocketConnection connectToServiceFinish(AsyncResultIF result) 446 { 447 GError* err = null; 448 449 auto __p = g_socket_client_connect_to_service_finish(gSocketClient, (result is null) ? null : result.getAsyncResultStruct(), &err); 450 451 if (err !is null) 452 { 453 throw new GException( new ErrorG(err) ); 454 } 455 456 if(__p is null) 457 { 458 return null; 459 } 460 461 return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) __p, true); 462 } 463 464 /** 465 * This is a helper function for g_socket_client_connect(). 466 * 467 * Attempts to create a TCP connection with a network URI. 468 * 469 * @uri may be any valid URI containing an "authority" (hostname/port) 470 * component. If a port is not specified in the URI, @default_port 471 * will be used. TLS will be negotiated if #GSocketClient:tls is %TRUE. 472 * (#GSocketClient does not know to automatically assume TLS for 473 * certain URI schemes.) 474 * 475 * Using this rather than g_socket_client_connect() or 476 * g_socket_client_connect_to_host() allows #GSocketClient to 477 * determine when to use application-specific proxy protocols. 478 * 479 * Upon a successful connection, a new #GSocketConnection is constructed 480 * and returned. The caller owns this new object and must drop their 481 * reference to it when finished with it. 482 * 483 * In the event of any failure (DNS error, service not found, no hosts 484 * connectable) %NULL is returned and @error (if non-%NULL) is set 485 * accordingly. 486 * 487 * Params: 488 * uri = A network URI 489 * defaultPort = the default port to connect to 490 * cancellable = a #GCancellable, or %NULL 491 * 492 * Returns: a #GSocketConnection on success, %NULL on error. 493 * 494 * Since: 2.26 495 * 496 * Throws: GException on failure. 497 */ 498 public SocketConnection connectToUri(string uri, ushort defaultPort, Cancellable cancellable) 499 { 500 GError* err = null; 501 502 auto __p = g_socket_client_connect_to_uri(gSocketClient, Str.toStringz(uri), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 503 504 if (err !is null) 505 { 506 throw new GException( new ErrorG(err) ); 507 } 508 509 if(__p is null) 510 { 511 return null; 512 } 513 514 return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) __p, true); 515 } 516 517 /** 518 * This is the asynchronous version of g_socket_client_connect_to_uri(). 519 * 520 * When the operation is finished @callback will be 521 * called. You can then call g_socket_client_connect_to_uri_finish() to get 522 * the result of the operation. 523 * 524 * Params: 525 * uri = a network uri 526 * defaultPort = the default port to connect to 527 * cancellable = a #GCancellable, or %NULL 528 * callback = a #GAsyncReadyCallback 529 * userData = user data for the callback 530 * 531 * Since: 2.26 532 */ 533 public void connectToUriAsync(string uri, ushort defaultPort, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 534 { 535 g_socket_client_connect_to_uri_async(gSocketClient, Str.toStringz(uri), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 536 } 537 538 /** 539 * Finishes an async connect operation. See g_socket_client_connect_to_uri_async() 540 * 541 * Params: 542 * result = a #GAsyncResult. 543 * 544 * Returns: a #GSocketConnection on success, %NULL on error. 545 * 546 * Since: 2.26 547 * 548 * Throws: GException on failure. 549 */ 550 public SocketConnection connectToUriFinish(AsyncResultIF result) 551 { 552 GError* err = null; 553 554 auto __p = g_socket_client_connect_to_uri_finish(gSocketClient, (result is null) ? null : result.getAsyncResultStruct(), &err); 555 556 if (err !is null) 557 { 558 throw new GException( new ErrorG(err) ); 559 } 560 561 if(__p is null) 562 { 563 return null; 564 } 565 566 return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) __p, true); 567 } 568 569 /** 570 * Gets the proxy enable state; see g_socket_client_set_enable_proxy() 571 * 572 * Returns: whether proxying is enabled 573 * 574 * Since: 2.26 575 */ 576 public bool getEnableProxy() 577 { 578 return g_socket_client_get_enable_proxy(gSocketClient) != 0; 579 } 580 581 /** 582 * Gets the socket family of the socket client. 583 * 584 * See g_socket_client_set_family() for details. 585 * 586 * Returns: a #GSocketFamily 587 * 588 * Since: 2.22 589 */ 590 public GSocketFamily getFamily() 591 { 592 return g_socket_client_get_family(gSocketClient); 593 } 594 595 /** 596 * Gets the local address of the socket client. 597 * 598 * See g_socket_client_set_local_address() for details. 599 * 600 * Returns: a #GSocketAddress or %NULL. Do not free. 601 * 602 * Since: 2.22 603 */ 604 public SocketAddress getLocalAddress() 605 { 606 auto __p = g_socket_client_get_local_address(gSocketClient); 607 608 if(__p is null) 609 { 610 return null; 611 } 612 613 return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) __p); 614 } 615 616 /** 617 * Gets the protocol name type of the socket client. 618 * 619 * See g_socket_client_set_protocol() for details. 620 * 621 * Returns: a #GSocketProtocol 622 * 623 * Since: 2.22 624 */ 625 public GSocketProtocol getProtocol() 626 { 627 return g_socket_client_get_protocol(gSocketClient); 628 } 629 630 /** 631 * Gets the #GProxyResolver being used by @client. Normally, this will 632 * be the resolver returned by g_proxy_resolver_get_default(), but you 633 * can override it with g_socket_client_set_proxy_resolver(). 634 * 635 * Returns: The #GProxyResolver being used by 636 * @client. 637 * 638 * Since: 2.36 639 */ 640 public ProxyResolverIF getProxyResolver() 641 { 642 auto __p = g_socket_client_get_proxy_resolver(gSocketClient); 643 644 if(__p is null) 645 { 646 return null; 647 } 648 649 return ObjectG.getDObject!(ProxyResolverIF)(cast(GProxyResolver*) __p); 650 } 651 652 /** 653 * Gets the socket type of the socket client. 654 * 655 * See g_socket_client_set_socket_type() for details. 656 * 657 * Returns: a #GSocketFamily 658 * 659 * Since: 2.22 660 */ 661 public GSocketType getSocketType() 662 { 663 return g_socket_client_get_socket_type(gSocketClient); 664 } 665 666 /** 667 * Gets the I/O timeout time for sockets created by @client. 668 * 669 * See g_socket_client_set_timeout() for details. 670 * 671 * Returns: the timeout in seconds 672 * 673 * Since: 2.26 674 */ 675 public uint getTimeout() 676 { 677 return g_socket_client_get_timeout(gSocketClient); 678 } 679 680 /** 681 * Gets whether @client creates TLS connections. See 682 * g_socket_client_set_tls() for details. 683 * 684 * Returns: whether @client uses TLS 685 * 686 * Since: 2.28 687 */ 688 public bool getTls() 689 { 690 return g_socket_client_get_tls(gSocketClient) != 0; 691 } 692 693 /** 694 * Gets the TLS validation flags used creating TLS connections via 695 * @client. 696 * 697 * Returns: the TLS validation flags 698 * 699 * Since: 2.28 700 */ 701 public GTlsCertificateFlags getTlsValidationFlags() 702 { 703 return g_socket_client_get_tls_validation_flags(gSocketClient); 704 } 705 706 /** 707 * Sets whether or not @client attempts to make connections via a 708 * proxy server. When enabled (the default), #GSocketClient will use a 709 * #GProxyResolver to determine if a proxy protocol such as SOCKS is 710 * needed, and automatically do the necessary proxy negotiation. 711 * 712 * See also g_socket_client_set_proxy_resolver(). 713 * 714 * Params: 715 * enable = whether to enable proxies 716 * 717 * Since: 2.26 718 */ 719 public void setEnableProxy(bool enable) 720 { 721 g_socket_client_set_enable_proxy(gSocketClient, enable); 722 } 723 724 /** 725 * Sets the socket family of the socket client. 726 * If this is set to something other than %G_SOCKET_FAMILY_INVALID 727 * then the sockets created by this object will be of the specified 728 * family. 729 * 730 * This might be useful for instance if you want to force the local 731 * connection to be an ipv4 socket, even though the address might 732 * be an ipv6 mapped to ipv4 address. 733 * 734 * Params: 735 * family = a #GSocketFamily 736 * 737 * Since: 2.22 738 */ 739 public void setFamily(GSocketFamily family) 740 { 741 g_socket_client_set_family(gSocketClient, family); 742 } 743 744 /** 745 * Sets the local address of the socket client. 746 * The sockets created by this object will bound to the 747 * specified address (if not %NULL) before connecting. 748 * 749 * This is useful if you want to ensure that the local 750 * side of the connection is on a specific port, or on 751 * a specific interface. 752 * 753 * Params: 754 * address = a #GSocketAddress, or %NULL 755 * 756 * Since: 2.22 757 */ 758 public void setLocalAddress(SocketAddress address) 759 { 760 g_socket_client_set_local_address(gSocketClient, (address is null) ? null : address.getSocketAddressStruct()); 761 } 762 763 /** 764 * Sets the protocol of the socket client. 765 * The sockets created by this object will use of the specified 766 * protocol. 767 * 768 * If @protocol is %G_SOCKET_PROTOCOL_DEFAULT that means to use the default 769 * protocol for the socket family and type. 770 * 771 * Params: 772 * protocol = a #GSocketProtocol 773 * 774 * Since: 2.22 775 */ 776 public void setProtocol(GSocketProtocol protocol) 777 { 778 g_socket_client_set_protocol(gSocketClient, protocol); 779 } 780 781 /** 782 * Overrides the #GProxyResolver used by @client. You can call this if 783 * you want to use specific proxies, rather than using the system 784 * default proxy settings. 785 * 786 * Note that whether or not the proxy resolver is actually used 787 * depends on the setting of #GSocketClient:enable-proxy, which is not 788 * changed by this function (but which is %TRUE by default) 789 * 790 * Params: 791 * proxyResolver = a #GProxyResolver, or %NULL for the 792 * default. 793 * 794 * Since: 2.36 795 */ 796 public void setProxyResolver(ProxyResolverIF proxyResolver) 797 { 798 g_socket_client_set_proxy_resolver(gSocketClient, (proxyResolver is null) ? null : proxyResolver.getProxyResolverStruct()); 799 } 800 801 /** 802 * Sets the socket type of the socket client. 803 * The sockets created by this object will be of the specified 804 * type. 805 * 806 * It doesn't make sense to specify a type of %G_SOCKET_TYPE_DATAGRAM, 807 * as GSocketClient is used for connection oriented services. 808 * 809 * Params: 810 * type = a #GSocketType 811 * 812 * Since: 2.22 813 */ 814 public void setSocketType(GSocketType type) 815 { 816 g_socket_client_set_socket_type(gSocketClient, type); 817 } 818 819 /** 820 * Sets the I/O timeout for sockets created by @client. @timeout is a 821 * time in seconds, or 0 for no timeout (the default). 822 * 823 * The timeout value affects the initial connection attempt as well, 824 * so setting this may cause calls to g_socket_client_connect(), etc, 825 * to fail with %G_IO_ERROR_TIMED_OUT. 826 * 827 * Params: 828 * timeout = the timeout 829 * 830 * Since: 2.26 831 */ 832 public void setTimeout(uint timeout) 833 { 834 g_socket_client_set_timeout(gSocketClient, timeout); 835 } 836 837 /** 838 * Sets whether @client creates TLS (aka SSL) connections. If @tls is 839 * %TRUE, @client will wrap its connections in a #GTlsClientConnection 840 * and perform a TLS handshake when connecting. 841 * 842 * Note that since #GSocketClient must return a #GSocketConnection, 843 * but #GTlsClientConnection is not a #GSocketConnection, this 844 * actually wraps the resulting #GTlsClientConnection in a 845 * #GTcpWrapperConnection when returning it. You can use 846 * g_tcp_wrapper_connection_get_base_io_stream() on the return value 847 * to extract the #GTlsClientConnection. 848 * 849 * If you need to modify the behavior of the TLS handshake (eg, by 850 * setting a client-side certificate to use, or connecting to the 851 * #GTlsConnection::accept-certificate signal), you can connect to 852 * @client's #GSocketClient::event signal and wait for it to be 853 * emitted with %G_SOCKET_CLIENT_TLS_HANDSHAKING, which will give you 854 * a chance to see the #GTlsClientConnection before the handshake 855 * starts. 856 * 857 * Params: 858 * tls = whether to use TLS 859 * 860 * Since: 2.28 861 */ 862 public void setTls(bool tls) 863 { 864 g_socket_client_set_tls(gSocketClient, tls); 865 } 866 867 /** 868 * Sets the TLS validation flags used when creating TLS connections 869 * via @client. The default value is %G_TLS_CERTIFICATE_VALIDATE_ALL. 870 * 871 * Params: 872 * flags = the validation flags 873 * 874 * Since: 2.28 875 */ 876 public void setTlsValidationFlags(GTlsCertificateFlags flags) 877 { 878 g_socket_client_set_tls_validation_flags(gSocketClient, flags); 879 } 880 881 /** 882 * Emitted when @client's activity on @connectable changes state. 883 * Among other things, this can be used to provide progress 884 * information about a network connection in the UI. The meanings of 885 * the different @event values are as follows: 886 * 887 * - %G_SOCKET_CLIENT_RESOLVING: @client is about to look up @connectable 888 * in DNS. @connection will be %NULL. 889 * 890 * - %G_SOCKET_CLIENT_RESOLVED: @client has successfully resolved 891 * @connectable in DNS. @connection will be %NULL. 892 * 893 * - %G_SOCKET_CLIENT_CONNECTING: @client is about to make a connection 894 * to a remote host; either a proxy server or the destination server 895 * itself. @connection is the #GSocketConnection, which is not yet 896 * connected. Since GLib 2.40, you can access the remote 897 * address via g_socket_connection_get_remote_address(). 898 * 899 * - %G_SOCKET_CLIENT_CONNECTED: @client has successfully connected 900 * to a remote host. @connection is the connected #GSocketConnection. 901 * 902 * - %G_SOCKET_CLIENT_PROXY_NEGOTIATING: @client is about to negotiate 903 * with a proxy to get it to connect to @connectable. @connection is 904 * the #GSocketConnection to the proxy server. 905 * 906 * - %G_SOCKET_CLIENT_PROXY_NEGOTIATED: @client has negotiated a 907 * connection to @connectable through a proxy server. @connection is 908 * the stream returned from g_proxy_connect(), which may or may not 909 * be a #GSocketConnection. 910 * 911 * - %G_SOCKET_CLIENT_TLS_HANDSHAKING: @client is about to begin a TLS 912 * handshake. @connection is a #GTlsClientConnection. 913 * 914 * - %G_SOCKET_CLIENT_TLS_HANDSHAKED: @client has successfully completed 915 * the TLS handshake. @connection is a #GTlsClientConnection. 916 * 917 * - %G_SOCKET_CLIENT_COMPLETE: @client has either successfully connected 918 * to @connectable (in which case @connection is the #GSocketConnection 919 * that it will be returning to the caller) or has failed (in which 920 * case @connection is %NULL and the client is about to return an error). 921 * 922 * Each event except %G_SOCKET_CLIENT_COMPLETE may be emitted 923 * multiple times (or not at all) for a given connectable (in 924 * particular, if @client ends up attempting to connect to more than 925 * one address). However, if @client emits the #GSocketClient::event 926 * signal at all for a given connectable, then it will always emit 927 * it with %G_SOCKET_CLIENT_COMPLETE when it is done. 928 * 929 * Note that there may be additional #GSocketClientEvent values in 930 * the future; unrecognized @event values should be ignored. 931 * 932 * Params: 933 * event = the event that is occurring 934 * connectable = the #GSocketConnectable that @event is occurring on 935 * connection = the current representation of the connection 936 * 937 * Since: 2.32 938 */ 939 gulong addOnEvent(void delegate(GSocketClientEvent, SocketConnectableIF, IOStream, SocketClient) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 940 { 941 return Signals.connect(this, "event", dlg, connectFlags ^ ConnectFlags.SWAPPED); 942 } 943 }