Ejemplo n.º 1
0
  /**
   * Sets the value of the SO_LINGER option on the socket. If the SO_LINGER option is set on a
   * socket and there is still data waiting to be sent when the socket is closed, then the close
   * operation will block until either that data is delivered or until the timeout period expires.
   * The linger interval is specified in hundreths of a second (platform specific?)
   *
   * @param on true to enable SO_LINGER, false to disable
   * @param linger The SO_LINGER timeout in hundreths of a second or -1 if SO_LINGER not set.
   * @exception SocketException If an error occurs or Socket not connected
   * @exception IllegalArgumentException If linger is negative
   * @since 1.1
   */
  public void setSoLinger(boolean on, int linger) throws SocketException {
    if (impl == null) throw new SocketException("No socket created");

    if (on == true) {
      if (linger < 0) throw new IllegalArgumentException("SO_LINGER must be >= 0");

      if (linger > 65535) linger = 65535;

      impl.setOption(SocketOptions.SO_LINGER, new Integer(linger));
    } else {
      impl.setOption(SocketOptions.SO_LINGER, new Boolean(false));
    }
  }
Ejemplo n.º 2
0
  /**
   * Sets the traffic class value
   *
   * @param tc The traffic class
   * @exception SocketException If an error occurs
   * @exception IllegalArgumentException If tc value is illegal
   * @see Socket:getTrafficClass
   * @since 1.4
   */
  public void setTrafficClass(int tc) throws SocketException {
    if (impl == null) throw new SocketException("Cannot initialize Socket implementation");

    if (tc < 0 || tc > 255) throw new IllegalArgumentException();

    impl.setOption(SocketOptions.IP_TOS, new Integer(tc));
  }
Ejemplo n.º 3
0
  /**
   * This method sets the value for the system level socket option SO_RCVBUF to the specified value.
   * Note that valid values for this option are specific to a given operating system.
   *
   * @param size The new receive buffer size.
   * @exception SocketException If an error occurs or Socket is not connected
   * @exception IllegalArgumentException If size is 0 or negative
   * @since 1.2
   */
  public void setReceiveBufferSize(int size) throws SocketException {
    if (impl == null) throw new SocketException("Not connected");

    if (size <= 0) throw new IllegalArgumentException("SO_RCVBUF value must be > 0");

    impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
  }
Ejemplo n.º 4
0
  /**
   * Sets the value of the SO_TIMEOUT option on the socket. If this value is set, and an read/write
   * is performed that does not complete within the timeout period, a short count is returned (or an
   * EWOULDBLOCK signal would be sent in Unix if no data had been read). A value of 0 for this
   * option implies that there is no timeout (ie, operations will block forever). On systems that
   * have separate read and write timeout values, this method returns the read timeout. This value
   * is in thousandths of a second (****????*****)
   *
   * @param timeout The length of the timeout in thousandth's of a second or 0 if not set
   * @exception SocketException If an error occurs or Socket not connected
   * @since 1.1
   */
  public synchronized void setSoTimeout(int timeout) throws SocketException {
    if (impl == null) throw new SocketException("Not connected");

    if (timeout < 0) throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");

    impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
  }
Ejemplo n.º 5
0
  /**
   * Enables/Disables the SO_REUSEADDR option
   *
   * @exception SocketException If an error occurs
   * @since 1.4
   */
  public void setReuseAddress(boolean on) throws SocketException {
    if (impl == null) throw new SocketException("Cannot initialize Socket implementation");

    impl.setOption(SocketOptions.SO_REUSEADDR, new Boolean(on));
  }
Ejemplo n.º 6
0
  /**
   * This method sets the value for the socket level socket option SO_KEEPALIVE.
   *
   * @param on True if SO_KEEPALIVE should be enabled
   * @exception SocketException If an error occurs or Socket is not connected
   * @since 1.3
   */
  public void setKeepAlive(boolean on) throws SocketException {
    if (impl == null) throw new SocketException("Not connected");

    impl.setOption(SocketOptions.SO_KEEPALIVE, new Boolean(on));
  }
Ejemplo n.º 7
0
  /**
   * Enables/disables the SO_OOBINLINE option
   *
   * @param on True if SO_OOBLINE should be enabled
   * @exception SocketException If an error occurs
   * @since 1.4
   */
  public void setOOBInline(boolean on) throws SocketException {
    if (impl == null) throw new SocketException("Not connected");

    impl.setOption(SocketOptions.SO_OOBINLINE, new Boolean(on));
  }
Ejemplo n.º 8
0
  /**
   * Sets the TCP_NODELAY option on the socket.
   *
   * @param on true to enable, false to disable
   * @exception SocketException If an error occurs or Socket is not connected
   * @since 1.1
   */
  public void setTcpNoDelay(boolean on) throws SocketException {
    if (impl == null) throw new SocketException("Not connected");

    impl.setOption(SocketOptions.TCP_NODELAY, new Boolean(on));
  }