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

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

Initial release

File size: 4.3 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.SocketAddress;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.SocketConnectableIF;
26private import gio.SocketConnectableT;
27private import glib.ConstructionException;
28private import glib.ErrorG;
29private import glib.GException;
30private import gobject.ObjectG;
31
32
33/**
34 * #GSocketAddress is the equivalent of struct sockaddr in the BSD
35 * sockets API. This is an abstract class; use #GInetSocketAddress
36 * for internet sockets, or #GUnixSocketAddress for UNIX domain sockets.
37 */
38public class SocketAddress : ObjectG, SocketConnectableIF
39{
40        /** the main Gtk struct */
41        protected GSocketAddress* gSocketAddress;
42
43        /** Get the main Gtk struct */
44        public GSocketAddress* getSocketAddressStruct()
45        {
46                return gSocketAddress;
47        }
48
49        /** the main Gtk struct as a void* */
50        protected override void* getStruct()
51        {
52                return cast(void*)gSocketAddress;
53        }
54
55        protected override void setStruct(GObject* obj)
56        {
57                gSocketAddress = cast(GSocketAddress*)obj;
58                super.setStruct(obj);
59        }
60
61        /**
62         * Sets our main struct and passes it to the parent class.
63         */
64        public this (GSocketAddress* gSocketAddress, bool ownedRef = false)
65        {
66                this.gSocketAddress = gSocketAddress;
67                super(cast(GObject*)gSocketAddress, ownedRef);
68        }
69
70        // add the SocketConnectable capabilities
71        mixin SocketConnectableT!(GSocketAddress);
72
73
74        /** */
75        public static GType getType()
76        {
77                return g_socket_address_get_type();
78        }
79
80        /**
81         * Creates a #GSocketAddress subclass corresponding to the native
82         * struct sockaddr @native.
83         *
84         * Params:
85         *     native = a pointer to a struct sockaddr
86         *     len = the size of the memory location pointed to by @native
87         *
88         * Returns: a new #GSocketAddress if @native could successfully
89         *     be converted, otherwise %NULL
90         *
91         * Since: 2.22
92         *
93         * Throws: ConstructionException GTK+ fails to create the object.
94         */
95        public this(void* native, size_t len)
96        {
97                auto p = g_socket_address_new_from_native(native, len);
98               
99                if(p is null)
100                {
101                        throw new ConstructionException("null returned by new_from_native");
102                }
103               
104                this(cast(GSocketAddress*) p, true);
105        }
106
107        /**
108         * Gets the socket family type of @address.
109         *
110         * Returns: the socket family type of @address
111         *
112         * Since: 2.22
113         */
114        public GSocketFamily getFamily()
115        {
116                return g_socket_address_get_family(gSocketAddress);
117        }
118
119        /**
120         * Gets the size of @address's native struct sockaddr.
121         * You can use this to allocate memory to pass to
122         * g_socket_address_to_native().
123         *
124         * Returns: the size of the native struct sockaddr that
125         *     @address represents
126         *
127         * Since: 2.22
128         */
129        public ptrdiff_t getNativeSize()
130        {
131                return g_socket_address_get_native_size(gSocketAddress);
132        }
133
134        /**
135         * Converts a #GSocketAddress to a native struct sockaddr, which can
136         * be passed to low-level functions like connect() or bind().
137         *
138         * If not enough space is available, a %G_IO_ERROR_NO_SPACE error
139         * is returned. If the address type is not known on the system
140         * then a %G_IO_ERROR_NOT_SUPPORTED error is returned.
141         *
142         * Params:
143         *     dest = a pointer to a memory location that will contain the native
144         *         struct sockaddr
145         *     destlen = the size of @dest. Must be at least as large as
146         *         g_socket_address_get_native_size()
147         *
148         * Returns: %TRUE if @dest was filled in, %FALSE on error
149         *
150         * Since: 2.22
151         *
152         * Throws: GException on failure.
153         */
154        public bool toNative(void* dest, size_t destlen)
155        {
156                GError* err = null;
157               
158                auto p = g_socket_address_to_native(gSocketAddress, dest, destlen, &err) != 0;
159               
160                if (err !is null)
161                {
162                        throw new GException( new ErrorG(err) );
163                }
164               
165                return p;
166        }
167}
Note: See TracBrowser for help on using the repository browser.