Class UnixSocketAddress
- All Implemented Interfaces:
Proxy
,SocketConnectable
struct sockaddr_un
.
UNIX domain sockets are generally visible in the filesystem.
However, some systems support abstract socket names which are not
visible in the filesystem and not affected by the filesystem
permissions, visibility, etc. Currently this is only supported
under Linux. If you attempt to use abstract sockets on other
systems, function calls may return G_IO_ERROR_NOT_SUPPORTED
errors. You can use abstractNamesSupported()
to see if abstract names are supported.
Since GLib 2.72, GUnixSocketAddress
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/gunixsocketaddress.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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
UnixSocketAddress.Builder<B extends UnixSocketAddress.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gio.SocketAddress
SocketAddress.SocketAddressClass, SocketAddress.SocketAddressImpl
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gio.SocketConnectable
SocketConnectable.SocketConnectableIface, SocketConnectable.SocketConnectableImpl
-
Constructor Summary
ConstructorDescriptionUnixSocketAddress
(MemorySegment address) Create a UnixSocketAddress proxy instance for the provided memory address.UnixSocketAddress
(String path) Creates a newGUnixSocketAddress
forpath
. -
Method Summary
Modifier and TypeMethodDescriptionstatic UnixSocketAddress
abstract_
(byte[] path) Deprecated.Use g_unix_socket_address_new_with_type().static boolean
Checks if abstract UNIX domain socket names are supported.protected UnixSocketAddress
asParent()
Returns this instance as if it were its parent type.static UnixSocketAddress.Builder
<? extends UnixSocketAddress.Builder> builder()
AUnixSocketAddress.Builder
object constructs aUnixSocketAddress
with the specified properties.Gets this UnixSocketAddress's type.boolean
Deprecated.Use g_unix_socket_address_get_address_type()static MemoryLayout
The memory layout of the native struct.getPath()
Gets this UnixSocketAddress's path, or for abstract sockets the "name".long
Gets the length of this UnixSocketAddress's path.static Type
getType()
Get the GType of the UnixSocketAddress classstatic UnixSocketAddress
withType
(byte[] path, UnixSocketAddressType type) Creates a newGUnixSocketAddress
of typetype
with namepath
.Methods inherited from class org.gnome.gio.SocketAddress
fromNative, getFamily, getNativeSize, toNative
Methods 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gio.SocketConnectable
enumerate, proxyEnumerate, toString_
-
Constructor Details
-
UnixSocketAddress
Create a UnixSocketAddress proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
UnixSocketAddress
Creates a newGUnixSocketAddress
forpath
.To create abstract socket addresses, on systems that support that, use g_unix_socket_address_new_abstract().
- Parameters:
path
- the socket path
-
-
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 Javasuper
keyword, 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:
asParent
in classSocketAddress
-
abstract_
Deprecated.Use g_unix_socket_address_new_with_type().- Parameters:
path
- the abstract name- Returns:
- a new
GUnixSocketAddress
-
withType
Creates a newGUnixSocketAddress
of typetype
with namepath
.If
type
isUnixSocketAddressType.PATH
, this is equivalent to calling g_unix_socket_address_new().If
type
isUnixSocketAddressType.ANONYMOUS
,path
andpathLen
will be ignored.If
pathType
isUnixSocketAddressType.ABSTRACT
, thenpathLen
bytes ofpath
will be copied to the socket's path, and only those bytes will be considered part of the name. (IfpathLen
is -1, thenpath
is assumed to be NUL-terminated.) For example, ifpath
was "test", then calling g_socket_address_get_native_size() on the returned socket would return 7 (2 bytes of overhead, 1 byte for the abstract-socket indicator byte, and 4 bytes for the name "test").If
pathType
isUnixSocketAddressType.ABSTRACT_PADDED
, thenpathLen
bytes ofpath
will be copied to the socket's path, the rest of the path will be padded with 0 bytes, and the entire zero-padded buffer will be considered the name. (As above, ifpathLen
is -1, thenpath
is assumed to be NUL-terminated.) In this case, g_socket_address_get_native_size() will always return the full size of astruct sockaddr_un
, although g_unix_socket_address_get_path_len() will still return just the length ofpath
.UnixSocketAddressType.ABSTRACT
is preferred overUnixSocketAddressType.ABSTRACT_PADDED
for new programs. Of course, when connecting to a server created by another process, you must use the appropriate type corresponding to how that process created its listening socket.- Parameters:
path
- the nametype
- aGUnixSocketAddressType
- Returns:
- a new
GUnixSocketAddress
-
abstractNamesSupported
public static boolean abstractNamesSupported()Checks if abstract UNIX domain socket names are supported.- Returns:
true
if supported,false
otherwise
-
getAddressType
Gets this UnixSocketAddress's type.- Returns:
- a
GUnixSocketAddressType
-
getIsAbstract
Deprecated.Use g_unix_socket_address_get_address_type()Tests if this UnixSocketAddress is abstract.- Returns:
true
if the address is abstract,false
otherwise
-
getPath
Gets this UnixSocketAddress's path, or for abstract sockets the "name".Guaranteed to be zero-terminated, but an abstract socket may contain embedded zeros, and thus you should use g_unix_socket_address_get_path_len() to get the true length of this string.
- Returns:
- the path for this UnixSocketAddress
-
getPathLen
public long getPathLen()Gets the length of this UnixSocketAddress's path.For details, see g_unix_socket_address_get_path().
- Returns:
- the length of the path
-
builder
AUnixSocketAddress.Builder
object constructs aUnixSocketAddress
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withUnixSocketAddress.Builder.build()
.
-