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

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

Initial release

File size: 8.2 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.SocketConnection;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.AsyncResultIF;
26private import gio.Cancellable;
27private import gio.IOStream;
28private import gio.Socket;
29private import gio.SocketAddress;
30private import glib.ErrorG;
31private import glib.GException;
32private import gobject.ObjectG;
33
34
35/**
36 * #GSocketConnection is a #GIOStream for a connected socket. They
37 * can be created either by #GSocketClient when connecting to a host,
38 * or by #GSocketListener when accepting a new client.
39 *
40 * The type of the #GSocketConnection object returned from these calls
41 * depends on the type of the underlying socket that is in use. For
42 * instance, for a TCP/IP connection it will be a #GTcpConnection.
43 *
44 * Choosing what type of object to construct is done with the socket
45 * connection factory, and it is possible for 3rd parties to register
46 * custom socket connection types for specific combination of socket
47 * family/type/protocol using g_socket_connection_factory_register_type().
48 *
49 * To close a #GSocketConnection, use g_io_stream_close(). Closing both
50 * substreams of the #GIOStream separately will not close the underlying
51 * #GSocket.
52 *
53 * Since: 2.22
54 */
55public class SocketConnection : IOStream
56{
57        /** the main Gtk struct */
58        protected GSocketConnection* gSocketConnection;
59
60        /** Get the main Gtk struct */
61        public GSocketConnection* getSocketConnectionStruct()
62        {
63                return gSocketConnection;
64        }
65
66        /** the main Gtk struct as a void* */
67        protected override void* getStruct()
68        {
69                return cast(void*)gSocketConnection;
70        }
71
72        protected override void setStruct(GObject* obj)
73        {
74                gSocketConnection = cast(GSocketConnection*)obj;
75                super.setStruct(obj);
76        }
77
78        /**
79         * Sets our main struct and passes it to the parent class.
80         */
81        public this (GSocketConnection* gSocketConnection, bool ownedRef = false)
82        {
83                this.gSocketConnection = gSocketConnection;
84                super(cast(GIOStream*)gSocketConnection, ownedRef);
85        }
86
87
88        /** */
89        public static GType getType()
90        {
91                return g_socket_connection_get_type();
92        }
93
94        /**
95         * Looks up the #GType to be used when creating socket connections on
96         * sockets with the specified @family, @type and @protocol_id.
97         *
98         * If no type is registered, the #GSocketConnection base type is returned.
99         *
100         * Params:
101         *     family = a #GSocketFamily
102         *     type = a #GSocketType
103         *     protocolId = a protocol id
104         *
105         * Returns: a #GType
106         *
107         * Since: 2.22
108         */
109        public static GType factoryLookupType(GSocketFamily family, GSocketType type, int protocolId)
110        {
111                return g_socket_connection_factory_lookup_type(family, type, protocolId);
112        }
113
114        /**
115         * Looks up the #GType to be used when creating socket connections on
116         * sockets with the specified @family, @type and @protocol.
117         *
118         * If no type is registered, the #GSocketConnection base type is returned.
119         *
120         * Params:
121         *     gType = a #GType, inheriting from %G_TYPE_SOCKET_CONNECTION
122         *     family = a #GSocketFamily
123         *     type = a #GSocketType
124         *     protocol = a protocol id
125         *
126         * Since: 2.22
127         */
128        public static void factoryRegisterType(GType gType, GSocketFamily family, GSocketType type, int protocol)
129        {
130                g_socket_connection_factory_register_type(gType, family, type, protocol);
131        }
132
133        /**
134         * Connect @connection to the specified remote address.
135         *
136         * Params:
137         *     address = a #GSocketAddress specifying the remote address.
138         *     cancellable = a %GCancellable or %NULL
139         *
140         * Returns: %TRUE if the connection succeeded, %FALSE on error
141         *
142         * Since: 2.32
143         *
144         * Throws: GException on failure.
145         */
146        public bool connect(SocketAddress address, Cancellable cancellable)
147        {
148                GError* err = null;
149               
150                auto p = g_socket_connection_connect(gSocketConnection, (address is null) ? null : address.getSocketAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
151               
152                if (err !is null)
153                {
154                        throw new GException( new ErrorG(err) );
155                }
156               
157                return p;
158        }
159
160        /**
161         * Asynchronously connect @connection to the specified remote address.
162         *
163         * This clears the #GSocket:blocking flag on @connection's underlying
164         * socket if it is currently set.
165         *
166         * Use g_socket_connection_connect_finish() to retrieve the result.
167         *
168         * Params:
169         *     address = a #GSocketAddress specifying the remote address.
170         *     cancellable = a %GCancellable or %NULL
171         *     callback = a #GAsyncReadyCallback
172         *     userData = user data for the callback
173         *
174         * Since: 2.32
175         */
176        public void connectAsync(SocketAddress address, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
177        {
178                g_socket_connection_connect_async(gSocketConnection, (address is null) ? null : address.getSocketAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
179        }
180
181        /**
182         * Gets the result of a g_socket_connection_connect_async() call.
183         *
184         * Params:
185         *     result = the #GAsyncResult
186         *
187         * Returns: %TRUE if the connection succeeded, %FALSE on error
188         *
189         * Since: 2.32
190         *
191         * Throws: GException on failure.
192         */
193        public bool connectFinish(AsyncResultIF result)
194        {
195                GError* err = null;
196               
197                auto p = g_socket_connection_connect_finish(gSocketConnection, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
198               
199                if (err !is null)
200                {
201                        throw new GException( new ErrorG(err) );
202                }
203               
204                return p;
205        }
206
207        /**
208         * Try to get the local address of a socket connection.
209         *
210         * Returns: a #GSocketAddress or %NULL on error.
211         *     Free the returned object with g_object_unref().
212         *
213         * Since: 2.22
214         *
215         * Throws: GException on failure.
216         */
217        public SocketAddress getLocalAddress()
218        {
219                GError* err = null;
220               
221                auto p = g_socket_connection_get_local_address(gSocketConnection, &err);
222               
223                if (err !is null)
224                {
225                        throw new GException( new ErrorG(err) );
226                }
227               
228                if(p is null)
229                {
230                        return null;
231                }
232               
233                return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p, true);
234        }
235
236        /**
237         * Try to get the remote address of a socket connection.
238         *
239         * Since GLib 2.40, when used with g_socket_client_connect() or
240         * g_socket_client_connect_async(), during emission of
241         * %G_SOCKET_CLIENT_CONNECTING, this function will return the remote
242         * address that will be used for the connection.  This allows
243         * applications to print e.g. "Connecting to example.com
244         * (10.42.77.3)...".
245         *
246         * Returns: a #GSocketAddress or %NULL on error.
247         *     Free the returned object with g_object_unref().
248         *
249         * Since: 2.22
250         *
251         * Throws: GException on failure.
252         */
253        public SocketAddress getRemoteAddress()
254        {
255                GError* err = null;
256               
257                auto p = g_socket_connection_get_remote_address(gSocketConnection, &err);
258               
259                if (err !is null)
260                {
261                        throw new GException( new ErrorG(err) );
262                }
263               
264                if(p is null)
265                {
266                        return null;
267                }
268               
269                return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p, true);
270        }
271
272        /**
273         * Gets the underlying #GSocket object of the connection.
274         * This can be useful if you want to do something unusual on it
275         * not supported by the #GSocketConnection APIs.
276         *
277         * Returns: a #GSocket or %NULL on error.
278         *
279         * Since: 2.22
280         */
281        public Socket getSocket()
282        {
283                auto p = g_socket_connection_get_socket(gSocketConnection);
284               
285                if(p is null)
286                {
287                        return null;
288                }
289               
290                return ObjectG.getDObject!(Socket)(cast(GSocket*) p);
291        }
292
293        /**
294         * Checks if @connection is connected. This is equivalent to calling
295         * g_socket_is_connected() on @connection's underlying #GSocket.
296         *
297         * Returns: whether @connection is connected
298         *
299         * Since: 2.32
300         */
301        public bool isConnected()
302        {
303                return g_socket_connection_is_connected(gSocketConnection) != 0;
304        }
305}
Note: See TracBrowser for help on using the repository browser.