Class SocketClient.Builder<B extends SocketClient.Builder<B>>

Type Parameters:
B - the type of the Builder that is returned
All Implemented Interfaces:
BuilderInterface
Enclosing class:
SocketClient

public static class SocketClient.Builder<B extends SocketClient.Builder<B>> extends GObject.Builder<B>
Inner class implementing a builder pattern to construct a GObject with properties.
Since:
2.22
  • Constructor Details

    • Builder

      protected Builder()
      Default constructor for a Builder object.
  • Method Details

    • build

      public SocketClient build()
      Finish building the SocketClient object. This will call GObject.withProperties(Type, String[], Value[]) to create a new GObject instance, which is then cast to SocketClient.
      Overrides:
      build in class GObject.Builder<B extends SocketClient.Builder<B>>
      Returns:
      a new instance of SocketClient with the properties that were set in the Builder object.
    • setEnableProxy

      public B setEnableProxy(boolean enableProxy)
      Enable proxy support.
      Parameters:
      enableProxy - the value for the enable-proxy property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.22
    • setFamily

      public B setFamily(SocketFamily family)
      The address family to use for socket construction.
      Parameters:
      family - the value for the family property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.22
    • setLocalAddress

      public B setLocalAddress(SocketAddress localAddress)
      The local address constructed sockets will be bound to.
      Parameters:
      localAddress - the value for the local-address property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.22
    • setProtocol

      public B setProtocol(SocketProtocol protocol)
      The protocol to use for socket construction, or 0 for default.
      Parameters:
      protocol - the value for the protocol property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.22
    • setProxyResolver

      public B setProxyResolver(ProxyResolver proxyResolver)
      The proxy resolver to use
      Parameters:
      proxyResolver - the value for the proxy-resolver property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.36
    • setTimeout

      public B setTimeout(int timeout)
      The I/O timeout for sockets, in seconds, or 0 for none.
      Parameters:
      timeout - the value for the timeout property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.22
    • setTls

      public B setTls(boolean tls)
      Whether to create TLS connections.
      Parameters:
      tls - the value for the tls property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.22
    • setTlsValidationFlags

      @Deprecated public B setTlsValidationFlags(Set<TlsCertificateFlags> tlsValidationFlags)
      Deprecated.
      Do not attempt to ignore validation errors.

      The TLS validation flags used when creating TLS connections. The default value is TlsCertificateFlags.VALIDATE_ALL.

      GLib guarantees that if certificate verification fails, at least one flag will be set, but it does not guarantee that all possible flags will be set. Accordingly, you may not safely decide to ignore any particular type of error. For example, it would be incorrect to mask TlsCertificateFlags.EXPIRED if you want to allow expired certificates, because this could potentially be the only error flag set even if other problems exist with the certificate. Therefore, there is no safe way to use this property. This is not a horrible problem, though, because you should not be attempting to ignore validation errors anyway. If you really must ignore TLS certificate errors, connect to the GSocketClient::event signal, wait for it to be emitted with SocketClientEvent.TLS_HANDSHAKING, and use that to connect to GTlsConnection::accept-certificate.

      Parameters:
      tlsValidationFlags - the value for the tls-validation-flags property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setType

      public B setType(SocketType type)
      The type to use for socket construction.
      Parameters:
      type - the value for the type property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.22
    • setTlsValidationFlags

      @Deprecated public B setTlsValidationFlags(TlsCertificateFlags... tlsValidationFlags)
      Deprecated.
      Do not attempt to ignore validation errors.

      The TLS validation flags used when creating TLS connections. The default value is TlsCertificateFlags.VALIDATE_ALL.

      GLib guarantees that if certificate verification fails, at least one flag will be set, but it does not guarantee that all possible flags will be set. Accordingly, you may not safely decide to ignore any particular type of error. For example, it would be incorrect to mask TlsCertificateFlags.EXPIRED if you want to allow expired certificates, because this could potentially be the only error flag set even if other problems exist with the certificate. Therefore, there is no safe way to use this property. This is not a horrible problem, though, because you should not be attempting to ignore validation errors anyway. If you really must ignore TLS certificate errors, connect to the GSocketClient::event signal, wait for it to be emitted with SocketClientEvent.TLS_HANDSHAKING, and use that to connect to GTlsConnection::accept-certificate.

      Parameters:
      tlsValidationFlags - the value for the tls-validation-flags property
      Returns:
      the Builder instance is returned, to allow method chaining
    • onEvent

      public B onEvent(SocketClient.EventCallback handler)

      Emitted when client's activity on connectable changes state. Among other things, this can be used to provide progress information about a network connection in the UI. The meanings of the different event values are as follows:

      • SocketClientEvent.RESOLVING: client is about to look up connectable in DNS. connection will be null.

      • SocketClientEvent.RESOLVED: client has successfully resolved connectable in DNS. connection will be null.

      • SocketClientEvent.CONNECTING: client is about to make a connection to a remote host; either a proxy server or the destination server itself. connection is the GSocketConnection, which is not yet connected. Since GLib 2.40, you can access the remote address via g_socket_connection_get_remote_address().

      • SocketClientEvent.CONNECTED: client has successfully connected to a remote host. connection is the connected GSocketConnection.

      • SocketClientEvent.PROXY_NEGOTIATING: client is about to negotiate with a proxy to get it to connect to connectable. connection is the GSocketConnection to the proxy server.

      • SocketClientEvent.PROXY_NEGOTIATED: client has negotiated a connection to connectable through a proxy server. connection is the stream returned from g_proxy_connect(), which may or may not be a GSocketConnection.

      • SocketClientEvent.TLS_HANDSHAKING: client is about to begin a TLS handshake. connection is a GTlsClientConnection.

      • SocketClientEvent.TLS_HANDSHAKED: client has successfully completed the TLS handshake. connection is a GTlsClientConnection.

      • SocketClientEvent.COMPLETE: client has either successfully connected to connectable (in which case connection is the GSocketConnection that it will be returning to the caller) or has failed (in which case connection is null and the client is about to return an error).

      Each event except SocketClientEvent.COMPLETE may be emitted multiple times (or not at all) for a given connectable (in particular, if client ends up attempting to connect to more than one address). However, if client emits the GSocketClient::event signal at all for a given connectable, then it will always emit it with SocketClientEvent.COMPLETE when it is done.

      Note that there may be additional GSocketClientEvent values in the future; unrecognized event values should be ignored.

      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      2.32
      See Also: