1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.SocketConnectableT; 26 27 public import gio.SocketAddressEnumerator; 28 public import glib.Str; 29 public import gobject.ObjectG; 30 public import gtkc.gio; 31 public import gtkc.giotypes; 32 33 34 /** 35 * Objects that describe one or more potential socket endpoints 36 * implement #GSocketConnectable. Callers can then use 37 * g_socket_connectable_enumerate() to get a #GSocketAddressEnumerator 38 * to try out each socket address in turn until one succeeds, as shown 39 * in the sample code below. 40 * 41 * |[<!-- language="C" --> 42 * MyConnectionType * 43 * connect_to_host (const char *hostname, 44 * guint16 port, 45 * GCancellable *cancellable, 46 * GError **error) 47 * { 48 * MyConnection *conn = NULL; 49 * GSocketConnectable *addr; 50 * GSocketAddressEnumerator *enumerator; 51 * GSocketAddress *sockaddr; 52 * GError *conn_error = NULL; 53 * 54 * addr = g_network_address_new (hostname, port); 55 * enumerator = g_socket_connectable_enumerate (addr); 56 * g_object_unref (addr); 57 * 58 * // Try each sockaddr until we succeed. Record the first connection error, 59 * // but not any further ones (since they'll probably be basically the same 60 * // as the first). 61 * while (!conn && (sockaddr = g_socket_address_enumerator_next (enumerator, cancellable, error)) 62 * { 63 * conn = connect_to_sockaddr (sockaddr, conn_error ? NULL : &conn_error); 64 * g_object_unref (sockaddr); 65 * } 66 * g_object_unref (enumerator); 67 * 68 * if (conn) 69 * { 70 * if (conn_error) 71 * { 72 * // We couldn't connect to the first address, but we succeeded 73 * // in connecting to a later address. 74 * g_error_free (conn_error); 75 * } 76 * return conn; 77 * } 78 * else if (error) 79 * { 80 * /// Either initial lookup failed, or else the caller cancelled us. 81 * if (conn_error) 82 * g_error_free (conn_error); 83 * return NULL; 84 * } 85 * else 86 * { 87 * g_error_propagate (error, conn_error); 88 * return NULL; 89 * } 90 * } 91 * ]| 92 */ 93 public template SocketConnectableT(TStruct) 94 { 95 /** Get the main Gtk struct */ 96 public GSocketConnectable* getSocketConnectableStruct() 97 { 98 return cast(GSocketConnectable*)getStruct(); 99 } 100 101 102 /** 103 * Creates a #GSocketAddressEnumerator for @connectable. 104 * 105 * Return: a new #GSocketAddressEnumerator. 106 * 107 * Since: 2.22 108 */ 109 public SocketAddressEnumerator enumerate() 110 { 111 auto p = g_socket_connectable_enumerate(getSocketConnectableStruct()); 112 113 if(p is null) 114 { 115 return null; 116 } 117 118 return ObjectG.getDObject!(SocketAddressEnumerator)(cast(GSocketAddressEnumerator*) p, true); 119 } 120 121 /** 122 * Creates a #GSocketAddressEnumerator for @connectable that will 123 * return #GProxyAddresses for addresses that you must connect 124 * to via a proxy. 125 * 126 * If @connectable does not implement 127 * g_socket_connectable_proxy_enumerate(), this will fall back to 128 * calling g_socket_connectable_enumerate(). 129 * 130 * Return: a new #GSocketAddressEnumerator. 131 * 132 * Since: 2.26 133 */ 134 public SocketAddressEnumerator proxyEnumerate() 135 { 136 auto p = g_socket_connectable_proxy_enumerate(getSocketConnectableStruct()); 137 138 if(p is null) 139 { 140 return null; 141 } 142 143 return ObjectG.getDObject!(SocketAddressEnumerator)(cast(GSocketAddressEnumerator*) p, true); 144 } 145 146 /** 147 * Format a #GSocketConnectable as a string. This is a human-readable format for 148 * use in debugging output, and is not a stable serialization format. It is not 149 * suitable for use in user interfaces as it exposes too much information for a 150 * user. 151 * 152 * If the #GSocketConnectable implementation does not support string formatting, 153 * the implementation’s type name will be returned as a fallback. 154 * 155 * Return: the formatted string 156 * 157 * Since: 2.48 158 */ 159 public override string toString() 160 { 161 auto retStr = g_socket_connectable_to_string(getSocketConnectableStruct()); 162 163 scope(exit) Str.freeString(retStr); 164 return Str.toString(retStr); 165 } 166 }