public class PlainSocketImpl extends SocketImpl
address, fd, localport, portIP_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_REUSEPORT, 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.
|
protected void |
listen(int backlog)
Listens for connection requests on this streaming socket.
|
void |
onBind(InetAddress localAddress,
int localPort)
Initialize the bind() state.
|
void |
onClose()
Initialize the close() state.
|
void |
onConnect(InetAddress remoteAddress,
int remotePort)
Initialize the connect() state.
|
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, toStringpublic 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
SocketImplaccept in class SocketImplnewImpl - the socket to accept connections on.IOException - if an error occurs while accepting a new connection.protected int available()
throws IOException
SocketImplavailable in class SocketImplIOException - if an error occurs while reading the number of bytes.protected void bind(InetAddress address, int port) throws IOException
SocketImplbind in class SocketImpladdress - 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.public void onBind(InetAddress localAddress, int localPort)
SocketImplonBind in class SocketImplprotected void close()
throws IOException
SocketImplclose in class SocketImplIOException - if an error occurs while closing this socket.public void onClose()
SocketImplonClose in class SocketImplprotected void connect(String aHost, int aPort) throws IOException
SocketImplconnect in class SocketImplaHost - 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
SocketImplconnect in class SocketImplanAddr - 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.public void onConnect(InetAddress remoteAddress, int remotePort)
SocketImplonConnect in class SocketImplprotected void create(boolean streaming)
throws IOException
SocketImplisStreaming
defines whether the new socket is a streaming or a datagram socket.create in class SocketImplstreaming - 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
ObjectNote 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
SocketImplgetInputStream in class SocketImplIOException - if an error occurs while accessing the input stream.public Object getOption(int option) throws SocketException
SocketOptionsoption - the option identifier.SocketException - if an error occurs reading the option value.protected OutputStream getOutputStream() throws IOException
SocketImplgetOutputStream in class SocketImplIOException - if an error occurs while accessing the output stream.protected void listen(int backlog)
throws IOException
SocketImplbacklog. Additional requests are rejected. This method
may only be invoked on stream sockets.listen in class SocketImplbacklog - the maximum number of outstanding connection requests.IOException - if an error occurs while listening.public void setOption(int option,
Object value)
throws SocketException
SocketOptionsoption - 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
IOExceptionprotected void shutdownInput()
throws IOException
shutdownInput in class SocketImplIOException - always because this method should be overridden.protected void shutdownOutput()
throws IOException
shutdownOutput in class SocketImplIOException - always because this method should be overridden.protected void connect(SocketAddress remoteAddr, int timeout) throws IOException
SocketImplSocketAddress object with the given timeout. This method
will block indefinitely if the timeout is set to zero.connect in class SocketImplremoteAddr - 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()
SocketImplsupportsUrgentData in class SocketImplfalse because subclasses must override this method.protected void sendUrgentData(int value)
throws IOException
SocketImplsendUrgentData in class SocketImplvalue - the byte of urgent data.IOException - if an error occurs sending urgent data.