Package EOorg.EOeolang.EOsys.Posix
Interface CStdLib
-
- All Superinterfaces:
com.sun.jna.Library
public interface CStdLib extends com.sun.jna.Library
C standard library with unix syscalls.- Since:
- 0.40
-
-
Field Summary
Fields Modifier and Type Field Description static int
AF_INET
TCP connection family.static CStdLib
INSTANCE
C STDLIB instance.static int
IPPROTO_TCP
Protocol for TCP connection.static int
O_RDONLY
Open flag for reading only.static int
O_RDWR
Open flag for reading and writing.static int
SOCK_STREAM
The "Socket as stream" type.static int
STDIN_FILENO
Standard input file descriptor.static int
STDOUT_FILENO
Standard output file descriptor.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
accept(int sockfd, SockaddrIn addr, com.sun.jna.ptr.IntByReference addrlen)
Accept connection on socket.int
bind(int sockfd, SockaddrIn addr, int addrlen)
Assigns the address specified byaddr
to the socket referred to by the file descriptorsockfd
.int
close(int descriptor)
Close file descriptor.int
connect(int sockfd, SockaddrIn addr, int addrlen)
Connects to the server at the specified IP address and port.int
dup(int descriptor)
Duplicates file descriptor.int
dup2(int descriptor, int other)
Duplicates a file descriptor to another.String
getenv(String name)
Get environment variable.int
getpid()
The "getpid" syscall.int
gettimeofday(GettimeofdaySyscall.Timeval timeval, com.sun.jna.Pointer timezone)
Get current time.int
inet_addr(String address)
Convert IP string to binary form.int
listen(int sockfd, int backlog)
Listen for incoming connections on socket.int
open(String path, int flags)
The "open" syscall.int
read(int descriptor, byte[] buf, int size)
Read bytes from file descriptor.int
recv(int sockfd, byte[] buf, int len, int flags)
Receive a message from a socket.int
send(int sockfd, byte[] buf, int len, int flags)
Send a message to a socket.int
socket(int domain, int type, int protocol)
Create an endpoint for communication.String
strerror(int errno)
Convertserrno
to a human-readable string.int
write(int descriptor, String buf, int size)
Writes given bytes buffer to file descriptor.
-
-
-
Field Detail
-
INSTANCE
static final CStdLib INSTANCE
C STDLIB instance.
-
STDIN_FILENO
static final int STDIN_FILENO
Standard input file descriptor.- See Also:
- Constant Field Values
-
STDOUT_FILENO
static final int STDOUT_FILENO
Standard output file descriptor.- See Also:
- Constant Field Values
-
O_RDONLY
static final int O_RDONLY
Open flag for reading only.- See Also:
- Constant Field Values
-
O_RDWR
static final int O_RDWR
Open flag for reading and writing.- See Also:
- Constant Field Values
-
AF_INET
static final int AF_INET
TCP connection family.- See Also:
- Constant Field Values
-
SOCK_STREAM
static final int SOCK_STREAM
The "Socket as stream" type.- See Also:
- Constant Field Values
-
IPPROTO_TCP
static final int IPPROTO_TCP
Protocol for TCP connection.- See Also:
- Constant Field Values
-
-
Method Detail
-
dup
int dup(int descriptor)
Duplicates file descriptor.- Parameters:
descriptor
- Old file descriptor- Returns:
- New file descriptor
-
dup2
int dup2(int descriptor, int other)
Duplicates a file descriptor to another.- Parameters:
descriptor
- Old file descriptorother
- New file descriptor- Returns:
- Duplicated file descriptor
-
getpid
int getpid()
The "getpid" syscall.- Returns:
- Process ID.
-
open
int open(String path, int flags)
The "open" syscall.- Parameters:
path
- Path to file to openflags
- Open flags- Returns:
- File descriptor
-
close
int close(int descriptor)
Close file descriptor.- Parameters:
descriptor
- File descriptor- Returns:
- Zero on success, -1 on error
-
write
int write(int descriptor, String buf, int size)
Writes given bytes buffer to file descriptor.- Parameters:
descriptor
- File descriptor.buf
- Buffer.size
- Number of bytes to be written.- Returns:
- Number of bytes was written.
-
read
int read(int descriptor, byte[] buf, int size)
Read bytes from file descriptor.- Parameters:
descriptor
- File descriptor.buf
- Buffer.size
- Number of bytes to be read.- Returns:
- Number of bytes was read.
-
getenv
String getenv(String name)
Get environment variable.- Parameters:
name
- Name of the variable- Returns:
- Name of the environment variable
-
gettimeofday
int gettimeofday(GettimeofdaySyscall.Timeval timeval, com.sun.jna.Pointer timezone)
Get current time.- Parameters:
timeval
- Timevaluetimezone
- Timezone- Returns:
- Zero on success, -1 on error
-
socket
int socket(int domain, int type, int protocol)
Create an endpoint for communication.- Parameters:
domain
- Socket domaintype
- Socket typeprotocol
- Socket protocol- Returns:
- New socket descriptor on success, -1 on error
-
connect
int connect(int sockfd, SockaddrIn addr, int addrlen)
Connects to the server at the specified IP address and port.- Parameters:
sockfd
- Socket descriptoraddr
- Address structureaddrlen
- The size of the address structure- Returns:
- Zero on success, -1 on error
-
bind
int bind(int sockfd, SockaddrIn addr, int addrlen)
Assigns the address specified byaddr
to the socket referred to by the file descriptorsockfd
.- Parameters:
sockfd
- Socket descriptoraddr
- Address structureaddrlen
- The size of the address structure- Returns:
- Zero on success, -1 on error
-
listen
int listen(int sockfd, int backlog)
Listen for incoming connections on socket.- Parameters:
sockfd
- Socket descriptorbacklog
- Specifies the queue length for completely established sockets waiting to be accepted- Returns:
- Zero on success, -1 on error
-
accept
int accept(int sockfd, SockaddrIn addr, com.sun.jna.ptr.IntByReference addrlen)
Accept connection on socket.- Parameters:
sockfd
- Socket descriptoraddr
- Address structureaddrlen
- The size of the address structure- Returns:
- On success, file descriptor for the accepted socket (a nonnegative integer) is returned. On error, -1 is returned.
-
recv
int recv(int sockfd, byte[] buf, int len, int flags)
Receive a message from a socket.- Parameters:
sockfd
- Socket descriptorbuf
- Byte buffer to store received byteslen
- Size of received dataflags
- Flags- Returns:
- The number of received bytes on success, -1 on error
-
send
int send(int sockfd, byte[] buf, int len, int flags)
Send a message to a socket.- Parameters:
sockfd
- Socket descriptorbuf
- Byte buffer to store sent byteslen
- Size of sent dataflags
- Flags- Returns:
- The number of sent bytes on success, -1 on error
-
inet_addr
int inet_addr(String address)
Convert IP string to binary form.- Parameters:
address
- IP address- Returns:
- IP address in binary form
-
strerror
String strerror(int errno)
Convertserrno
to a human-readable string.- Parameters:
errno
- The error number- Returns:
- Error as string
-
-