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

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

Initial release

File size: 57.1 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.Socket;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.Cancellable;
26private import gio.Credentials;
27private import gio.DatagramBasedIF;
28private import gio.DatagramBasedT;
29private import gio.InetAddress;
30private import gio.InitableIF;
31private import gio.InitableT;
32private import gio.SocketAddress;
33private import gio.SocketConnection;
34private import gio.SocketControlMessage;
35private import glib.ConstructionException;
36private import glib.ErrorG;
37private import glib.GException;
38private import glib.Source;
39private import glib.Str;
40private import gobject.ObjectG;
41
42
43/**
44 * A #GSocket is a low-level networking primitive. It is a more or less
45 * direct mapping of the BSD socket API in a portable GObject based API.
46 * It supports both the UNIX socket implementations and winsock2 on Windows.
47 *
48 * #GSocket is the platform independent base upon which the higher level
49 * network primitives are based. Applications are not typically meant to
50 * use it directly, but rather through classes like #GSocketClient,
51 * #GSocketService and #GSocketConnection. However there may be cases where
52 * direct use of #GSocket is useful.
53 *
54 * #GSocket implements the #GInitable interface, so if it is manually constructed
55 * by e.g. g_object_new() you must call g_initable_init() and check the
56 * results before using the object. This is done automatically in
57 * g_socket_new() and g_socket_new_from_fd(), so these functions can return
58 * %NULL.
59 *
60 * Sockets operate in two general modes, blocking or non-blocking. When
61 * in blocking mode all operations block until the requested operation
62 * is finished or there is an error. In non-blocking mode all calls that
63 * would block return immediately with a %G_IO_ERROR_WOULD_BLOCK error.
64 * To know when a call would successfully run you can call g_socket_condition_check(),
65 * or g_socket_condition_wait(). You can also use g_socket_create_source() and
66 * attach it to a #GMainContext to get callbacks when I/O is possible.
67 * Note that all sockets are always set to non blocking mode in the system, and
68 * blocking mode is emulated in GSocket.
69 *
70 * When working in non-blocking mode applications should always be able to
71 * handle getting a %G_IO_ERROR_WOULD_BLOCK error even when some other
72 * function said that I/O was possible. This can easily happen in case
73 * of a race condition in the application, but it can also happen for other
74 * reasons. For instance, on Windows a socket is always seen as writable
75 * until a write returns %G_IO_ERROR_WOULD_BLOCK.
76 *
77 * #GSockets can be either connection oriented or datagram based.
78 * For connection oriented types you must first establish a connection by
79 * either connecting to an address or accepting a connection from another
80 * address. For connectionless socket types the target/source address is
81 * specified or received in each I/O operation.
82 *
83 * All socket file descriptors are set to be close-on-exec.
84 *
85 * Note that creating a #GSocket causes the signal %SIGPIPE to be
86 * ignored for the remainder of the program. If you are writing a
87 * command-line utility that uses #GSocket, you may need to take into
88 * account the fact that your program will not automatically be killed
89 * if it tries to write to %stdout after it has been closed.
90 *
91 * Like most other APIs in GLib, #GSocket is not inherently thread safe. To use
92 * a #GSocket concurrently from multiple threads, you must implement your own
93 * locking.
94 *
95 * Since: 2.22
96 */
97public class Socket : ObjectG, DatagramBasedIF, InitableIF
98{
99        /** the main Gtk struct */
100        protected GSocket* gSocket;
101
102        /** Get the main Gtk struct */
103        public GSocket* getSocketStruct()
104        {
105                return gSocket;
106        }
107
108        /** the main Gtk struct as a void* */
109        protected override void* getStruct()
110        {
111                return cast(void*)gSocket;
112        }
113
114        protected override void setStruct(GObject* obj)
115        {
116                gSocket = cast(GSocket*)obj;
117                super.setStruct(obj);
118        }
119
120        /**
121         * Sets our main struct and passes it to the parent class.
122         */
123        public this (GSocket* gSocket, bool ownedRef = false)
124        {
125                this.gSocket = gSocket;
126                super(cast(GObject*)gSocket, ownedRef);
127        }
128
129        // add the DatagramBased capabilities
130        mixin DatagramBasedT!(GSocket);
131
132        // add the Initable capabilities
133        mixin InitableT!(GSocket);
134
135
136        /** */
137        public static GType getType()
138        {
139                return g_socket_get_type();
140        }
141
142        /**
143         * Creates a new #GSocket with the defined family, type and protocol.
144         * If @protocol is 0 (%G_SOCKET_PROTOCOL_DEFAULT) the default protocol type
145         * for the family and type is used.
146         *
147         * The @protocol is a family and type specific int that specifies what
148         * kind of protocol to use. #GSocketProtocol lists several common ones.
149         * Many families only support one protocol, and use 0 for this, others
150         * support several and using 0 means to use the default protocol for
151         * the family and type.
152         *
153         * The protocol id is passed directly to the operating
154         * system, so you can use protocols not listed in #GSocketProtocol if you
155         * know the protocol number used for it.
156         *
157         * Params:
158         *     family = the socket family to use, e.g. %G_SOCKET_FAMILY_IPV4.
159         *     type = the socket type to use.
160         *     protocol = the id of the protocol to use, or 0 for default.
161         *
162         * Returns: a #GSocket or %NULL on error.
163         *     Free the returned object with g_object_unref().
164         *
165         * Since: 2.22
166         *
167         * Throws: GException on failure.
168         * Throws: ConstructionException GTK+ fails to create the object.
169         */
170        public this(GSocketFamily family, GSocketType type, GSocketProtocol protocol)
171        {
172                GError* err = null;
173               
174                auto p = g_socket_new(family, type, protocol, &err);
175               
176                if (err !is null)
177                {
178                        throw new GException( new ErrorG(err) );
179                }
180               
181                if(p is null)
182                {
183                        throw new ConstructionException("null returned by new");
184                }
185               
186                this(cast(GSocket*) p, true);
187        }
188
189        /**
190         * Creates a new #GSocket from a native file descriptor
191         * or winsock SOCKET handle.
192         *
193         * This reads all the settings from the file descriptor so that
194         * all properties should work. Note that the file descriptor
195         * will be set to non-blocking mode, independent on the blocking
196         * mode of the #GSocket.
197         *
198         * On success, the returned #GSocket takes ownership of @fd. On failure, the
199         * caller must close @fd themselves.
200         *
201         * Since GLib 2.46, it is no longer a fatal error to call this on a non-socket
202         * descriptor.  Instead, a GError will be set with code %G_IO_ERROR_FAILED
203         *
204         * Params:
205         *     fd = a native socket file descriptor.
206         *
207         * Returns: a #GSocket or %NULL on error.
208         *     Free the returned object with g_object_unref().
209         *
210         * Since: 2.22
211         *
212         * Throws: GException on failure.
213         * Throws: ConstructionException GTK+ fails to create the object.
214         */
215        public this(int fd)
216        {
217                GError* err = null;
218               
219                auto p = g_socket_new_from_fd(fd, &err);
220               
221                if (err !is null)
222                {
223                        throw new GException( new ErrorG(err) );
224                }
225               
226                if(p is null)
227                {
228                        throw new ConstructionException("null returned by new_from_fd");
229                }
230               
231                this(cast(GSocket*) p, true);
232        }
233
234        /**
235         * Accept incoming connections on a connection-based socket. This removes
236         * the first outstanding connection request from the listening socket and
237         * creates a #GSocket object for it.
238         *
239         * The @socket must be bound to a local address with g_socket_bind() and
240         * must be listening for incoming connections (g_socket_listen()).
241         *
242         * If there are no outstanding connections then the operation will block
243         * or return %G_IO_ERROR_WOULD_BLOCK if non-blocking I/O is enabled.
244         * To be notified of an incoming connection, wait for the %G_IO_IN condition.
245         *
246         * Params:
247         *     cancellable = a %GCancellable or %NULL
248         *
249         * Returns: a new #GSocket, or %NULL on error.
250         *     Free the returned object with g_object_unref().
251         *
252         * Since: 2.22
253         *
254         * Throws: GException on failure.
255         */
256        public Socket accept(Cancellable cancellable)
257        {
258                GError* err = null;
259               
260                auto p = g_socket_accept(gSocket, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
261               
262                if (err !is null)
263                {
264                        throw new GException( new ErrorG(err) );
265                }
266               
267                if(p is null)
268                {
269                        return null;
270                }
271               
272                return ObjectG.getDObject!(Socket)(cast(GSocket*) p, true);
273        }
274
275        /**
276         * When a socket is created it is attached to an address family, but it
277         * doesn't have an address in this family. g_socket_bind() assigns the
278         * address (sometimes called name) of the socket.
279         *
280         * It is generally required to bind to a local address before you can
281         * receive connections. (See g_socket_listen() and g_socket_accept() ).
282         * In certain situations, you may also want to bind a socket that will be
283         * used to initiate connections, though this is not normally required.
284         *
285         * If @socket is a TCP socket, then @allow_reuse controls the setting
286         * of the `SO_REUSEADDR` socket option; normally it should be %TRUE for
287         * server sockets (sockets that you will eventually call
288         * g_socket_accept() on), and %FALSE for client sockets. (Failing to
289         * set this flag on a server socket may cause g_socket_bind() to return
290         * %G_IO_ERROR_ADDRESS_IN_USE if the server program is stopped and then
291         * immediately restarted.)
292         *
293         * If @socket is a UDP socket, then @allow_reuse determines whether or
294         * not other UDP sockets can be bound to the same address at the same
295         * time. In particular, you can have several UDP sockets bound to the
296         * same address, and they will all receive all of the multicast and
297         * broadcast packets sent to that address. (The behavior of unicast
298         * UDP packets to an address with multiple listeners is not defined.)
299         *
300         * Params:
301         *     address = a #GSocketAddress specifying the local address.
302         *     allowReuse = whether to allow reusing this address
303         *
304         * Returns: %TRUE on success, %FALSE on error.
305         *
306         * Since: 2.22
307         *
308         * Throws: GException on failure.
309         */
310        public bool bind(SocketAddress address, bool allowReuse)
311        {
312                GError* err = null;
313               
314                auto p = g_socket_bind(gSocket, (address is null) ? null : address.getSocketAddressStruct(), allowReuse, &err) != 0;
315               
316                if (err !is null)
317                {
318                        throw new GException( new ErrorG(err) );
319                }
320               
321                return p;
322        }
323
324        /**
325         * Checks and resets the pending connect error for the socket.
326         * This is used to check for errors when g_socket_connect() is
327         * used in non-blocking mode.
328         *
329         * Returns: %TRUE if no error, %FALSE otherwise, setting @error to the error
330         *
331         * Since: 2.22
332         *
333         * Throws: GException on failure.
334         */
335        public bool checkConnectResult()
336        {
337                GError* err = null;
338               
339                auto p = g_socket_check_connect_result(gSocket, &err) != 0;
340               
341                if (err !is null)
342                {
343                        throw new GException( new ErrorG(err) );
344                }
345               
346                return p;
347        }
348
349        /**
350         * Closes the socket, shutting down any active connection.
351         *
352         * Closing a socket does not wait for all outstanding I/O operations
353         * to finish, so the caller should not rely on them to be guaranteed
354         * to complete even if the close returns with no error.
355         *
356         * Once the socket is closed, all other operations will return
357         * %G_IO_ERROR_CLOSED. Closing a socket multiple times will not
358         * return an error.
359         *
360         * Sockets will be automatically closed when the last reference
361         * is dropped, but you might want to call this function to make sure
362         * resources are released as early as possible.
363         *
364         * Beware that due to the way that TCP works, it is possible for
365         * recently-sent data to be lost if either you close a socket while the
366         * %G_IO_IN condition is set, or else if the remote connection tries to
367         * send something to you after you close the socket but before it has
368         * finished reading all of the data you sent. There is no easy generic
369         * way to avoid this problem; the easiest fix is to design the network
370         * protocol such that the client will never send data "out of turn".
371         * Another solution is for the server to half-close the connection by
372         * calling g_socket_shutdown() with only the @shutdown_write flag set,
373         * and then wait for the client to notice this and close its side of the
374         * connection, after which the server can safely call g_socket_close().
375         * (This is what #GTcpConnection does if you call
376         * g_tcp_connection_set_graceful_disconnect(). But of course, this
377         * only works if the client will close its connection after the server
378         * does.)
379         *
380         * Returns: %TRUE on success, %FALSE on error
381         *
382         * Since: 2.22
383         *
384         * Throws: GException on failure.
385         */
386        public bool close()
387        {
388                GError* err = null;
389               
390                auto p = g_socket_close(gSocket, &err) != 0;
391               
392                if (err !is null)
393                {
394                        throw new GException( new ErrorG(err) );
395                }
396               
397                return p;
398        }
399
400        /**
401         * Checks on the readiness of @socket to perform operations.
402         * The operations specified in @condition are checked for and masked
403         * against the currently-satisfied conditions on @socket. The result
404         * is returned.
405         *
406         * Note that on Windows, it is possible for an operation to return
407         * %G_IO_ERROR_WOULD_BLOCK even immediately after
408         * g_socket_condition_check() has claimed that the socket is ready for
409         * writing. Rather than calling g_socket_condition_check() and then
410         * writing to the socket if it succeeds, it is generally better to
411         * simply try writing to the socket right away, and try again later if
412         * the initial attempt returns %G_IO_ERROR_WOULD_BLOCK.
413         *
414         * It is meaningless to specify %G_IO_ERR or %G_IO_HUP in condition;
415         * these conditions will always be set in the output if they are true.
416         *
417         * This call never blocks.
418         *
419         * Params:
420         *     condition = a #GIOCondition mask to check
421         *
422         * Returns: the @GIOCondition mask of the current state
423         *
424         * Since: 2.22
425         */
426        public GIOCondition conditionCheck(GIOCondition condition)
427        {
428                return g_socket_condition_check(gSocket, condition);
429        }
430
431        /**
432         * Waits for up to @timeout microseconds for @condition to become true
433         * on @socket. If the condition is met, %TRUE is returned.
434         *
435         * If @cancellable is cancelled before the condition is met, or if
436         * @timeout (or the socket's #GSocket:timeout) is reached before the
437         * condition is met, then %FALSE is returned and @error, if non-%NULL,
438         * is set to the appropriate value (%G_IO_ERROR_CANCELLED or
439         * %G_IO_ERROR_TIMED_OUT).
440         *
441         * If you don't want a timeout, use g_socket_condition_wait().
442         * (Alternatively, you can pass -1 for @timeout.)
443         *
444         * Note that although @timeout is in microseconds for consistency with
445         * other GLib APIs, this function actually only has millisecond
446         * resolution, and the behavior is undefined if @timeout is not an
447         * exact number of milliseconds.
448         *
449         * Params:
450         *     condition = a #GIOCondition mask to wait for
451         *     timeout = the maximum time (in microseconds) to wait, or -1
452         *     cancellable = a #GCancellable, or %NULL
453         *
454         * Returns: %TRUE if the condition was met, %FALSE otherwise
455         *
456         * Since: 2.32
457         *
458         * Throws: GException on failure.
459         */
460        public bool conditionTimedWait(GIOCondition condition, long timeout, Cancellable cancellable)
461        {
462                GError* err = null;
463               
464                auto p = g_socket_condition_timed_wait(gSocket, condition, timeout, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
465               
466                if (err !is null)
467                {
468                        throw new GException( new ErrorG(err) );
469                }
470               
471                return p;
472        }
473
474        /**
475         * Waits for @condition to become true on @socket. When the condition
476         * is met, %TRUE is returned.
477         *
478         * If @cancellable is cancelled before the condition is met, or if the
479         * socket has a timeout set and it is reached before the condition is
480         * met, then %FALSE is returned and @error, if non-%NULL, is set to
481         * the appropriate value (%G_IO_ERROR_CANCELLED or
482         * %G_IO_ERROR_TIMED_OUT).
483         *
484         * See also g_socket_condition_timed_wait().
485         *
486         * Params:
487         *     condition = a #GIOCondition mask to wait for
488         *     cancellable = a #GCancellable, or %NULL
489         *
490         * Returns: %TRUE if the condition was met, %FALSE otherwise
491         *
492         * Since: 2.22
493         *
494         * Throws: GException on failure.
495         */
496        public bool conditionWait(GIOCondition condition, Cancellable cancellable)
497        {
498                GError* err = null;
499               
500                auto p = g_socket_condition_wait(gSocket, condition, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
501               
502                if (err !is null)
503                {
504                        throw new GException( new ErrorG(err) );
505                }
506               
507                return p;
508        }
509
510        /**
511         * Connect the socket to the specified remote address.
512         *
513         * For connection oriented socket this generally means we attempt to make
514         * a connection to the @address. For a connection-less socket it sets
515         * the default address for g_socket_send() and discards all incoming datagrams
516         * from other sources.
517         *
518         * Generally connection oriented sockets can only connect once, but
519         * connection-less sockets can connect multiple times to change the
520         * default address.
521         *
522         * If the connect call needs to do network I/O it will block, unless
523         * non-blocking I/O is enabled. Then %G_IO_ERROR_PENDING is returned
524         * and the user can be notified of the connection finishing by waiting
525         * for the G_IO_OUT condition. The result of the connection must then be
526         * checked with g_socket_check_connect_result().
527         *
528         * Params:
529         *     address = a #GSocketAddress specifying the remote address.
530         *     cancellable = a %GCancellable or %NULL
531         *
532         * Returns: %TRUE if connected, %FALSE on error.
533         *
534         * Since: 2.22
535         *
536         * Throws: GException on failure.
537         */
538        public bool connect(SocketAddress address, Cancellable cancellable)
539        {
540                GError* err = null;
541               
542                auto p = g_socket_connect(gSocket, (address is null) ? null : address.getSocketAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
543               
544                if (err !is null)
545                {
546                        throw new GException( new ErrorG(err) );
547                }
548               
549                return p;
550        }
551
552        /**
553         * Creates a #GSocketConnection subclass of the right type for
554         * @socket.
555         *
556         * Returns: a #GSocketConnection
557         *
558         * Since: 2.22
559         */
560        public SocketConnection connectionFactoryCreateConnection()
561        {
562                auto p = g_socket_connection_factory_create_connection(gSocket);
563               
564                if(p is null)
565                {
566                        return null;
567                }
568               
569                return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
570        }
571
572        /**
573         * Creates a #GSource that can be attached to a %GMainContext to monitor
574         * for the availability of the specified @condition on the socket. The #GSource
575         * keeps a reference to the @socket.
576         *
577         * The callback on the source is of the #GSocketSourceFunc type.
578         *
579         * It is meaningless to specify %G_IO_ERR or %G_IO_HUP in @condition;
580         * these conditions will always be reported output if they are true.
581         *
582         * @cancellable if not %NULL can be used to cancel the source, which will
583         * cause the source to trigger, reporting the current condition (which
584         * is likely 0 unless cancellation happened at the same time as a
585         * condition change). You can check for this in the callback using
586         * g_cancellable_is_cancelled().
587         *
588         * If @socket has a timeout set, and it is reached before @condition
589         * occurs, the source will then trigger anyway, reporting %G_IO_IN or
590         * %G_IO_OUT depending on @condition. However, @socket will have been
591         * marked as having had a timeout, and so the next #GSocket I/O method
592         * you call will then fail with a %G_IO_ERROR_TIMED_OUT.
593         *
594         * Params:
595         *     condition = a #GIOCondition mask to monitor
596         *     cancellable = a %GCancellable or %NULL
597         *
598         * Returns: a newly allocated %GSource, free with g_source_unref().
599         *
600         * Since: 2.22
601         */
602        public Source createSource(GIOCondition condition, Cancellable cancellable)
603        {
604                auto p = g_socket_create_source(gSocket, condition, (cancellable is null) ? null : cancellable.getCancellableStruct());
605               
606                if(p is null)
607                {
608                        return null;
609                }
610               
611                return new Source(cast(GSource*) p, true);
612        }
613
614        /**
615         * Get the amount of data pending in the OS input buffer.
616         *
617         * If @socket is a UDP or SCTP socket, this will return the size of
618         * just the next packet, even if additional packets are buffered after
619         * that one.
620         *
621         * Note that on Windows, this function is rather inefficient in the
622         * UDP case, and so if you know any plausible upper bound on the size
623         * of the incoming packet, it is better to just do a
624         * g_socket_receive() with a buffer of that size, rather than calling
625         * g_socket_get_available_bytes() first and then doing a receive of
626         * exactly the right size.
627         *
628         * Returns: the number of bytes that can be read from the socket
629         *     without blocking or truncating, or -1 on error.
630         *
631         * Since: 2.32
632         */
633        public ptrdiff_t getAvailableBytes()
634        {
635                return g_socket_get_available_bytes(gSocket);
636        }
637
638        /**
639         * Gets the blocking mode of the socket. For details on blocking I/O,
640         * see g_socket_set_blocking().
641         *
642         * Returns: %TRUE if blocking I/O is used, %FALSE otherwise.
643         *
644         * Since: 2.22
645         */
646        public bool getBlocking()
647        {
648                return g_socket_get_blocking(gSocket) != 0;
649        }
650
651        /**
652         * Gets the broadcast setting on @socket; if %TRUE,
653         * it is possible to send packets to broadcast
654         * addresses.
655         *
656         * Returns: the broadcast setting on @socket
657         *
658         * Since: 2.32
659         */
660        public bool getBroadcast()
661        {
662                return g_socket_get_broadcast(gSocket) != 0;
663        }
664
665        /**
666         * Returns the credentials of the foreign process connected to this
667         * socket, if any (e.g. it is only supported for %G_SOCKET_FAMILY_UNIX
668         * sockets).
669         *
670         * If this operation isn't supported on the OS, the method fails with
671         * the %G_IO_ERROR_NOT_SUPPORTED error. On Linux this is implemented
672         * by reading the %SO_PEERCRED option on the underlying socket.
673         *
674         * Other ways to obtain credentials from a foreign peer includes the
675         * #GUnixCredentialsMessage type and
676         * g_unix_connection_send_credentials() /
677         * g_unix_connection_receive_credentials() functions.
678         *
679         * Returns: %NULL if @error is set, otherwise a #GCredentials object
680         *     that must be freed with g_object_unref().
681         *
682         * Since: 2.26
683         *
684         * Throws: GException on failure.
685         */
686        public Credentials getCredentials()
687        {
688                GError* err = null;
689               
690                auto p = g_socket_get_credentials(gSocket, &err);
691               
692                if (err !is null)
693                {
694                        throw new GException( new ErrorG(err) );
695                }
696               
697                if(p is null)
698                {
699                        return null;
700                }
701               
702                return ObjectG.getDObject!(Credentials)(cast(GCredentials*) p, true);
703        }
704
705        /**
706         * Gets the socket family of the socket.
707         *
708         * Returns: a #GSocketFamily
709         *
710         * Since: 2.22
711         */
712        public GSocketFamily getFamily()
713        {
714                return g_socket_get_family(gSocket);
715        }
716
717        /**
718         * Returns the underlying OS socket object. On unix this
719         * is a socket file descriptor, and on Windows this is
720         * a Winsock2 SOCKET handle. This may be useful for
721         * doing platform specific or otherwise unusual operations
722         * on the socket.
723         *
724         * Returns: the file descriptor of the socket.
725         *
726         * Since: 2.22
727         */
728        public int getFd()
729        {
730                return g_socket_get_fd(gSocket);
731        }
732
733        /**
734         * Gets the keepalive mode of the socket. For details on this,
735         * see g_socket_set_keepalive().
736         *
737         * Returns: %TRUE if keepalive is active, %FALSE otherwise.
738         *
739         * Since: 2.22
740         */
741        public bool getKeepalive()
742        {
743                return g_socket_get_keepalive(gSocket) != 0;
744        }
745
746        /**
747         * Gets the listen backlog setting of the socket. For details on this,
748         * see g_socket_set_listen_backlog().
749         *
750         * Returns: the maximum number of pending connections.
751         *
752         * Since: 2.22
753         */
754        public int getListenBacklog()
755        {
756                return g_socket_get_listen_backlog(gSocket);
757        }
758
759        /**
760         * Try to get the local address of a bound socket. This is only
761         * useful if the socket has been bound to a local address,
762         * either explicitly or implicitly when connecting.
763         *
764         * Returns: a #GSocketAddress or %NULL on error.
765         *     Free the returned object with g_object_unref().
766         *
767         * Since: 2.22
768         *
769         * Throws: GException on failure.
770         */
771        public SocketAddress getLocalAddress()
772        {
773                GError* err = null;
774               
775                auto p = g_socket_get_local_address(gSocket, &err);
776               
777                if (err !is null)
778                {
779                        throw new GException( new ErrorG(err) );
780                }
781               
782                if(p is null)
783                {
784                        return null;
785                }
786               
787                return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p, true);
788        }
789
790        /**
791         * Gets the multicast loopback setting on @socket; if %TRUE (the
792         * default), outgoing multicast packets will be looped back to
793         * multicast listeners on the same host.
794         *
795         * Returns: the multicast loopback setting on @socket
796         *
797         * Since: 2.32
798         */
799        public bool getMulticastLoopback()
800        {
801                return g_socket_get_multicast_loopback(gSocket) != 0;
802        }
803
804        /**
805         * Gets the multicast time-to-live setting on @socket; see
806         * g_socket_set_multicast_ttl() for more details.
807         *
808         * Returns: the multicast time-to-live setting on @socket
809         *
810         * Since: 2.32
811         */
812        public uint getMulticastTtl()
813        {
814                return g_socket_get_multicast_ttl(gSocket);
815        }
816
817        /**
818         * Gets the value of an integer-valued option on @socket, as with
819         * getsockopt(). (If you need to fetch a  non-integer-valued option,
820         * you will need to call getsockopt() directly.)
821         *
822         * The [<gio/gnetworking.h>][gio-gnetworking.h]
823         * header pulls in system headers that will define most of the
824         * standard/portable socket options. For unusual socket protocols or
825         * platform-dependent options, you may need to include additional
826         * headers.
827         *
828         * Note that even for socket options that are a single byte in size,
829         * @value is still a pointer to a #gint variable, not a #guchar;
830         * g_socket_get_option() will handle the conversion internally.
831         *
832         * Params:
833         *     level = the "API level" of the option (eg, `SOL_SOCKET`)
834         *     optname = the "name" of the option (eg, `SO_BROADCAST`)
835         *     value = return location for the option value
836         *
837         * Returns: success or failure. On failure, @error will be set, and
838         *     the system error value (`errno` or WSAGetLastError()) will still
839         *     be set to the result of the getsockopt() call.
840         *
841         * Since: 2.36
842         *
843         * Throws: GException on failure.
844         */
845        public bool getOption(int level, int optname, out int value)
846        {
847                GError* err = null;
848               
849                auto p = g_socket_get_option(gSocket, level, optname, &value, &err) != 0;
850               
851                if (err !is null)
852                {
853                        throw new GException( new ErrorG(err) );
854                }
855               
856                return p;
857        }
858
859        /**
860         * Gets the socket protocol id the socket was created with.
861         * In case the protocol is unknown, -1 is returned.
862         *
863         * Returns: a protocol id, or -1 if unknown
864         *
865         * Since: 2.22
866         */
867        public GSocketProtocol getProtocol()
868        {
869                return g_socket_get_protocol(gSocket);
870        }
871
872        /**
873         * Try to get the remove address of a connected socket. This is only
874         * useful for connection oriented sockets that have been connected.
875         *
876         * Returns: a #GSocketAddress or %NULL on error.
877         *     Free the returned object with g_object_unref().
878         *
879         * Since: 2.22
880         *
881         * Throws: GException on failure.
882         */
883        public SocketAddress getRemoteAddress()
884        {
885                GError* err = null;
886               
887                auto p = g_socket_get_remote_address(gSocket, &err);
888               
889                if (err !is null)
890                {
891                        throw new GException( new ErrorG(err) );
892                }
893               
894                if(p is null)
895                {
896                        return null;
897                }
898               
899                return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p, true);
900        }
901
902        /**
903         * Gets the socket type of the socket.
904         *
905         * Returns: a #GSocketType
906         *
907         * Since: 2.22
908         */
909        public GSocketType getSocketType()
910        {
911                return g_socket_get_socket_type(gSocket);
912        }
913
914        /**
915         * Gets the timeout setting of the socket. For details on this, see
916         * g_socket_set_timeout().
917         *
918         * Returns: the timeout in seconds
919         *
920         * Since: 2.26
921         */
922        public uint getTimeout()
923        {
924                return g_socket_get_timeout(gSocket);
925        }
926
927        /**
928         * Gets the unicast time-to-live setting on @socket; see
929         * g_socket_set_ttl() for more details.
930         *
931         * Returns: the time-to-live setting on @socket
932         *
933         * Since: 2.32
934         */
935        public uint getTtl()
936        {
937                return g_socket_get_ttl(gSocket);
938        }
939
940        /**
941         * Checks whether a socket is closed.
942         *
943         * Returns: %TRUE if socket is closed, %FALSE otherwise
944         *
945         * Since: 2.22
946         */
947        public bool isClosed()
948        {
949                return g_socket_is_closed(gSocket) != 0;
950        }
951
952        /**
953         * Check whether the socket is connected. This is only useful for
954         * connection-oriented sockets.
955         *
956         * Returns: %TRUE if socket is connected, %FALSE otherwise.
957         *
958         * Since: 2.22
959         */
960        public bool isConnected()
961        {
962                return g_socket_is_connected(gSocket) != 0;
963        }
964
965        /**
966         * Registers @socket to receive multicast messages sent to @group.
967         * @socket must be a %G_SOCKET_TYPE_DATAGRAM socket, and must have
968         * been bound to an appropriate interface and port with
969         * g_socket_bind().
970         *
971         * If @iface is %NULL, the system will automatically pick an interface
972         * to bind to based on @group.
973         *
974         * If @source_specific is %TRUE, source-specific multicast as defined
975         * in RFC 4604 is used. Note that on older platforms this may fail
976         * with a %G_IO_ERROR_NOT_SUPPORTED error.
977         *
978         * Params:
979         *     group = a #GInetAddress specifying the group address to join.
980         *     sourceSpecific = %TRUE if source-specific multicast should be used
981         *     iface = Name of the interface to use, or %NULL
982         *
983         * Returns: %TRUE on success, %FALSE on error.
984         *
985         * Since: 2.32
986         *
987         * Throws: GException on failure.
988         */
989        public bool joinMulticastGroup(InetAddress group, bool sourceSpecific, string iface)
990        {
991                GError* err = null;
992               
993                auto p = g_socket_join_multicast_group(gSocket, (group is null) ? null : group.getInetAddressStruct(), sourceSpecific, Str.toStringz(iface), &err) != 0;
994               
995                if (err !is null)
996                {
997                        throw new GException( new ErrorG(err) );
998                }
999               
1000                return p;
1001        }
1002
1003        /**
1004         * Removes @socket from the multicast group defined by @group, @iface,
1005         * and @source_specific (which must all have the same values they had
1006         * when you joined the group).
1007         *
1008         * @socket remains bound to its address and port, and can still receive
1009         * unicast messages after calling this.
1010         *
1011         * Params:
1012         *     group = a #GInetAddress specifying the group address to leave.
1013         *     sourceSpecific = %TRUE if source-specific multicast was used
1014         *     iface = Interface used
1015         *
1016         * Returns: %TRUE on success, %FALSE on error.
1017         *
1018         * Since: 2.32
1019         *
1020         * Throws: GException on failure.
1021         */
1022        public bool leaveMulticastGroup(InetAddress group, bool sourceSpecific, string iface)
1023        {
1024                GError* err = null;
1025               
1026                auto p = g_socket_leave_multicast_group(gSocket, (group is null) ? null : group.getInetAddressStruct(), sourceSpecific, Str.toStringz(iface), &err) != 0;
1027               
1028                if (err !is null)
1029                {
1030                        throw new GException( new ErrorG(err) );
1031                }
1032               
1033                return p;
1034        }
1035
1036        /**
1037         * Marks the socket as a server socket, i.e. a socket that is used
1038         * to accept incoming requests using g_socket_accept().
1039         *
1040         * Before calling this the socket must be bound to a local address using
1041         * g_socket_bind().
1042         *
1043         * To set the maximum amount of outstanding clients, use
1044         * g_socket_set_listen_backlog().
1045         *
1046         * Returns: %TRUE on success, %FALSE on error.
1047         *
1048         * Since: 2.22
1049         *
1050         * Throws: GException on failure.
1051         */
1052        public bool listen()
1053        {
1054                GError* err = null;
1055               
1056                auto p = g_socket_listen(gSocket, &err) != 0;
1057               
1058                if (err !is null)
1059                {
1060                        throw new GException( new ErrorG(err) );
1061                }
1062               
1063                return p;
1064        }
1065
1066        /**
1067         * Receive data (up to @size bytes) from a socket. This is mainly used by
1068         * connection-oriented sockets; it is identical to g_socket_receive_from()
1069         * with @address set to %NULL.
1070         *
1071         * For %G_SOCKET_TYPE_DATAGRAM and %G_SOCKET_TYPE_SEQPACKET sockets,
1072         * g_socket_receive() will always read either 0 or 1 complete messages from
1073         * the socket. If the received message is too large to fit in @buffer, then
1074         * the data beyond @size bytes will be discarded, without any explicit
1075         * indication that this has occurred.
1076         *
1077         * For %G_SOCKET_TYPE_STREAM sockets, g_socket_receive() can return any
1078         * number of bytes, up to @size. If more than @size bytes have been
1079         * received, the additional data will be returned in future calls to
1080         * g_socket_receive().
1081         *
1082         * If the socket is in blocking mode the call will block until there
1083         * is some data to receive, the connection is closed, or there is an
1084         * error. If there is no data available and the socket is in
1085         * non-blocking mode, a %G_IO_ERROR_WOULD_BLOCK error will be
1086         * returned. To be notified when data is available, wait for the
1087         * %G_IO_IN condition.
1088         *
1089         * On error -1 is returned and @error is set accordingly.
1090         *
1091         * Params:
1092         *     buffer = a buffer to
1093         *         read data into (which should be at least @size bytes long).
1094         *     size = the number of bytes you want to read from the socket
1095         *     cancellable = a %GCancellable or %NULL
1096         *
1097         * Returns: Number of bytes read, or 0 if the connection was closed by
1098         *     the peer, or -1 on error
1099         *
1100         * Since: 2.22
1101         *
1102         * Throws: GException on failure.
1103         */
1104        public ptrdiff_t receive(ref char[] buffer, Cancellable cancellable)
1105        {
1106                GError* err = null;
1107               
1108                auto p = g_socket_receive(gSocket, buffer.ptr, cast(size_t)buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1109               
1110                if (err !is null)
1111                {
1112                        throw new GException( new ErrorG(err) );
1113                }
1114               
1115                return p;
1116        }
1117
1118        /**
1119         * Receive data (up to @size bytes) from a socket.
1120         *
1121         * If @address is non-%NULL then @address will be set equal to the
1122         * source address of the received packet.
1123         * @address is owned by the caller.
1124         *
1125         * See g_socket_receive() for additional information.
1126         *
1127         * Params:
1128         *     address = a pointer to a #GSocketAddress
1129         *         pointer, or %NULL
1130         *     buffer = a buffer to
1131         *         read data into (which should be at least @size bytes long).
1132         *     size = the number of bytes you want to read from the socket
1133         *     cancellable = a %GCancellable or %NULL
1134         *
1135         * Returns: Number of bytes read, or 0 if the connection was closed by
1136         *     the peer, or -1 on error
1137         *
1138         * Since: 2.22
1139         *
1140         * Throws: GException on failure.
1141         */
1142        public ptrdiff_t receiveFrom(out SocketAddress address, ref char[] buffer, Cancellable cancellable)
1143        {
1144                GSocketAddress* outaddress = null;
1145                GError* err = null;
1146               
1147                auto p = g_socket_receive_from(gSocket, &outaddress, buffer.ptr, cast(size_t)buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1148               
1149                if (err !is null)
1150                {
1151                        throw new GException( new ErrorG(err) );
1152                }
1153               
1154                address = ObjectG.getDObject!(SocketAddress)(outaddress);
1155               
1156                return p;
1157        }
1158
1159        /**
1160         * Receive data from a socket.  This is the most complicated and
1161         * fully-featured version of this call. For easier use, see
1162         * g_socket_receive() and g_socket_receive_from().
1163         *
1164         * If @address is non-%NULL then @address will be set equal to the
1165         * source address of the received packet.
1166         * @address is owned by the caller.
1167         *
1168         * @vector must point to an array of #GInputVector structs and
1169         * @num_vectors must be the length of this array.  These structs
1170         * describe the buffers that received data will be scattered into.
1171         * If @num_vectors is -1, then @vectors is assumed to be terminated
1172         * by a #GInputVector with a %NULL buffer pointer.
1173         *
1174         * As a special case, if @num_vectors is 0 (in which case, @vectors
1175         * may of course be %NULL), then a single byte is received and
1176         * discarded. This is to facilitate the common practice of sending a
1177         * single '\0' byte for the purposes of transferring ancillary data.
1178         *
1179         * @messages, if non-%NULL, will be set to point to a newly-allocated
1180         * array of #GSocketControlMessage instances or %NULL if no such
1181         * messages was received. These correspond to the control messages
1182         * received from the kernel, one #GSocketControlMessage per message
1183         * from the kernel. This array is %NULL-terminated and must be freed
1184         * by the caller using g_free() after calling g_object_unref() on each
1185         * element. If @messages is %NULL, any control messages received will
1186         * be discarded.
1187         *
1188         * @num_messages, if non-%NULL, will be set to the number of control
1189         * messages received.
1190         *
1191         * If both @messages and @num_messages are non-%NULL, then
1192         * @num_messages gives the number of #GSocketControlMessage instances
1193         * in @messages (ie: not including the %NULL terminator).
1194         *
1195         * @flags is an in/out parameter. The commonly available arguments
1196         * for this are available in the #GSocketMsgFlags enum, but the
1197         * values there are the same as the system values, and the flags
1198         * are passed in as-is, so you can pass in system-specific flags too
1199         * (and g_socket_receive_message() may pass system-specific flags out).
1200         *
1201         * As with g_socket_receive(), data may be discarded if @socket is
1202         * %G_SOCKET_TYPE_DATAGRAM or %G_SOCKET_TYPE_SEQPACKET and you do not
1203         * provide enough buffer space to read a complete message. You can pass
1204         * %G_SOCKET_MSG_PEEK in @flags to peek at the current message without
1205         * removing it from the receive queue, but there is no portable way to find
1206         * out the length of the message other than by reading it into a
1207         * sufficiently-large buffer.
1208         *
1209         * If the socket is in blocking mode the call will block until there
1210         * is some data to receive, the connection is closed, or there is an
1211         * error. If there is no data available and the socket is in
1212         * non-blocking mode, a %G_IO_ERROR_WOULD_BLOCK error will be
1213         * returned. To be notified when data is available, wait for the
1214         * %G_IO_IN condition.
1215         *
1216         * On error -1 is returned and @error is set accordingly.
1217         *
1218         * Params:
1219         *     address = a pointer to a #GSocketAddress
1220         *         pointer, or %NULL
1221         *     vectors = an array of #GInputVector structs
1222         *     numVectors = the number of elements in @vectors, or -1
1223         *     messages = a pointer which
1224         *         may be filled with an array of #GSocketControlMessages, or %NULL
1225         *     numMessages = a pointer which will be filled with the number of
1226         *         elements in @messages, or %NULL
1227         *     flags = a pointer to an int containing #GSocketMsgFlags flags
1228         *     cancellable = a %GCancellable or %NULL
1229         *
1230         * Returns: Number of bytes read, or 0 if the connection was closed by
1231         *     the peer, or -1 on error
1232         *
1233         * Since: 2.22
1234         *
1235         * Throws: GException on failure.
1236         */
1237        public ptrdiff_t receiveMessage(out SocketAddress address, GInputVector[] vectors, out SocketControlMessage[] messages, int* flags, Cancellable cancellable)
1238        {
1239                GSocketAddress* outaddress = null;
1240                GSocketControlMessage** outmessages = null;
1241                int numMessages;
1242                GError* err = null;
1243               
1244                auto p = g_socket_receive_message(gSocket, &outaddress, vectors.ptr, cast(int)vectors.length, &outmessages, &numMessages, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1245               
1246                if (err !is null)
1247                {
1248                        throw new GException( new ErrorG(err) );
1249                }
1250               
1251                address = ObjectG.getDObject!(SocketAddress)(outaddress);
1252               
1253                messages = new SocketControlMessage[numMessages];
1254                for(size_t i = 0; i < numMessages; i++)
1255                {
1256                        messages[i] = ObjectG.getDObject!(SocketControlMessage)(cast(GSocketControlMessage*) outmessages[i]);
1257                }
1258               
1259                return p;
1260        }
1261
1262        /** */
1263        public int receiveMessages(GInputMessage* messages, uint numMessages, int flags, Cancellable cancellable)
1264        {
1265                GError* err = null;
1266               
1267                auto p = g_socket_receive_messages(gSocket, messages, numMessages, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1268               
1269                if (err !is null)
1270                {
1271                        throw new GException( new ErrorG(err) );
1272                }
1273               
1274                return p;
1275        }
1276
1277        /**
1278         * This behaves exactly the same as g_socket_receive(), except that
1279         * the choice of blocking or non-blocking behavior is determined by
1280         * the @blocking argument rather than by @socket's properties.
1281         *
1282         * Params:
1283         *     buffer = a buffer to
1284         *         read data into (which should be at least @size bytes long).
1285         *     size = the number of bytes you want to read from the socket
1286         *     blocking = whether to do blocking or non-blocking I/O
1287         *     cancellable = a %GCancellable or %NULL
1288         *
1289         * Returns: Number of bytes read, or 0 if the connection was closed by
1290         *     the peer, or -1 on error
1291         *
1292         * Since: 2.26
1293         *
1294         * Throws: GException on failure.
1295         */
1296        public ptrdiff_t receiveWithBlocking(string buffer, bool blocking, Cancellable cancellable)
1297        {
1298                GError* err = null;
1299               
1300                auto p = g_socket_receive_with_blocking(gSocket, Str.toStringz(buffer), cast(size_t)buffer.length, blocking, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1301               
1302                if (err !is null)
1303                {
1304                        throw new GException( new ErrorG(err) );
1305                }
1306               
1307                return p;
1308        }
1309
1310        /**
1311         * Tries to send @size bytes from @buffer on the socket. This is
1312         * mainly used by connection-oriented sockets; it is identical to
1313         * g_socket_send_to() with @address set to %NULL.
1314         *
1315         * If the socket is in blocking mode the call will block until there is
1316         * space for the data in the socket queue. If there is no space available
1317         * and the socket is in non-blocking mode a %G_IO_ERROR_WOULD_BLOCK error
1318         * will be returned. To be notified when space is available, wait for the
1319         * %G_IO_OUT condition. Note though that you may still receive
1320         * %G_IO_ERROR_WOULD_BLOCK from g_socket_send() even if you were previously
1321         * notified of a %G_IO_OUT condition. (On Windows in particular, this is
1322         * very common due to the way the underlying APIs work.)
1323         *
1324         * On error -1 is returned and @error is set accordingly.
1325         *
1326         * Params:
1327         *     buffer = the buffer
1328         *         containing the data to send.
1329         *     size = the number of bytes to send
1330         *     cancellable = a %GCancellable or %NULL
1331         *
1332         * Returns: Number of bytes written (which may be less than @size), or -1
1333         *     on error
1334         *
1335         * Since: 2.22
1336         *
1337         * Throws: GException on failure.
1338         */
1339        public ptrdiff_t send(string buffer, Cancellable cancellable)
1340        {
1341                GError* err = null;
1342               
1343                auto p = g_socket_send(gSocket, Str.toStringz(buffer), cast(size_t)buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1344               
1345                if (err !is null)
1346                {
1347                        throw new GException( new ErrorG(err) );
1348                }
1349               
1350                return p;
1351        }
1352
1353        /**
1354         * Send data to @address on @socket.  This is the most complicated and
1355         * fully-featured version of this call. For easier use, see
1356         * g_socket_send() and g_socket_send_to().
1357         *
1358         * If @address is %NULL then the message is sent to the default receiver
1359         * (set by g_socket_connect()).
1360         *
1361         * @vectors must point to an array of #GOutputVector structs and
1362         * @num_vectors must be the length of this array. (If @num_vectors is -1,
1363         * then @vectors is assumed to be terminated by a #GOutputVector with a
1364         * %NULL buffer pointer.) The #GOutputVector structs describe the buffers
1365         * that the sent data will be gathered from. Using multiple
1366         * #GOutputVectors is more memory-efficient than manually copying
1367         * data from multiple sources into a single buffer, and more
1368         * network-efficient than making multiple calls to g_socket_send().
1369         *
1370         * @messages, if non-%NULL, is taken to point to an array of @num_messages
1371         * #GSocketControlMessage instances. These correspond to the control
1372         * messages to be sent on the socket.
1373         * If @num_messages is -1 then @messages is treated as a %NULL-terminated
1374         * array.
1375         *
1376         * @flags modify how the message is sent. The commonly available arguments
1377         * for this are available in the #GSocketMsgFlags enum, but the
1378         * values there are the same as the system values, and the flags
1379         * are passed in as-is, so you can pass in system-specific flags too.
1380         *
1381         * If the socket is in blocking mode the call will block until there is
1382         * space for the data in the socket queue. If there is no space available
1383         * and the socket is in non-blocking mode a %G_IO_ERROR_WOULD_BLOCK error
1384         * will be returned. To be notified when space is available, wait for the
1385         * %G_IO_OUT condition. Note though that you may still receive
1386         * %G_IO_ERROR_WOULD_BLOCK from g_socket_send() even if you were previously
1387         * notified of a %G_IO_OUT condition. (On Windows in particular, this is
1388         * very common due to the way the underlying APIs work.)
1389         *
1390         * On error -1 is returned and @error is set accordingly.
1391         *
1392         * Params:
1393         *     address = a #GSocketAddress, or %NULL
1394         *     vectors = an array of #GOutputVector structs
1395         *     numVectors = the number of elements in @vectors, or -1
1396         *     messages = a pointer to an
1397         *         array of #GSocketControlMessages, or %NULL.
1398         *     numMessages = number of elements in @messages, or -1.
1399         *     flags = an int containing #GSocketMsgFlags flags
1400         *     cancellable = a %GCancellable or %NULL
1401         *
1402         * Returns: Number of bytes written (which may be less than @size), or -1
1403         *     on error
1404         *
1405         * Since: 2.22
1406         *
1407         * Throws: GException on failure.
1408         */
1409        public ptrdiff_t sendMessage(SocketAddress address, GOutputVector[] vectors, SocketControlMessage[] messages, int flags, Cancellable cancellable)
1410        {
1411                GSocketControlMessage*[] messagesArray = new GSocketControlMessage*[messages.length];
1412                for ( int i = 0; i < messages.length; i++ )
1413                {
1414                        messagesArray[i] = messages[i].getSocketControlMessageStruct();
1415                }
1416               
1417                GError* err = null;
1418               
1419                auto p = g_socket_send_message(gSocket, (address is null) ? null : address.getSocketAddressStruct(), vectors.ptr, cast(int)vectors.length, messagesArray.ptr, cast(int)messages.length, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1420               
1421                if (err !is null)
1422                {
1423                        throw new GException( new ErrorG(err) );
1424                }
1425               
1426                return p;
1427        }
1428
1429        /**
1430         * Send multiple data messages from @socket in one go.  This is the most
1431         * complicated and fully-featured version of this call. For easier use, see
1432         * g_socket_send(), g_socket_send_to(), and g_socket_send_message().
1433         *
1434         * @messages must point to an array of #GOutputMessage structs and
1435         * @num_messages must be the length of this array. Each #GOutputMessage
1436         * contains an address to send the data to, and a pointer to an array of
1437         * #GOutputVector structs to describe the buffers that the data to be sent
1438         * for each message will be gathered from. Using multiple #GOutputVectors is
1439         * more memory-efficient than manually copying data from multiple sources
1440         * into a single buffer, and more network-efficient than making multiple
1441         * calls to g_socket_send(). Sending multiple messages in one go avoids the
1442         * overhead of making a lot of syscalls in scenarios where a lot of data
1443         * packets need to be sent (e.g. high-bandwidth video streaming over RTP/UDP),
1444         * or where the same data needs to be sent to multiple recipients.
1445         *
1446         * @flags modify how the message is sent. The commonly available arguments
1447         * for this are available in the #GSocketMsgFlags enum, but the
1448         * values there are the same as the system values, and the flags
1449         * are passed in as-is, so you can pass in system-specific flags too.
1450         *
1451         * If the socket is in blocking mode the call will block until there is
1452         * space for all the data in the socket queue. If there is no space available
1453         * and the socket is in non-blocking mode a %G_IO_ERROR_WOULD_BLOCK error
1454         * will be returned if no data was written at all, otherwise the number of
1455         * messages sent will be returned. To be notified when space is available,
1456         * wait for the %G_IO_OUT condition. Note though that you may still receive
1457         * %G_IO_ERROR_WOULD_BLOCK from g_socket_send() even if you were previously
1458         * notified of a %G_IO_OUT condition. (On Windows in particular, this is
1459         * very common due to the way the underlying APIs work.)
1460         *
1461         * On error -1 is returned and @error is set accordingly.
1462         *
1463         * Params:
1464         *     messages = an array of #GOutputMessage structs
1465         *     numMessages = the number of elements in @messages
1466         *     flags = an int containing #GSocketMsgFlags flags
1467         *     cancellable = a %GCancellable or %NULL
1468         *
1469         * Returns: number of messages sent, or -1 on error. Note that the number of
1470         *     messages sent may be smaller than @num_messages if the socket is
1471         *     non-blocking or if @num_messages was larger than UIO_MAXIOV (1024),
1472         *     in which case the caller may re-try to send the remaining messages.
1473         *
1474         * Since: 2.44
1475         *
1476         * Throws: GException on failure.
1477         */
1478        public int sendMessages(GOutputMessage[] messages, int flags, Cancellable cancellable)
1479        {
1480                GError* err = null;
1481               
1482                auto p = g_socket_send_messages(gSocket, messages.ptr, cast(uint)messages.length, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1483               
1484                if (err !is null)
1485                {
1486                        throw new GException( new ErrorG(err) );
1487                }
1488               
1489                return p;
1490        }
1491
1492        /**
1493         * Tries to send @size bytes from @buffer to @address. If @address is
1494         * %NULL then the message is sent to the default receiver (set by
1495         * g_socket_connect()).
1496         *
1497         * See g_socket_send() for additional information.
1498         *
1499         * Params:
1500         *     address = a #GSocketAddress, or %NULL
1501         *     buffer = the buffer
1502         *         containing the data to send.
1503         *     size = the number of bytes to send
1504         *     cancellable = a %GCancellable or %NULL
1505         *
1506         * Returns: Number of bytes written (which may be less than @size), or -1
1507         *     on error
1508         *
1509         * Since: 2.22
1510         *
1511         * Throws: GException on failure.
1512         */
1513        public ptrdiff_t sendTo(SocketAddress address, string buffer, Cancellable cancellable)
1514        {
1515                GError* err = null;
1516               
1517                auto p = g_socket_send_to(gSocket, (address is null) ? null : address.getSocketAddressStruct(), Str.toStringz(buffer), cast(size_t)buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1518               
1519                if (err !is null)
1520                {
1521                        throw new GException( new ErrorG(err) );
1522                }
1523               
1524                return p;
1525        }
1526
1527        /**
1528         * This behaves exactly the same as g_socket_send(), except that
1529         * the choice of blocking or non-blocking behavior is determined by
1530         * the @blocking argument rather than by @socket's properties.
1531         *
1532         * Params:
1533         *     buffer = the buffer
1534         *         containing the data to send.
1535         *     size = the number of bytes to send
1536         *     blocking = whether to do blocking or non-blocking I/O
1537         *     cancellable = a %GCancellable or %NULL
1538         *
1539         * Returns: Number of bytes written (which may be less than @size), or -1
1540         *     on error
1541         *
1542         * Since: 2.26
1543         *
1544         * Throws: GException on failure.
1545         */
1546        public ptrdiff_t sendWithBlocking(string buffer, bool blocking, Cancellable cancellable)
1547        {
1548                GError* err = null;
1549               
1550                auto p = g_socket_send_with_blocking(gSocket, Str.toStringz(buffer), cast(size_t)buffer.length, blocking, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
1551               
1552                if (err !is null)
1553                {
1554                        throw new GException( new ErrorG(err) );
1555                }
1556               
1557                return p;
1558        }
1559
1560        /**
1561         * Sets the blocking mode of the socket. In blocking mode
1562         * all operations block until they succeed or there is an error. In
1563         * non-blocking mode all functions return results immediately or
1564         * with a %G_IO_ERROR_WOULD_BLOCK error.
1565         *
1566         * All sockets are created in blocking mode. However, note that the
1567         * platform level socket is always non-blocking, and blocking mode
1568         * is a GSocket level feature.
1569         *
1570         * Params:
1571         *     blocking = Whether to use blocking I/O or not.
1572         *
1573         * Since: 2.22
1574         */
1575        public void setBlocking(bool blocking)
1576        {
1577                g_socket_set_blocking(gSocket, blocking);
1578        }
1579
1580        /**
1581         * Sets whether @socket should allow sending to broadcast addresses.
1582         * This is %FALSE by default.
1583         *
1584         * Params:
1585         *     broadcast = whether @socket should allow sending to broadcast
1586         *         addresses
1587         *
1588         * Since: 2.32
1589         */
1590        public void setBroadcast(bool broadcast)
1591        {
1592                g_socket_set_broadcast(gSocket, broadcast);
1593        }
1594
1595        /**
1596         * Sets or unsets the %SO_KEEPALIVE flag on the underlying socket. When
1597         * this flag is set on a socket, the system will attempt to verify that the
1598         * remote socket endpoint is still present if a sufficiently long period of
1599         * time passes with no data being exchanged. If the system is unable to
1600         * verify the presence of the remote endpoint, it will automatically close
1601         * the connection.
1602         *
1603         * This option is only functional on certain kinds of sockets. (Notably,
1604         * %G_SOCKET_PROTOCOL_TCP sockets.)
1605         *
1606         * The exact time between pings is system- and protocol-dependent, but will
1607         * normally be at least two hours. Most commonly, you would set this flag
1608         * on a server socket if you want to allow clients to remain idle for long
1609         * periods of time, but also want to ensure that connections are eventually
1610         * garbage-collected if clients crash or become unreachable.
1611         *
1612         * Params:
1613         *     keepalive = Value for the keepalive flag
1614         *
1615         * Since: 2.22
1616         */
1617        public void setKeepalive(bool keepalive)
1618        {
1619                g_socket_set_keepalive(gSocket, keepalive);
1620        }
1621
1622        /**
1623         * Sets the maximum number of outstanding connections allowed
1624         * when listening on this socket. If more clients than this are
1625         * connecting to the socket and the application is not handling them
1626         * on time then the new connections will be refused.
1627         *
1628         * Note that this must be called before g_socket_listen() and has no
1629         * effect if called after that.
1630         *
1631         * Params:
1632         *     backlog = the maximum number of pending connections.
1633         *
1634         * Since: 2.22
1635         */
1636        public void setListenBacklog(int backlog)
1637        {
1638                g_socket_set_listen_backlog(gSocket, backlog);
1639        }
1640
1641        /**
1642         * Sets whether outgoing multicast packets will be received by sockets
1643         * listening on that multicast address on the same host. This is %TRUE
1644         * by default.
1645         *
1646         * Params:
1647         *     loopback = whether @socket should receive messages sent to its
1648         *         multicast groups from the local host
1649         *
1650         * Since: 2.32
1651         */
1652        public void setMulticastLoopback(bool loopback)
1653        {
1654                g_socket_set_multicast_loopback(gSocket, loopback);
1655        }
1656
1657        /**
1658         * Sets the time-to-live for outgoing multicast datagrams on @socket.
1659         * By default, this is 1, meaning that multicast packets will not leave
1660         * the local network.
1661         *
1662         * Params:
1663         *     ttl = the time-to-live value for all multicast datagrams on @socket
1664         *
1665         * Since: 2.32
1666         */
1667        public void setMulticastTtl(uint ttl)
1668        {
1669                g_socket_set_multicast_ttl(gSocket, ttl);
1670        }
1671
1672        /**
1673         * Sets the value of an integer-valued option on @socket, as with
1674         * setsockopt(). (If you need to set a non-integer-valued option,
1675         * you will need to call setsockopt() directly.)
1676         *
1677         * The [<gio/gnetworking.h>][gio-gnetworking.h]
1678         * header pulls in system headers that will define most of the
1679         * standard/portable socket options. For unusual socket protocols or
1680         * platform-dependent options, you may need to include additional
1681         * headers.
1682         *
1683         * Params:
1684         *     level = the "API level" of the option (eg, `SOL_SOCKET`)
1685         *     optname = the "name" of the option (eg, `SO_BROADCAST`)
1686         *     value = the value to set the option to
1687         *
1688         * Returns: success or failure. On failure, @error will be set, and
1689         *     the system error value (`errno` or WSAGetLastError()) will still
1690         *     be set to the result of the setsockopt() call.
1691         *
1692         * Since: 2.36
1693         *
1694         * Throws: GException on failure.
1695         */
1696        public bool setOption(int level, int optname, int value)
1697        {
1698                GError* err = null;
1699               
1700                auto p = g_socket_set_option(gSocket, level, optname, value, &err) != 0;
1701               
1702                if (err !is null)
1703                {
1704                        throw new GException( new ErrorG(err) );
1705                }
1706               
1707                return p;
1708        }
1709
1710        /**
1711         * Sets the time in seconds after which I/O operations on @socket will
1712         * time out if they have not yet completed.
1713         *
1714         * On a blocking socket, this means that any blocking #GSocket
1715         * operation will time out after @timeout seconds of inactivity,
1716         * returning %G_IO_ERROR_TIMED_OUT.
1717         *
1718         * On a non-blocking socket, calls to g_socket_condition_wait() will
1719         * also fail with %G_IO_ERROR_TIMED_OUT after the given time. Sources
1720         * created with g_socket_create_source() will trigger after
1721         * @timeout seconds of inactivity, with the requested condition
1722         * set, at which point calling g_socket_receive(), g_socket_send(),
1723         * g_socket_check_connect_result(), etc, will fail with
1724         * %G_IO_ERROR_TIMED_OUT.
1725         *
1726         * If @timeout is 0 (the default), operations will never time out
1727         * on their own.
1728         *
1729         * Note that if an I/O operation is interrupted by a signal, this may
1730         * cause the timeout to be reset.
1731         *
1732         * Params:
1733         *     timeout = the timeout for @socket, in seconds, or 0 for none
1734         *
1735         * Since: 2.26
1736         */
1737        public void setTimeout(uint timeout)
1738        {
1739                g_socket_set_timeout(gSocket, timeout);
1740        }
1741
1742        /**
1743         * Sets the time-to-live for outgoing unicast packets on @socket.
1744         * By default the platform-specific default value is used.
1745         *
1746         * Params:
1747         *     ttl = the time-to-live value for all unicast packets on @socket
1748         *
1749         * Since: 2.32
1750         */
1751        public void setTtl(uint ttl)
1752        {
1753                g_socket_set_ttl(gSocket, ttl);
1754        }
1755
1756        /**
1757         * Shut down part of a full-duplex connection.
1758         *
1759         * If @shutdown_read is %TRUE then the receiving side of the connection
1760         * is shut down, and further reading is disallowed.
1761         *
1762         * If @shutdown_write is %TRUE then the sending side of the connection
1763         * is shut down, and further writing is disallowed.
1764         *
1765         * It is allowed for both @shutdown_read and @shutdown_write to be %TRUE.
1766         *
1767         * One example where this is used is graceful disconnect for TCP connections
1768         * where you close the sending side, then wait for the other side to close
1769         * the connection, thus ensuring that the other side saw all sent data.
1770         *
1771         * Params:
1772         *     shutdownRead = whether to shut down the read side
1773         *     shutdownWrite = whether to shut down the write side
1774         *
1775         * Returns: %TRUE on success, %FALSE on error
1776         *
1777         * Since: 2.22
1778         *
1779         * Throws: GException on failure.
1780         */
1781        public bool shutdown(bool shutdownRead, bool shutdownWrite)
1782        {
1783                GError* err = null;
1784               
1785                auto p = g_socket_shutdown(gSocket, shutdownRead, shutdownWrite, &err) != 0;
1786               
1787                if (err !is null)
1788                {
1789                        throw new GException( new ErrorG(err) );
1790                }
1791               
1792                return p;
1793        }
1794
1795        /**
1796         * Checks if a socket is capable of speaking IPv4.
1797         *
1798         * IPv4 sockets are capable of speaking IPv4.  On some operating systems
1799         * and under some combinations of circumstances IPv6 sockets are also
1800         * capable of speaking IPv4.  See RFC 3493 section 3.7 for more
1801         * information.
1802         *
1803         * No other types of sockets are currently considered as being capable
1804         * of speaking IPv4.
1805         *
1806         * Returns: %TRUE if this socket can be used with IPv4.
1807         *
1808         * Since: 2.22
1809         */
1810        public bool speaksIpv4()
1811        {
1812                return g_socket_speaks_ipv4(gSocket) != 0;
1813        }
1814}
Note: See TracBrowser for help on using the repository browser.