| 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 = GSocketClient.html |
|---|
| 27 |
* outPack = gio |
|---|
| 28 |
* outFile = SocketClient |
|---|
| 29 |
* strct = GSocketClient |
|---|
| 30 |
* realStrct= |
|---|
| 31 |
* ctorStrct= |
|---|
| 32 |
* clss = SocketClient |
|---|
| 33 |
* interf = |
|---|
| 34 |
* class Code: No |
|---|
| 35 |
* interface Code: No |
|---|
| 36 |
* template for: |
|---|
| 37 |
* extend = |
|---|
| 38 |
* implements: |
|---|
| 39 |
* prefixes: |
|---|
| 40 |
* - g_socket_client_ |
|---|
| 41 |
* omit structs: |
|---|
| 42 |
* omit prefixes: |
|---|
| 43 |
* omit code: |
|---|
| 44 |
* omit signals: |
|---|
| 45 |
* imports: |
|---|
| 46 |
* - glib.Str |
|---|
| 47 |
* - glib.ErrorG |
|---|
| 48 |
* - glib.GException |
|---|
| 49 |
* - gio.AsyncResultIF |
|---|
| 50 |
* - gio.Cancellable |
|---|
| 51 |
* - gio.SocketAddress |
|---|
| 52 |
* - gio.SocketConnection |
|---|
| 53 |
* - gio.SocketConnectableIF |
|---|
| 54 |
* structWrap: |
|---|
| 55 |
* - GAsyncResult* -> AsyncResultIF |
|---|
| 56 |
* - GCancellable* -> Cancellable |
|---|
| 57 |
* - GSocketAddress* -> SocketAddress |
|---|
| 58 |
* - GSocketConnectable* -> SocketConnectableIF |
|---|
| 59 |
* - GSocketConnection* -> SocketConnection |
|---|
| 60 |
* module aliases: |
|---|
| 61 |
* local aliases: |
|---|
| 62 |
* overrides: |
|---|
| 63 |
*/ |
|---|
| 64 |
|
|---|
| 65 |
module gio.SocketClient; |
|---|
| 66 |
|
|---|
| 67 |
public import gtkc.giotypes; |
|---|
| 68 |
|
|---|
| 69 |
private import gtkc.gio; |
|---|
| 70 |
private import glib.ConstructionException; |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
private import glib.Str; |
|---|
| 74 |
private import glib.ErrorG; |
|---|
| 75 |
private import glib.GException; |
|---|
| 76 |
private import gio.AsyncResultIF; |
|---|
| 77 |
private import gio.Cancellable; |
|---|
| 78 |
private import gio.SocketAddress; |
|---|
| 79 |
private import gio.SocketConnection; |
|---|
| 80 |
private import gio.SocketConnectableIF; |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
private import gobject.ObjectG; |
|---|
| 85 |
|
|---|
| 86 |
/** |
|---|
| 87 |
* Description |
|---|
| 88 |
* GSocketClient is a high-level utility class for connecting to a |
|---|
| 89 |
* network host using a connection oriented socket type. |
|---|
| 90 |
* You create a GSocketClient object, set any options you want, then |
|---|
| 91 |
* call a sync or async connect operation, which returns a GSocketConnection |
|---|
| 92 |
* subclass on success. |
|---|
| 93 |
* The type of the GSocketConnection object returned depends on the type of |
|---|
| 94 |
* the underlying socket that is in use. For instance, for a TCP/IP connection |
|---|
| 95 |
* it will be a GTcpConnection. |
|---|
| 96 |
*/ |
|---|
| 97 |
public class SocketClient : ObjectG |
|---|
| 98 |
{ |
|---|
| 99 |
|
|---|
| 100 |
/** the main Gtk struct */ |
|---|
| 101 |
protected GSocketClient* gSocketClient; |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
public GSocketClient* getSocketClientStruct() |
|---|
| 105 |
{ |
|---|
| 106 |
return gSocketClient; |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
/** the main Gtk struct as a void* */ |
|---|
| 111 |
protected override void* getStruct() |
|---|
| 112 |
{ |
|---|
| 113 |
return cast(void*)gSocketClient; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
/** |
|---|
| 117 |
* Sets our main struct and passes it to the parent class |
|---|
| 118 |
*/ |
|---|
| 119 |
public this (GSocketClient* gSocketClient) |
|---|
| 120 |
{ |
|---|
| 121 |
if(gSocketClient is null) |
|---|
| 122 |
{ |
|---|
| 123 |
this = null; |
|---|
| 124 |
return; |
|---|
| 125 |
} |
|---|
| 126 |
//Check if there already is a D object for this gtk struct |
|---|
| 127 |
void* ptr = getDObject(cast(GObject*)gSocketClient); |
|---|
| 128 |
if( ptr !is null ) |
|---|
| 129 |
{ |
|---|
| 130 |
this = cast(SocketClient)ptr; |
|---|
| 131 |
return; |
|---|
| 132 |
} |
|---|
| 133 |
super(cast(GObject*)gSocketClient); |
|---|
| 134 |
this.gSocketClient = gSocketClient; |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
protected override void setStruct(GObject* obj) |
|---|
| 138 |
{ |
|---|
| 139 |
super.setStruct(obj); |
|---|
| 140 |
gSocketClient = cast(GSocketClient*)obj; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
/** |
|---|
| 144 |
*/ |
|---|
| 145 |
|
|---|
| 146 |
/** |
|---|
| 147 |
* Enable proxy protocols to be handled by the application. When the |
|---|
| 148 |
* indicated proxy protocol is returned by the GProxyResolver, |
|---|
| 149 |
* GSocketClient will consider this protocol as supported but will |
|---|
| 150 |
* not try find a GProxy instance to handle handshaking. The |
|---|
| 151 |
* application must check for this case by calling |
|---|
| 152 |
* g_socket_connection_get_remote_address() on the returned |
|---|
| 153 |
* GSocketConnection, and seeing if it's a GProxyAddress of the |
|---|
| 154 |
* appropriate type, to determine whether or not it needs to handle |
|---|
| 155 |
* the proxy handshaking itself. |
|---|
| 156 |
* This should be used for proxy protocols that are dialects of |
|---|
| 157 |
* another protocol such as HTTP proxy. It also allows cohabitation of |
|---|
| 158 |
* proxy protocols that are reused between protocols. A good example |
|---|
| 159 |
* is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also |
|---|
| 160 |
* be use as generic socket proxy through the HTTP CONNECT method. |
|---|
| 161 |
* Params: |
|---|
| 162 |
* protocol = The proxy protocol |
|---|
| 163 |
*/ |
|---|
| 164 |
public void addApplicationProxy(string protocol) |
|---|
| 165 |
{ |
|---|
| 166 |
// void g_socket_client_add_application_proxy (GSocketClient *client, const gchar *protocol); |
|---|
| 167 |
g_socket_client_add_application_proxy(gSocketClient, Str.toStringz(protocol)); |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
/** |
|---|
| 171 |
* Creates a new GSocketClient with the default options. |
|---|
| 172 |
* Since 2.22 |
|---|
| 173 |
* Throws: ConstructionException GTK+ fails to create the object. |
|---|
| 174 |
*/ |
|---|
| 175 |
public this () |
|---|
| 176 |
{ |
|---|
| 177 |
// GSocketClient * g_socket_client_new (void); |
|---|
| 178 |
auto p = g_socket_client_new(); |
|---|
| 179 |
if(p is null) |
|---|
| 180 |
{ |
|---|
| 181 |
throw new ConstructionException("null returned by g_socket_client_new()"); |
|---|
| 182 |
} |
|---|
| 183 |
this(cast(GSocketClient*) p); |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
/** |
|---|
| 187 |
* Tries to resolve the connectable and make a network connection to it.. |
|---|
| 188 |
* Upon a successful connection, a new GSocketConnection is constructed |
|---|
| 189 |
* and returned. The caller owns this new object and must drop their |
|---|
| 190 |
* reference to it when finished with it. |
|---|
| 191 |
* The type of the GSocketConnection object returned depends on the type of |
|---|
| 192 |
* the underlying socket that is used. For instance, for a TCP/IP connection |
|---|
| 193 |
* it will be a GTcpConnection. |
|---|
| 194 |
* The socket created will be the same family as the the address that the |
|---|
| 195 |
* connectable resolves to, unless family is set with g_socket_client_set_family() |
|---|
| 196 |
* or indirectly via g_socket_client_set_local_address(). The socket type |
|---|
| 197 |
* defaults to G_SOCKET_TYPE_STREAM but can be set with |
|---|
| 198 |
* g_socket_client_set_socket_type(). |
|---|
| 199 |
* If a local address is specified with g_socket_client_set_local_address() the |
|---|
| 200 |
* socket will be bound to this address before connecting. |
|---|
| 201 |
* Since 2.22 |
|---|
| 202 |
* Params: |
|---|
| 203 |
* connectable = a GSocketConnectable specifying the remote address. |
|---|
| 204 |
* cancellable = optional GCancellable object, NULL to ignore. [allow-none] |
|---|
| 205 |
* Returns: a GSocketConnection on success, NULL on error. [transfer full] |
|---|
| 206 |
* Throws: GException on failure. |
|---|
| 207 |
*/ |
|---|
| 208 |
public SocketConnection connect(SocketConnectableIF connectable, Cancellable cancellable) |
|---|
| 209 |
{ |
|---|
| 210 |
// GSocketConnection * g_socket_client_connect (GSocketClient *client, GSocketConnectable *connectable, GCancellable *cancellable, GError **error); |
|---|
| 211 |
GError* err = null; |
|---|
| 212 |
|
|---|
| 213 |
auto p = g_socket_client_connect(gSocketClient, (connectable is null) ? null : connectable.getSocketConnectableTStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); |
|---|
| 214 |
|
|---|
| 215 |
if (err !is null) |
|---|
| 216 |
{ |
|---|
| 217 |
throw new GException( new ErrorG(err) ); |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
if(p is null) |
|---|
| 221 |
{ |
|---|
| 222 |
return null; |
|---|
| 223 |
} |
|---|
| 224 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
/** |
|---|
| 228 |
* This is the asynchronous version of g_socket_client_connect(). |
|---|
| 229 |
* When the operation is finished callback will be |
|---|
| 230 |
* called. You can then call g_socket_client_connect_finish() to get |
|---|
| 231 |
* the result of the operation. |
|---|
| 232 |
* Since 2.22 |
|---|
| 233 |
* Params: |
|---|
| 234 |
* connectable = a GSocketConnectable specifying the remote address. |
|---|
| 235 |
* cancellable = a GCancellable, or NULL. [allow-none] |
|---|
| 236 |
* callback = a GAsyncReadyCallback. [scope async] |
|---|
| 237 |
* userData = user data for the callback. [closure] |
|---|
| 238 |
*/ |
|---|
| 239 |
public void connectAsync(SocketConnectableIF connectable, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) |
|---|
| 240 |
{ |
|---|
| 241 |
// void g_socket_client_connect_async (GSocketClient *client, GSocketConnectable *connectable, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); |
|---|
| 242 |
g_socket_client_connect_async(gSocketClient, (connectable is null) ? null : connectable.getSocketConnectableTStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
/** |
|---|
| 246 |
* Finishes an async connect operation. See g_socket_client_connect_async() |
|---|
| 247 |
* Since 2.22 |
|---|
| 248 |
* Params: |
|---|
| 249 |
* result = a GAsyncResult. |
|---|
| 250 |
* Returns: a GSocketConnection on success, NULL on error. [transfer full] |
|---|
| 251 |
* Throws: GException on failure. |
|---|
| 252 |
*/ |
|---|
| 253 |
public SocketConnection connectFinish(AsyncResultIF result) |
|---|
| 254 |
{ |
|---|
| 255 |
// GSocketConnection * g_socket_client_connect_finish (GSocketClient *client, GAsyncResult *result, GError **error); |
|---|
| 256 |
GError* err = null; |
|---|
| 257 |
|
|---|
| 258 |
auto p = g_socket_client_connect_finish(gSocketClient, (result is null) ? null : result.getAsyncResultTStruct(), &err); |
|---|
| 259 |
|
|---|
| 260 |
if (err !is null) |
|---|
| 261 |
{ |
|---|
| 262 |
throw new GException( new ErrorG(err) ); |
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
if(p is null) |
|---|
| 266 |
{ |
|---|
| 267 |
return null; |
|---|
| 268 |
} |
|---|
| 269 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 270 |
} |
|---|
| 271 |
|
|---|
| 272 |
/** |
|---|
| 273 |
* This is a helper function for g_socket_client_connect(). |
|---|
| 274 |
* Attempts to create a TCP connection to the named host. |
|---|
| 275 |
* host_and_port may be in any of a number of recognised formats; an IPv6 |
|---|
| 276 |
* address, an IPv4 address, or a domain name (in which case a DNS |
|---|
| 277 |
* lookup is performed). Quoting with [] is supported for all address |
|---|
| 278 |
* types. A port override may be specified in the usual way with a |
|---|
| 279 |
* colon. Ports may be given as decimal numbers or symbolic names (in |
|---|
| 280 |
* which case an /etc/services lookup is performed). |
|---|
| 281 |
* If no port override is given in host_and_port then default_port will be |
|---|
| 282 |
* used as the port number to connect to. |
|---|
| 283 |
* In general, host_and_port is expected to be provided by the user (allowing |
|---|
| 284 |
* them to give the hostname, and a port overide if necessary) and |
|---|
| 285 |
* default_port is expected to be provided by the application. |
|---|
| 286 |
* In the case that an IP address is given, a single connection |
|---|
| 287 |
* attempt is made. In the case that a name is given, multiple |
|---|
| 288 |
* connection attempts may be made, in turn and according to the |
|---|
| 289 |
* number of address records in DNS, until a connection succeeds. |
|---|
| 290 |
* Upon a successful connection, a new GSocketConnection is constructed |
|---|
| 291 |
* and returned. The caller owns this new object and must drop their |
|---|
| 292 |
* reference to it when finished with it. |
|---|
| 293 |
* In the event of any failure (DNS error, service not found, no hosts |
|---|
| 294 |
* connectable) NULL is returned and error (if non-NULL) is set |
|---|
| 295 |
* accordingly. |
|---|
| 296 |
* Since 2.22 |
|---|
| 297 |
* Params: |
|---|
| 298 |
* hostAndPort = the name and optionally port of the host to connect to |
|---|
| 299 |
* defaultPort = the default port to connect to |
|---|
| 300 |
* cancellable = a GCancellable, or NULL. [allow-none] |
|---|
| 301 |
* Returns: a GSocketConnection on success, NULL on error. [transfer full] |
|---|
| 302 |
* Throws: GException on failure. |
|---|
| 303 |
*/ |
|---|
| 304 |
public SocketConnection connectToHost(string hostAndPort, ushort defaultPort, Cancellable cancellable) |
|---|
| 305 |
{ |
|---|
| 306 |
// GSocketConnection * g_socket_client_connect_to_host (GSocketClient *client, const gchar *host_and_port, guint16 default_port, GCancellable *cancellable, GError **error); |
|---|
| 307 |
GError* err = null; |
|---|
| 308 |
|
|---|
| 309 |
auto p = g_socket_client_connect_to_host(gSocketClient, Str.toStringz(hostAndPort), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); |
|---|
| 310 |
|
|---|
| 311 |
if (err !is null) |
|---|
| 312 |
{ |
|---|
| 313 |
throw new GException( new ErrorG(err) ); |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|
| 316 |
if(p is null) |
|---|
| 317 |
{ |
|---|
| 318 |
return null; |
|---|
| 319 |
} |
|---|
| 320 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 321 |
} |
|---|
| 322 |
|
|---|
| 323 |
/** |
|---|
| 324 |
* This is the asynchronous version of g_socket_client_connect_to_host(). |
|---|
| 325 |
* When the operation is finished callback will be |
|---|
| 326 |
* called. You can then call g_socket_client_connect_to_host_finish() to get |
|---|
| 327 |
* the result of the operation. |
|---|
| 328 |
* Since 2.22 |
|---|
| 329 |
* Params: |
|---|
| 330 |
* hostAndPort = the name and optionally the port of the host to connect to |
|---|
| 331 |
* defaultPort = the default port to connect to |
|---|
| 332 |
* cancellable = a GCancellable, or NULL. [allow-none] |
|---|
| 333 |
* callback = a GAsyncReadyCallback. [scope async] |
|---|
| 334 |
* userData = user data for the callback. [closure] |
|---|
| 335 |
*/ |
|---|
| 336 |
public void connectToHostAsync(string hostAndPort, ushort defaultPort, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) |
|---|
| 337 |
{ |
|---|
| 338 |
// void g_socket_client_connect_to_host_async (GSocketClient *client, const gchar *host_and_port, guint16 default_port, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); |
|---|
| 339 |
g_socket_client_connect_to_host_async(gSocketClient, Str.toStringz(hostAndPort), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
/** |
|---|
| 343 |
* Finishes an async connect operation. See g_socket_client_connect_to_host_async() |
|---|
| 344 |
* Since 2.22 |
|---|
| 345 |
* Params: |
|---|
| 346 |
* result = a GAsyncResult. |
|---|
| 347 |
* Returns: a GSocketConnection on success, NULL on error. [transfer full] |
|---|
| 348 |
* Throws: GException on failure. |
|---|
| 349 |
*/ |
|---|
| 350 |
public SocketConnection connectToHostFinish(AsyncResultIF result) |
|---|
| 351 |
{ |
|---|
| 352 |
// GSocketConnection * g_socket_client_connect_to_host_finish (GSocketClient *client, GAsyncResult *result, GError **error); |
|---|
| 353 |
GError* err = null; |
|---|
| 354 |
|
|---|
| 355 |
auto p = g_socket_client_connect_to_host_finish(gSocketClient, (result is null) ? null : result.getAsyncResultTStruct(), &err); |
|---|
| 356 |
|
|---|
| 357 |
if (err !is null) |
|---|
| 358 |
{ |
|---|
| 359 |
throw new GException( new ErrorG(err) ); |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
if(p is null) |
|---|
| 363 |
{ |
|---|
| 364 |
return null; |
|---|
| 365 |
} |
|---|
| 366 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 367 |
} |
|---|
| 368 |
|
|---|
| 369 |
/** |
|---|
| 370 |
* Attempts to create a TCP connection to a service. |
|---|
| 371 |
* This call looks up the SRV record for service at domain for the |
|---|
| 372 |
* "tcp" protocol. It then attempts to connect, in turn, to each of |
|---|
| 373 |
* the hosts providing the service until either a connection succeeds |
|---|
| 374 |
* or there are no hosts remaining. |
|---|
| 375 |
* Upon a successful connection, a new GSocketConnection is constructed |
|---|
| 376 |
* and returned. The caller owns this new object and must drop their |
|---|
| 377 |
* reference to it when finished with it. |
|---|
| 378 |
* In the event of any failure (DNS error, service not found, no hosts |
|---|
| 379 |
* connectable) NULL is returned and error (if non-NULL) is set |
|---|
| 380 |
* accordingly. |
|---|
| 381 |
* Params: |
|---|
| 382 |
* domain = a domain name |
|---|
| 383 |
* service = the name of the service to connect to |
|---|
| 384 |
* cancellable = a GCancellable, or NULL. [allow-none] |
|---|
| 385 |
* Returns: a GSocketConnection if successful, or NULL on error. [transfer full] |
|---|
| 386 |
* Throws: GException on failure. |
|---|
| 387 |
*/ |
|---|
| 388 |
public SocketConnection connectToService(string domain, string service, Cancellable cancellable) |
|---|
| 389 |
{ |
|---|
| 390 |
// GSocketConnection * g_socket_client_connect_to_service (GSocketClient *client, const gchar *domain, const gchar *service, GCancellable *cancellable, GError **error); |
|---|
| 391 |
GError* err = null; |
|---|
| 392 |
|
|---|
| 393 |
auto p = g_socket_client_connect_to_service(gSocketClient, Str.toStringz(domain), Str.toStringz(service), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); |
|---|
| 394 |
|
|---|
| 395 |
if (err !is null) |
|---|
| 396 |
{ |
|---|
| 397 |
throw new GException( new ErrorG(err) ); |
|---|
| 398 |
} |
|---|
| 399 |
|
|---|
| 400 |
if(p is null) |
|---|
| 401 |
{ |
|---|
| 402 |
return null; |
|---|
| 403 |
} |
|---|
| 404 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 405 |
} |
|---|
| 406 |
|
|---|
| 407 |
/** |
|---|
| 408 |
* This is the asynchronous version of |
|---|
| 409 |
* g_socket_client_connect_to_service(). |
|---|
| 410 |
* Since 2.22 |
|---|
| 411 |
* Params: |
|---|
| 412 |
* domain = a domain name |
|---|
| 413 |
* service = the name of the service to connect to |
|---|
| 414 |
* cancellable = a GCancellable, or NULL. [allow-none] |
|---|
| 415 |
* callback = a GAsyncReadyCallback. [scope async] |
|---|
| 416 |
* userData = user data for the callback. [closure] |
|---|
| 417 |
*/ |
|---|
| 418 |
public void connectToServiceAsync(string domain, string service, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) |
|---|
| 419 |
{ |
|---|
| 420 |
// void g_socket_client_connect_to_service_async (GSocketClient *client, const gchar *domain, const gchar *service, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); |
|---|
| 421 |
g_socket_client_connect_to_service_async(gSocketClient, Str.toStringz(domain), Str.toStringz(service), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); |
|---|
| 422 |
} |
|---|
| 423 |
|
|---|
| 424 |
/** |
|---|
| 425 |
* Finishes an async connect operation. See g_socket_client_connect_to_service_async() |
|---|
| 426 |
* Since 2.22 |
|---|
| 427 |
* Params: |
|---|
| 428 |
* result = a GAsyncResult. |
|---|
| 429 |
* Returns: a GSocketConnection on success, NULL on error. [transfer full] |
|---|
| 430 |
* Throws: GException on failure. |
|---|
| 431 |
*/ |
|---|
| 432 |
public SocketConnection connectToServiceFinish(AsyncResultIF result) |
|---|
| 433 |
{ |
|---|
| 434 |
// GSocketConnection * g_socket_client_connect_to_service_finish (GSocketClient *client, GAsyncResult *result, GError **error); |
|---|
| 435 |
GError* err = null; |
|---|
| 436 |
|
|---|
| 437 |
auto p = g_socket_client_connect_to_service_finish(gSocketClient, (result is null) ? null : result.getAsyncResultTStruct(), &err); |
|---|
| 438 |
|
|---|
| 439 |
if (err !is null) |
|---|
| 440 |
{ |
|---|
| 441 |
throw new GException( new ErrorG(err) ); |
|---|
| 442 |
} |
|---|
| 443 |
|
|---|
| 444 |
if(p is null) |
|---|
| 445 |
{ |
|---|
| 446 |
return null; |
|---|
| 447 |
} |
|---|
| 448 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 449 |
} |
|---|
| 450 |
|
|---|
| 451 |
/** |
|---|
| 452 |
* This is a helper function for g_socket_client_connect(). |
|---|
| 453 |
* Attempts to create a TCP connection with a network URI. |
|---|
| 454 |
* uri may be any valid URI containing an "authority" (hostname/port) |
|---|
| 455 |
* component. If a port is not specified in the URI, default_port |
|---|
| 456 |
* will be used. TLS will be negotiated if "tls" is TRUE. |
|---|
| 457 |
* (GSocketClient does not know to automatically assume TLS for |
|---|
| 458 |
* certain URI schemes.) |
|---|
| 459 |
* Using this rather than g_socket_client_connect() or |
|---|
| 460 |
* g_socket_client_connect_to_host() allows GSocketClient to |
|---|
| 461 |
* determine when to use application-specific proxy protocols. |
|---|
| 462 |
* Upon a successful connection, a new GSocketConnection is constructed |
|---|
| 463 |
* and returned. The caller owns this new object and must drop their |
|---|
| 464 |
* reference to it when finished with it. |
|---|
| 465 |
* In the event of any failure (DNS error, service not found, no hosts |
|---|
| 466 |
* connectable) NULL is returned and error (if non-NULL) is set |
|---|
| 467 |
* accordingly. |
|---|
| 468 |
* Since 2.26 |
|---|
| 469 |
* Params: |
|---|
| 470 |
* uri = A network URI |
|---|
| 471 |
* defaultPort = the default port to connect to |
|---|
| 472 |
* cancellable = a GCancellable, or NULL. [allow-none] |
|---|
| 473 |
* Returns: a GSocketConnection on success, NULL on error. [transfer full] |
|---|
| 474 |
* Throws: GException on failure. |
|---|
| 475 |
*/ |
|---|
| 476 |
public SocketConnection connectToUri(string uri, ushort defaultPort, Cancellable cancellable) |
|---|
| 477 |
{ |
|---|
| 478 |
// GSocketConnection * g_socket_client_connect_to_uri (GSocketClient *client, const gchar *uri, guint16 default_port, GCancellable *cancellable, GError **error); |
|---|
| 479 |
GError* err = null; |
|---|
| 480 |
|
|---|
| 481 |
auto p = g_socket_client_connect_to_uri(gSocketClient, Str.toStringz(uri), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); |
|---|
| 482 |
|
|---|
| 483 |
if (err !is null) |
|---|
| 484 |
{ |
|---|
| 485 |
throw new GException( new ErrorG(err) ); |
|---|
| 486 |
} |
|---|
| 487 |
|
|---|
| 488 |
if(p is null) |
|---|
| 489 |
{ |
|---|
| 490 |
return null; |
|---|
| 491 |
} |
|---|
| 492 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 493 |
} |
|---|
| 494 |
|
|---|
| 495 |
/** |
|---|
| 496 |
* This is the asynchronous version of g_socket_client_connect_to_uri(). |
|---|
| 497 |
* When the operation is finished callback will be |
|---|
| 498 |
* called. You can then call g_socket_client_connect_to_uri_finish() to get |
|---|
| 499 |
* the result of the operation. |
|---|
| 500 |
* Since 2.26 |
|---|
| 501 |
* Params: |
|---|
| 502 |
* uri = a network uri |
|---|
| 503 |
* defaultPort = the default port to connect to |
|---|
| 504 |
* cancellable = a GCancellable, or NULL. [allow-none] |
|---|
| 505 |
* callback = a GAsyncReadyCallback. [scope async] |
|---|
| 506 |
* userData = user data for the callback. [closure] |
|---|
| 507 |
*/ |
|---|
| 508 |
public void connectToUriAsync(string uri, ushort defaultPort, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) |
|---|
| 509 |
{ |
|---|
| 510 |
// void g_socket_client_connect_to_uri_async (GSocketClient *client, const gchar *uri, guint16 default_port, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); |
|---|
| 511 |
g_socket_client_connect_to_uri_async(gSocketClient, Str.toStringz(uri), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); |
|---|
| 512 |
} |
|---|
| 513 |
|
|---|
| 514 |
/** |
|---|
| 515 |
* Finishes an async connect operation. See g_socket_client_connect_to_uri_async() |
|---|
| 516 |
* Since 2.26 |
|---|
| 517 |
* Params: |
|---|
| 518 |
* result = a GAsyncResult. |
|---|
| 519 |
* Returns: a GSocketConnection on success, NULL on error. [transfer full] |
|---|
| 520 |
* Throws: GException on failure. |
|---|
| 521 |
*/ |
|---|
| 522 |
public SocketConnection connectToUriFinish(AsyncResultIF result) |
|---|
| 523 |
{ |
|---|
| 524 |
// GSocketConnection * g_socket_client_connect_to_uri_finish (GSocketClient *client, GAsyncResult *result, GError **error); |
|---|
| 525 |
GError* err = null; |
|---|
| 526 |
|
|---|
| 527 |
auto p = g_socket_client_connect_to_uri_finish(gSocketClient, (result is null) ? null : result.getAsyncResultTStruct(), &err); |
|---|
| 528 |
|
|---|
| 529 |
if (err !is null) |
|---|
| 530 |
{ |
|---|
| 531 |
throw new GException( new ErrorG(err) ); |
|---|
| 532 |
} |
|---|
| 533 |
|
|---|
| 534 |
if(p is null) |
|---|
| 535 |
{ |
|---|
| 536 |
return null; |
|---|
| 537 |
} |
|---|
| 538 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 539 |
} |
|---|
| 540 |
|
|---|
| 541 |
/** |
|---|
| 542 |
* Sets the socket family of the socket client. |
|---|
| 543 |
* If this is set to something other than G_SOCKET_FAMILY_INVALID |
|---|
| 544 |
* then the sockets created by this object will be of the specified |
|---|
| 545 |
* family. |
|---|
| 546 |
* This might be useful for instance if you want to force the local |
|---|
| 547 |
* connection to be an ipv4 socket, even though the address might |
|---|
| 548 |
* be an ipv6 mapped to ipv4 address. |
|---|
| 549 |
* Since 2.22 |
|---|
| 550 |
* Params: |
|---|
| 551 |
* family = a GSocketFamily |
|---|
| 552 |
*/ |
|---|
| 553 |
public void setFamily(GSocketFamily family) |
|---|
| 554 |
{ |
|---|
| 555 |
// void g_socket_client_set_family (GSocketClient *client, GSocketFamily family); |
|---|
| 556 |
g_socket_client_set_family(gSocketClient, family); |
|---|
| 557 |
} |
|---|
| 558 |
|
|---|
| 559 |
/** |
|---|
| 560 |
* Sets the local address of the socket client. |
|---|
| 561 |
* The sockets created by this object will bound to the |
|---|
| 562 |
* specified address (if not NULL) before connecting. |
|---|
| 563 |
* This is useful if you want to ensure the the local |
|---|
| 564 |
* side of the connection is on a specific port, or on |
|---|
| 565 |
* a specific interface. |
|---|
| 566 |
* Since 2.22 |
|---|
| 567 |
* Params: |
|---|
| 568 |
* address = a GSocketAddress, or NULL |
|---|
| 569 |
*/ |
|---|
| 570 |
public void setLocalAddress(SocketAddress address) |
|---|
| 571 |
{ |
|---|
| 572 |
// void g_socket_client_set_local_address (GSocketClient *client, GSocketAddress *address); |
|---|
| 573 |
g_socket_client_set_local_address(gSocketClient, (address is null) ? null : address.getSocketAddressStruct()); |
|---|
| 574 |
} |
|---|
| 575 |
|
|---|
| 576 |
/** |
|---|
| 577 |
* Sets the protocol of the socket client. |
|---|
| 578 |
* The sockets created by this object will use of the specified |
|---|
| 579 |
* protocol. |
|---|
| 580 |
* If protocol is 0 that means to use the default |
|---|
| 581 |
* protocol for the socket family and type. |
|---|
| 582 |
* Since 2.22 |
|---|
| 583 |
* Params: |
|---|
| 584 |
* protocol = a GSocketProtocol |
|---|
| 585 |
*/ |
|---|
| 586 |
public void setProtocol(GSocketProtocol protocol) |
|---|
| 587 |
{ |
|---|
| 588 |
// void g_socket_client_set_protocol (GSocketClient *client, GSocketProtocol protocol); |
|---|
| 589 |
g_socket_client_set_protocol(gSocketClient, protocol); |
|---|
| 590 |
} |
|---|
| 591 |
|
|---|
| 592 |
/** |
|---|
| 593 |
* Sets the socket type of the socket client. |
|---|
| 594 |
* The sockets created by this object will be of the specified |
|---|
| 595 |
* type. |
|---|
| 596 |
* It doesn't make sense to specify a type of G_SOCKET_TYPE_DATAGRAM, |
|---|
| 597 |
* as GSocketClient is used for connection oriented services. |
|---|
| 598 |
* Since 2.22 |
|---|
| 599 |
* Params: |
|---|
| 600 |
* type = a GSocketType |
|---|
| 601 |
*/ |
|---|
| 602 |
public void setSocketType(GSocketType type) |
|---|
| 603 |
{ |
|---|
| 604 |
// void g_socket_client_set_socket_type (GSocketClient *client, GSocketType type); |
|---|
| 605 |
g_socket_client_set_socket_type(gSocketClient, type); |
|---|
| 606 |
} |
|---|
| 607 |
|
|---|
| 608 |
/** |
|---|
| 609 |
* Sets the I/O timeout for sockets created by client. timeout is a |
|---|
| 610 |
* time in seconds, or 0 for no timeout (the default). |
|---|
| 611 |
* The timeout value affects the initial connection attempt as well, |
|---|
| 612 |
* so setting this may cause calls to g_socket_client_connect(), etc, |
|---|
| 613 |
* to fail with G_IO_ERROR_TIMED_OUT. |
|---|
| 614 |
* Since 2.26 |
|---|
| 615 |
* Params: |
|---|
| 616 |
* timeout = the timeout |
|---|
| 617 |
*/ |
|---|
| 618 |
public void setTimeout(uint timeout) |
|---|
| 619 |
{ |
|---|
| 620 |
// void g_socket_client_set_timeout (GSocketClient *client, guint timeout); |
|---|
| 621 |
g_socket_client_set_timeout(gSocketClient, timeout); |
|---|
| 622 |
} |
|---|
| 623 |
|
|---|
| 624 |
/** |
|---|
| 625 |
* Sets whether or not client attempts to make connections via a |
|---|
| 626 |
* proxy server. When enabled (the default), GSocketClient will use a |
|---|
| 627 |
* GProxyResolver to determine if a proxy protocol such as SOCKS is |
|---|
| 628 |
* needed, and automatically do the necessary proxy negotiation. |
|---|
| 629 |
* Since 2.26 |
|---|
| 630 |
* Params: |
|---|
| 631 |
* enable = whether to enable proxies |
|---|
| 632 |
*/ |
|---|
| 633 |
public void setEnableProxy(int enable) |
|---|
| 634 |
{ |
|---|
| 635 |
// void g_socket_client_set_enable_proxy (GSocketClient *client, gboolean enable); |
|---|
| 636 |
g_socket_client_set_enable_proxy(gSocketClient, enable); |
|---|
| 637 |
} |
|---|
| 638 |
|
|---|
| 639 |
/** |
|---|
| 640 |
* Sets whether client creates TLS (aka SSL) connections. If tls is |
|---|
| 641 |
* TRUE, client will wrap its connections in a GTlsClientConnection |
|---|
| 642 |
* and perform a TLS handshake when connecting. |
|---|
| 643 |
* Note that since GSocketClient must return a GSocketConnection, |
|---|
| 644 |
* but GTlsClientConnection is not a GSocketConnection, this |
|---|
| 645 |
* actually wraps the resulting GTlsClientConnection in a |
|---|
| 646 |
* GTcpWrapperConnection when returning it. You can use |
|---|
| 647 |
* g_tcp_wrapper_connection_get_base_io_stream() on the return value |
|---|
| 648 |
* to extract the GTlsClientConnection. |
|---|
| 649 |
* Since 2.28 |
|---|
| 650 |
* Params: |
|---|
| 651 |
* tls = whether to use TLS |
|---|
| 652 |
*/ |
|---|
| 653 |
public void setTls(int tls) |
|---|
| 654 |
{ |
|---|
| 655 |
// void g_socket_client_set_tls (GSocketClient *client, gboolean tls); |
|---|
| 656 |
g_socket_client_set_tls(gSocketClient, tls); |
|---|
| 657 |
} |
|---|
| 658 |
|
|---|
| 659 |
/** |
|---|
| 660 |
* Sets the TLS validation flags used when creating TLS connections |
|---|
| 661 |
* via client. The default value is G_TLS_CERTIFICATE_VALIDATE_ALL. |
|---|
| 662 |
* Since 2.28 |
|---|
| 663 |
* Params: |
|---|
| 664 |
* flags = the validation flags |
|---|
| 665 |
*/ |
|---|
| 666 |
public void setTlsValidationFlags(GTlsCertificateFlags flags) |
|---|
| 667 |
{ |
|---|
| 668 |
// void g_socket_client_set_tls_validation_flags (GSocketClient *client, GTlsCertificateFlags flags); |
|---|
| 669 |
g_socket_client_set_tls_validation_flags(gSocketClient, flags); |
|---|
| 670 |
} |
|---|
| 671 |
|
|---|
| 672 |
/** |
|---|
| 673 |
* Gets the socket family of the socket client. |
|---|
| 674 |
* See g_socket_client_set_family() for details. |
|---|
| 675 |
* Since 2.22 |
|---|
| 676 |
* Returns: a GSocketFamily |
|---|
| 677 |
*/ |
|---|
| 678 |
public GSocketFamily getFamily() |
|---|
| 679 |
{ |
|---|
| 680 |
// GSocketFamily g_socket_client_get_family (GSocketClient *client); |
|---|
| 681 |
return g_socket_client_get_family(gSocketClient); |
|---|
| 682 |
} |
|---|
| 683 |
|
|---|
| 684 |
/** |
|---|
| 685 |
* Gets the local address of the socket client. |
|---|
| 686 |
* See g_socket_client_set_local_address() for details. |
|---|
| 687 |
* Since 2.22 |
|---|
| 688 |
* Returns: a GSocketAddres or NULL. don't free. [transfer none] |
|---|
| 689 |
*/ |
|---|
| 690 |
public SocketAddress getLocalAddress() |
|---|
| 691 |
{ |
|---|
| 692 |
// GSocketAddress * g_socket_client_get_local_address (GSocketClient *client); |
|---|
| 693 |
auto p = g_socket_client_get_local_address(gSocketClient); |
|---|
| 694 |
if(p is null) |
|---|
| 695 |
{ |
|---|
| 696 |
return null; |
|---|
| 697 |
} |
|---|
| 698 |
return new SocketAddress(cast(GSocketAddress*) p); |
|---|
| 699 |
} |
|---|
| 700 |
|
|---|
| 701 |
/** |
|---|
| 702 |
* Gets the protocol name type of the socket client. |
|---|
| 703 |
* See g_socket_client_set_protocol() for details. |
|---|
| 704 |
* Since 2.22 |
|---|
| 705 |
* Returns: a GSocketProtocol |
|---|
| 706 |
*/ |
|---|
| 707 |
public GSocketProtocol getProtocol() |
|---|
| 708 |
{ |
|---|
| 709 |
// GSocketProtocol g_socket_client_get_protocol (GSocketClient *client); |
|---|
| 710 |
return g_socket_client_get_protocol(gSocketClient); |
|---|
| 711 |
} |
|---|
| 712 |
|
|---|
| 713 |
/** |
|---|
| 714 |
* Gets the socket type of the socket client. |
|---|
| 715 |
* See g_socket_client_set_socket_type() for details. |
|---|
| 716 |
* Since 2.22 |
|---|
| 717 |
* Returns: a GSocketFamily |
|---|
| 718 |
*/ |
|---|
| 719 |
public GSocketType getSocketType() |
|---|
| 720 |
{ |
|---|
| 721 |
// GSocketType g_socket_client_get_socket_type (GSocketClient *client); |
|---|
| 722 |
return g_socket_client_get_socket_type(gSocketClient); |
|---|
| 723 |
} |
|---|
| 724 |
|
|---|
| 725 |
/** |
|---|
| 726 |
* Gets the I/O timeout time for sockets created by client. |
|---|
| 727 |
* See g_socket_client_set_timeout() for details. |
|---|
| 728 |
* Since 2.26 |
|---|
| 729 |
* Returns: the timeout in seconds |
|---|
| 730 |
*/ |
|---|
| 731 |
public uint getTimeout() |
|---|
| 732 |
{ |
|---|
| 733 |
// guint g_socket_client_get_timeout (GSocketClient *client); |
|---|
| 734 |
return g_socket_client_get_timeout(gSocketClient); |
|---|
| 735 |
} |
|---|
| 736 |
|
|---|
| 737 |
/** |
|---|
| 738 |
* Gets the proxy enable state; see g_socket_client_set_enable_proxy() |
|---|
| 739 |
* Since 2.26 |
|---|
| 740 |
* Returns: whether proxying is enabled |
|---|
| 741 |
*/ |
|---|
| 742 |
public int getEnableProxy() |
|---|
| 743 |
{ |
|---|
| 744 |
// gboolean g_socket_client_get_enable_proxy (GSocketClient *client); |
|---|
| 745 |
return g_socket_client_get_enable_proxy(gSocketClient); |
|---|
| 746 |
} |
|---|
| 747 |
|
|---|
| 748 |
/** |
|---|
| 749 |
* Gets whether client creates TLS connections. See |
|---|
| 750 |
* g_socket_client_set_tls() for details. |
|---|
| 751 |
* Since 2.28 |
|---|
| 752 |
* Returns: whether client uses TLS |
|---|
| 753 |
*/ |
|---|
| 754 |
public int getTls() |
|---|
| 755 |
{ |
|---|
| 756 |
// gboolean g_socket_client_get_tls (GSocketClient *client); |
|---|
| 757 |
return g_socket_client_get_tls(gSocketClient); |
|---|
| 758 |
} |
|---|
| 759 |
|
|---|
| 760 |
/** |
|---|
| 761 |
* Gets the TLS validation flags used creating TLS connections via |
|---|
| 762 |
* client. |
|---|
| 763 |
* Since 2.28 |
|---|
| 764 |
* Returns: the TLS validation flags |
|---|
| 765 |
*/ |
|---|
| 766 |
public GTlsCertificateFlags getTlsValidationFlags() |
|---|
| 767 |
{ |
|---|
| 768 |
// GTlsCertificateFlags g_socket_client_get_tls_validation_flags (GSocketClient *client); |
|---|
| 769 |
return g_socket_client_get_tls_validation_flags(gSocketClient); |
|---|
| 770 |
} |
|---|
| 771 |
} |
|---|