More information: http://www.cs.berkeley.edu/~mdw/proj/seda/

seda.nbio
Class NonblockingSocket

java.lang.Object
  |
  +--java.net.Socket
        |
        +--seda.nbio.NonblockingSocket
All Implemented Interfaces:
Selectable

public class NonblockingSocket
extends java.net.Socket
implements Selectable

A NonblockingSocket is a socket which exports nonblocking input/output streams. It is otherwise idential to a standard socket. Socket connection can be either blocking or nonblocking. Use of the standard constructors causes the current thread to block until the connection is established. Otherwise, there are 3 ways to check if the connection has been established: (1) Call finishConnection, (2) Call connectDone, or (3) Create a SelectSet and select on the event Selectable.CONNECT_READY, then call connectDone.

See Also:
SelectSet

Field Summary
(package private)  NonblockingSocketImpl impl
           
(package private)  boolean is_connected
           
(package private) static boolean nativeLibraryLoaded
           
(package private) static java.lang.Object nativeLibraryLoadLock
           
 
Fields inherited from interface seda.nbio.Selectable
ACCEPT_READY, CONNECT_READY, READ_READY, SELECT_ERROR, WRITE_READY
 
Constructor Summary
(package private) NonblockingSocket()
           
  NonblockingSocket(java.net.InetAddress address, int port)
          Create a NonblockingSocket connection to the given host and port number.
  NonblockingSocket(java.net.InetAddress address, int port, boolean block)
          Create a NonblockingSocket connection to the given host and port number.
  NonblockingSocket(java.lang.String host, int port)
          Create a NonblockingSocket connection to the given host and port number.
  NonblockingSocket(java.lang.String host, int port, boolean block)
          Create a NonblockingSocket connection to the given host and port number.
 
Method Summary
(package private) static void ()
           
 void close()
          Closes the socket.
 boolean connectDone()
          Indicate whether the connection on this socket has been established.
 boolean finishConnect(int timeout)
          Block until the connection on this socket has been established.
 java.net.InetAddress getInetAddress()
          Return the remote address to which this socket is bound.
 java.io.InputStream getInputStream()
          Return an InputStream from which data on this socket can be read.
 java.net.InetAddress getLocalAddress()
          Return the local address to which this socket is bound.
 int getLocalPort()
          Return the local port to which this socket is bound.
 java.io.OutputStream getOutputStream()
          Return an OutputStream to which data on this socket can be written.
 int getPort()
          Return the remote port to which this socket is bound.
 int getSoLinger()
          Currently unimplemented.
 int getSoTimeout()
          Currently unimplemented.
 boolean getTcpNoDelay()
          Currently unimplemented.
(package private) static void loadNativeLibrary()
           
 void setSoLinger(boolean on, int val)
          Currently unimplemented.
 void setSoTimeout(int timeout)
          Currently unimplemented.
 void setTcpNoDelay(boolean on)
          Currently unimplemented.
 java.lang.String toString()
           
 
Methods inherited from class java.net.Socket
getKeepAlive, getReceiveBufferSize, getSendBufferSize, setKeepAlive, setReceiveBufferSize, setSendBufferSize, setSocketImplFactory, shutdownInput, shutdownOutput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

impl

NonblockingSocketImpl impl

is_connected

boolean is_connected

nativeLibraryLoaded

static boolean nativeLibraryLoaded

nativeLibraryLoadLock

static java.lang.Object nativeLibraryLoadLock
Constructor Detail

NonblockingSocket

NonblockingSocket()
            throws java.io.IOException

NonblockingSocket

public NonblockingSocket(java.lang.String host,
                         int port)
                  throws java.net.UnknownHostException,
                         java.io.IOException
Create a NonblockingSocket connection to the given host and port number. This will block until the connection is established.

NonblockingSocket

public NonblockingSocket(java.lang.String host,
                         int port,
                         boolean block)
                  throws java.net.UnknownHostException,
                         java.io.IOException
Create a NonblockingSocket connection to the given host and port number. If 'block' is true, block until the connection is done.

NonblockingSocket

public NonblockingSocket(java.net.InetAddress address,
                         int port)
                  throws java.net.UnknownHostException,
                         java.io.IOException
Create a NonblockingSocket connection to the given host and port number. This will block until the connection is established.

NonblockingSocket

public NonblockingSocket(java.net.InetAddress address,
                         int port,
                         boolean block)
                  throws java.io.IOException
Create a NonblockingSocket connection to the given host and port number. If 'block' is true, block until the connection is done.
Method Detail

loadNativeLibrary

static void loadNativeLibrary()

static void ()

finishConnect

public boolean finishConnect(int timeout)
                      throws java.net.SocketException
Block until the connection on this socket has been established. 'timeout' specifies the maximum number of milliseconds to block. A timeout of zero indicates no blocking (in which case this call is equivalent to connectDone). A timeout of -1 causes this call to block indefinitely until the connection is established.
Returns:
true is the connection was established, false if still pending.

connectDone

public boolean connectDone()
                    throws java.net.SocketException
Indicate whether the connection on this socket has been established. Throws an exception if an error occurred trying to connect.

getInetAddress

public java.net.InetAddress getInetAddress()
Return the remote address to which this socket is bound.
Overrides:
getInetAddress in class java.net.Socket

getLocalAddress

public java.net.InetAddress getLocalAddress()
Return the local address to which this socket is bound.
Overrides:
getLocalAddress in class java.net.Socket

getPort

public int getPort()
Return the remote port to which this socket is bound.
Overrides:
getPort in class java.net.Socket

getLocalPort

public int getLocalPort()
Return the local port to which this socket is bound.
Overrides:
getLocalPort in class java.net.Socket

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Return an InputStream from which data on this socket can be read. The returned InputStream is actually a NonblockingInputStream and provides nonblocking semantics.
Overrides:
getInputStream in class java.net.Socket

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Return an OutputStream to which data on this socket can be written. The returned OutputStream is actually a NonblockingOutputStream and provides nonblocking semantics.
Overrides:
getOutputStream in class java.net.Socket

setTcpNoDelay

public void setTcpNoDelay(boolean on)
                   throws java.net.SocketException
Currently unimplemented.
Overrides:
setTcpNoDelay in class java.net.Socket

getTcpNoDelay

public boolean getTcpNoDelay()
                      throws java.net.SocketException
Currently unimplemented.
Overrides:
getTcpNoDelay in class java.net.Socket

setSoLinger

public void setSoLinger(boolean on,
                        int val)
                 throws java.net.SocketException
Currently unimplemented.
Overrides:
setSoLinger in class java.net.Socket

getSoLinger

public int getSoLinger()
                throws java.net.SocketException
Currently unimplemented.
Overrides:
getSoLinger in class java.net.Socket

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Currently unimplemented.
Overrides:
setSoTimeout in class java.net.Socket

getSoTimeout

public int getSoTimeout()
                 throws java.net.SocketException
Currently unimplemented.
Overrides:
getSoTimeout in class java.net.Socket

close

public void close()
           throws java.io.IOException
Closes the socket.
Overrides:
close in class java.net.Socket

toString

public java.lang.String toString()
Overrides:
toString in class java.net.Socket

More information: http://www.cs.berkeley.edu/~mdw/proj/seda/