### Method

# Gio Socket send_message

since: 2.22

#### Declaration [src]

    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
    )

#### Description [src]

Send data to `address` on `socket`. For sending multiple messages see g_socket_send_messages(); for easier use, see `g_socket_send()` and g_socket_send_to().

If `address` is `NULL` then the message is sent to the default receiver (set by g_socket_connect()).

`vectors` must point to an array of `GOutputVector` structs and `num_vectors` must be the length of this array. (If `num_vectors` is -1, then `vectors` is assumed to be terminated by a `GOutputVector` with a `NULL` buffer pointer.) The `GOutputVector` structs describe the buffers that the sent data will be gathered from. Using multiple `GOutputVectors` is more memory-efficient than manually copying data from multiple sources into a single buffer, and more network-efficient than making multiple calls to g_socket_send().

`messages`, if non-`NULL`, is taken to point to an array of `num_messages` `GSocketControlMessage` instances. These correspond to the control messages to be sent on the socket. If `num_messages` is -1 then `messages` is treated as a `NULL`-terminated array.

`flags` modify how the message is sent. The commonly available arguments for this are available in the `GSocketMsgFlags` enum, but the values there are the same as the system values, and the flags are passed in as-is, so you can pass in system-specific flags too.

If the socket is in blocking mode the call will block until there is space for the data in the socket queue. If there is no space available and the socket is in non-blocking mode a `G_IO_ERROR_WOULD_BLOCK` error will be returned. To be notified when space is available, wait for the `G_IO_OUT` condition. Note though that you may still receive `G_IO_ERROR_WOULD_BLOCK` from `g_socket_send()` even if you were previously notified of a `G_IO_OUT` condition. (On Windows in particular, this is very common due to the way the underlying APIs work.)

The sum of the sizes of each `GOutputVector` in vectors must not be greater than `G_MAXSSIZE`. If the message can be larger than this, then it is mandatory to use the `g_socket_send_message_with_timeout()` function.

On error -1 is returned and `error` is set accordingly.

Available since: 2.22

#### Parameters

`address`

  Type: `GSocketAddress`

  A `GSocketAddress`, or `NULL`.

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

`vectors`

  Type: An array of `GOutputVector`

  An array of `GOutputVector` structs.

  The length of the array is specified in the `num_vectors` argument.
  The data is owned by the caller of the method.

`num_vectors`

  Type: `gint`

  The number of elements in `vectors`, or -1.

`messages`

  Type: An array of `GSocketControlMessage*`

  A pointer to an array of `GSocketControlMessages`, or `NULL`.

  The argument can be `NULL`.
  The length of the array is specified in the `num_messages` argument.
  The data is owned by the caller of the method.

`num_messages`

  Type: `gint`

  Number of elements in `messages`, or -1.

`flags`

  Type: `gint`

  An int containing `GSocketMsgFlags` flags, which may additionally contain other platform specific flags.

`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: `gssize`

Number of bytes written (which may be less than `size`), or -1 on error.