Class UnixSocket

java.lang.Object
cx.ath.matthew.unix.UnixSocket

public class UnixSocket extends Object
Represents a UnixSocket.
  • Constructor Details

    • UnixSocket

      public UnixSocket()
      Create an unconnected socket.
    • UnixSocket

      public UnixSocket(UnixSocketAddress address) throws IOException
      Create a socket connected to the given address.
      Parameters:
      address - The Unix Socket address to connect to
      Throws:
      IOException
    • UnixSocket

      public UnixSocket(String address) throws IOException
      Create a socket connected to the given address.
      Parameters:
      address - The Unix Socket address to connect to
      Throws:
      IOException
  • Method Details

    • connect

      public void connect(UnixSocketAddress address) throws IOException
      Connect the socket to this address.
      Parameters:
      address - The Unix Socket address to connect to
      Throws:
      IOException
    • connect

      public void connect(String address) throws IOException
      Connect the socket to this address.
      Parameters:
      address - The Unix Socket address to connect to
      Throws:
      IOException
    • finalize

      public void finalize()
      Overrides:
      finalize in class Object
    • close

      public void close() throws IOException
      Closes the connection.
      Throws:
      IOException
    • getInputStream

      public InputStream getInputStream()
      Returns an InputStream for reading from the socket.
      Returns:
      An InputStream connected to this socket.
    • getOutputStream

      public OutputStream getOutputStream()
      Returns an OutputStream for writing to the socket.
      Returns:
      An OutputStream connected to this socket.
    • getAddress

      public UnixSocketAddress 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

      public void sendCredentialByte(byte data) throws IOException
      Send a single byte of data with credentials. (Works on BSDs)
      Parameters:
      data - The byte of data to send.
      Throws:
      IOException
    • recvCredentialByte

      public byte recvCredentialByte() throws IOException
      Receive a single byte of data, with credentials. (Works on BSDs)
      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

      public void setPassCred(boolean enable) throws IOException
      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.