Package cx.ath.matthew.unix
Class UnixSocket
java.lang.Object
cx.ath.matthew.unix.UnixSocket
Represents a UnixSocket.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an unconnected socket.UnixSocket
(UnixSocketAddress address) Create a socket connected to the given address.UnixSocket
(String address) Create a socket connected to the given address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the connection.void
connect
(UnixSocketAddress address) Connect the socket to this address.void
Connect the socket to this address.void
finalize()
Returns the address this socket is connected to.boolean
Get the blocking mode.Returns an InputStream for reading from the socket.Returns an OutputStream for writing to the socket.boolean
Get the credential passing status.int
Return the gid of the remote process.int
Return the pid of the remote process.int
Return the uid of the remote process.boolean
isClosed()
Check the socket status.boolean
Check the socket status.boolean
Check the socket status.boolean
Check the socket status.byte
Receive a single byte of data, with credentials.void
sendCredentialByte
(byte data) Send a single byte of data with credentials.void
setBlocking
(boolean enable) Set the blocking mode.void
setPassCred
(boolean enable) Set the credential passing status.void
setSoTimeout
(int timeout) Set timeout of read requests.void
Shuts down the input stream.void
Shuts down the output stream.
-
Constructor Details
-
UnixSocket
public UnixSocket()Create an unconnected socket. -
UnixSocket
Create a socket connected to the given address.- Parameters:
address
- The Unix Socket address to connect to- Throws:
IOException
-
UnixSocket
Create a socket connected to the given address.- Parameters:
address
- The Unix Socket address to connect to- Throws:
IOException
-
-
Method Details
-
connect
Connect the socket to this address.- Parameters:
address
- The Unix Socket address to connect to- Throws:
IOException
-
connect
Connect the socket to this address.- Parameters:
address
- The Unix Socket address to connect to- Throws:
IOException
-
finalize
public void finalize() -
close
Closes the connection.- Throws:
IOException
-
getInputStream
Returns an InputStream for reading from the socket.- Returns:
- An InputStream connected to this socket.
-
getOutputStream
Returns an OutputStream for writing to the socket.- Returns:
- An OutputStream connected to this socket.
-
getAddress
Returns the address this socket is connected to. Returns null if the socket is unconnected.- Returns:
- The UnixSocketAddress the socket is connected to
-
sendCredentialByte
Send a single byte of data with credentials. (Works on BSDs)- Parameters:
data
- The byte of data to send.- Throws:
IOException
-
recvCredentialByte
Receive a single byte of data, with credentials. (Works on BSDs)- Parameters:
data
- The byte of data to send.- Throws:
IOException
- See Also:
-
getPassCred
public boolean getPassCred()Get the credential passing status. (only effective on linux)- Returns:
- The current status of credential passing.
- See Also:
-
getPeerUID
public int getPeerUID()Return the uid of the remote process. Some data must have been received on the socket to do this. Either setPassCred must be called on Linux first, or recvCredentialByte on BSD.- Returns:
- the UID or -1 if it is not available
-
getPeerGID
public int getPeerGID()Return the gid of the remote process. Some data must have been received on the socket to do this. Either setPassCred must be called on Linux first, or recvCredentialByte on BSD.- Returns:
- the GID or -1 if it is not available
-
getPeerPID
public int getPeerPID()Return the pid of the remote process. Some data must have been received on the socket to do this. Either setPassCred must be called on Linux first, or recvCredentialByte on BSD.- Returns:
- the PID or -1 if it is not available
-
setPassCred
Set the credential passing status. (Only does anything on linux, for other OS, you need to use send/recv credentials)- Parameters:
enable
- Set to true for credentials to be passed.- Throws:
IOException
-
getBlocking
public boolean getBlocking()Get the blocking mode.- Returns:
- true if reads are blocking.
- See Also:
-
setBlocking
public void setBlocking(boolean enable) Set the blocking mode.- Parameters:
enable
- Set to false for non-blocking reads.
-
isClosed
public boolean isClosed()Check the socket status.- Returns:
- true if closed.
-
isConnected
public boolean isConnected()Check the socket status.- Returns:
- true if connected.
-
isInputShutdown
public boolean isInputShutdown()Check the socket status.- Returns:
- true if the input stream has been shutdown
-
isOutputShutdown
public boolean isOutputShutdown()Check the socket status.- Returns:
- true if the output stream has been shutdown
-
shutdownInput
public void shutdownInput()Shuts down the input stream. Subsequent reads on the associated InputStream will fail. -
shutdownOutput
public void shutdownOutput()Shuts down the output stream. Subsequent writes to the associated OutputStream will fail. -
setSoTimeout
public void setSoTimeout(int timeout) Set timeout of read requests.
-