Gio.Socket.receive_bytes

### Method

# Gio Socketreceive_bytes

since: 2.80

#### Declaration [src]

    GBytes*
    g_socket_receive_bytes (
      GSocket* socket,
      gsize size,
      gint64 timeout_us,
      GCancellable* cancellable,
      GError** error
    )

#### Description [src]

Receives data (up to `size` bytes) from a socket.

This function is a variant of `g_socket_receive()` which returns a `GBytes` rather than a plain buffer.

Pass `-1` to `timeout_us` to block indefinitely until data is received (or the connection is closed, or there is an error). Pass `0` to use the default timeout from `GSocket:timeout`, or pass a positive number to wait for that many microseconds for data before returning `G_IO_ERROR_TIMED_OUT`.

Available since: 2.80

#### Parameters

`size`

  Type: `gsize`

  The number of bytes you want to read from the socket.

`timeout_us`

  Type: `gint64`

  The timeout to wait for, in microseconds, or `-1` to block indefinitely.

`cancellable`

  Type: `GCancellable`

  A %GCancellable, or `NULL`.

  The argument can be `NULL`.
  The data is owned by the caller of the method.

`error`

  Type: `GError **`

  The return location for a recoverable error.

  The argument can be `NULL`.
  If the return location is not `NULL`, then you must initialize it to a `NULL` `GError*`.
  The argument will be left initialized to `NULL` by the method if there are no errors.
  In case of error, the argument will be set to a newly allocated `GError`; the caller will take ownership of the data, and be responsible for freeing it.

#### Return value

Type: `GBytes`

A bytes buffer containing the received bytes, or `NULL` on error.

The caller of the method takes ownership of the returned data, and is responsible for freeing it.