Interface

Gio-2.0GioDtlsConnectionInterface

Interface for implementing DtlsConnection. Contains only the virtual methods that need to be implemented.

interface Interface {
    vfunc_accept_certificate(
        peer_cert: Gio.TlsCertificate,
        errors: Gio.TlsCertificateFlags,
    ): boolean;
    vfunc_condition_check(condition: GLib.IOCondition): GLib.IOCondition;
    vfunc_condition_wait(
        condition: GLib.IOCondition,
        timeout: number,
        cancellable?: Gio.Cancellable,
    ): boolean;
    vfunc_create_source(
        condition: GLib.IOCondition,
        cancellable?: Gio.Cancellable,
    ): GLib.Source;
    vfunc_get_binding_data(
        type: Gio.TlsChannelBindingType,
        data: string | Uint8Array<ArrayBufferLike>,
    ): boolean;
    vfunc_get_negotiated_protocol(): string;
    vfunc_handshake(cancellable?: Gio.Cancellable): boolean;
    vfunc_handshake_async(
        io_priority: number,
        cancellable?: Gio.Cancellable,
        callback?: AsyncReadyCallback<Gio.DtlsConnection.Interface>,
    ): void;
    vfunc_handshake_finish(result: Gio.AsyncResult): boolean;
    vfunc_receive_messages(
        messages: InputMessage[],
        flags: number,
        timeout: number,
        cancellable?: Gio.Cancellable,
    ): number;
    vfunc_send_messages(
        messages: OutputMessage[],
        flags: number,
        timeout: number,
        cancellable?: Gio.Cancellable,
    ): number;
    vfunc_set_advertised_protocols(protocols?: string[]): void;
    vfunc_shutdown(
        shutdown_read: boolean,
        shutdown_write: boolean,
        cancellable?: Gio.Cancellable,
    ): boolean;
    vfunc_shutdown_async(
        shutdown_read: boolean,
        shutdown_write: boolean,
        io_priority: number,
        cancellable?: Gio.Cancellable,
        callback?: AsyncReadyCallback<Gio.DtlsConnection.Interface>,
    ): void;
    vfunc_shutdown_finish(result: Gio.AsyncResult): boolean;
}

Hierarchy (View Summary)

Index

Methods

  • Gets the name of the application-layer protocol negotiated during the handshake.

    If the peer did not use the ALPN extension, or did not advertise a protocol that matched one of conn's protocols, or the TLS backend does not support ALPN, then this will be null. See g_dtls_connection_set_advertised_protocols().

    Returns string

  • Attempts a TLS handshake on conn.

    On the client side, it is never necessary to call this method; although the connection needs to perform a handshake after connecting, Gio.DtlsConnection will handle this for you automatically when you try to send or receive data on the connection. You can call g_dtls_connection_handshake() manually if you want to know whether the initial handshake succeeded or failed (as opposed to just immediately trying to use conn to read or write, in which case, if it fails, it may not be possible to tell if it failed before or after completing the handshake), but beware that servers may reject client authentication after the handshake has completed, so a successful handshake does not indicate the connection will be usable.

    Likewise, on the server side, although a handshake is necessary at the beginning of the communication, you do not need to call this function explicitly unless you want clearer error reporting.

    Previously, calling g_dtls_connection_handshake() after the initial handshake would trigger a rehandshake; however, this usage was deprecated in GLib 2.60 because rehandshaking was removed from the TLS protocol in TLS 1.3. Since GLib 2.64, calling this function after the initial handshake will no longer do anything.

    Gio.DtlsConnection.SignalSignatures.accept_certificate | Gio.DtlsConnection::accept_certificate may be emitted during the handshake.

    Parameters

    Returns boolean

  • Sets the list of application-layer protocols to advertise that the caller is willing to speak on this connection. The Application-Layer Protocol Negotiation (ALPN) extension will be used to negotiate a compatible protocol with the peer; use g_dtls_connection_get_negotiated_protocol() to find the negotiated protocol after the handshake. Specifying null for the the value of protocols will disable ALPN negotiation.

    See IANA TLS ALPN Protocol IDs for a list of registered protocol IDs.

    Parameters

    • Optionalprotocols: string[]

      a null-terminated array of ALPN protocol names (eg, "http/1.1", "h2"), or null

    Returns void

  • Shut down part or all of a DTLS connection.

    If shutdown_read is true then the receiving side of the connection is shut down, and further reading is disallowed. Subsequent calls to g_datagram_based_receive_messages() will return Gio.IOErrorEnum.CLOSED.

    If shutdown_write is true then the sending side of the connection is shut down, and further writing is disallowed. Subsequent calls to g_datagram_based_send_messages() will return Gio.IOErrorEnum.CLOSED.

    It is allowed for both shutdown_read and shutdown_write to be TRUE — this is equivalent to calling g_dtls_connection_close().

    If cancellable is cancelled, the Gio.DtlsConnection may be left partially-closed and any pending untransmitted data may be lost. Call g_dtls_connection_shutdown() again to complete closing the Gio.DtlsConnection.

    Parameters

    • shutdown_read: boolean

      true to stop reception of incoming datagrams

    • shutdown_write: boolean

      true to stop sending outgoing datagrams

    • Optionalcancellable: Gio.Cancellable

      a Gio.Cancellable, or null

    Returns boolean

Methods - Inherited from Gio.DatagramBased.Interface

  • 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.

    GObject.IOCondition.IN will be set in the return value if data is available to read with g_datagram_based_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 g_socket_close() or g_socket_shutdown() with shutdown_read set, if it’s a Gio.Socket).

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

    GObject.IOCondition.OUT will be set if it is expected that at least one byte can be sent using g_datagram_based_send_messages() without blocking. It will not be set if the datagram_based has been closed locally.

    GObject.IOCondition.HUP will be set if the connection has been closed locally.

    GObject.IOCondition.ERR will be set if there was an asynchronous error in transmitting data previously enqueued using g_datagram_based_send_messages().

    Note that on Windows, it is possible for an operation to return Gio.IOErrorEnum.WOULD_BLOCK even immediately after g_datagram_based_condition_check() has claimed that the Gio.DatagramBased is ready for writing. Rather than calling g_datagram_based_condition_check() and then writing to the Gio.DatagramBased if 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 GObject.IOCondition.ERR or GObject.IOCondition.HUP in 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.

    Parameters

    Returns GLib.IOCondition

  • Receive one or more data messages from datagram_based in one go.

    messages must point to an array of Gio.InputMessage structs and num_messages must be the length of this array. Each Gio.InputMessage contains a pointer to an array of Gio.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 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. These flags affect the overall receive operation. Flags affecting individual messages are returned in Gio.InputMessage.flags.

    The other members of Gio.InputMessage are 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_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, Gio.IOErrorEnum.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 GObject.IOCondition.IN condition. Note though that you may still receive Gio.IOErrorEnum.WOULD_BLOCK from g_datagram_based_receive_messages() even if you were previously notified of a GObject.IOCondition.IN condition.

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

    If the connection is shut down or closed (by calling g_socket_close() or g_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.CANCELLED is returned as with any other error.

    Parameters

    Returns number

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

    messages must point to an array of Gio.OutputMessage structs and num_messages must be the length of this array. Each Gio.OutputMessage contains an address to send the data to, and a pointer to an array of Gio.OutputVector 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 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.

    The other members of Gio.OutputMessage 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 Gio.IOErrorEnum.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, Gio.IOErrorEnum.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 GObject.IOCondition.OUT condition. Note though that you may still receive Gio.IOErrorEnum.WOULD_BLOCK from g_datagram_based_send_messages() even if you were previously notified of a GObject.IOCondition.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 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.CANCELLED is returned as with any other error.

    Parameters

    Returns number