Class UnixConnection
- All Implemented Interfaces:
AutoCloseable,Proxy,AutoCloseable
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUnixConnection.Builder<B extends UnixConnection.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gio.SocketConnection
SocketConnection.SocketConnectionClassNested classes/interfaces inherited from class org.gnome.gio.IOStream
IOStream.IOStream$Impl, IOStream.IOStreamClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new UnixConnection.UnixConnection(MemorySegment address) Create a UnixConnection proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected UnixConnectionasParent()Returns this instance as if it were its parent type.static UnixConnection.Builder<? extends UnixConnection.Builder> builder()AUnixConnection.Builderobject constructs aUnixConnectionwith the specified properties.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the UnixConnection classreceiveCredentials(@Nullable Cancellable cancellable) Receives credentials from the sending end of the connection.voidreceiveCredentialsAsync(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously receive credentials.receiveCredentialsFinish(AsyncResult result) Finishes an asynchronous receive credentials operation started with g_unix_connection_receive_credentials_async().intreceiveFd(@Nullable Cancellable cancellable) Receives a file descriptor from the sending end of the connection.booleansendCredentials(@Nullable Cancellable cancellable) Passes the credentials of the current user the receiving side of the connection.voidsendCredentialsAsync(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously send credentials.booleansendCredentialsFinish(AsyncResult result) Finishes an asynchronous send credentials operation started with g_unix_connection_send_credentials_async().booleansendFd(int fd, @Nullable Cancellable cancellable) Passes a file descriptor to the receiving side of the connection.Methods inherited from class org.gnome.gio.SocketConnection
connect, connectAsync, connectFinish, factoryLookupType, factoryRegisterType, getLocalAddress, getRemoteAddress, getSocket, isConnectedMethods inherited from class org.gnome.gio.IOStream
clearPending, close, closeAsync, closeFinish, closeFn, getInputStream, getOutputStream, hasPending, isClosed, setPending, spliceAsync, spliceAsync, spliceFinishMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.javagi.gio.AutoCloseable
close
-
Constructor Details
-
UnixConnection
Create a UnixConnection proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
UnixConnection
public UnixConnection()Creates a new UnixConnection.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type.- Overrides:
asParentin classSocketConnection
-
receiveCredentials
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
GUnixCredentialsMessagetype and g_socket_get_credentials() function.- Parameters:
cancellable- AGCancellableornull.- Returns:
- Received credentials on success (free with
g_object_unref()),
nulliferroris set. - Throws:
GErrorException- seeGError- 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,
callbackwill be called. You can then call g_unix_connection_receive_credentials_finish() to get the result of the operation.- Parameters:
cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.32
-
receiveCredentialsFinish
Finishes an asynchronous receive credentials operation started with g_unix_connection_receive_credentials_async().- Parameters:
result- aGAsyncResult.- Returns:
- a
GCredentials, ornullon error. Free the returned object with g_object_unref(). - Throws:
GErrorException- seeGError- Since:
- 2.32
-
receiveFd
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- optionalGCancellableobject,nullto ignore- Returns:
- a file descriptor on success, -1 on error.
- Throws:
GErrorException- seeGError- Since:
- 2.22
-
sendCredentials
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
GUnixCredentialsMessagetype and g_socket_get_credentials() function.- Parameters:
cancellable- AGCancellableornull.- Returns:
trueon success,falseiferroris set.- Throws:
GErrorException- seeGError- 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,
callbackwill be called. You can then call g_unix_connection_send_credentials_finish() to get the result of the operation.- Parameters:
cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.32
-
sendCredentialsFinish
Finishes an asynchronous send credentials operation started with g_unix_connection_send_credentials_async().- Parameters:
result- aGAsyncResult.- Returns:
trueif the operation was successful, otherwisefalse.- Throws:
GErrorException- seeGError- Since:
- 2.32
-
sendFd
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 descriptorcancellable- optionalGCancellableobject,nullto ignore.- Returns:
- a
trueon success,nullon error. - Throws:
GErrorException- seeGError- Since:
- 2.22
-
builder
AUnixConnection.Builderobject constructs aUnixConnectionwith the specified properties. Use the variousset...()methods to set properties, and finish construction withUnixConnection.Builder.build().- Returns:
- the builder object
-