Add GBytes variants for GSocket receive methods

The current buffer API is pretty much C-specific, and cannot be
adequately described in a way that is friendly to introspection and
language bindings: the passed buffer is allocated by the caller, but the
written size of the buffer is in the return value.

Using GBytes, we get a better API at the cost of an additional
allocation.
This commit is contained in:
Emmanuele Bassi
2023-10-02 18:22:02 +01:00
committed by Philip Withnall
parent 7688965491
commit 7cb953dab8
2 changed files with 155 additions and 0 deletions

View File

@@ -210,6 +210,12 @@ gssize g_socket_receive (GSocket
gsize size,
GCancellable *cancellable,
GError **error);
GIO_AVAILABLE_IN_2_80
GBytes * g_socket_receive_bytes (GSocket *socket,
gsize size,
gint64 timeout_us,
GCancellable *cancellable,
GError **error);
GIO_AVAILABLE_IN_ALL
gssize g_socket_receive_from (GSocket *socket,
GSocketAddress **address,
@@ -217,6 +223,13 @@ gssize g_socket_receive_from (GSocket
gsize size,
GCancellable *cancellable,
GError **error);
GIO_AVAILABLE_IN_2_80
GBytes * g_socket_receive_bytes_from (GSocket *socket,
GSocketAddress **address,
gsize size,
gint64 timeout_us,
GCancellable *cancellable,
GError **error);
GIO_AVAILABLE_IN_ALL
gssize g_socket_send (GSocket *socket,
const gchar *buffer,