Class UnixSocketAddress
- All Implemented Interfaces:
SocketConnectable, Proxy
Support for UNIX-domain (also known as local) sockets, corresponding to
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
Nested ClassesModifier and TypeClassDescriptionstatic classUnixSocketAddress.Builder<B extends UnixSocketAddress.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class SocketAddress
SocketAddress.SocketAddress$Impl, SocketAddress.SocketAddressClassNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface SocketConnectable
SocketConnectable.SocketConnectable$Impl, SocketConnectable.SocketConnectableIface -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new UnixSocketAddress.UnixSocketAddress(MemorySegment address) Create a UnixSocketAddress instance for the provided memory address.UnixSocketAddress(String path) Creates a newGUnixSocketAddressforpath. -
Method Summary
Modifier and TypeMethodDescriptionstatic SocketAddressabstract_(@Nullable byte @Nullable [] path) Deprecated.Use g_unix_socket_address_new_with_type().static booleanChecks if abstract UNIX domain socket names are supported.protected UnixSocketAddressasParent()Return this instance as if it were its parent type.static UnixSocketAddress.Builder<? extends UnixSocketAddress.Builder> builder()AUnixSocketAddress.Builderobject constructs aUnixSocketAddresswith the specified properties.Getsaddress'stype.booleanDeprecated.Use g_unix_socket_address_get_address_type()static MemoryLayoutThe memory layout of the native struct.getPath()Getsaddress'spath, or for abstract sockets the "name".longGets the length ofaddress'spath.static @Nullable TypegetType()Get the GType of the UnixSocketAddress class.static SocketAddresswithType(@Nullable byte @Nullable [] path, UnixSocketAddressType type) Creates a newGUnixSocketAddressof typetypewith namepath.Methods inherited from class SocketAddress
fromNative, getFamily, getNativeSize, toNativeMethods inherited from class 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 TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCodeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SocketConnectable
enumerate, formatAsString, proxyEnumerate
-
Constructor Details
-
UnixSocketAddress
Create a UnixSocketAddress instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
UnixSocketAddress
Creates a new
GUnixSocketAddressforpath.To create abstract socket addresses, on systems that support that, use g_unix_socket_address_new_abstract().
- Parameters:
path- the socket path- Since:
- 2.22
-
UnixSocketAddress
public UnixSocketAddress()Create a new UnixSocketAddress.
-
-
Method Details
-
getType
Get the GType of the UnixSocketAddress class.- Returns:
- the GType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code.- Overrides:
asParentin classSocketAddress- Returns:
- the instance as if it were its parent type
-
abstract_
Deprecated.Use g_unix_socket_address_new_with_type().- Parameters:
path- the abstract name- Returns:
- a new
GUnixSocketAddress
-
withType
Creates a new
GUnixSocketAddressof typetypewith namepath.If
typeisUnixSocketAddressType.PATH, this is equivalent to calling g_unix_socket_address_new().If
typeisUnixSocketAddressType.ANONYMOUS,pathandpathLenwill be ignored.If
pathTypeisUnixSocketAddressType.ABSTRACT, thenpathLenbytes ofpathwill be copied to the socket's path, and only those bytes will be considered part of the name. (IfpathLenis -1, thenpathis assumed to be NUL-terminated.) For example, ifpathwas "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
pathTypeisUnixSocketAddressType.ABSTRACT_PADDED, thenpathLenbytes ofpathwill 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, ifpathLenis -1, thenpathis 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.ABSTRACTis preferred overUnixSocketAddressType.ABSTRACT_PADDEDfor 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 - Since:
- 2.26
-
abstractNamesSupported
public static boolean abstractNamesSupported()Checks if abstract UNIX domain socket names are supported.- Returns:
trueif supported,falseotherwise- Since:
- 2.22
-
getAddressType
Getsaddress'stype.- Returns:
- a
GUnixSocketAddressType - Since:
- 2.26
-
getIsAbstract
Deprecated.Use g_unix_socket_address_get_address_type()Tests if this UnixSocketAddress is abstract.- Returns:
trueif the address is abstract,falseotherwise- Since:
- 2.22
-
getPath
Gets
address'spath, 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
- Since:
- 2.22
-
getPathLen
public long getPathLen()Gets the length of
address'spath.For details, see g_unix_socket_address_get_path().
- Returns:
- the length of the path
- Since:
- 2.22
-
builder
AUnixSocketAddress.Builderobject constructs aUnixSocketAddresswith the specified properties. Use the variousset...()methods to set properties, and finish construction withUnixSocketAddress.Builder.build().- Returns:
- the builder object
-