public class PlainSocketImpl extends SocketImpl
address, fd, localport, port
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 and Description |
---|
PlainSocketImpl() |
PlainSocketImpl(FileDescriptor fd) |
PlainSocketImpl(FileDescriptor fd,
int localport,
InetAddress addr,
int port) |
PlainSocketImpl(Proxy proxy) |
Modifier and Type | Method and Description |
---|---|
protected void |
accept(SocketImpl newImpl)
Waits for an incoming request and blocks until the connection is opened
on the given socket.
|
protected int |
available()
Returns the available number of bytes which are readable from this socket
without blocking.
|
protected void |
bind(InetAddress address,
int port)
Binds this socket to the specified local host address and port number.
|
protected void |
close()
Closes this socket.
|
protected void |
connect(InetAddress anAddr,
int aPort)
Connects this socket to the specified remote host address and port
number.
|
protected void |
connect(SocketAddress remoteAddr,
int timeout)
Connects this socket to the remote host address and port number specified
by the
SocketAddress object with the given timeout. |
protected void |
connect(String aHost,
int aPort)
Connects this socket to the specified remote host and port number.
|
protected void |
create(boolean streaming)
Creates a new unconnected socket.
|
protected void |
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
protected InputStream |
getInputStream()
Gets the input stream of this socket.
|
Object |
getOption(int option)
Gets the value for the specified socket option.
|
protected OutputStream |
getOutputStream()
Gets the output stream of this socket.
|
void |
initLocalPort(int localPort) |
void |
initRemoteAddressAndPort(InetAddress remoteAddress,
int remotePort) |
protected void |
listen(int backlog)
Listens for connection requests on this streaming socket.
|
protected void |
sendUrgentData(int value)
Sends the single byte of urgent data on the socket.
|
void |
setOption(int option,
Object value)
Sets the value of the specified socket option.
|
protected void |
shutdownInput()
Shutdown the input portion of the socket.
|
protected void |
shutdownOutput()
Shutdown the output portion of the socket.
|
void |
socksAccept()
Perform an accept for a SOCKS bind.
|
protected boolean |
supportsUrgentData()
Returns whether the socket supports urgent data or not.
|
getFD$, getFileDescriptor, getInetAddress, getLocalPort, getPort, setPerformancePreferences, toString
public PlainSocketImpl(FileDescriptor fd)
public PlainSocketImpl(Proxy proxy)
public PlainSocketImpl()
public PlainSocketImpl(FileDescriptor fd, int localport, InetAddress addr, int port)
protected void accept(SocketImpl newImpl) throws IOException
SocketImpl
accept
in class SocketImpl
newImpl
- the socket to accept connections on.IOException
- if an error occurs while accepting a new connection.public void initLocalPort(int localPort)
public void initRemoteAddressAndPort(InetAddress remoteAddress, int remotePort)
protected int available() throws IOException
SocketImpl
available
in class SocketImpl
IOException
- if an error occurs while reading the number of bytes.protected void bind(InetAddress address, int port) throws IOException
SocketImpl
bind
in class SocketImpl
address
- the local machine address to bind this socket to.port
- the port on the local machine to bind this socket to.IOException
- if an error occurs while binding this socket.protected void close() throws IOException
SocketImpl
close
in class SocketImpl
IOException
- if an error occurs while closing this socket.protected void connect(String aHost, int aPort) throws IOException
SocketImpl
connect
in class SocketImpl
aHost
- the remote host this socket has to be connected to.aPort
- the remote port on which this socket has to be connected.IOException
- if an error occurs while connecting to the remote host.protected void connect(InetAddress anAddr, int aPort) throws IOException
SocketImpl
connect
in class SocketImpl
anAddr
- the remote host address this socket has to be connected to.aPort
- the remote port on which this socket has to be connected.IOException
- if an error occurs while connecting to the remote host.protected void create(boolean streaming) throws IOException
SocketImpl
isStreaming
defines whether the new socket is a streaming or a datagram socket.create
in class SocketImpl
streaming
- defines whether the type of the new socket is streaming or
datagram.IOException
- if an error occurs while creating the socket.protected void finalize() throws Throwable
Object
Note that objects that override finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
protected InputStream getInputStream() throws IOException
SocketImpl
getInputStream
in class SocketImpl
IOException
- if an error occurs while accessing the input stream.public Object getOption(int option) throws SocketException
SocketOptions
option
- the option identifier.SocketException
- if an error occurs reading the option value.protected OutputStream getOutputStream() throws IOException
SocketImpl
getOutputStream
in class SocketImpl
IOException
- if an error occurs while accessing the output stream.protected void listen(int backlog) throws IOException
SocketImpl
backlog
. Additional requests are rejected. This method
may only be invoked on stream sockets.listen
in class SocketImpl
backlog
- the maximum number of outstanding connection requests.IOException
- if an error occurs while listening.public void setOption(int option, Object value) throws SocketException
SocketOptions
option
- the option identifier.value
- the value to be set for the option.SocketException
- if an error occurs setting the option value.public void socksAccept() throws IOException
IOException
protected void shutdownInput() throws IOException
shutdownInput
in class SocketImpl
IOException
- always because this method should be overridden.protected void shutdownOutput() throws IOException
shutdownOutput
in class SocketImpl
IOException
- always because this method should be overridden.protected void connect(SocketAddress remoteAddr, int timeout) throws IOException
SocketImpl
SocketAddress
object with the given timeout. This method
will block indefinitely if the timeout is set to zero.connect
in class SocketImpl
remoteAddr
- the remote host address and port number to connect to.timeout
- the timeout value in milliseconds.IOException
- if an error occurs while connecting.protected boolean supportsUrgentData()
SocketImpl
supportsUrgentData
in class SocketImpl
false
because subclasses must override this method.protected void sendUrgentData(int value) throws IOException
SocketImpl
sendUrgentData
in class SocketImpl
value
- the byte of urgent data.IOException
- if an error occurs sending urgent data.