Class PlainSocketImpl
- All Implemented Interfaces:
SocketOptions
- Direct Known Subclasses:
PlainServerSocketImpl
public class PlainSocketImpl extends SocketImpl
-
Field Summary
Fields inherited from class java.net.SocketImpl
address, fd, localport, portFields 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
Constructors Constructor Description PlainSocketImpl()PlainSocketImpl(FileDescriptor fd)PlainSocketImpl(FileDescriptor fd, int localport, InetAddress addr, int port)PlainSocketImpl(Proxy proxy) -
Method Summary
Modifier and Type Method Description protected voidaccept(SocketImpl newImpl)Waits for an incoming request and blocks until the connection is opened on the given socket.protected intavailable()Returns the available number of bytes which are readable from this socket without blocking.protected voidbind(InetAddress address, int port)Binds this socket to the specified local host address and port number.protected voidclose()Closes this socket.protected voidconnect(String aHost, int aPort)Connects this socket to the specified remote host and port number.protected voidconnect(InetAddress anAddr, int aPort)Connects this socket to the specified remote host address and port number.protected voidconnect(SocketAddress remoteAddr, int timeout)Connects this socket to the remote host address and port number specified by theSocketAddressobject with the given timeout.protected voidcreate(boolean streaming)Creates a new unconnected socket.protected voidfinalize()Invoked when the garbage collector has detected that this instance is no longer reachable.protected InputStreamgetInputStream()Gets the input stream of this socket.ObjectgetOption(int option)Gets the value for the specified socket option.protected OutputStreamgetOutputStream()Gets the output stream of this socket.voidinitLocalPort(int localPort)voidinitRemoteAddressAndPort(InetAddress remoteAddress, int remotePort)protected voidlisten(int backlog)Listens for connection requests on this streaming socket.protected voidsendUrgentData(int value)Sends the single byte of urgent data on the socket.voidsetOption(int option, Object value)Sets the value of the specified socket option.protected voidshutdownInput()Shutdown the input portion of the socket.protected voidshutdownOutput()Shutdown the output portion of the socket.voidsocksAccept()Perform an accept for a SOCKS bind.protected booleansupportsUrgentData()Returns whether the socket supports urgent data or not.Methods inherited from class java.net.SocketImpl
getFD$, getFileDescriptor, getInetAddress, getLocalPort, getPort, setPerformancePreferences, toString
-
Constructor Details
-
PlainSocketImpl
-
PlainSocketImpl
-
PlainSocketImpl
public PlainSocketImpl() -
PlainSocketImpl
-
-
Method Details
-
accept
Description copied from class:SocketImplWaits for an incoming request and blocks until the connection is opened on the given socket.- Specified by:
acceptin classSocketImpl- Parameters:
newImpl- the socket to accept connections on.- Throws:
IOException- if an error occurs while accepting a new connection.
-
initLocalPort
public void initLocalPort(int localPort) -
initRemoteAddressAndPort
-
available
Description copied from class:SocketImplReturns the available number of bytes which are readable from this socket without blocking.- Specified by:
availablein classSocketImpl- Returns:
- the number of bytes that may be read without blocking.
- Throws:
IOException- if an error occurs while reading the number of bytes.
-
bind
Description copied from class:SocketImplBinds this socket to the specified local host address and port number.- Specified by:
bindin classSocketImpl- Parameters:
address- the local machine address to bind this socket to.port- the port on the local machine to bind this socket to.- Throws:
IOException- if an error occurs while binding this socket.
-
close
Description copied from class:SocketImplCloses this socket. This makes later access invalid.- Specified by:
closein classSocketImpl- Throws:
IOException- if an error occurs while closing this socket.
-
connect
Description copied from class:SocketImplConnects this socket to the specified remote host and port number.- Specified by:
connectin classSocketImpl- Parameters:
aHost- the remote host this socket has to be connected to.aPort- the remote port on which this socket has to be connected.- Throws:
IOException- if an error occurs while connecting to the remote host.
-
connect
Description copied from class:SocketImplConnects this socket to the specified remote host address and port number.- Specified by:
connectin classSocketImpl- Parameters:
anAddr- the remote host address this socket has to be connected to.aPort- the remote port on which this socket has to be connected.- Throws:
IOException- if an error occurs while connecting to the remote host.
-
create
Description copied from class:SocketImplCreates a new unconnected socket. The argumentisStreamingdefines whether the new socket is a streaming or a datagram socket.- Specified by:
createin classSocketImpl- Parameters:
streaming- defines whether the type of the new socket is streaming or datagram.- Throws:
IOException- if an error occurs while creating the socket.
-
finalize
Description copied from class:ObjectInvoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.Note that objects that override
finalizeare 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 explicitclosemethod (and implementCloseable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like aBigIntegerwhere 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
ReferenceQueueand 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.
-
getInputStream
Description copied from class:SocketImplGets the input stream of this socket.- Specified by:
getInputStreamin classSocketImpl- Returns:
- the input stream of this socket.
- Throws:
IOException- if an error occurs while accessing the input stream.
-
getOption
Description copied from interface:SocketOptionsGets the value for the specified socket option.- Parameters:
option- the option identifier.- Returns:
- the option value.
- Throws:
SocketException- if an error occurs reading the option value.
-
getOutputStream
Description copied from class:SocketImplGets the output stream of this socket.- Specified by:
getOutputStreamin classSocketImpl- Returns:
- the output stream of this socket.
- Throws:
IOException- if an error occurs while accessing the output stream.
-
listen
Description copied from class:SocketImplListens for connection requests on this streaming socket. Incoming connection requests are queued up to the limit specified bybacklog. Additional requests are rejected. This method may only be invoked on stream sockets.- Specified by:
listenin classSocketImpl- Parameters:
backlog- the maximum number of outstanding connection requests.- Throws:
IOException- if an error occurs while listening.
-
setOption
Description copied from interface:SocketOptionsSets the value of the specified socket option.- Parameters:
option- the option identifier.value- the value to be set for the option.- Throws:
SocketException- if an error occurs setting the option value.
-
socksAccept
Perform an accept for a SOCKS bind.- Throws:
IOException
-
shutdownInput
Shutdown the input portion of the socket.- Overrides:
shutdownInputin classSocketImpl- Throws:
IOException- always because this method should be overridden.
-
shutdownOutput
Shutdown the output portion of the socket.- Overrides:
shutdownOutputin classSocketImpl- Throws:
IOException- always because this method should be overridden.
-
connect
Description copied from class:SocketImplConnects this socket to the remote host address and port number specified by theSocketAddressobject with the given timeout. This method will block indefinitely if the timeout is set to zero.- Specified by:
connectin classSocketImpl- Parameters:
remoteAddr- the remote host address and port number to connect to.timeout- the timeout value in milliseconds.- Throws:
IOException- if an error occurs while connecting.
-
supportsUrgentData
protected boolean supportsUrgentData()Description copied from class:SocketImplReturns whether the socket supports urgent data or not. Subclasses should override this method.- Overrides:
supportsUrgentDatain classSocketImpl- Returns:
falsebecause subclasses must override this method.
-
sendUrgentData
Description copied from class:SocketImplSends the single byte of urgent data on the socket.- Specified by:
sendUrgentDatain classSocketImpl- Parameters:
value- the byte of urgent data.- Throws:
IOException- if an error occurs sending urgent data.
-