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.
-
-
Field Summary
Fields Modifier and Type Field Description static int
F_SETFD
Command to set the close-on-exec flag on a file descriptor viafcntl(int, int, int)
.static int
FD_CLOEXEC
Specifies that a file descriptor shall not be inherited by child processes.static java.lang.String
LIBRARY_NAME
Library to load.-
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_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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
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.
-
-
-
Field Detail
-
LIBRARY_NAME
static final java.lang.String LIBRARY_NAME
Library to load. These functions live in libc.- See Also:
- Constant Field Values
-
F_SETFD
static final int F_SETFD
Command to set the close-on-exec flag on a file descriptor viafcntl(int, int, int)
.- See Also:
- Constant Field Values
-
FD_CLOEXEC
static final int FD_CLOEXEC
Specifies that a file descriptor shall not be inherited by child processes.- See Also:
- Constant Field Values
-
-
Method Detail
-
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
int connect(int fd, Sockets.SockAddr addr, int addrLen) throws com.sun.jna.LastErrorException
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
-
-