Class PlainSocketImpl
- java.lang.Object
-
- java.net.SocketImpl
-
- java.net.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, 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_REUSEPORT, 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
All Methods Instance Methods Concrete Methods 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.protected voidlisten(int backlog)Listens for connection requests on this streaming socket.voidonBind(InetAddress localAddress, int localPort)Initialize the bind() state.voidonClose()Initialize the close() state.voidonConnect(InetAddress remoteAddress, int remotePort)Initialize the connect() state.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 Detail
-
PlainSocketImpl
public PlainSocketImpl(FileDescriptor fd)
-
PlainSocketImpl
public PlainSocketImpl(Proxy proxy)
-
PlainSocketImpl
public PlainSocketImpl()
-
PlainSocketImpl
public PlainSocketImpl(FileDescriptor fd, int localport, InetAddress addr, int port)
-
-
Method Detail
-
accept
protected void accept(SocketImpl newImpl) throws IOException
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.
-
available
protected int available() throws IOExceptionDescription 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
protected void bind(InetAddress address, int port) throws IOException
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.
-
onBind
public void onBind(InetAddress localAddress, int localPort)
Description copied from class:SocketImplInitialize the bind() state.- Overrides:
onBindin classSocketImpl
-
close
protected void close() throws IOExceptionDescription 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.
-
onClose
public void onClose()
Description copied from class:SocketImplInitialize the close() state.- Overrides:
onClosein classSocketImpl
-
connect
protected void connect(String aHost, int aPort) throws IOException
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
protected void connect(InetAddress anAddr, int aPort) throws IOException
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.
-
onConnect
public void onConnect(InetAddress remoteAddress, int remotePort)
Description copied from class:SocketImplInitialize the connect() state.- Overrides:
onConnectin classSocketImpl
-
create
protected void create(boolean streaming) throws IOExceptionDescription 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
protected void finalize() throws ThrowableDescription 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
protected InputStream getInputStream() throws IOException
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
public Object getOption(int option) throws SocketException
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
protected OutputStream getOutputStream() throws IOException
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
protected void listen(int backlog) throws IOExceptionDescription 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
public void setOption(int option, Object value) throws SocketExceptionDescription 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
public void socksAccept() throws IOExceptionPerform an accept for a SOCKS bind.- Throws:
IOException
-
shutdownInput
protected void shutdownInput() throws IOExceptionShutdown the input portion of the socket.- Overrides:
shutdownInputin classSocketImpl- Throws:
IOException- always because this method should be overridden.
-
shutdownOutput
protected void shutdownOutput() throws IOExceptionShutdown the output portion of the socket.- Overrides:
shutdownOutputin classSocketImpl- Throws:
IOException- always because this method should be overridden.
-
connect
protected void connect(SocketAddress remoteAddr, int timeout) throws IOException
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
protected void sendUrgentData(int value) throws IOExceptionDescription 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.
-
-