gnu.net.local
Class AfUnixSocketImpl

java.lang.Object
  |
  +--gnu.net.local.AfUnixSocketImpl

public class AfUnixSocketImpl
extends java.lang.Object

Implementation class of AfUnixSocket - links to the native library


Field Summary
 int native_fd
          This is the native file descriptor for this socket
 
Method Summary
protected  void accept(AfUnixSocketImpl impl)
          Accepts a new connection on this socket and returns in in the passed in AfUnixSocketImpl.
protected  int available()
          Returns the number of bytes that the caller can read from this socket without blocking.
protected  void bind(java.lang.String sockname)
          Binds to the specified socket
protected  void close()
          Closes the socket.
protected  void connect(java.lang.String sockname)
          Connects to the socket specified as arguments.
protected  void create(boolean stream)
          Creates a new socket that is not bound to any local address/port and is not connected to any remote address/port.
static AfUnixSocketImpl createNew()
          return new instance loads the native libraray - throws UnsatisfiedLinkError on failure
protected  java.io.InputStream getInputStream()
          Returns an InputStream object for reading from this socket.
protected  java.lang.Object getOption(int option_id)
          Returns the current setting of the specified option.
protected  java.io.OutputStream getOutputStream()
          Returns an OutputStream object for writing to this socket.
protected  void listen(int queuelen)
          Starts listening for connections on a socket.
static void loadNativeLibrary()
          loads the native library.
protected  int read(byte[] buf, int offset, int len)
          Internal method used by SocketInputStream for reading data from the connection.
protected  void setOption(int option_id, java.lang.Object val)
          Sets the specified option on a socket to the passed in object.
protected  void shutdownInput()
          NOT IMPLEMENTED
protected  void shutdownOutput()
          NOT IMPLEMENTED
protected  void write(byte[] buf, int offset, int len)
          Internal method used by SocketOuputStream for writing data to the connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

native_fd

public int native_fd
This is the native file descriptor for this socket

Method Detail

loadNativeLibrary

public static void loadNativeLibrary()
loads the native library. throws UnsatisfiedLinkError on failure. Use this method to check if the AF_UNIX native libraray is available. might be used as indicator whether AF_UNIX sockets are supported on the machine.


createNew

public static AfUnixSocketImpl createNew()
return new instance loads the native libraray - throws UnsatisfiedLinkError on failure


accept

protected void accept(AfUnixSocketImpl impl)
               throws java.io.IOException
Accepts a new connection on this socket and returns in in the passed in AfUnixSocketImpl.

Parameters:
impl - The AfUnixSocketImpl object to accept this connection.
java.io.IOException

available

protected int available()
                 throws java.io.IOException
Returns the number of bytes that the caller can read from this socket without blocking. is not implemented - always returns 0!

Returns:
The number of readable bytes before blocking
Throws:
java.io.IOException - If an error occurs

bind

protected void bind(java.lang.String sockname)
             throws java.io.IOException
Binds to the specified socket

Parameters:
sockname - The socket to bind to
Throws:
java.io.IOException - If an error occurs

close

protected void close()
              throws java.io.IOException
Closes the socket. This will cause any InputStream or OutputStream objects for this Socket to be closed as well.

Note that if the SO_LINGER option is set on this socket, then the operation could block. (not implemented yet)

Throws:
java.io.IOException - If an error occurs

connect

protected void connect(java.lang.String sockname)
                throws java.io.IOException
Connects to the socket specified as arguments.

Parameters:
sockname - The socket to connect to
Throws:
java.io.IOException - If an error occurs

create

protected void create(boolean stream)
               throws java.io.IOException
Creates a new socket that is not bound to any local address/port and is not connected to any remote address/port. This will be created as a stream socket if the stream parameter is true, or a datagram socket if the stream parameter is false.

Parameters:
stream - true for a stream socket, false for a datagram socket
java.io.IOException

listen

protected void listen(int queuelen)
               throws java.io.IOException
Starts listening for connections on a socket. The queuelen parameter is how many pending connections will queue up waiting to be serviced before being accept'ed. If the queue of pending requests exceeds this number, additional connections will be refused.

Parameters:
queuelen - The length of the pending connection queue
Throws:
java.io.IOException - If an error occurs

read

protected int read(byte[] buf,
                   int offset,
                   int len)
            throws java.io.IOException
Internal method used by SocketInputStream for reading data from the connection. Reads up to len bytes of data into the buffer buf starting at offset bytes into the buffer.

Returns:
The actual number of bytes read or -1 if end of stream.
Throws:
java.io.IOException - If an error occurs

write

protected void write(byte[] buf,
                     int offset,
                     int len)
              throws java.io.IOException
Internal method used by SocketOuputStream for writing data to the connection. Writes up to len bytes of data from the buffer buf starting at offset bytes into the buffer.

Throws:
java.io.IOException - If an error occurs

setOption

protected void setOption(int option_id,
                         java.lang.Object val)
                  throws java.net.SocketException
Sets the specified option on a socket to the passed in object. For options that take an integer argument, the passed in object is an Integer. The option_id parameter is one of the defined constants in this interface.

NOT IMPLEMENTED

Parameters:
option_id - The identifier of the option
val - The value to set the option to
Throws:
java.net.SocketException - If an error occurs

getOption

protected java.lang.Object getOption(int option_id)
                              throws java.net.SocketException
Returns the current setting of the specified option. The Object returned will be an Integer for options that have integer values. The option_id is one of the defined constants in this interface.

NOT IMPLEMENTED

Parameters:
option_id - The option identifier
Returns:
The current value of the option
Throws:
java.net.SocketException - If an error occurs

getInputStream

protected java.io.InputStream getInputStream()
                                      throws java.io.IOException
Returns an InputStream object for reading from this socket. This will be an instance of SocketInputStream.

Returns:
An InputStream
Throws:
java.io.IOException - If an error occurs

getOutputStream

protected java.io.OutputStream getOutputStream()
                                        throws java.io.IOException
Returns an OutputStream object for writing to this socket. This will be an instance of SocketOutputStream.

Returns:
An OutputStream
Throws:
java.io.IOException - If an error occurs

shutdownInput

protected void shutdownInput()
NOT IMPLEMENTED


shutdownOutput

protected void shutdownOutput()
NOT IMPLEMENTED