source: appstream-generator/build/girepo/gio/SocketClient.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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