Interface PosixCLibrary
- All Superinterfaces:
NativeLibrary
PosixCLibrary relies on preview features of the Java platform:
PosixCLibraryrefers to one or more preview APIs:MemorySegment.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Provides access to methods in libc.so available on POSIX systems.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interfacecorresponds to struct rlimitstatic interfaceMarker interface for sockaddr struct implementations.static interfacecorresponds to struct stat64 -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final shortsocket domain indicating unix file socketstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intsocket type indicating a datagram-oriented socket -
Method Summary
Modifier and TypeMethodDescriptionintclose(int fd) Close a file descriptorintconnect(int sockfd, PosixCLibrary.SockAddr addr) Connect a socket to an address.interrno()Return the error number from the last failed C library call.intfcntl(int fd, int cmd, PosixCLibrary.FStore fst) intfstat64(int fd, PosixCLibrary.Stat64 stats) intftruncate(int fd, long length) intgeteuid()Gets the effective userid of the current process.intReturns native page size.intgetrlimit(int resource, PosixCLibrary.RLimit rlimit) Retrieve the current rlimit values for the given resource.intmadvise(MemorySegmentPREVIEW segment, long offset, long length, int advice) Provides advice to the operating system about how a region of memory will be accessed, allowing the kernel to optimize memory management.intmlockall(int flags) Lock all the current process's virtual address space into RAM.Create a new RLimit struct for use by getrlimit.newStat64(int sizeof, int stSizeOffset, int stBlocksOffset) newUnixSockAddr(String path) Create a sockaddr for the AF_UNIX family.intintlongsend(int sockfd, CloseableByteBuffer buffer, int flags) Send a message to a socket.intsetrlimit(int resource, PosixCLibrary.RLimit rlimit) intsocket(int domain, int type, int protocol) Open a file descriptor to connect to a socket.strerror(int errno) Return a string description for an error.
-
Field Details
-
AF_UNIX
static final short AF_UNIXsocket domain indicating unix file socket- See Also:
-
SOCK_DGRAM
static final int SOCK_DGRAMsocket type indicating a datagram-oriented socket- See Also:
-
POSIX_MADV_NORMAL
static final int POSIX_MADV_NORMAL- See Also:
-
POSIX_MADV_RANDOM
static final int POSIX_MADV_RANDOM- See Also:
-
POSIX_MADV_SEQUENTIAL
static final int POSIX_MADV_SEQUENTIAL- See Also:
-
POSIX_MADV_WILLNEED
static final int POSIX_MADV_WILLNEED- See Also:
-
POSIX_MADV_DONTNEED
static final int POSIX_MADV_DONTNEED- See Also:
-
POSIX_MADV_NOREUSE
static final int POSIX_MADV_NOREUSE- See Also:
-
-
Method Details
-
geteuid
int geteuid()Gets the effective userid of the current process.- Returns:
- the effective user id
- See Also:
-
newRLimit
PosixCLibrary.RLimit newRLimit()Create a new RLimit struct for use by getrlimit. -
getrlimit
Retrieve the current rlimit values for the given resource.- Returns:
- 0 on success, -1 on failure with errno set
- See Also:
-
setrlimit
-
mlockall
int mlockall(int flags) Lock all the current process's virtual address space into RAM.- Parameters:
flags- flags determining how memory will be locked- Returns:
- 0 on success, -1 on failure with errno set
- See Also:
-
madvise
Provides advice to the operating system about how a region of memory will be accessed, allowing the kernel to optimize memory management.This method is a thin wrapper around the POSIX
madvise(2)system call. The call is advisory only and does not guarantee any specific behavior.Requirements:
- The starting address of
segmentmust be aligned to the system page size. segmentmust represent native (off-heap) memory. Passing a non-nativeMemorySegmentPREVIEW will result in anIllegalArgumentException.
- Parameters:
segment- the starting memory segment of the region to be advised; must refer to native memory and be page-size alignedlength- the length in bytes of the memory region starting atsegmentadvice- the access pattern advice (for exampleMADV_WILLNEED,MADV_DONTNEED,MADV_SEQUENTIAL, etc.)- Returns:
0on success, or-1on failure witherrnoset to indicate the error- Throws:
IllegalArgumentException- ifsegmentdoes not represent native memory- See Also:
- The starting address of
-
getPageSize
int getPageSize()Returns native page size. -
newStat64
-
open
-
open
-
fstat64
-
ftruncate
int ftruncate(int fd, long length) -
newFStore
PosixCLibrary.FStore newFStore() -
fcntl
-
socket
int socket(int domain, int type, int protocol) Open a file descriptor to connect to a socket.- Parameters:
domain- The socket protocol family, eg AF_UNIXtype- The socket type, eg SOCK_DGRAMprotocol- The protocol for the given protocl family, normally 0- Returns:
- an open file descriptor, or -1 on failure with errno set
- See Also:
-
newUnixSockAddr
Create a sockaddr for the AF_UNIX family. -
connect
Connect a socket to an address.- Parameters:
sockfd- An open socket file descriptoraddr- The address to connect to- Returns:
- 0 on success, -1 on failure with errno set
-
send
Send a message to a socket.- Parameters:
sockfd- The open socket file descriptorbuffer- The message bytes to sendflags- Flags that may adjust how the message is sent- Returns:
- The number of bytes sent, or -1 on failure with errno set
- See Also:
-
close
int close(int fd) Close a file descriptor- Parameters:
fd- The file descriptor to close- Returns:
- 0 on success, -1 on failure with errno set
- See Also:
-
strerror
Return a string description for an error.- Parameters:
errno- The error number- Returns:
- a String description for the error
- See Also:
-
errno
int errno()Return the error number from the last failed C library call.- See Also:
-
PosixCLibrarywhen preview features are enabled.