Virtual Method

GioDatagramBasedsend_messages

since: 2.48

Declaration [src]

gint
send_messages (
  GDatagramBased* datagram_based,
  GOutputMessage* messages,
  guint num_messages,
  gint flags,
  gint64 timeout,
  GCancellable* cancellable,
  GError** error
)

Description [src]

Send one or more data messages from datagram_based in one go.

messages must point to an array of GOutputMessage structs and num_messages must be the length of this array. Each GOutputMessage contains an address to send the data to, and a pointer to an array of GOutputVector structs to describe the buffers that the data to be sent for each message will be gathered from.

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.

The other members of GOutputMessage are treated as described in its documentation.

If timeout is negative the call will block until num_messages have been sent, cancellable is cancelled, or an error occurs.

If timeout is 0 the call will send up to num_messages without blocking, or will return G_IO_ERROR_WOULD_BLOCK if there is no space to send messages.

If timeout is positive the call will block on the same conditions as if timeout were negative. If the timeout is reached before any messages are sent, G_IO_ERROR_TIMED_OUT is returned, otherwise it will return the number of messages sent before timing out.

To be notified when messages can be sent, wait for the G_IO_OUT condition. Note though that you may still receive G_IO_ERROR_WOULD_BLOCK from g_datagram_based_send_messages() 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.)

If the connection is shut down or closed (by calling g_socket_close() or g_socket_shutdown() with shutdown_write set, if it’s a GSocket, for example), all calls to this function will return G_IO_ERROR_CLOSED.

On error -1 is returned and error is set accordingly. An error will only be returned if zero messages could be sent; otherwise the number of messages successfully sent before the error will be returned. If cancellable is cancelled, G_IO_ERROR_CANCELLED is returned as with any other error.

Available since: 2.48

Parameters

messages

Type: An array of GOutputMessage

An array of GOutputMessage structs.

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: guint

The number of elements in messages.

flags

Type: gint

An int containing GSocketMsgFlags flags.

timeout

Type: gint64

The maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely.

cancellable

Type: GCancellable

A %GCancellable.

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 virtual function 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: gint

Number of messages sent, or -1 on error. Note that the number of messages sent may be smaller than num_messages if timeout is zero or positive, or if num_messages was larger than UIO_MAXIOV (1024), in which case the caller may re-try to send the remaining messages.