Socket.sendMessage

Send data to address on socket. For sending multiple messages see gio.socket.Socket.sendMessages; for easier use, see gio.socket.Socket.send and gio.socket.Socket.sendTo.

If address is null then the message is sent to the default receiver (set by gio.socket.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 gio.socket.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 gio.types.IOErrorEnum.WouldBlock error will be returned. To be notified when space is available, wait for the glib.types.IOCondition.Out condition. Note though that you may still receive gio.types.IOErrorEnum.WouldBlock from gio.socket.Socket.send even if you were previously notified of a glib.types.IOCondition.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 gio.socket.Socket.sendMessageWithTimeout function.

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

Parameters

address gio.socket_address.SocketAddress

a #GSocketAddress, or null

vectors gio.types.OutputVector[]

an array of #GOutputVector structs

messages gio.socket_control_message.SocketControlMessage[]

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

flags int

an int containing #GSocketMsgFlags flags, which may additionally contain other platform specific flags

cancellable gio.cancellable.Cancellable

Return Value

Type: ptrdiff_t

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