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