コード例 #1
0
 /**
  * Creates a new socket that is not bound to any local address/port and is not connected to any
  * remote address/port. The stream parameter will be ignored since PlainSocketImpl always is a
  * stream socket. Datagram sockets are handled by PlainDatagramSocketImpl.
  *
  * @param stream <code>true</code> for stream sockets, <code>false</code> for datagram sockets
  */
 protected synchronized void create(boolean stream) throws IOException {
   channel = new SocketChannelImpl(false);
   VMChannel vmchannel = channel.getVMChannel();
   vmchannel.initSocket(stream);
   channel.configureBlocking(true);
   impl.getState().setChannelFD(vmchannel.getState());
 }
コード例 #2
0
  /**
   * Returns the current setting of the specified option. The Object returned will be an Integer for
   * options that have integer values. The option_id is one of the defined constants in this
   * interface.
   *
   * @param optionId the option identifier
   * @return the current value of the option
   * @throws SocketException if an error occurs
   */
  public Object getOption(int optionId) throws SocketException {
    if (optionId == SO_BINDADDR) {
      try {
        return channel.getVMChannel().getLocalAddress().getAddress();
      } catch (IOException ioe) {
        SocketException se = new SocketException();
        se.initCause(ioe);
        throw se;
      }
    }

    // This filters options which are invalid for TCP.
    switch (optionId) {
      case SO_LINGER:
      case IP_MULTICAST_LOOP:
      case SO_BROADCAST:
      case SO_KEEPALIVE:
      case SO_OOBINLINE:
      case TCP_NODELAY:
      case IP_TOS:
      case SO_RCVBUF:
      case SO_SNDBUF:
      case SO_TIMEOUT:
      case SO_REUSEADDR:
        return impl.getOption(optionId);
      default:
        throw new SocketException("Unrecognized TCP option: " + optionId);
    }
  }
コード例 #3
0
 /**
  * Sets the specified option on a socket to the passed in object. For options that take an integer
  * argument, the passed in object is an Integer. The option_id parameter is one of the defined
  * constants in this interface.
  *
  * @param optionId The identifier of the option
  * @param value The value to set the option to
  * @throws SocketException if an error occurs
  */
 public void setOption(int optionId, Object value) throws SocketException {
   switch (optionId) {
     case SO_LINGER:
     case IP_MULTICAST_LOOP:
     case SO_BROADCAST:
     case SO_KEEPALIVE:
     case SO_OOBINLINE:
     case TCP_NODELAY:
     case IP_TOS:
     case SO_RCVBUF:
     case SO_SNDBUF:
     case SO_TIMEOUT:
     case SO_REUSEADDR:
       impl.setOption(optionId, value);
       return;
     default:
       throw new SocketException("Unrecognized TCP option: " + optionId);
   }
 }
コード例 #4
0
 public void sendUrgentData(int data) throws IOException {
   impl.sendUrgentData(data);
 }
コード例 #5
0
  /**
   * Closes the socket. This will cause any InputStream or OutputStream objects for this Socket to
   * be closed as well.
   *
   * <p>Note that if the SO_LINGER option is set on this socket, then the operation could block.
   *
   * @throws IOException if an error occurs
   */
  protected void close() throws IOException {
    if (impl.getState().isValid()) impl.close();

    address = null;
    port = -1;
  }
コード例 #6
0
 /**
  * Starts listening for connections on a socket. The queuelen parameter is how many pending
  * connections will queue up waiting to be serviced before being accept'ed. If the queue of
  * pending requests exceeds this number, additional connections will be refused.
  *
  * @param queuelen The length of the pending connection queue
  * @throws IOException If an error occurs
  */
 protected synchronized void listen(int queuelen) throws IOException {
   impl.listen(queuelen);
 }
コード例 #7
0
 /**
  * Binds to the specified port on the specified addr. Note that this addr must represent a local
  * IP address. **** How bind to INADDR_ANY? ****
  *
  * @param addr the address to bind to
  * @param port the port number to bind to
  * @throws IOException if an error occurs
  */
 protected synchronized void bind(InetAddress addr, int port) throws IOException {
   if (channel == null) create(true);
   impl.bind(new InetSocketAddress(addr, port));
   localport = channel.getVMChannel().getLocalAddress().getPort();
 }
コード例 #8
0
 public void shutdownOutput() throws IOException {
   impl.shutdownOutput();
 }