Gio.DatagramBased¶
| Implementations: | |
|---|---|
| Gio.Socket | |
Methods¶
| condition_check(condition) | |
| condition_wait(condition, timeout, cancellable) | |
| create_source(condition, cancellable) | |
| receive_messages(messages, flags, timeout, cancellable) | |
| send_messages(messages, flags, timeout, cancellable) | 
Virtual Methods¶
| do_condition_check(condition) | |
| do_condition_wait(condition, timeout, cancellable) | |
| do_create_source(condition, cancellable) | |
| do_receive_messages(messages, flags, timeout, cancellable) | |
| do_send_messages(messages, flags, timeout, cancellable) | 
Properties¶
None
Signals¶
None
Fields¶
None
Class Details¶
- 
class Gio.DatagramBased¶
- Bases: - GObject.GInterface- Structure: - Gio.DatagramBasedInterface- A - Gio.DatagramBasedis a networking interface for representing datagram-based communications. It is a more or less direct mapping of the core parts of the BSD socket API in a portable- GObject.Objectinterface. It is implemented by- Gio.Socket, which wraps the UNIX socket API on UNIX and winsock2 on Windows.- Gio.DatagramBasedis entirely platform independent, and is intended to be used alongside higher-level networking APIs such as- Gio.IOStream.- It uses vectored scatter/gather I/O by default, allowing for many messages to be sent or received in a single call. Where possible, implementations of the interface should take advantage of vectored I/O to minimise processing or system calls. For example, - Gio.Socketuses recvmmsg() and sendmmsg() where possible. Callers should take advantage of scatter/gather I/O (the use of multiple buffers per message) to avoid unnecessary copying of data to assemble or disassemble a message.- Each - Gio.DatagramBasedoperation has a timeout parameter which may be negative for blocking behaviour, zero for non-blocking behaviour, or positive for timeout behaviour. A blocking operation blocks until finished or there is an error. A non-blocking operation will return immediately with a- Gio.IOErrorEnum.WOULD_BLOCKerror if it cannot make progress. A timeout operation will block until the operation is complete or the timeout expires; if the timeout expires it will return what progress it made, or- Gio.IOErrorEnum.TIMED_OUTif no progress was made. To know when a call would successfully run you can call- Gio.DatagramBased.condition_check() or- Gio.DatagramBased.condition_wait(). You can also use- Gio.DatagramBased.create_source() and attach it to a- GLib.MainContextto get callbacks when I/O is possible.- When running a non-blocking operation applications should always be able to handle getting a - Gio.IOErrorEnum.WOULD_BLOCKerror even when some other function said that I/O was possible. This can easily happen in case of a race condition in the application, but it can also happen for other reasons. For instance, on Windows a socket is always seen as writable until a write returns- Gio.IOErrorEnum.WOULD_BLOCK.- As with - Gio.Socket,- Gio.DatagramBasedscan be either connection oriented (for example, SCTP) or connectionless (for example, UDP).- Gio.DatagramBasedsmust be datagram-based, not stream-based. The interface does not cover connection establishment — use methods on the underlying type to establish a connection before sending and receiving data through the- Gio.DatagramBasedAPI. For connectionless socket types the target/source address is specified or received in each I/O operation.- Like most other APIs in GLib, - Gio.DatagramBasedis not inherently thread safe. To use a- Gio.DatagramBasedconcurrently from multiple threads, you must implement your own locking.- New in version 2.48. - 
condition_check(condition)[source]¶
- Parameters: - condition ( - GLib.IOCondition) – a- GLib.IOConditionmask to check- Returns: - the - GLib.IOConditionmask of the current state- Return type: - GLib.IOCondition- Checks on the readiness of self to perform operations. The operations specified in condition are checked for and masked against the currently-satisfied conditions on self. The result is returned. - GLib.IOCondition.INwill be set in the return value if data is available to read with- Gio.DatagramBased.receive_messages(), or if the connection is closed remotely (EOS); and if the datagram_based has not been closed locally using some implementation-specific method (such as- Gio.Socket.close() or- Gio.Socket.shutdown() with shutdown_read set, if it’s a- Gio.Socket).- If the connection is shut down or closed (by calling - Gio.Socket.close() or- Gio.Socket.shutdown() with shutdown_read set, if it’s a- Gio.Socket, for example), all calls to this function will return- Gio.IOErrorEnum.CLOSED.- GLib.IOCondition.OUTwill be set if it is expected that at least one byte can be sent using- Gio.DatagramBased.send_messages() without blocking. It will not be set if the datagram_based has been closed locally.- GLib.IOCondition.HUPwill be set if the connection has been closed locally.- GLib.IOCondition.ERRwill be set if there was an asynchronous error in transmitting data previously enqueued using- Gio.DatagramBased.send_messages().- Note that on Windows, it is possible for an operation to return - Gio.IOErrorEnum.WOULD_BLOCKeven immediately after- Gio.DatagramBased.condition_check() has claimed that the- Gio.DatagramBasedis ready for writing. Rather than calling- Gio.DatagramBased.condition_check() and then writing to the- Gio.DatagramBasedif it succeeds, it is generally better to simply try writing right away, and try again later if the initial attempt returns- Gio.IOErrorEnum.WOULD_BLOCK.- It is meaningless to specify - GLib.IOCondition.ERRor- GLib.IOCondition.HUPin condition; these conditions will always be set in the output if they are true. Apart from these flags, the output is guaranteed to be masked by condition.- This call never blocks. - New in version 2.48. 
 - 
condition_wait(condition, timeout, cancellable)[source]¶
- Parameters: - condition (GLib.IOCondition) – aGLib.IOConditionmask to wait for
- timeout (int) – the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
- cancellable (Gio.CancellableorNone) – aGio.Cancellable
 - Raises: - Returns: - Return type: - Waits for up to timeout microseconds for condition to become true on self. If the condition is met, - Trueis returned.- If cancellable is cancelled before the condition is met, or if timeout is reached before the condition is met, then - Falseis returned and error is set appropriately (- Gio.IOErrorEnum.CANCELLEDor- Gio.IOErrorEnum.TIMED_OUT).- New in version 2.48. 
- condition (
 - 
create_source(condition, cancellable)[source]¶
- Parameters: - condition (GLib.IOCondition) – aGLib.IOConditionmask to monitor
- cancellable (Gio.CancellableorNone) – aGio.Cancellable
 - Returns: - a newly allocated - GLib.Source- Return type: - Creates a - GLib.Sourcethat can be attached to a- GLib.MainContextto monitor for the availability of the specified condition on the- Gio.DatagramBased. The- GLib.Sourcekeeps a reference to the self.- The callback on the source is of the - Gio.DatagramBasedSourceFunctype.- It is meaningless to specify - GLib.IOCondition.ERRor- GLib.IOCondition.HUPin condition; these conditions will always be reported in the callback if they are true.- If non- - None, cancellable can be used to cancel the source, which will cause the source to trigger, reporting the current condition (which is likely 0 unless cancellation happened at the same time as a condition change). You can check for this in the callback using- Gio.Cancellable.is_cancelled().- New in version 2.48. 
- condition (
 - 
receive_messages(messages, flags, timeout, cancellable)[source]¶
- Parameters: - messages ([Gio.InputMessage]) – an array ofGio.InputMessagestructs
- flags (int) – an int containingGio.SocketMsgFlagsflags for the overall operation
- timeout (int) – the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
- cancellable (Gio.CancellableorNone) – aGio.Cancellable
 - Raises: - Returns: - number of messages received, or -1 on error. Note that the number of messages received may be smaller than num_messages if timeout is zero or positive, if the peer closed the connection, or if num_messages was larger than - UIO_MAXIOV(1024), in which case the caller may re-try to receive the remaining messages.- Return type: - Receive one or more data messages from self in one go. - messages must point to an array of - Gio.InputMessagestructs and num_messages must be the length of this array. Each- Gio.InputMessagecontains a pointer to an array of- Gio.InputVectorstructs 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 - Gio.SocketMsgFlagsenum, 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 Gio.InputMessage.flags.- The other members of - Gio.InputMessageare treated as described in its documentation.- If timeout is negative the call will block until num_messages 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 num_messages without blocking, or - Gio.IOErrorEnum.WOULD_BLOCKif 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, - Gio.IOErrorEnum.TIMED_OUTis returned, otherwise it will return the number of messages received before timing out. (Note: This is effectively the behaviour of- MSG_WAITFORONEwith recvmmsg().)- To be notified when messages are available, wait for the - GLib.IOCondition.INcondition. Note though that you may still receive- Gio.IOErrorEnum.WOULD_BLOCKfrom- Gio.DatagramBased.receive_messages() even if you were previously notified of a- GLib.IOCondition.INcondition.- If the remote peer closes the connection, any messages queued in the underlying receive buffer will be returned, and subsequent calls to - Gio.DatagramBased.receive_messages() will return 0 (with no error set).- If the connection is shut down or closed (by calling - Gio.Socket.close() or- Gio.Socket.shutdown() with shutdown_read set, if it’s a- Gio.Socket, for example), all calls to this function will return- Gio.IOErrorEnum.CLOSED.- On error -1 is returned and error 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, - Gio.IOErrorEnum.CANCELLEDis returned as with any other error.- New in version 2.48. 
- messages ([
 - 
send_messages(messages, flags, timeout, cancellable)[source]¶
- Parameters: - messages ([Gio.OutputMessage]) – an array ofGio.OutputMessagestructs
- flags (int) – an int containingGio.SocketMsgFlagsflags
- timeout (int) – the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
- cancellable (Gio.CancellableorNone) – aGio.Cancellable
 - Raises: - Returns: - 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.- Return type: - Send one or more data messages from self in one go. - messages must point to an array of - Gio.OutputMessagestructs and num_messages must be the length of this array. Each- Gio.OutputMessagecontains an address to send the data to, and a pointer to an array of- Gio.OutputVectorstructs 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 - Gio.SocketMsgFlagsenum, 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 - Gio.OutputMessageare 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 - Gio.IOErrorEnum.WOULD_BLOCKif 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, - Gio.IOErrorEnum.TIMED_OUTis returned, otherwise it will return the number of messages sent before timing out.- To be notified when messages can be sent, wait for the - GLib.IOCondition.OUTcondition. Note though that you may still receive- Gio.IOErrorEnum.WOULD_BLOCKfrom- Gio.DatagramBased.send_messages() even if you were previously notified of a- GLib.IOCondition.OUTcondition. (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 - Gio.Socket.close() or- Gio.Socket.shutdown() with shutdown_write set, if it’s a- Gio.Socket, for example), all calls to this function will return- Gio.IOErrorEnum.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, - Gio.IOErrorEnum.CANCELLEDis returned as with any other error.- New in version 2.48. 
- messages ([
 - 
do_condition_check(condition) virtual¶
- Parameters: - condition ( - GLib.IOCondition) – a- GLib.IOConditionmask to check- Returns: - the - GLib.IOConditionmask of the current state- Return type: - GLib.IOCondition- Checks on the readiness of datagram_based to perform operations. The operations specified in condition are checked for and masked against the currently-satisfied conditions on datagram_based. The result is returned. - GLib.IOCondition.INwill be set in the return value if data is available to read with- Gio.DatagramBased.receive_messages(), or if the connection is closed remotely (EOS); and if the datagram_based has not been closed locally using some implementation-specific method (such as- Gio.Socket.close() or- Gio.Socket.shutdown() with shutdown_read set, if it’s a- Gio.Socket).- If the connection is shut down or closed (by calling - Gio.Socket.close() or- Gio.Socket.shutdown() with shutdown_read set, if it’s a- Gio.Socket, for example), all calls to this function will return- Gio.IOErrorEnum.CLOSED.- GLib.IOCondition.OUTwill be set if it is expected that at least one byte can be sent using- Gio.DatagramBased.send_messages() without blocking. It will not be set if the datagram_based has been closed locally.- GLib.IOCondition.HUPwill be set if the connection has been closed locally.- GLib.IOCondition.ERRwill be set if there was an asynchronous error in transmitting data previously enqueued using- Gio.DatagramBased.send_messages().- Note that on Windows, it is possible for an operation to return - Gio.IOErrorEnum.WOULD_BLOCKeven immediately after- Gio.DatagramBased.condition_check() has claimed that the- Gio.DatagramBasedis ready for writing. Rather than calling- Gio.DatagramBased.condition_check() and then writing to the- Gio.DatagramBasedif it succeeds, it is generally better to simply try writing right away, and try again later if the initial attempt returns- Gio.IOErrorEnum.WOULD_BLOCK.- It is meaningless to specify - GLib.IOCondition.ERRor- GLib.IOCondition.HUPin condition; these conditions will always be set in the output if they are true. Apart from these flags, the output is guaranteed to be masked by condition.- This call never blocks. - New in version 2.48. 
 - 
do_condition_wait(condition, timeout, cancellable) virtual¶
- Parameters: - condition (GLib.IOCondition) – aGLib.IOConditionmask to wait for
- timeout (int) – the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
- cancellable (Gio.CancellableorNone) – aGio.Cancellable
 - Returns: - Return type: - Waits for up to timeout microseconds for condition to become true on datagram_based. If the condition is met, - Trueis returned.- If cancellable is cancelled before the condition is met, or if timeout is reached before the condition is met, then - Falseis returned and error is set appropriately (- Gio.IOErrorEnum.CANCELLEDor- Gio.IOErrorEnum.TIMED_OUT).- New in version 2.48. 
- condition (
 - 
do_create_source(condition, cancellable) virtual¶
- Parameters: - condition (GLib.IOCondition) – aGLib.IOConditionmask to monitor
- cancellable (Gio.CancellableorNone) – aGio.Cancellable
 - Returns: - a newly allocated - GLib.Source- Return type: - Creates a - GLib.Sourcethat can be attached to a- GLib.MainContextto monitor for the availability of the specified condition on the- Gio.DatagramBased. The- GLib.Sourcekeeps a reference to the datagram_based.- The callback on the source is of the - Gio.DatagramBasedSourceFunctype.- It is meaningless to specify - GLib.IOCondition.ERRor- GLib.IOCondition.HUPin condition; these conditions will always be reported in the callback if they are true.- If non- - None, cancellable can be used to cancel the source, which will cause the source to trigger, reporting the current condition (which is likely 0 unless cancellation happened at the same time as a condition change). You can check for this in the callback using- Gio.Cancellable.is_cancelled().- New in version 2.48. 
- condition (
 - 
do_receive_messages(messages, flags, timeout, cancellable) virtual¶
- Parameters: - messages ([Gio.InputMessage]) – an array ofGio.InputMessagestructs
- flags (int) – an int containingGio.SocketMsgFlagsflags for the overall operation
- timeout (int) – the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
- cancellable (Gio.CancellableorNone) – aGio.Cancellable
 - Returns: - number of messages received, or -1 on error. Note that the number of messages received may be smaller than num_messages if timeout is zero or positive, if the peer closed the connection, or if num_messages was larger than - UIO_MAXIOV(1024), in which case the caller may re-try to receive the remaining messages.- Return type: - Receive one or more data messages from datagram_based in one go. - messages must point to an array of - Gio.InputMessagestructs and num_messages must be the length of this array. Each- Gio.InputMessagecontains a pointer to an array of- Gio.InputVectorstructs 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 - Gio.SocketMsgFlagsenum, 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 Gio.InputMessage.flags.- The other members of - Gio.InputMessageare treated as described in its documentation.- If timeout is negative the call will block until num_messages 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 num_messages without blocking, or - Gio.IOErrorEnum.WOULD_BLOCKif 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, - Gio.IOErrorEnum.TIMED_OUTis returned, otherwise it will return the number of messages received before timing out. (Note: This is effectively the behaviour of- MSG_WAITFORONEwith recvmmsg().)- To be notified when messages are available, wait for the - GLib.IOCondition.INcondition. Note though that you may still receive- Gio.IOErrorEnum.WOULD_BLOCKfrom- Gio.DatagramBased.receive_messages() even if you were previously notified of a- GLib.IOCondition.INcondition.- If the remote peer closes the connection, any messages queued in the underlying receive buffer will be returned, and subsequent calls to - Gio.DatagramBased.receive_messages() will return 0 (with no error set).- If the connection is shut down or closed (by calling - Gio.Socket.close() or- Gio.Socket.shutdown() with shutdown_read set, if it’s a- Gio.Socket, for example), all calls to this function will return- Gio.IOErrorEnum.CLOSED.- On error -1 is returned and error 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, - Gio.IOErrorEnum.CANCELLEDis returned as with any other error.- New in version 2.48. 
- messages ([
 - 
do_send_messages(messages, flags, timeout, cancellable) virtual¶
- Parameters: - messages ([Gio.OutputMessage]) – an array ofGio.OutputMessagestructs
- flags (int) – an int containingGio.SocketMsgFlagsflags
- timeout (int) – the maximum time (in microseconds) to wait, 0 to not block, or -1 to block indefinitely
- cancellable (Gio.CancellableorNone) – aGio.Cancellable
 - Returns: - 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.- Return type: - Send one or more data messages from datagram_based in one go. - messages must point to an array of - Gio.OutputMessagestructs and num_messages must be the length of this array. Each- Gio.OutputMessagecontains an address to send the data to, and a pointer to an array of- Gio.OutputVectorstructs 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 - Gio.SocketMsgFlagsenum, 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 - Gio.OutputMessageare 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 - Gio.IOErrorEnum.WOULD_BLOCKif 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, - Gio.IOErrorEnum.TIMED_OUTis returned, otherwise it will return the number of messages sent before timing out.- To be notified when messages can be sent, wait for the - GLib.IOCondition.OUTcondition. Note though that you may still receive- Gio.IOErrorEnum.WOULD_BLOCKfrom- Gio.DatagramBased.send_messages() even if you were previously notified of a- GLib.IOCondition.OUTcondition. (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 - Gio.Socket.close() or- Gio.Socket.shutdown() with shutdown_write set, if it’s a- Gio.Socket, for example), all calls to this function will return- Gio.IOErrorEnum.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, - Gio.IOErrorEnum.CANCELLEDis returned as with any other error.- New in version 2.48. 
- messages ([
 
-