gnu.java.net

Class PlainSocketImpl

Implemented Interfaces:
SocketOptions
Known Direct Subclasses:
NIOSocketImpl

public final class PlainSocketImpl
extends SocketImpl

Unless the application installs its own SocketImplFactory, this is the default socket implemetation that will be used. It simply uses a combination of Java and native routines to implement standard BSD style sockets of family AF_INET and types SOCK_STREAM and SOCK_DGRAM

Field Summary

Fields inherited from class java.net.SocketImpl

address, fd, localport, port

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

PlainSocketImpl()
Default do nothing constructor

Method Summary

protected void
accept(SocketImpl impl)
Accepts a new connection on this socket and returns in in the passed in SocketImpl.
protected int
available()
Returns the number of bytes that the caller can read from this socket without blocking.
protected void
bind(InetAddress host, int port)
Binds to the specified port on the specified addr.
protected void
close()
Closes the socket.
protected void
connect(String host, int port)
Connects to the remote hostname and port specified as arguments.
protected void
connect(InetAddress host, int port)
Connects to the remote address and port specified as arguments.
protected void
connect(SocketAddress addr, int timeout)
Connects to the remote socket address with a specified timeout.
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.
protected void
finalize()
protected InputStream
getInputStream()
Returns an InputStream object for reading from this socket.
InetSocketAddress
getLocalAddress()
int
getNativeFD()
Object
getOption(int optID)
Returns the current setting of the specified option.
protected OutputStream
getOutputStream()
Returns an OutputStream object for writing to this socket.
boolean
isInChannelOperation()
Indicates whether we should ignore whether any associated channel is set to non-blocking mode.
protected void
listen(int queuelen)
Starts listening for connections on a socket.
protected void
sendUrgentData(int data)
void
setInChannelOperation(boolean b)
Sets our indicator of whether an I/O operation is being initiated by a channel.
void
setOption(int optID, Object value)
Sets the specified option on a socket to the passed in object.
void
shutdownInput()
Flushes the input stream and closes it.
void
shutdownOutput()
Flushes the output stream and closes it.

Methods inherited from class java.net.SocketImpl

accept, available, bind, close, connect, connect, connect, create, getFileDescriptor, getInetAddress, getInputStream, getLocalPort, getOutputStream, getPort, listen, sendUrgentData, shutdownInput, shutdownOutput, supportsUrgentData, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

PlainSocketImpl

public PlainSocketImpl()
Default do nothing constructor

Method Details

accept

protected void accept(SocketImpl impl)
            throws IOException
Accepts a new connection on this socket and returns in in the passed in SocketImpl.
Overrides:
accept in interface SocketImpl
Parameters:
impl - The SocketImpl object to accept this connection.

available

protected int available()
            throws IOException
Returns the number of bytes that the caller can read from this socket without blocking.
Overrides:
available in interface SocketImpl
Returns:
The number of readable bytes before blocking
Throws:
IOException - If an error occurs

bind

protected void bind(InetAddress host,
                    int port)
            throws IOException
Binds to the specified port on the specified addr. Note that this addr must represent a local IP address. **** How bind to INADDR_ANY? ****
Overrides:
bind in interface SocketImpl
Parameters:
port - The port number to bind to
Throws:
IOException - If an error occurs

close

protected void close()
            throws 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.

Overrides:
close in interface SocketImpl
Throws:
IOException - If an error occurs

connect

protected void connect(String host,
                       int port)
            throws IOException
Connects to the remote hostname and port specified as arguments.
Overrides:
connect in interface SocketImpl
Parameters:
port - The remote port to connect to
Throws:
IOException - If an error occurs

connect

protected void connect(InetAddress host,
                       int port)
            throws IOException
Connects to the remote address and port specified as arguments.
Overrides:
connect in interface SocketImpl
Parameters:
port - The remote port to connect to
Throws:
IOException - If an error occurs

connect

protected void connect(SocketAddress addr,
                       int timeout)
            throws IOException
Connects to the remote socket address with a specified timeout.
Overrides:
connect in interface SocketImpl
Parameters:
timeout - The timeout to use for this connect, 0 means infinite.
Throws:
IOException - If an error occurs

create

public void create(boolean stream)
            throws 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.
Overrides:
create in interface SocketImpl
Parameters:
stream - true for a stream socket, false for a datagram socket

finalize

protected void finalize()
            throws Throwable
Overrides:
finalize in interface Object

getInputStream

protected InputStream getInputStream()
            throws IOException
Returns an InputStream object for reading from this socket. This will be an instance of SocketInputStream.
Overrides:
getInputStream in interface SocketImpl
Returns:
An input stream attached to the socket.
Throws:
IOException - If an error occurs

getLocalAddress

public InetSocketAddress getLocalAddress()

getNativeFD

public int getNativeFD()

getOption

public Object getOption(int optID)
            throws 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.
Specified by:
getOption in interface SocketOptions
Parameters:
Returns:
The current value of the option
Throws:
SocketException - If an error occurs

getOutputStream

protected OutputStream getOutputStream()
            throws IOException
Returns an OutputStream object for writing to this socket. This will be an instance of SocketOutputStream.
Overrides:
getOutputStream in interface SocketImpl
Returns:
An output stream attached to the socket.
Throws:
IOException - If an error occurs

isInChannelOperation

public final boolean isInChannelOperation()
Indicates whether we should ignore whether any associated channel is set to non-blocking mode. Certain operations throw an IllegalBlockingModeException if the associated channel is in non-blocking mode, except if the operation is invoked by the channel itself.

listen

protected void listen(int queuelen)
            throws 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.
Overrides:
listen in interface SocketImpl
Parameters:
queuelen - The length of the pending connection queue
Throws:
IOException - If an error occurs

sendUrgentData

protected void sendUrgentData(int data)
            throws IOException
Overrides:
sendUrgentData in interface SocketImpl

setInChannelOperation

public final void setInChannelOperation(boolean b)
Sets our indicator of whether an I/O operation is being initiated by a channel.

setOption

public void setOption(int optID,
                      Object value)
            throws 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.
Specified by:
setOption in interface SocketOptions
Parameters:
Throws:
SocketException - If an error occurs

shutdownInput

public void shutdownInput()
            throws IOException
Flushes the input stream and closes it. If you read from the input stream after calling this method a IOException will be thrown.
Overrides:
shutdownInput in interface SocketImpl
Throws:
IOException - if an error occurs

shutdownOutput

public void shutdownOutput()
            throws IOException
Flushes the output stream and closes it. If you write to the output stream after calling this method a IOException will be thrown.
Overrides:
shutdownOutput in interface SocketImpl
Throws:
IOException - if an error occurs

PlainSocketImpl.java -- Default socket implementation Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.