Class UnixConnection

All Implemented Interfaces:
AutoCloseable, Proxy, AutoCloseable

@Generated("org.javagi.JavaGI") public class UnixConnection extends SocketConnection

This is the subclass of SocketConnection that is created for UNIX domain sockets.

It contains functions to do some of the UNIX socket specific functionality like passing file descriptors.

Since GLib 2.72, GUnixConnection is available on all platforms. It requires underlying system support (such as Windows 10 with AF_UNIX) at run time.

Before GLib 2.72, <gio/gunixconnection.h> belonged to the UNIX-specific GIO interfaces, thus you had to use the gio-unix-2.0.pc pkg-config file when using it. This is no longer necessary since GLib 2.72.

Since:
2.22
  • Constructor Details

    • UnixConnection

      public UnixConnection(MemorySegment address)
      Create a UnixConnection instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • UnixConnection

      public UnixConnection()
      Create a new UnixConnection.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the UnixConnection class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected UnixConnection asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class SocketConnection
      Returns:
      the instance as if it were its parent type
    • receiveCredentials

      public Credentials receiveCredentials(@Nullable Cancellable cancellable) throws GErrorException

      Receives credentials from the sending end of the connection. The sending end has to call g_unix_connection_send_credentials() (or similar) for this to work.

      As well as reading the credentials this also reads (and discards) a single byte from the stream, as this is required for credentials passing to work on some implementations.

      This method can be expected to be available on the following platforms:

      • Linux since GLib 2.26
      • FreeBSD since GLib 2.26
      • GNU/kFreeBSD since GLib 2.36
      • Solaris, Illumos and OpenSolaris since GLib 2.40
      • GNU/Hurd since GLib 2.40

      Other ways to exchange credentials with a foreign peer includes the GUnixCredentialsMessage type and g_socket_get_credentials() function.

      Parameters:
      cancellable - A GCancellable or null.
      Returns:
      Received credentials on success (free with g_object_unref()), null if error is set.
      Throws:
      GErrorException - see GError
      Since:
      2.26
    • receiveCredentialsAsync

      public void receiveCredentialsAsync(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously receive credentials.

      For more details, see g_unix_connection_receive_credentials() which is the synchronous version of this call.

      When the operation is finished, callback will be called. You can then call g_unix_connection_receive_credentials_finish() to get the result of the operation.

      Parameters:
      cancellable - optional GCancellable object, null to ignore.
      callback - a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.32
    • receiveCredentialsFinish

      public Credentials receiveCredentialsFinish(AsyncResult result) throws GErrorException
      Finishes an asynchronous receive credentials operation started with g_unix_connection_receive_credentials_async().
      Parameters:
      result - a GAsyncResult.
      Returns:
      a GCredentials, or null on error. Free the returned object with g_object_unref().
      Throws:
      GErrorException - see GError
      Since:
      2.32
    • receiveFd

      public int receiveFd(@Nullable Cancellable cancellable) throws GErrorException

      Receives a file descriptor from the sending end of the connection. The sending end has to call g_unix_connection_send_fd() for this to work.

      As well as reading the fd this also reads a single byte from the stream, as this is required for fd passing to work on some implementations.

      Parameters:
      cancellable - optional GCancellable object, null to ignore
      Returns:
      a file descriptor on success, -1 on error.
      Throws:
      GErrorException - see GError
      Since:
      2.22
    • sendCredentials

      public boolean sendCredentials(@Nullable Cancellable cancellable) throws GErrorException

      Passes the credentials of the current user the receiving side of the connection. The receiving end has to call g_unix_connection_receive_credentials() (or similar) to accept the credentials.

      As well as sending the credentials this also writes a single NUL byte to the stream, as this is required for credentials passing to work on some implementations.

      This method can be expected to be available on the following platforms:

      • Linux since GLib 2.26
      • FreeBSD since GLib 2.26
      • GNU/kFreeBSD since GLib 2.36
      • Solaris, Illumos and OpenSolaris since GLib 2.40
      • GNU/Hurd since GLib 2.40

      Other ways to exchange credentials with a foreign peer includes the GUnixCredentialsMessage type and g_socket_get_credentials() function.

      Parameters:
      cancellable - A GCancellable or null.
      Returns:
      true on success, false if error is set.
      Throws:
      GErrorException - see GError
      Since:
      2.26
    • sendCredentialsAsync

      public void sendCredentialsAsync(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously send credentials.

      For more details, see g_unix_connection_send_credentials() which is the synchronous version of this call.

      When the operation is finished, callback will be called. You can then call g_unix_connection_send_credentials_finish() to get the result of the operation.

      Parameters:
      cancellable - optional GCancellable object, null to ignore.
      callback - a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.32
    • sendCredentialsFinish

      public boolean sendCredentialsFinish(AsyncResult result) throws GErrorException
      Finishes an asynchronous send credentials operation started with g_unix_connection_send_credentials_async().
      Parameters:
      result - a GAsyncResult.
      Returns:
      true if the operation was successful, otherwise false.
      Throws:
      GErrorException - see GError
      Since:
      2.32
    • sendFd

      public boolean sendFd(int fd, @Nullable Cancellable cancellable) throws GErrorException

      Passes a file descriptor to the receiving side of the connection. The receiving end has to call g_unix_connection_receive_fd() to accept the file descriptor.

      As well as sending the fd this also writes a single byte to the stream, as this is required for fd passing to work on some implementations.

      Parameters:
      fd - a file descriptor
      cancellable - optional GCancellable object, null to ignore.
      Returns:
      a true on success, null on error.
      Throws:
      GErrorException - see GError
      Since:
      2.22
    • builder

      public static UnixConnection.Builder<? extends UnixConnection.Builder> builder()
      A UnixConnection.Builder object constructs a UnixConnection with the specified properties. Use the various set...() methods to set properties, and finish construction with UnixConnection.Builder.build().
      Returns:
      the builder object