Package java.net

Class PlainSocketImpl

java.lang.Object
java.net.SocketImpl
java.net.PlainSocketImpl
All Implemented Interfaces:
SocketOptions
Direct Known Subclasses:
PlainServerSocketImpl

public class PlainSocketImpl
extends SocketImpl
  • Constructor Details

    • 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 Details

    • accept

      protected void accept​(SocketImpl newImpl) throws IOException
      Description copied from class: SocketImpl
      Waits for an incoming request and blocks until the connection is opened on the given socket.
      Specified by:
      accept in class SocketImpl
      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

      public void initRemoteAddressAndPort​(InetAddress remoteAddress, int remotePort)
    • available

      protected int available() throws IOException
      Description copied from class: SocketImpl
      Returns the available number of bytes which are readable from this socket without blocking.
      Specified by:
      available in class SocketImpl
      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: SocketImpl
      Binds this socket to the specified local host address and port number.
      Specified by:
      bind in class SocketImpl
      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

      protected void close() throws IOException
      Description copied from class: SocketImpl
      Closes this socket. This makes later access invalid.
      Specified by:
      close in class SocketImpl
      Throws:
      IOException - if an error occurs while closing this socket.
    • connect

      protected void connect​(String aHost, int aPort) throws IOException
      Description copied from class: SocketImpl
      Connects this socket to the specified remote host and port number.
      Specified by:
      connect in class SocketImpl
      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: SocketImpl
      Connects this socket to the specified remote host address and port number.
      Specified by:
      connect in class SocketImpl
      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

      protected void create​(boolean streaming) throws IOException
      Description copied from class: SocketImpl
      Creates a new unconnected socket. The argument isStreaming defines whether the new socket is a streaming or a datagram socket.
      Specified by:
      create in class SocketImpl
      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 Throwable
      Description copied from class: Object
      Invoked 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 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.

      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • getInputStream

      protected InputStream getInputStream() throws IOException
      Description copied from class: SocketImpl
      Gets the input stream of this socket.
      Specified by:
      getInputStream in class SocketImpl
      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: SocketOptions
      Gets 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: SocketImpl
      Gets the output stream of this socket.
      Specified by:
      getOutputStream in class SocketImpl
      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 IOException
      Description copied from class: SocketImpl
      Listens for connection requests on this streaming socket. Incoming connection requests are queued up to the limit specified by backlog. Additional requests are rejected. This method may only be invoked on stream sockets.
      Specified by:
      listen in class SocketImpl
      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 SocketException
      Description copied from interface: SocketOptions
      Sets 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 IOException
      Perform an accept for a SOCKS bind.
      Throws:
      IOException
    • shutdownInput

      protected void shutdownInput() throws IOException
      Shutdown the input portion of the socket.
      Overrides:
      shutdownInput in class SocketImpl
      Throws:
      IOException - always because this method should be overridden.
    • shutdownOutput

      protected void shutdownOutput() throws IOException
      Shutdown the output portion of the socket.
      Overrides:
      shutdownOutput in class SocketImpl
      Throws:
      IOException - always because this method should be overridden.
    • connect

      protected void connect​(SocketAddress remoteAddr, int timeout) throws IOException
      Description copied from class: SocketImpl
      Connects this socket to the remote host address and port number specified by the SocketAddress object with the given timeout. This method will block indefinitely if the timeout is set to zero.
      Specified by:
      connect in class SocketImpl
      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: SocketImpl
      Returns whether the socket supports urgent data or not. Subclasses should override this method.
      Overrides:
      supportsUrgentData in class SocketImpl
      Returns:
      false because subclasses must override this method.
    • sendUrgentData

      protected void sendUrgentData​(int value) throws IOException
      Description copied from class: SocketImpl
      Sends the single byte of urgent data on the socket.
      Specified by:
      sendUrgentData in class SocketImpl
      Parameters:
      value - the byte of urgent data.
      Throws:
      IOException - if an error occurs sending urgent data.