Gio.Socket.prototype.send_message

function send_message(address: Gio.SocketAddress, vectors: Array(Gio.OutputVector), messages: Array(Gio.SocketControlMessage), flags: Number(gint), cancellable: Gio.Cancellable): Number(gssize) {
    // Gjs wrapper for g_socket_send_message()
}
  

Send data to address on socket. This is the most complicated and fully-featured version of this call. For easier use, see Gio.Socket.prototype.send and Gio.Socket.prototype.send_to.

If address is null then the message is sent to the default receiver (set by Gio.Socket.prototype.connect).

vectors must point to an array of Gio.OutputVector 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 Gio.OutputVector with a null buffer pointer.) The Gio.OutputVector 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 Gio.Socket.prototype.send.

messages, if non-null, is taken to point to an array of num_messages Gio.SocketControlMessage 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 Gio.SocketMsgFlags 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 Gio.IOErrorEnum.would_block error will be returned. To be notified when space is available, wait for the GLib.IOCondition.out condition. Note though that you may still receive Gio.IOErrorEnum.would_block from Gio.Socket.prototype.send even if you were previously notified of a GLib.IOCondition.out condition. (On Windows in particular, this is very common due to the way the underlying APIs work.)

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

Since 2.22

address

a Gio.SocketAddress, or null

vectors

an array of Gio.OutputVector structs

messages

a pointer to an array of #GSocketControlMessages, or null.

flags

an int containing Gio.SocketMsgFlags flags

cancellable

a %GCancellable or null

Returns

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