receive_messages


Description:

public int receive_messages (InputMessage[] messages, int flags, int64 timeout, Cancellable? cancellable = null) throws Error

Receive one or more data messages from this in one go.

messages must point to an array of InputMessage structs and messages.length must be the length of this array. Each InputMessage contains a pointer to an array of InputVector structs describing the buffers that the data received in each message will be written to.

flags modify how all messages are received. The commonly available arguments for this are available in the 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. These flags affect the overall receive operation. Flags affecting individual messages are returned in flags.

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

If timeout is negative the call will block until messages.length have been received, the connection is closed remotely (EOS), cancellable is cancelled, or an error occurs.

If timeout is 0 the call will return up to messages.length without blocking, or g_io_error_would_block if no messages are queued in the operating system to be received.

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 received, g_io_error_timed_out is returned, otherwise it will return the number of messages received before timing out. (Note: This is effectively the behaviour of `MSG_WAITFORONE` with recvmmsg.)

To be notified when messages are available, wait for the g_io_in condition. Note though that you may still receive g_io_error_would_block from receive_messages even if you were previously notified of a g_io_in condition.

If the remote peer closes the connection, any messages queued in the underlying receive buffer will be returned, and subsequent calls to receive_messages will return 0 (with no error set).

If the connection is shut down or closed (by calling close or shutdown with shutdown_read set, if it’s a Socket, for example), all calls to this function will return g_io_error_closed.

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

Parameters:

this

a DatagramBased

messages

an array of InputMessage structs

flags

an int containing SocketMsgFlags flags for the overall operation

timeout

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

cancellable

a gcancellable

num_messages

the number of elements in messages

Returns:

number of messages received, or -1 on error. Note that the number of messages received may be smaller than messages.length if timeout is zero or positive, if the peer closed the connection, or if messages.length was larger than `UIO_MAXIOV` (1024), in which case the caller may re-try to receive the remaining messages.