Interface UnixSockets
- All Superinterfaces:
com.sun.jna.platform.unix.LibCAPI
,com.sun.jna.Library
,com.sun.jna.platform.unix.Reboot
,com.sun.jna.platform.unix.Resource
interface UnixSockets
extends com.sun.jna.platform.unix.LibCAPI, com.sun.jna.Library
Low-level Unix/Linux JNA socket API.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.sun.jna.platform.unix.LibCAPI
com.sun.jna.platform.unix.LibCAPI.size_t, com.sun.jna.platform.unix.LibCAPI.ssize_t
Nested classes/interfaces inherited from interface com.sun.jna.Library
com.sun.jna.Library.Handler
Nested classes/interfaces inherited from interface com.sun.jna.platform.unix.Resource
com.sun.jna.platform.unix.Resource.Rlimit
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Command to set the close-on-exec flag on a file descriptor viafcntl(int, int, int)
.static final int
Specifies that a file descriptor shall not be inherited by child processes.static final String
Library to load.Fields inherited from interface com.sun.jna.platform.unix.LibCAPI
HOST_NAME_MAX
Fields inherited from interface com.sun.jna.Library
OPTION_ALLOW_OBJECTS, OPTION_CALLING_CONVENTION, OPTION_CLASSLOADER, OPTION_FUNCTION_MAPPER, OPTION_INVOCATION_MAPPER, OPTION_OPEN_FLAGS, OPTION_STRING_ENCODING, OPTION_STRUCTURE_ALIGNMENT, OPTION_SYMBOL_PROVIDER, OPTION_TYPE_MAPPER
Fields inherited from interface com.sun.jna.platform.unix.Reboot
RB_AUTOBOOT, RB_DISABLE_CAD, RB_ENABLE_CAD, RB_HALT_SYSTEM, RB_KEXEC, RB_POWER_OFF, RB_SW_SUSPEND
Fields inherited from interface com.sun.jna.platform.unix.Resource
RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE, RLIMIT_LOCKS, RLIMIT_MEMLOCK, RLIMIT_MSGQUEUE, RLIMIT_NICE, RLIMIT_NLIMITS, RLIMIT_NOFILE, RLIMIT_NPROC, RLIMIT_RSS, RLIMIT_RTPRIO, RLIMIT_RTTIME, RLIMIT_SIGPENDING, RLIMIT_STACK
-
Method Summary
Modifier and TypeMethodDescriptionint
connect
(int fd, Sockets.SockAddr addr, int addrLen) Connects a file descriptor, which must refer to a socket, to aSockets.SockAddr
.int
fcntl
(int fd, int command, int flag) Simple binding to fcntl; used to set the FD_CLOEXEC flag.com.sun.jna.platform.unix.LibCAPI.ssize_t
read
(int fd, byte[] buf, com.sun.jna.platform.unix.LibCAPI.size_t bufLen) Read data from a file descriptor.int
socket
(int domain, int type, int protocol) Creates a socket and returns a file descriptor for it.com.sun.jna.platform.unix.LibCAPI.ssize_t
write
(int fd, byte[] data, com.sun.jna.platform.unix.LibCAPI.size_t dataLen) Write data to a file descriptor.Methods inherited from interface com.sun.jna.platform.unix.LibCAPI
close, getdomainname, getegid, getenv, geteuid, getgid, gethostname, getloadavg, getuid, msync, munmap, setdomainname, setegid, setenv, seteuid, setgid, sethostname, setuid, unsetenv
Methods inherited from interface com.sun.jna.platform.unix.Reboot
reboot
Methods inherited from interface com.sun.jna.platform.unix.Resource
getrlimit, setrlimit
-
Field Details
-
LIBRARY_NAME
Library to load. These functions live in libc.- See Also:
-
F_SETFD
static final int F_SETFDCommand to set the close-on-exec flag on a file descriptor viafcntl(int, int, int)
.- See Also:
-
FD_CLOEXEC
static final int FD_CLOEXECSpecifies that a file descriptor shall not be inherited by child processes.- See Also:
-
-
Method Details
-
socket
int socket(int domain, int type, int protocol) throws com.sun.jna.LastErrorException Creates a socket and returns a file descriptor for it.- Parameters:
domain
- socket domain; useSockets.AF_UNIX
type
- socket type; useSockets.SOCK_STREAM
protocol
- socket communication protocol; useSockets.DEFAULT_PROTOCOL
.- Returns:
- file descriptor for the socket; should be closed eventually, or -1 on error.
- Throws:
com.sun.jna.LastErrorException
- on errors- See Also:
-
LibCAPI.close(int)
-
fcntl
int fcntl(int fd, int command, int flag) throws com.sun.jna.LastErrorException Simple binding to fcntl; used to set the FD_CLOEXEC flag. On OS X, we cannot include SOCK_CLOEXEC in the socket() call.- Parameters:
fd
- file descriptor to operate oncommand
- set toF_SETFD
flag
- zero to clear the close-on-exec flag,FD_CLOEXEC
to set it- Returns:
- -1 on error, otherwise a value >= 0
- Throws:
com.sun.jna.LastErrorException
-
connect
Connects a file descriptor, which must refer to a socket, to aSockets.SockAddr
.- Parameters:
fd
- file descriptor of the socket, as returned bysocket(int, int, int)
addr
- address to connect toaddrLen
- Length ofaddr
, useStructure.size()
- Returns:
- 0 on success; -1 otherwise
- Throws:
com.sun.jna.LastErrorException
- on errors
-
read
com.sun.jna.platform.unix.LibCAPI.ssize_t read(int fd, byte[] buf, com.sun.jna.platform.unix.LibCAPI.size_t bufLen) throws com.sun.jna.LastErrorException Read data from a file descriptor.- Parameters:
fd
- file descriptor to read frombuf
- buffer to read intobufLen
- maximum number of bytes to read; at most length ofbuf
- Returns:
- number of bytes actually read; zero for EOF, -1 on error
- Throws:
com.sun.jna.LastErrorException
- on errors
-
write
com.sun.jna.platform.unix.LibCAPI.ssize_t write(int fd, byte[] data, com.sun.jna.platform.unix.LibCAPI.size_t dataLen) throws com.sun.jna.LastErrorException Write data to a file descriptor.- Parameters:
fd
- file descriptor to write todata
- data to writedataLen
- number of bytes to write- Returns:
- number of bytes actually written; -1 on error
- Throws:
com.sun.jna.LastErrorException
- on errors
-