Build 1.0_r1(from source)

java.net
Class SocketImpl

java.lang.Object
  extended by java.net.SocketImpl
All Implemented Interfaces:
SocketOptions

public abstract class SocketImpl
extends Object
implements SocketOptions

The abstract superclass of all classes that implement streaming sockets. Streaming sockets are wrapped by two classes, ServerSocket and Socket at the server and client end of a connection respectively. At the server there are two types of sockets engaged in communication, the ServerSocket on a well known port (hereafter refered to as the listener) used to establish a connection and the resulting Socket (hereafter refered to as host). Some of the SocketImpl instance variable values must be interpreted in the context of the wrapper. See the getter methods for these details.


Field Summary
protected  InetAddress address
           
protected  FileDescriptor fd
           
protected  int localport
           
(package private)  org.apache.harmony.luni.platform.INetworkSystem netImpl
           
protected  int port
           
protected  int receiveTimeout
           
(package private)  boolean shutdownInput
           
(package private)  boolean streaming
           
 
Fields inherited from interface java.net.SocketOptions
IP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY
 
Constructor Summary
SocketImpl()
          Construct a connection-oriented SocketImpl.
 
Method Summary
protected abstract  void accept(SocketImpl newSocket)
          Accepts a connection on the provided socket.
protected abstract  int available()
          Answer the number of bytes that may be read from this socket without blocking.
protected abstract  void bind(InetAddress address, int port)
          Binds this socket to the specified local host/port.
protected abstract  void close()
          Close the socket.
protected abstract  void connect(InetAddress address, int port)
          Connects this socket to the specified remote host address/port.
protected abstract  void connect(SocketAddress remoteAddr, int timeout)
          Connect the socket to the host/port specified by the SocketAddress with a specified timeout.
protected abstract  void connect(String host, int port)
          Connects this socket to the specified remote host/port.
protected abstract  void create(boolean isStreaming)
          Creates a new unconnected socket.
protected  FileDescriptor getFileDescriptor()
          Answer the socket's file descriptor.
protected  InetAddress getInetAddress()
          Answer the socket's address.
protected abstract  InputStream getInputStream()
          Answer the socket input stream.
protected  int getLocalPort()
          Answer the socket's localport.
abstract  Object getOption(int optID)
          Answer the nominated socket option.
protected abstract  OutputStream getOutputStream()
          Answer the socket output stream.
protected  int getPort()
          Answer the socket's remote port.
protected abstract  void listen(int backlog)
          Listen for connection requests on this stream socket.
(package private)  int read(byte[] buffer, int offset, int count)
          In the IP stack, read at most count bytes off the socket into the buffer, at the offset.
protected abstract  void sendUrgentData(int value)
          Send the single byte of urgent data on the socket.
abstract  void setOption(int optID, Object val)
          Set the nominated socket option.
protected  void setPerformancePreferences(int connectionTime, int latency, int bandwidth)
          Sets performance preference for connectionTime, latency and bandwidth.
protected  void shutdownInput()
          Shutdown the input portion of the socket.
protected  void shutdownOutput()
          Shutdown the output portion of the socket.
protected  boolean supportsUrgentData()
          Answer if the socket supports urgent data.
 String toString()
          Returns a string containing a concise, human-readable description of the socket.
(package private)  int write(byte[] buffer, int offset, int count)
          In the IP stack, write at most count bytes on the socket from the buffer, from the offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

address

protected InetAddress address

port

protected int port

fd

protected FileDescriptor fd

localport

protected int localport

netImpl

org.apache.harmony.luni.platform.INetworkSystem netImpl

receiveTimeout

protected int receiveTimeout

streaming

boolean streaming

shutdownInput

boolean shutdownInput
Constructor Detail

SocketImpl

public SocketImpl()
Construct a connection-oriented SocketImpl.

See Also:
SocketImplFactory
Method Detail

accept

protected abstract void accept(SocketImpl newSocket)
                        throws IOException
Accepts a connection on the provided socket.

Parameters:
newSocket - the socket to accept connections on
Throws:
SocketException - if an error occurs while accepting
IOException

available

protected abstract int available()
                          throws IOException
Answer the number of bytes that may be read from this socket without blocking. This call does not block.

Returns:
int the number of bytes that may be read without blocking
Throws:
SocketException - if an error occurs while peeking
IOException

bind

protected abstract void bind(InetAddress address,
                             int port)
                      throws IOException
Binds this socket to the specified local host/port.

Parameters:
address - the local machine address to bind the socket to
port - the port on the local machine to bind the socket to
Throws:
IOException - if an error occurs while binding

close

protected abstract void close()
                       throws IOException
Close the socket. Usage thereafter is invalid.

Throws:
IOException - if an error occurs while closing

connect

protected abstract void connect(String host,
                                int port)
                         throws IOException
Connects this socket to the specified remote host/port.

Parameters:
host - the remote host to connect to
port - the remote port to connect to
Throws:
IOException - if an error occurs while connecting

connect

protected abstract void connect(InetAddress address,
                                int port)
                         throws IOException
Connects this socket to the specified remote host address/port.

Parameters:
address - the remote host address to connect to
port - the remote port to connect to
Throws:
IOException - if an error occurs while connecting

create

protected abstract void create(boolean isStreaming)
                        throws IOException
Creates a new unconnected socket. If streaming is true, create a stream socket, else a datagram socket.

Parameters:
isStreaming - true, if the socket is type streaming
Throws:
SocketException - if an error occurs while creating the socket
IOException

getFileDescriptor

protected FileDescriptor getFileDescriptor()
Answer the socket's file descriptor.

Returns:
FileDescriptor the socket FileDescriptor

getInetAddress

protected InetAddress getInetAddress()
Answer the socket's address. Refering to the class comment: Listener: The local machines IP address to which this socket is bound. Host: The client machine, to which this socket is connected. Client: The host machine, to which this socket is connected.

Returns:
InetAddress the socket address

getInputStream

protected abstract InputStream getInputStream()
                                       throws IOException
Answer the socket input stream.

Returns:
InputStream an InputStream on the socket
Throws:
IOException - thrown if an error occurs while accessing the stream

getLocalPort

protected int getLocalPort()
Answer the socket's localport. The field is initialized to -1 and upon demand will go to the IP stack to get the bound value. See the class comment for the context of the local port.

Returns:
int the socket localport

getOption

public abstract Object getOption(int optID)
                          throws SocketException
Answer the nominated socket option.

Specified by:
getOption in interface SocketOptions
Parameters:
optID - the socket option to retrieve
Returns:
Object the option value
Throws:
SocketException - thrown if an error occurs while accessing the option

getOutputStream

protected abstract OutputStream getOutputStream()
                                         throws IOException
Answer the socket output stream.

Returns:
OutputStream an OutputStream on the socket
Throws:
IOException - thrown if an error occurs while accessing the stream

getPort

protected int getPort()
Answer the socket's remote port. This value is not meaningful when the socketImpl is wrapped by a ServerSocket.

Returns:
int the remote port the socket is connected to

listen

protected abstract void listen(int backlog)
                        throws IOException
Listen for connection requests on this stream socket. Incoming connection requests are queued, up to the limit nominated by backlog. Additional requests are rejected. listen() may only be invoked on stream sockets.

Parameters:
backlog - the max number of outstanding connection requests
Throws:
IOException - thrown if an error occurs while listening

read

int read(byte[] buffer,
         int offset,
         int count)
   throws IOException
In the IP stack, read at most count bytes off the socket into the buffer, at the offset. If the timeout is zero, block indefinitely waiting for data, otherwise wait the specified period (in milliseconds).

Parameters:
buffer - the buffer to read into
offset - the offset into the buffer
count - the max number of bytes to read
Returns:
int the actual number of bytes read
Throws:
IOException - thrown if an error occurs while reading

setOption

public abstract void setOption(int optID,
                               Object val)
                        throws SocketException
Set the nominated socket option.

Specified by:
setOption in interface SocketOptions
Parameters:
optID - the socket option to set
val - the option value
Throws:
SocketException - thrown if an error occurs while setting the option

toString

public String toString()
Returns a string containing a concise, human-readable description of the socket.

Overrides:
toString in class Object
Returns:
String the description

write

int write(byte[] buffer,
          int offset,
          int count)
    throws IOException
In the IP stack, write at most count bytes on the socket from the buffer, from the offset.

Parameters:
buffer - the buffer to read into
offset - the offset into the buffer
count - the number of bytes to write
Returns:
int the actual number of bytes written
Throws:
IOException - thrown if an error occurs while writing

shutdownInput

protected void shutdownInput()
                      throws IOException
Shutdown the input portion of the socket. The default implementation always throws an IOException to indicate that the subclass should have overridden this method.

Throws:
IOException - Always. Designed to be subclassed.

shutdownOutput

protected void shutdownOutput()
                       throws IOException
Shutdown the output portion of the socket. The default implementation always throws an IOException to indicate that the subclass should have overridden this method.

Throws:
IOException - Always. Designed to be subclassed.

connect

protected abstract void connect(SocketAddress remoteAddr,
                                int timeout)
                         throws IOException
Connect the socket to the host/port specified by the SocketAddress with a specified timeout.

Parameters:
remoteAddr - the remote machine address and port to connect to
timeout - the millisecond timeout value, the connect will block indefinitely for a zero value.
Throws:
IOException - if a problem occurs during the connect

supportsUrgentData

protected boolean supportsUrgentData()
Answer if the socket supports urgent data. Subclasses should override this method.

Returns:
false, subclasses must override

sendUrgentData

protected abstract void sendUrgentData(int value)
                                throws IOException
Send the single byte of urgent data on the socket.

Parameters:
value - the byte of urgent data
Throws:
IOException - when an error occurs sending urgent data

setPerformancePreferences

protected void setPerformancePreferences(int connectionTime,
                                         int latency,
                                         int bandwidth)
Sets performance preference for connectionTime, latency and bandwidth. Does nothing by default.

Parameters:
connectionTime - the importance of connect time
latency - the importance of latency
bandwidth - the importance of bandwidth

Build 1.0_r1(from source)

Please submit a feedback, bug or feature