PageRenderTime 28ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/Sources/linux/gtkD/import/gio/Socket.d

https://bitbucket.org/coder78/tutorial
D | 1235 lines | 371 code | 124 blank | 740 comment | 31 complexity | 6ceacfe19a8e2578bdab7ef72f8dfbd8 MD5 | raw file
  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 as published by
  6. * the Free Software Foundation; either version 2.1 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * gtkD 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 gtkD; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. // generated automatically - do not change
  19. // find conversion definition on APILookup.txt
  20. // implement new conversion functionalities on the wrap.utils pakage
  21. /*
  22. * Conversion parameters:
  23. * inFile = GSocket.html
  24. * outPack = gio
  25. * outFile = Socket
  26. * strct = GSocket
  27. * realStrct=
  28. * ctorStrct=
  29. * clss = Socket
  30. * interf =
  31. * class Code: Yes
  32. * interface Code: No
  33. * template for:
  34. * extend =
  35. * implements:
  36. * - InitableIF
  37. * prefixes:
  38. * - g_socket_
  39. * omit structs:
  40. * omit prefixes:
  41. * omit code:
  42. * omit signals:
  43. * imports:
  44. * - glib.Str
  45. * - glib.ErrorG
  46. * - glib.GException
  47. * - glib.Source
  48. * - gio.SocketAddress
  49. * - gio.Cancellable
  50. * - gio.Credentials
  51. * - gio.SocketControlMessage
  52. * - gio.InitableT
  53. * - gio.InitableIF
  54. * structWrap:
  55. * - GCancellable* -> Cancellable
  56. * - GCredentials* -> Credentials
  57. * - GSocketAddress* -> SocketAddress
  58. * - GSocketControlMessage* -> SocketControlMessage
  59. * - GSource* -> Source
  60. * module aliases:
  61. * local aliases:
  62. * - GLIB_SYSDEF_MSG_DONTROUTE -> 4
  63. * - GLIB_SYSDEF_MSG_OOB -> 1
  64. * - GLIB_SYSDEF_MSG_PEEK -> 2
  65. * overrides:
  66. */
  67. module gio.Socket;
  68. public import gtkc.giotypes;
  69. private import gtkc.gio;
  70. private import glib.ConstructionException;
  71. private import glib.Str;
  72. private import glib.ErrorG;
  73. private import glib.GException;
  74. private import glib.Source;
  75. private import gio.SocketAddress;
  76. private import gio.Cancellable;
  77. private import gio.Credentials;
  78. private import gio.SocketControlMessage;
  79. private import gio.InitableT;
  80. private import gio.InitableIF;
  81. private import gobject.ObjectG;
  82. /**
  83. * Description
  84. * A GSocket is a low-level networking primitive. It is a more or less
  85. * direct mapping of the BSD socket API in a portable GObject based API.
  86. * It supports both the UNIX socket implementations and winsock2 on Windows.
  87. * GSocket is the platform independent base upon which the higher level
  88. * network primitives are based. Applications are not typically meant to
  89. * use it directly, but rather through classes like GSocketClient,
  90. * GSocketService and GSocketConnection. However there may be cases where
  91. * direct use of GSocket is useful.
  92. * GSocket implements the GInitable interface, so if it is manually constructed
  93. * by e.g. g_object_new() you must call g_initable_init() and check the
  94. * results before using the object. This is done automatically in
  95. * g_socket_new() and g_socket_new_from_fd(), so these functions can return
  96. * NULL.
  97. * Sockets operate in two general modes, blocking or non-blocking. When
  98. * in blocking mode all operations block until the requested operation
  99. * is finished or there is an error. In non-blocking mode all calls that
  100. * would block return immediately with a G_IO_ERROR_WOULD_BLOCK error.
  101. * To know when a call would successfully run you can call g_socket_condition_check(),
  102. * or g_socket_condition_wait(). You can also use g_socket_create_source() and
  103. * attach it to a GMainContext to get callbacks when I/O is possible.
  104. * Note that all sockets are always set to non blocking mode in the system, and
  105. * blocking mode is emulated in GSocket.
  106. * When working in non-blocking mode applications should always be able to
  107. * handle getting a G_IO_ERROR_WOULD_BLOCK error even when some other
  108. * function said that I/O was possible. This can easily happen in case
  109. * of a race condition in the application, but it can also happen for other
  110. * reasons. For instance, on Windows a socket is always seen as writable
  111. * until a write returns G_IO_ERROR_WOULD_BLOCK.
  112. * GSockets can be either connection oriented or datagram based.
  113. * For connection oriented types you must first establish a connection by
  114. * either connecting to an address or accepting a connection from another
  115. * address. For connectionless socket types the target/source address is
  116. * specified or received in each I/O operation.
  117. * All socket file descriptors are set to be close-on-exec.
  118. * Note that creating a GSocket causes the signal SIGPIPE to be
  119. * ignored for the remainder of the program. If you are writing a
  120. * command-line utility that uses GSocket, you may need to take into
  121. * account the fact that your program will not automatically be killed
  122. * if it tries to write to stdout after it has been closed.
  123. */
  124. public class Socket : ObjectG, InitableIF
  125. {
  126. /** the main Gtk struct */
  127. protected GSocket* gSocket;
  128. public GSocket* getSocketStruct()
  129. {
  130. return gSocket;
  131. }
  132. /** the main Gtk struct as a void* */
  133. protected override void* getStruct()
  134. {
  135. return cast(void*)gSocket;
  136. }
  137. /**
  138. * Sets our main struct and passes it to the parent class
  139. */
  140. public this (GSocket* gSocket)
  141. {
  142. if(gSocket is null)
  143. {
  144. this = null;
  145. return;
  146. }
  147. //Check if there already is a D object for this gtk struct
  148. void* ptr = getDObject(cast(GObject*)gSocket);
  149. if( ptr !is null )
  150. {
  151. this = cast(Socket)ptr;
  152. return;
  153. }
  154. super(cast(GObject*)gSocket);
  155. this.gSocket = gSocket;
  156. }
  157. protected override void setStruct(GObject* obj)
  158. {
  159. super.setStruct(obj);
  160. gSocket = cast(GSocket*)obj;
  161. }
  162. // add the Initable capabilities
  163. mixin InitableT!(GSocket);
  164. /**
  165. */
  166. /**
  167. * Creates a new GSocket with the defined family, type and protocol.
  168. * If protocol is 0 (G_SOCKET_PROTOCOL_DEFAULT) the default protocol type
  169. * for the family and type is used.
  170. * The protocol is a family and type specific int that specifies what
  171. * kind of protocol to use. GSocketProtocol lists several common ones.
  172. * Many families only support one protocol, and use 0 for this, others
  173. * support several and using 0 means to use the default protocol for
  174. * the family and type.
  175. * The protocol id is passed directly to the operating
  176. * system, so you can use protocols not listed in GSocketProtocol if you
  177. * know the protocol number used for it.
  178. * Since 2.22
  179. * Params:
  180. * family = the socket family to use, e.g. G_SOCKET_FAMILY_IPV4.
  181. * type = the socket type to use.
  182. * protocol = the id of the protocol to use, or 0 for default.
  183. * Throws: GException on failure.
  184. * Throws: ConstructionException GTK+ fails to create the object.
  185. */
  186. public this (GSocketFamily family, GSocketType type, GSocketProtocol protocol)
  187. {
  188. // GSocket * g_socket_new (GSocketFamily family, GSocketType type, GSocketProtocol protocol, GError **error);
  189. GError* err = null;
  190. auto p = g_socket_new(family, type, protocol, &err);
  191. if (err !is null)
  192. {
  193. throw new GException( new ErrorG(err) );
  194. }
  195. if(p is null)
  196. {
  197. throw new ConstructionException("null returned by g_socket_new(family, type, protocol, &err)");
  198. }
  199. this(cast(GSocket*) p);
  200. }
  201. /**
  202. * Creates a new GSocket from a native file descriptor
  203. * or winsock SOCKET handle.
  204. * This reads all the settings from the file descriptor so that
  205. * all properties should work. Note that the file descriptor
  206. * will be set to non-blocking mode, independent on the blocking
  207. * mode of the GSocket.
  208. * Since 2.22
  209. * Params:
  210. * fd = a native socket file descriptor.
  211. * Throws: GException on failure.
  212. * Throws: ConstructionException GTK+ fails to create the object.
  213. */
  214. public this (int fd)
  215. {
  216. // GSocket * g_socket_new_from_fd (gint fd, GError **error);
  217. GError* err = null;
  218. auto p = g_socket_new_from_fd(fd, &err);
  219. if (err !is null)
  220. {
  221. throw new GException( new ErrorG(err) );
  222. }
  223. if(p is null)
  224. {
  225. throw new ConstructionException("null returned by g_socket_new_from_fd(fd, &err)");
  226. }
  227. this(cast(GSocket*) p);
  228. }
  229. /**
  230. * When a socket is created it is attached to an address family, but it
  231. * doesn't have an address in this family. g_socket_bind() assigns the
  232. * address (sometimes called name) of the socket.
  233. * It is generally required to bind to a local address before you can
  234. * receive connections. (See g_socket_listen() and g_socket_accept() ).
  235. * In certain situations, you may also want to bind a socket that will be
  236. * used to initiate connections, though this is not normally required.
  237. * allow_reuse should be TRUE for server sockets (sockets that you will
  238. * eventually call g_socket_accept() on), and FALSE for client sockets.
  239. * (Specifically, if it is TRUE, then g_socket_bind() will set the
  240. * SO_REUSEADDR flag on the socket, allowing it to bind address even if
  241. * that address was previously used by another socket that has not yet been
  242. * fully cleaned-up by the kernel. Failing to set this flag on a server
  243. * socket may cause the bind call to return G_IO_ERROR_ADDRESS_IN_USE if
  244. * the server program is stopped and then immediately restarted.)
  245. * Since 2.22
  246. * Params:
  247. * address = a GSocketAddress specifying the local address.
  248. * allowReuse = whether to allow reusing this address
  249. * Returns: TRUE on success, FALSE on error.
  250. * Throws: GException on failure.
  251. */
  252. public int bind(SocketAddress address, int allowReuse)
  253. {
  254. // gboolean g_socket_bind (GSocket *socket, GSocketAddress *address, gboolean allow_reuse, GError **error);
  255. GError* err = null;
  256. auto p = g_socket_bind(gSocket, (address is null) ? null : address.getSocketAddressStruct(), allowReuse, &err);
  257. if (err !is null)
  258. {
  259. throw new GException( new ErrorG(err) );
  260. }
  261. return p;
  262. }
  263. /**
  264. * Marks the socket as a server socket, i.e. a socket that is used
  265. * to accept incoming requests using g_socket_accept().
  266. * Before calling this the socket must be bound to a local address using
  267. * g_socket_bind().
  268. * To set the maximum amount of outstanding clients, use
  269. * g_socket_set_listen_backlog().
  270. * Since 2.22
  271. * Returns: TRUE on success, FALSE on error.
  272. * Throws: GException on failure.
  273. */
  274. public int listen()
  275. {
  276. // gboolean g_socket_listen (GSocket *socket, GError **error);
  277. GError* err = null;
  278. auto p = g_socket_listen(gSocket, &err);
  279. if (err !is null)
  280. {
  281. throw new GException( new ErrorG(err) );
  282. }
  283. return p;
  284. }
  285. /**
  286. * Accept incoming connections on a connection-based socket. This removes
  287. * the first outstanding connection request from the listening socket and
  288. * creates a GSocket object for it.
  289. * The socket must be bound to a local address with g_socket_bind() and
  290. * must be listening for incoming connections (g_socket_listen()).
  291. * If there are no outstanding connections then the operation will block
  292. * or return G_IO_ERROR_WOULD_BLOCK if non-blocking I/O is enabled.
  293. * To be notified of an incoming connection, wait for the G_IO_IN condition.
  294. * Since 2.22
  295. * Params:
  296. * cancellable = a GCancellable or NULL
  297. * Returns: a new GSocket, or NULL on error. Free the returned object with g_object_unref().
  298. * Throws: GException on failure.
  299. */
  300. public GSocket* accept(Cancellable cancellable)
  301. {
  302. // GSocket * g_socket_accept (GSocket *socket, GCancellable *cancellable, GError **error);
  303. GError* err = null;
  304. auto p = g_socket_accept(gSocket, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  305. if (err !is null)
  306. {
  307. throw new GException( new ErrorG(err) );
  308. }
  309. return p;
  310. }
  311. /**
  312. * Connect the socket to the specified remote address.
  313. * For connection oriented socket this generally means we attempt to make
  314. * a connection to the address. For a connection-less socket it sets
  315. * the default address for g_socket_send() and discards all incoming datagrams
  316. * from other sources.
  317. * Generally connection oriented sockets can only connect once, but
  318. * connection-less sockets can connect multiple times to change the
  319. * default address.
  320. * If the connect call needs to do network I/O it will block, unless
  321. * non-blocking I/O is enabled. Then G_IO_ERROR_PENDING is returned
  322. * and the user can be notified of the connection finishing by waiting
  323. * for the G_IO_OUT condition. The result of the connection can then be
  324. * checked with g_socket_check_connect_result().
  325. * Since 2.22
  326. * Params:
  327. * address = a GSocketAddress specifying the remote address.
  328. * cancellable = a GCancellable or NULL
  329. * Returns: TRUE if connected, FALSE on error.
  330. * Throws: GException on failure.
  331. */
  332. public int connect(SocketAddress address, Cancellable cancellable)
  333. {
  334. // gboolean g_socket_connect (GSocket *socket, GSocketAddress *address, GCancellable *cancellable, GError **error);
  335. GError* err = null;
  336. auto p = g_socket_connect(gSocket, (address is null) ? null : address.getSocketAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  337. if (err !is null)
  338. {
  339. throw new GException( new ErrorG(err) );
  340. }
  341. return p;
  342. }
  343. /**
  344. * Checks and resets the pending connect error for the socket.
  345. * This is used to check for errors when g_socket_connect() is
  346. * used in non-blocking mode.
  347. * Since 2.22
  348. * Returns: TRUE if no error, FALSE otherwise, setting error to the error
  349. * Throws: GException on failure.
  350. */
  351. public int checkConnectResult()
  352. {
  353. // gboolean g_socket_check_connect_result (GSocket *socket, GError **error);
  354. GError* err = null;
  355. auto p = g_socket_check_connect_result(gSocket, &err);
  356. if (err !is null)
  357. {
  358. throw new GException( new ErrorG(err) );
  359. }
  360. return p;
  361. }
  362. /**
  363. * Receive data (up to size bytes) from a socket. This is mainly used by
  364. * connection-oriented sockets; it is identical to g_socket_receive_from()
  365. * with address set to NULL.
  366. * For G_SOCKET_TYPE_DATAGRAM and G_SOCKET_TYPE_SEQPACKET sockets,
  367. * g_socket_receive() will always read either 0 or 1 complete messages from
  368. * the socket. If the received message is too large to fit in buffer, then
  369. * the data beyond size bytes will be discarded, without any explicit
  370. * indication that this has occurred.
  371. * For G_SOCKET_TYPE_STREAM sockets, g_socket_receive() can return any
  372. * number of bytes, up to size. If more than size bytes have been
  373. * received, the additional data will be returned in future calls to
  374. * g_socket_receive().
  375. * If the socket is in blocking mode the call will block until there is
  376. * some data to receive or there is an error. If there is no data available
  377. * and the socket is in non-blocking mode, a G_IO_ERROR_WOULD_BLOCK error
  378. * will be returned. To be notified when data is available, wait for the
  379. * G_IO_IN condition.
  380. * On error -1 is returned and error is set accordingly.
  381. * Since 2.22
  382. * Params:
  383. * buffer = a buffer to read data into (which should be at least size
  384. * bytes long).
  385. * size = the number of bytes you want to read from the socket
  386. * cancellable = a GCancellable or NULL
  387. * Returns: Number of bytes read, or -1 on error
  388. * Throws: GException on failure.
  389. */
  390. public gssize receive(string buffer, gsize size, Cancellable cancellable)
  391. {
  392. // gssize g_socket_receive (GSocket *socket, gchar *buffer, gsize size, GCancellable *cancellable, GError **error);
  393. GError* err = null;
  394. auto p = g_socket_receive(gSocket, Str.toStringz(buffer), size, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  395. if (err !is null)
  396. {
  397. throw new GException( new ErrorG(err) );
  398. }
  399. return p;
  400. }
  401. /**
  402. * Receive data (up to size bytes) from a socket.
  403. * If address is non-NULL then address will be set equal to the
  404. * source address of the received packet.
  405. * address is owned by the caller.
  406. * See g_socket_receive() for additional information.
  407. * Since 2.22
  408. * Params:
  409. * address = a pointer to a GSocketAddress pointer, or NULL
  410. * buffer = a buffer to read data into (which should be at least size
  411. * bytes long).
  412. * size = the number of bytes you want to read from the socket
  413. * cancellable = a GCancellable or NULL
  414. * Returns: Number of bytes read, or -1 on error
  415. * Throws: GException on failure.
  416. */
  417. public gssize receiveFrom(ref SocketAddress address, char[] buffer, Cancellable cancellable)
  418. {
  419. // gssize g_socket_receive_from (GSocket *socket, GSocketAddress **address, gchar *buffer, gsize size, GCancellable *cancellable, GError **error);
  420. GSocketAddress* outaddress = (address is null) ? null : address.getSocketAddressStruct();
  421. GError* err = null;
  422. auto p = g_socket_receive_from(gSocket, &outaddress, buffer.ptr, cast(int) buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  423. if (err !is null)
  424. {
  425. throw new GException( new ErrorG(err) );
  426. }
  427. address = new SocketAddress(outaddress);
  428. return p;
  429. }
  430. /**
  431. * Receive data from a socket. This is the most complicated and
  432. * fully-featured version of this call. For easier use, see
  433. * g_socket_receive() and g_socket_receive_from().
  434. * If address is non-NULL then address will be set equal to the
  435. * source address of the received packet.
  436. * address is owned by the caller.
  437. * vector must point to an array of GInputVector structs and
  438. * num_vectors must be the length of this array. These structs
  439. * describe the buffers that received data will be scattered into.
  440. * If num_vectors is -1, then vectors is assumed to be terminated
  441. * by a GInputVector with a NULL buffer pointer.
  442. * As a special case, if num_vectors is 0 (in which case, vectors
  443. * may of course be NULL), then a single byte is received and
  444. * discarded. This is to facilitate the common practice of sending a
  445. * single '\0' byte for the purposes of transferring ancillary data.
  446. * messages, if non-NULL, will be set to point to a newly-allocated
  447. * array of GSocketControlMessage instances or NULL if no such
  448. * messages was received. These correspond to the control messages
  449. * received from the kernel, one GSocketControlMessage per message
  450. * from the kernel. This array is NULL-terminated and must be freed
  451. * by the caller using g_free() after calling g_object_unref() on each
  452. * element. If messages is NULL, any control messages received will
  453. * be discarded.
  454. * num_messages, if non-NULL, will be set to the number of control
  455. * messages received.
  456. * If both messages and num_messages are non-NULL, then
  457. * num_messages gives the number of GSocketControlMessage instances
  458. * in messages (ie: not including the NULL terminator).
  459. * flags is an in/out parameter. The commonly available arguments
  460. * for this are available in the GSocketMsgFlags enum, but the
  461. * values there are the same as the system values, and the flags
  462. * are passed in as-is, so you can pass in system-specific flags too
  463. * (and g_socket_receive_message() may pass system-specific flags out).
  464. * As with g_socket_receive(), data may be discarded if socket is
  465. * G_SOCKET_TYPE_DATAGRAM or G_SOCKET_TYPE_SEQPACKET and you do not
  466. * provide enough buffer space to read a complete message. You can pass
  467. * G_SOCKET_MSG_PEEK in flags to peek at the current message without
  468. * removing it from the receive queue, but there is no portable way to find
  469. * out the length of the message other than by reading it into a
  470. * sufficiently-large buffer.
  471. * If the socket is in blocking mode the call will block until there
  472. * is some data to receive or there is an error. If there is no data
  473. * available and the socket is in non-blocking mode, a
  474. * G_IO_ERROR_WOULD_BLOCK error will be returned. To be notified when
  475. * data is available, wait for the G_IO_IN condition.
  476. * On error -1 is returned and error is set accordingly.
  477. * Since 2.22
  478. * Params:
  479. * address = a pointer to a GSocketAddress pointer, or NULL
  480. * vectors = an array of GInputVector structs
  481. * messages = a pointer which may be filled with an array of
  482. * GSocketControlMessages, or NULL
  483. * flags = a pointer to an int containing GSocketMsgFlags flags
  484. * cancellable = a GCancellable or NULL
  485. * Returns: Number of bytes read, or -1 on error
  486. * Throws: GException on failure.
  487. */
  488. public gssize receiveMessage(ref SocketAddress address, GInputVector[] vectors, ref SocketControlMessage[] messages, ref int flags, Cancellable cancellable)
  489. {
  490. // gssize g_socket_receive_message (GSocket *socket, GSocketAddress **address, GInputVector *vectors, gint num_vectors, GSocketControlMessage ***messages, gint *num_messages, gint *flags, GCancellable *cancellable, GError **error);
  491. GSocketAddress* outaddress = (address is null) ? null : address.getSocketAddressStruct();
  492. GSocketControlMessage*[] inoutmessages = new GSocketControlMessage*[messages.length];
  493. for ( int i = 0; i < messages.length ; i++ )
  494. {
  495. inoutmessages[i] = messages[i].getSocketControlMessageStruct();
  496. }
  497. GSocketControlMessage** outmessages = inoutmessages.ptr;
  498. int numMessages = cast(int) messages.length;
  499. GError* err = null;
  500. auto p = g_socket_receive_message(gSocket, &outaddress, vectors.ptr, cast(int) vectors.length, &outmessages, &numMessages, &flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  501. if (err !is null)
  502. {
  503. throw new GException( new ErrorG(err) );
  504. }
  505. address = new SocketAddress(outaddress);
  506. messages = new SocketControlMessage[numMessages];
  507. for(int i = 0; i < numMessages; i++)
  508. {
  509. messages[i] = new SocketControlMessage(cast(GSocketControlMessage*) outmessages[i]);
  510. }
  511. return p;
  512. }
  513. /**
  514. * This behaves exactly the same as g_socket_receive(), except that
  515. * the choice of blocking or non-blocking behavior is determined by
  516. * the blocking argument rather than by socket's properties.
  517. * Since 2.26
  518. * Params:
  519. * buffer = a buffer to read data into (which should be at least size
  520. * bytes long).
  521. * size = the number of bytes you want to read from the socket
  522. * blocking = whether to do blocking or non-blocking I/O
  523. * cancellable = a GCancellable or NULL
  524. * Returns: Number of bytes read, or -1 on error
  525. * Throws: GException on failure.
  526. */
  527. public gssize receiveWithBlocking(string buffer, gsize size, int blocking, Cancellable cancellable)
  528. {
  529. // gssize g_socket_receive_with_blocking (GSocket *socket, gchar *buffer, gsize size, gboolean blocking, GCancellable *cancellable, GError **error);
  530. GError* err = null;
  531. auto p = g_socket_receive_with_blocking(gSocket, Str.toStringz(buffer), size, blocking, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  532. if (err !is null)
  533. {
  534. throw new GException( new ErrorG(err) );
  535. }
  536. return p;
  537. }
  538. /**
  539. * Tries to send size bytes from buffer on the socket. This is
  540. * mainly used by connection-oriented sockets; it is identical to
  541. * g_socket_send_to() with address set to NULL.
  542. * If the socket is in blocking mode the call will block until there is
  543. * space for the data in the socket queue. If there is no space available
  544. * and the socket is in non-blocking mode a G_IO_ERROR_WOULD_BLOCK error
  545. * will be returned. To be notified when space is available, wait for the
  546. * G_IO_OUT condition. Note though that you may still receive
  547. * G_IO_ERROR_WOULD_BLOCK from g_socket_send() even if you were previously
  548. * notified of a G_IO_OUT condition. (On Windows in particular, this is
  549. * very common due to the way the underlying APIs work.)
  550. * On error -1 is returned and error is set accordingly.
  551. * Since 2.22
  552. * Params:
  553. * buffer = the buffer containing the data to send.
  554. * size = the number of bytes to send
  555. * cancellable = a GCancellable or NULL
  556. * Returns: Number of bytes written (which may be less than size), or -1 on error
  557. * Throws: GException on failure.
  558. */
  559. public gssize send(string buffer, gsize size, Cancellable cancellable)
  560. {
  561. // gssize g_socket_send (GSocket *socket, const gchar *buffer, gsize size, GCancellable *cancellable, GError **error);
  562. GError* err = null;
  563. auto p = g_socket_send(gSocket, Str.toStringz(buffer), size, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  564. if (err !is null)
  565. {
  566. throw new GException( new ErrorG(err) );
  567. }
  568. return p;
  569. }
  570. /**
  571. * Tries to send size bytes from buffer to address. If address is
  572. * NULL then the message is sent to the default receiver (set by
  573. * g_socket_connect()).
  574. * See g_socket_send() for additional information.
  575. * Since 2.22
  576. * Params:
  577. * address = a GSocketAddress, or NULL
  578. * buffer = the buffer containing the data to send.
  579. * size = the number of bytes to send
  580. * cancellable = a GCancellable or NULL
  581. * Returns: Number of bytes written (which may be less than size), or -1 on error
  582. * Throws: GException on failure.
  583. */
  584. public gssize sendTo(SocketAddress address, string buffer, gsize size, Cancellable cancellable)
  585. {
  586. // gssize g_socket_send_to (GSocket *socket, GSocketAddress *address, const gchar *buffer, gsize size, GCancellable *cancellable, GError **error);
  587. GError* err = null;
  588. auto p = g_socket_send_to(gSocket, (address is null) ? null : address.getSocketAddressStruct(), Str.toStringz(buffer), size, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  589. if (err !is null)
  590. {
  591. throw new GException( new ErrorG(err) );
  592. }
  593. return p;
  594. }
  595. /**
  596. * Send data to address on socket. This is the most complicated and
  597. * fully-featured version of this call. For easier use, see
  598. * g_socket_send() and g_socket_send_to().
  599. * If address is NULL then the message is sent to the default receiver
  600. * (set by g_socket_connect()).
  601. * vectors must point to an array of GOutputVector structs and
  602. * num_vectors must be the length of this array. (If num_vectors is -1,
  603. * then vectors is assumed to be terminated by a GOutputVector with a
  604. * NULL buffer pointer.) The GOutputVector structs describe the buffers
  605. * that the sent data will be gathered from. Using multiple
  606. * GOutputVectors is more memory-efficient than manually copying
  607. * data from multiple sources into a single buffer, and more
  608. * network-efficient than making multiple calls to g_socket_send().
  609. * messages, if non-NULL, is taken to point to an array of num_messages
  610. * GSocketControlMessage instances. These correspond to the control
  611. * messages to be sent on the socket.
  612. * If num_messages is -1 then messages is treated as a NULL-terminated
  613. * array.
  614. * flags modify how the message is sent. The commonly available arguments
  615. * for this are available in the GSocketMsgFlags enum, but the
  616. * values there are the same as the system values, and the flags
  617. * are passed in as-is, so you can pass in system-specific flags too.
  618. * If the socket is in blocking mode the call will block until there is
  619. * space for the data in the socket queue. If there is no space available
  620. * and the socket is in non-blocking mode a G_IO_ERROR_WOULD_BLOCK error
  621. * will be returned. To be notified when space is available, wait for the
  622. * G_IO_OUT condition. Note though that you may still receive
  623. * G_IO_ERROR_WOULD_BLOCK from g_socket_send() even if you were previously
  624. * notified of a G_IO_OUT condition. (On Windows in particular, this is
  625. * very common due to the way the underlying APIs work.)
  626. * On error -1 is returned and error is set accordingly.
  627. * Since 2.22
  628. * Params:
  629. * address = a GSocketAddress, or NULL
  630. * vectors = an array of GOutputVector structs
  631. * messages = a pointer to an array of GSocketControlMessages, or
  632. * NULL.
  633. * flags = an int containing GSocketMsgFlags flags
  634. * cancellable = a GCancellable or NULL
  635. * Returns: Number of bytes written (which may be less than size), or -1 on error
  636. * Throws: GException on failure.
  637. */
  638. public gssize sendMessage(SocketAddress address, GOutputVector[] vectors, ref GSocketControlMessage[] messages, int flags, Cancellable cancellable)
  639. {
  640. // gssize g_socket_send_message (GSocket *socket, GSocketAddress *address, GOutputVector *vectors, gint num_vectors, GSocketControlMessage **messages, gint num_messages, gint flags, GCancellable *cancellable, GError **error);
  641. GSocketControlMessage* outmessages = messages.ptr;
  642. int numMessages = cast(int) messages.length;
  643. GError* err = null;
  644. auto p = g_socket_send_message(gSocket, (address is null) ? null : address.getSocketAddressStruct(), vectors.ptr, cast(int) vectors.length, &outmessages, numMessages, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  645. if (err !is null)
  646. {
  647. throw new GException( new ErrorG(err) );
  648. }
  649. messages = outmessages[0 .. numMessages];
  650. return p;
  651. }
  652. /**
  653. * This behaves exactly the same as g_socket_send(), except that
  654. * the choice of blocking or non-blocking behavior is determined by
  655. * the blocking argument rather than by socket's properties.
  656. * Since 2.26
  657. * Params:
  658. * buffer = the buffer containing the data to send.
  659. * size = the number of bytes to send
  660. * blocking = whether to do blocking or non-blocking I/O
  661. * cancellable = a GCancellable or NULL
  662. * Returns: Number of bytes written (which may be less than size), or -1 on error
  663. * Throws: GException on failure.
  664. */
  665. public gssize sendWithBlocking(string buffer, gsize size, int blocking, Cancellable cancellable)
  666. {
  667. // gssize g_socket_send_with_blocking (GSocket *socket, const gchar *buffer, gsize size, gboolean blocking, GCancellable *cancellable, GError **error);
  668. GError* err = null;
  669. auto p = g_socket_send_with_blocking(gSocket, Str.toStringz(buffer), size, blocking, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  670. if (err !is null)
  671. {
  672. throw new GException( new ErrorG(err) );
  673. }
  674. return p;
  675. }
  676. /**
  677. * Closes the socket, shutting down any active connection.
  678. * Closing a socket does not wait for all outstanding I/O operations
  679. * to finish, so the caller should not rely on them to be guaranteed
  680. * to complete even if the close returns with no error.
  681. * Once the socket is closed, all other operations will return
  682. * G_IO_ERROR_CLOSED. Closing a socket multiple times will not
  683. * return an error.
  684. * Sockets will be automatically closed when the last reference
  685. * is dropped, but you might want to call this function to make sure
  686. * resources are released as early as possible.
  687. * Beware that due to the way that TCP works, it is possible for
  688. * recently-sent data to be lost if either you close a socket while the
  689. * G_IO_IN condition is set, or else if the remote connection tries to
  690. * send something to you after you close the socket but before it has
  691. * finished reading all of the data you sent. There is no easy generic
  692. * way to avoid this problem; the easiest fix is to design the network
  693. * protocol such that the client will never send data "out of turn".
  694. * Another solution is for the server to half-close the connection by
  695. * calling g_socket_shutdown() with only the shutdown_write flag set,
  696. * and then wait for the client to notice this and close its side of the
  697. * connection, after which the server can safely call g_socket_close().
  698. * (This is what GTcpConnection does if you call
  699. * g_tcp_connection_set_graceful_disconnect(). But of course, this
  700. * only works if the client will close its connection after the server
  701. * does.)
  702. * Since 2.22
  703. * Returns: TRUE on success, FALSE on error
  704. * Throws: GException on failure.
  705. */
  706. public int close()
  707. {
  708. // gboolean g_socket_close (GSocket *socket, GError **error);
  709. GError* err = null;
  710. auto p = g_socket_close(gSocket, &err);
  711. if (err !is null)
  712. {
  713. throw new GException( new ErrorG(err) );
  714. }
  715. return p;
  716. }
  717. /**
  718. * Checks whether a socket is closed.
  719. * Since 2.22
  720. * Returns: TRUE if socket is closed, FALSE otherwise
  721. */
  722. public int isClosed()
  723. {
  724. // gboolean g_socket_is_closed (GSocket *socket);
  725. return g_socket_is_closed(gSocket);
  726. }
  727. /**
  728. * Shut down part of a full-duplex connection.
  729. * If shutdown_read is TRUE then the recieving side of the connection
  730. * is shut down, and further reading is disallowed.
  731. * If shutdown_write is TRUE then the sending side of the connection
  732. * is shut down, and further writing is disallowed.
  733. * It is allowed for both shutdown_read and shutdown_write to be TRUE.
  734. * One example where this is used is graceful disconnect for TCP connections
  735. * where you close the sending side, then wait for the other side to close
  736. * the connection, thus ensuring that the other side saw all sent data.
  737. * Since 2.22
  738. * Params:
  739. * shutdownRead = whether to shut down the read side
  740. * shutdownWrite = whether to shut down the write side
  741. * Returns: TRUE on success, FALSE on error
  742. * Throws: GException on failure.
  743. */
  744. public int shutdown(int shutdownRead, int shutdownWrite)
  745. {
  746. // gboolean g_socket_shutdown (GSocket *socket, gboolean shutdown_read, gboolean shutdown_write, GError **error);
  747. GError* err = null;
  748. auto p = g_socket_shutdown(gSocket, shutdownRead, shutdownWrite, &err);
  749. if (err !is null)
  750. {
  751. throw new GException( new ErrorG(err) );
  752. }
  753. return p;
  754. }
  755. /**
  756. * Check whether the socket is connected. This is only useful for
  757. * connection-oriented sockets.
  758. * Since 2.22
  759. * Returns: TRUE if socket is connected, FALSE otherwise.
  760. */
  761. public int isConnected()
  762. {
  763. // gboolean g_socket_is_connected (GSocket *socket);
  764. return g_socket_is_connected(gSocket);
  765. }
  766. /**
  767. * Creates a GSource that can be attached to a GMainContext to monitor
  768. * for the availibility of the specified condition on the socket.
  769. * The callback on the source is of the GSocketSourceFunc type.
  770. * It is meaningless to specify G_IO_ERR or G_IO_HUP in condition;
  771. * these conditions will always be reported output if they are true.
  772. * cancellable if not NULL can be used to cancel the source, which will
  773. * cause the source to trigger, reporting the current condition (which
  774. * is likely 0 unless cancellation happened at the same time as a
  775. * condition change). You can check for this in the callback using
  776. * g_cancellable_is_cancelled().
  777. * If socket has a timeout set, and it is reached before condition
  778. * occurs, the source will then trigger anyway, reporting G_IO_IN or
  779. * G_IO_OUT depending on condition. However, socket will have been
  780. * marked as having had a timeout, and so the next GSocket I/O method
  781. * you call will then fail with a G_IO_ERROR_TIMED_OUT.
  782. * Since 2.22
  783. * Params:
  784. * condition = a GIOCondition mask to monitor
  785. * cancellable = a GCancellable or NULL
  786. * Returns: a newly allocated GSource, free with g_source_unref().
  787. */
  788. public Source createSource(GIOCondition condition, Cancellable cancellable)
  789. {
  790. // GSource * g_socket_create_source (GSocket *socket, GIOCondition condition, GCancellable *cancellable);
  791. auto p = g_socket_create_source(gSocket, condition, (cancellable is null) ? null : cancellable.getCancellableStruct());
  792. if(p is null)
  793. {
  794. return null;
  795. }
  796. return new Source(cast(GSource*) p);
  797. }
  798. /**
  799. * Checks on the readiness of socket to perform operations.
  800. * The operations specified in condition are checked for and masked
  801. * against the currently-satisfied conditions on socket. The result
  802. * is returned.
  803. * Note that on Windows, it is possible for an operation to return
  804. * G_IO_ERROR_WOULD_BLOCK even immediately after
  805. * g_socket_condition_check() has claimed that the socket is ready for
  806. * writing. Rather than calling g_socket_condition_check() and then
  807. * writing to the socket if it succeeds, it is generally better to
  808. * simply try writing to the socket right away, and try again later if
  809. * the initial attempt returns G_IO_ERROR_WOULD_BLOCK.
  810. * It is meaningless to specify G_IO_ERR or G_IO_HUP in condition;
  811. * these conditions will always be set in the output if they are true.
  812. * This call never blocks.
  813. * Since 2.22
  814. * Params:
  815. * condition = a GIOCondition mask to check
  816. * Returns: the GIOCondition mask of the current state
  817. */
  818. public GIOCondition conditionCheck(GIOCondition condition)
  819. {
  820. // GIOCondition g_socket_condition_check (GSocket *socket, GIOCondition condition);
  821. return g_socket_condition_check(gSocket, condition);
  822. }
  823. /**
  824. * Waits for condition to become true on socket. When the condition
  825. * is met, TRUE is returned.
  826. * If cancellable is cancelled before the condition is met, or if the
  827. * socket has a timeout set and it is reached before the condition is
  828. * met, then FALSE is returned and error, if non-NULL, is set to
  829. * the appropriate value (G_IO_ERROR_CANCELLED or
  830. * G_IO_ERROR_TIMED_OUT).
  831. * Since 2.22
  832. * Params:
  833. * condition = a GIOCondition mask to wait for
  834. * cancellable = a GCancellable, or NULL
  835. * Returns: TRUE if the condition was met, FALSE otherwise
  836. * Throws: GException on failure.
  837. */
  838. public int conditionWait(GIOCondition condition, Cancellable cancellable)
  839. {
  840. // gboolean g_socket_condition_wait (GSocket *socket, GIOCondition condition, GCancellable *cancellable, GError **error);
  841. GError* err = null;
  842. auto p = g_socket_condition_wait(gSocket, condition, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
  843. if (err !is null)
  844. {
  845. throw new GException( new ErrorG(err) );
  846. }
  847. return p;
  848. }
  849. /**
  850. * Sets the maximum number of outstanding connections allowed
  851. * when listening on this socket. If more clients than this are
  852. * connecting to the socket and the application is not handling them
  853. * on time then the new connections will be refused.
  854. * Note that this must be called before g_socket_listen() and has no
  855. * effect if called after that.
  856. * Since 2.22
  857. * Params:
  858. * backlog = the maximum number of pending connections.
  859. */
  860. public void setListenBacklog(int backlog)
  861. {
  862. // void g_socket_set_listen_backlog (GSocket *socket, gint backlog);
  863. g_socket_set_listen_backlog(gSocket, backlog);
  864. }
  865. /**
  866. * Gets the listen backlog setting of the socket. For details on this,
  867. * see g_socket_set_listen_backlog().
  868. * Since 2.22
  869. * Returns: the maximum number of pending connections.
  870. */
  871. public int getListenBacklog()
  872. {
  873. // gint g_socket_get_listen_backlog (GSocket *socket);
  874. return g_socket_get_listen_backlog(gSocket);
  875. }
  876. /**
  877. * Gets the blocking mode of the socket. For details on blocking I/O,
  878. * see g_socket_set_blocking().
  879. * Since 2.22
  880. * Returns: TRUE if blocking I/O is used, FALSE otherwise.
  881. */
  882. public int getBlocking()
  883. {
  884. // gboolean g_socket_get_blocking (GSocket *socket);
  885. return g_socket_get_blocking(gSocket);
  886. }
  887. /**
  888. * Sets the blocking mode of the socket. In blocking mode
  889. * all operations block until they succeed or there is an error. In
  890. * non-blocking mode all functions return results immediately or
  891. * with a G_IO_ERROR_WOULD_BLOCK error.
  892. * All sockets are created in blocking mode. However, note that the
  893. * platform level socket is always non-blocking, and blocking mode
  894. * is a GSocket level feature.
  895. * Since 2.22
  896. * Params:
  897. * blocking = Whether to use blocking I/O or not.
  898. */
  899. public void setBlocking(int blocking)
  900. {
  901. // void g_socket_set_blocking (GSocket *socket, gboolean blocking);
  902. g_socket_set_blocking(gSocket, blocking);
  903. }
  904. /**
  905. * Gets the keepalive mode of the socket. For details on this,
  906. * see g_socket_set_keepalive().
  907. * Since 2.22
  908. * Returns: TRUE if keepalive is active, FALSE otherwise.
  909. */
  910. public int getKeepalive()
  911. {
  912. // gboolean g_socket_get_keepalive (GSocket *socket);
  913. return g_socket_get_keepalive(gSocket);
  914. }
  915. /**
  916. * Sets or unsets the SO_KEEPALIVE flag on the underlying socket. When
  917. * this flag is set on a socket, the system will attempt to verify that the
  918. * remote socket endpoint is still present if a sufficiently long period of
  919. * time passes with no data being exchanged. If the system is unable to
  920. * verify the presence of the remote endpoint, it will automatically close
  921. * the connection.
  922. * This option is only functional on certain kinds of sockets. (Notably,
  923. * G_SOCKET_PROTOCOL_TCP sockets.)
  924. * The exact time between pings is system- and protocol-dependent, but will
  925. * normally be at least two hours. Most commonly, you would set this flag
  926. * on a server socket if you want to allow clients to remain idle for long
  927. * periods of time, but also want to ensure that connections are eventually
  928. * garbage-collected if clients crash or become unreachable.
  929. * Since 2.22
  930. * Params:
  931. * keepalive = Value for the keepalive flag
  932. */
  933. public void setKeepalive(int keepalive)
  934. {
  935. // void g_socket_set_keepalive (GSocket *socket, gboolean keepalive);
  936. g_socket_set_keepalive(gSocket, keepalive);
  937. }
  938. /**
  939. * Gets the timeout setting of the socket. For details on this, see
  940. * g_socket_set_timeout().
  941. * Since 2.26
  942. * Returns: the timeout in seconds
  943. */
  944. public uint getTimeout()
  945. {
  946. // guint g_socket_get_timeout (GSocket *socket);
  947. return g_socket_get_timeout(gSocket);
  948. }
  949. /**
  950. * Sets the time in seconds after which I/O operations on socket will
  951. * time out if they have not yet completed.
  952. * On a blocking socket, this means that any blocking GSocket
  953. * operation will time out after timeout seconds of inactivity,
  954. * returning G_IO_ERROR_TIMED_OUT.
  955. * On a non-blocking socket, calls to g_socket_condition_wait() will
  956. * also fail with G_IO_ERROR_TIMED_OUT after the given time. Sources
  957. * created with g_socket_create_source() will trigger after
  958. * timeout seconds of inactivity, with the requested condition
  959. * set, at which point calling g_socket_receive(), g_socket_send(),
  960. * g_socket_check_connect_result(), etc, will fail with
  961. * G_IO_ERROR_TIMED_OUT.
  962. * If timeout is 0 (the default), operations will never time out
  963. * on their own.
  964. * Note that if an I/O operation is interrupted by a signal, this may
  965. * cause the timeout to be reset.
  966. * Since 2.26
  967. * Params:
  968. * timeout = the timeout for socket, in seconds, or 0 for none
  969. */
  970. public void setTimeout(uint timeout)
  971. {
  972. // void g_socket_set_timeout (GSocket *socket, guint timeout);
  973. g_socket_set_timeout(gSocket, timeout);
  974. }
  975. /**
  976. * Gets the socket family of the socket.
  977. * Since 2.22
  978. * Returns: a GSocketFamily
  979. */
  980. public GSocketFamily getFamily()
  981. {
  982. // GSocketFamily g_socket_get_family (GSocket *socket);
  983. return g_socket_get_family(gSocket);
  984. }
  985. /**
  986. * Returns the underlying OS socket object. On unix this
  987. * is a socket file descriptor, and on windows this is
  988. * a Winsock2 SOCKET handle. This may be useful for
  989. * doing platform specific or otherwise unusual operations
  990. * on the socket.
  991. * Since 2.22
  992. * Returns: the file descriptor of the socket.
  993. */
  994. public int getFd()
  995. {
  996. // int g_socket_get_fd (GSocket *socket);
  997. return g_socket_get_fd(gSocket);
  998. }
  999. /**
  1000. * Try to get the local address of a bound socket. This is only
  1001. * useful if the socket has been bound to a local address,
  1002. * either explicitly or implicitly when connecting.
  1003. * Since 2.22
  1004. * Returns: a GSocketAddress or NULL on error. Free the returned object with g_object_unref().
  1005. * Throws: GException on failure.
  1006. */
  1007. public SocketAddress getLocalAddress()
  1008. {
  1009. // GSocketAddress * g_socket_get_local_address (GSocket *socket, GError **error);
  1010. GError* err = null;
  1011. auto p = g_socket_get_local_address(gSocket, &err);
  1012. if (err !is null)
  1013. {
  1014. throw new GException( new ErrorG(err) );
  1015. }
  1016. if(p is null)
  1017. {
  1018. return null;
  1019. }
  1020. return new SocketAddress(cast(GSocketAddress*) p);
  1021. }
  1022. /**
  1023. * Gets the socket protocol id the socket was created with.
  1024. * In case the protocol is unknown, -1 is returned.
  1025. * Since 2.22
  1026. * Returns: a protocol id, or -1 if unknown
  1027. */
  1028. public GSocketProtocol getProtocol()
  1029. {
  1030. // GSocketProtocol g_socket_get_protocol (GSocket *socket);
  1031. return g_socket_get_protocol(gSocket);
  1032. }
  1033. /**
  1034. * Try to get the remove address of a connected socket. This is only
  1035. * useful for connection oriented sockets that have been connected.
  1036. * Since 2.22
  1037. * Returns: a GSocketAddress or NULL on error. Free the returned object with g_object_unref().
  1038. * Throws: GException on failure.
  1039. */
  1040. public SocketAddress getRemoteAddress()
  1041. {
  1042. // GSocketAddress * g_socket_get_remote_address (GSocket *socket, GError **error);
  1043. GError* err = null;
  1044. auto p = g_socket_get_remote_address(gSocket, &err);
  1045. if (err !is null)
  1046. {
  1047. throw new GException( new ErrorG(err) );
  1048. }
  1049. if(p is null)
  1050. {
  1051. return null;
  1052. }
  1053. return new SocketAddress(cast(GSocketAddress*) p);
  1054. }
  1055. /**
  1056. * Gets the socket type of the socket.
  1057. * Since 2.22
  1058. * Returns: a GSocketType
  1059. */
  1060. public GSocketType getSocketType()
  1061. {
  1062. // GSocketType g_socket_get_socket_type (GSocket *socket);
  1063. return g_socket_get_socket_type(gSocket);
  1064. }
  1065. /**
  1066. * Checks if a socket is capable of speaking IPv4.
  1067. * IPv4 sockets are capable of speaking IPv4. On some operating systems
  1068. * and under some combinations of circumstances IPv6 sockets are also
  1069. * capable of speaking IPv4. See RFC 3493 section 3.7 for more
  1070. * information.
  1071. * No other types of sockets are currently considered as being capable
  1072. * of speaking IPv4.
  1073. * Since 2.22
  1074. * Returns: TRUE if this socket can be used with IPv4.
  1075. */
  1076. public int speaksIpv4()
  1077. {
  1078. // gboolean g_socket_speaks_ipv4 (GSocket *socket);
  1079. return g_socket_speaks_ipv4(gSocket);
  1080. }
  1081. /**
  1082. * Returns the credentials of the foreign process connected to this
  1083. * socket, if any (e.g. it is only supported for G_SOCKET_FAMILY_UNIX
  1084. * sockets).
  1085. * If this operation isn't supported on the OS, the method fails with
  1086. * the G_IO_ERROR_NOT_SUPPORTED error. On Linux this is implemented
  1087. * by reading the SO_PEERCRED option on the underlying socket.
  1088. * Other ways to obtain credentials from a foreign peer includes the
  1089. * GUnixCredentialsMessage type and
  1090. * g_unix_connection_send_credentials() /
  1091. * g_unix_connection_receive_credentials() functions.
  1092. * Since 2.26
  1093. * Returns: NULL if error is set, otherwise a GCredentials object that must be freed with g_object_unref().
  1094. * Throws: GException on failure.
  1095. */
  1096. public Credentials getCredentials()
  1097. {
  1098. // GCredentials * g_socket_get_credentials (GSocket *socket, GError **error);
  1099. GError* err = null;
  1100. auto p = g_socket_get_credentials(gSocket, &err);
  1101. if (err !is null)
  1102. {
  1103. throw new GException( new ErrorG(err) );
  1104. }
  1105. if(p is null)
  1106. {
  1107. return null;
  1108. }
  1109. return new Credentials(cast(GCredentials*) p);
  1110. }
  1111. }