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 * Conversion parameters: 26 * inFile = GSocketAddress.html 27 * outPack = gio 28 * outFile = SocketAddress 29 * strct = GSocketAddress 30 * realStrct= 31 * ctorStrct= 32 * clss = SocketAddress 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - SocketConnectableIF 40 * prefixes: 41 * - g_socket_address_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * omit signals: 46 * imports: 47 * - glib.ErrorG 48 * - glib.GException 49 * - gio.SocketConnectableT 50 * - gio.SocketConnectableIF 51 * structWrap: 52 * module aliases: 53 * local aliases: 54 * - GLIB_SYSDEF_AF_INET -> 2 55 * - GLIB_SYSDEF_AF_INET6 -> 23 56 * - GLIB_SYSDEF_AF_UNIX -> 1 57 * overrides: 58 */ 59 60 module gio.SocketAddress; 61 62 public import gtkc.giotypes; 63 64 private import gtkc.gio; 65 private import glib.ConstructionException; 66 private import gobject.ObjectG; 67 68 69 private import glib.ErrorG; 70 private import glib.GException; 71 private import gio.SocketConnectableT; 72 private import gio.SocketConnectableIF; 73 74 75 76 private import gobject.ObjectG; 77 78 /** 79 * GSocketAddress is the equivalent of struct sockaddr 80 * in the BSD sockets API. This is an abstract class; use 81 * GInetSocketAddress for internet sockets, or GUnixSocketAddress 82 * for UNIX domain sockets. 83 */ 84 public class SocketAddress : ObjectG, SocketConnectableIF 85 { 86 87 /** the main Gtk struct */ 88 protected GSocketAddress* gSocketAddress; 89 90 91 public GSocketAddress* getSocketAddressStruct() 92 { 93 return gSocketAddress; 94 } 95 96 97 /** the main Gtk struct as a void* */ 98 protected override void* getStruct() 99 { 100 return cast(void*)gSocketAddress; 101 } 102 103 /** 104 * Sets our main struct and passes it to the parent class 105 */ 106 public this (GSocketAddress* gSocketAddress) 107 { 108 super(cast(GObject*)gSocketAddress); 109 this.gSocketAddress = gSocketAddress; 110 } 111 112 protected override void setStruct(GObject* obj) 113 { 114 super.setStruct(obj); 115 gSocketAddress = cast(GSocketAddress*)obj; 116 } 117 118 // add the SocketConnectable capabilities 119 mixin SocketConnectableT!(GSocketAddress); 120 121 /** 122 */ 123 124 /** 125 * Creates a GSocketAddress subclass corresponding to the native 126 * struct sockaddr native. 127 * Since 2.22 128 * Params: 129 * native = a pointer to a struct sockaddr 130 * len = the size of the memory location pointed to by native 131 * Throws: ConstructionException GTK+ fails to create the object. 132 */ 133 public this (void* native, gsize len) 134 { 135 // GSocketAddress * g_socket_address_new_from_native (gpointer native, gsize len); 136 auto p = g_socket_address_new_from_native(native, len); 137 if(p is null) 138 { 139 throw new ConstructionException("null returned by g_socket_address_new_from_native(native, len)"); 140 } 141 this(cast(GSocketAddress*) p); 142 } 143 144 /** 145 * Gets the socket family type of address. 146 * Since 2.22 147 * Returns: the socket family type of address. 148 */ 149 public GSocketFamily getFamily() 150 { 151 // GSocketFamily g_socket_address_get_family (GSocketAddress *address); 152 return g_socket_address_get_family(gSocketAddress); 153 } 154 155 /** 156 * Converts a GSocketAddress to a native struct 157 * sockaddr, which can be passed to low-level functions like 158 * connect() or bind(). 159 * If not enough space is available, a G_IO_ERROR_NO_SPACE error is 160 * returned. If the address type is not known on the system 161 * then a G_IO_ERROR_NOT_SUPPORTED error is returned. 162 * Since 2.22 163 * Params: 164 * dest = a pointer to a memory location that will contain the native 165 * struct sockaddr. 166 * destlen = the size of dest. Must be at least as large as 167 * g_socket_address_get_native_size(). 168 * Returns: TRUE if dest was filled in, FALSE on error 169 * Throws: GException on failure. 170 */ 171 public int toNative(void* dest, gsize destlen) 172 { 173 // gboolean g_socket_address_to_native (GSocketAddress *address, gpointer dest, gsize destlen, GError **error); 174 GError* err = null; 175 176 auto p = g_socket_address_to_native(gSocketAddress, dest, destlen, &err); 177 178 if (err !is null) 179 { 180 throw new GException( new ErrorG(err) ); 181 } 182 183 return p; 184 } 185 186 /** 187 * Gets the size of address's native struct sockaddr. 188 * You can use this to allocate memory to pass to 189 * g_socket_address_to_native(). 190 * Since 2.22 191 * Returns: the size of the native struct sockaddr that address represents 192 */ 193 public gssize getNativeSize() 194 { 195 // gssize g_socket_address_get_native_size (GSocketAddress *address); 196 return g_socket_address_get_native_size(gSocketAddress); 197 } 198 }