gnu.net.local
Class AfUnixServerSocket

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

public class AfUnixServerSocket
extends java.lang.Object

This class models local AF_UNIX server side sockets. The basic model is that the server socket is created and bound to some well known unix filesystem address (a file representing the socket is created) It then listens for and accepts connections.

Be aware that the socket-file is not removed after closing the server-socket.

To use this library you have to include the native library 'libgnu_net_localX.so' in your LD_LIBRARY_PATH

If you want to check whether the AF_UNIX native library can be loaded/used at all before creating a socket try AfUnixSocketImpl.loadNativeLibrary() and catch UnsatisfiedLinkError.


Constructor Summary
AfUnixServerSocket()
          Constructor that simply sets the implementation.
AfUnixServerSocket(java.lang.String sockname)
          Creates a server socket and binds it to the specified filename.
AfUnixServerSocket(java.lang.String sockname, int backlog)
          Creates a server socket and binds it to the specified filename.
 
Method Summary
 AfUnixSocket accept()
          Accepts a new connection and returns a connected Socket instance representing that connection.
 void bind(java.lang.String sockname)
          Binds the server socket to a specified socket name
 void bind(java.lang.String sockname, int backlog)
          Binds the server socket to a specified socket name
 void close()
          Closes this socket and stops listening for connections
protected  void implAccept(AfUnixSocket s)
          This protected method is used to help subclasses override ServerSocket.accept().
 java.lang.String toString()
          Returns the value of this socket as a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AfUnixServerSocket

public AfUnixServerSocket()
                   throws java.io.IOException
Constructor that simply sets the implementation.

Throws:
java.io.IOException - If an error occurs
java.lang.UnsatisfiedLinkError - loads the native library - throws UnsatisfiedLinkError on failure

AfUnixServerSocket

public AfUnixServerSocket(java.lang.String sockname)
                   throws java.io.IOException
Creates a server socket and binds it to the specified filename. The pending connection queue on this socket will be set to 50.

Parameters:
sockname - The 'filename' to bind to
Throws:
java.io.IOException - If an error occurs
java.lang.UnsatisfiedLinkError - loads the native library - throws UnsatisfiedLinkError on failure

AfUnixServerSocket

public AfUnixServerSocket(java.lang.String sockname,
                          int backlog)
                   throws java.io.IOException
Creates a server socket and binds it to the specified filename. The pending connection queue on this socket will be set to the value passed as arg2.

Parameters:
sockname - The 'filename' to bind to
backlog - The length of the pending connection queue
Throws:
java.io.IOException - If an error occurs
java.lang.UnsatisfiedLinkError - loads the native library - throws UnsatisfiedLinkError on failure
Method Detail

bind

public void bind(java.lang.String sockname)
          throws java.io.IOException
Binds the server socket to a specified socket name

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

bind

public void bind(java.lang.String sockname,
                 int backlog)
          throws java.io.IOException
Binds the server socket to a specified socket name

Parameters:
sockname - The socket name to bind to
backlog - The length of the pending connection queue
Throws:
java.io.IOException - If an error occurs

accept

public AfUnixSocket accept()
                    throws java.io.IOException
Accepts a new connection and returns a connected Socket instance representing that connection. This method will block until a connection is available.

Throws:
java.io.IOException - If an error occurs
IllegalBlockingModeException - If this socket has an associated channel, and the channel is in non-blocking mode
SocketTimeoutException - If a timeout was previously set with setSoTimeout and the timeout has been reached

implAccept

protected final void implAccept(AfUnixSocket s)
                         throws java.io.IOException
This protected method is used to help subclasses override ServerSocket.accept(). The passed in socket will be connected when this method returns.

Throws:
java.io.IOException - If an error occurs
IllegalBlockingModeException - If this socket has an associated channel, and the channel is in non-blocking mode (not implemented)

close

public void close()
           throws java.io.IOException
Closes this socket and stops listening for connections

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

toString

public java.lang.String toString()
Returns the value of this socket as a String.

Overrides:
toString in class java.lang.Object
Returns:
This socket represented as a String.