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