605 return closed; |
605 return closed; |
606 } |
606 } |
607 } |
607 } |
608 |
608 |
609 /** |
609 /** |
610 * Enable/disable SO_TIMEOUT with the specified timeout, in |
610 * Enable/disable {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT} with the |
611 * milliseconds. With this option set to a non-zero timeout, |
611 * specified timeout, in milliseconds. With this option set to a non-zero |
612 * a call to accept() for this ServerSocket |
612 * timeout, a call to accept() for this ServerSocket |
613 * will block for only this amount of time. If the timeout expires, |
613 * will block for only this amount of time. If the timeout expires, |
614 * a <B>java.net.SocketTimeoutException</B> is raised, though the |
614 * a <B>java.net.SocketTimeoutException</B> is raised, though the |
615 * ServerSocket is still valid. The option <B>must</B> be enabled |
615 * ServerSocket is still valid. The option <B>must</B> be enabled |
616 * prior to entering the blocking operation to have effect. The |
616 * prior to entering the blocking operation to have effect. The |
617 * timeout must be > 0. |
617 * timeout must be > 0. |
627 throw new SocketException("Socket is closed"); |
627 throw new SocketException("Socket is closed"); |
628 getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout)); |
628 getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout)); |
629 } |
629 } |
630 |
630 |
631 /** |
631 /** |
632 * Retrieve setting for SO_TIMEOUT. 0 returns implies that the |
632 * Retrieve setting for {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT}. |
633 * option is disabled (i.e., timeout of infinity). |
633 * 0 returns implies that the option is disabled (i.e., timeout of infinity). |
634 * @return the SO_TIMEOUT value |
634 * @return the {@link SocketOptions#SO_TIMEOUT SO_TIMEOUT} value |
635 * @exception IOException if an I/O error occurs |
635 * @exception IOException if an I/O error occurs |
636 * @since JDK1.1 |
636 * @since JDK1.1 |
637 * @see #setSoTimeout(int) |
637 * @see #setSoTimeout(int) |
638 */ |
638 */ |
639 public synchronized int getSoTimeout() throws IOException { |
639 public synchronized int getSoTimeout() throws IOException { |
647 return 0; |
647 return 0; |
648 } |
648 } |
649 } |
649 } |
650 |
650 |
651 /** |
651 /** |
652 * Enable/disable the SO_REUSEADDR socket option. |
652 * Enable/disable the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} |
|
653 * socket option. |
653 * <p> |
654 * <p> |
654 * When a TCP connection is closed the connection may remain |
655 * When a TCP connection is closed the connection may remain |
655 * in a timeout state for a period of time after the connection |
656 * in a timeout state for a period of time after the connection |
656 * is closed (typically known as the <tt>TIME_WAIT</tt> state |
657 * is closed (typically known as the <tt>TIME_WAIT</tt> state |
657 * or <tt>2MSL</tt> wait state). |
658 * or <tt>2MSL</tt> wait state). |
658 * For applications using a well known socket address or port |
659 * For applications using a well known socket address or port |
659 * it may not be possible to bind a socket to the required |
660 * it may not be possible to bind a socket to the required |
660 * <tt>SocketAddress</tt> if there is a connection in the |
661 * <tt>SocketAddress</tt> if there is a connection in the |
661 * timeout state involving the socket address or port. |
662 * timeout state involving the socket address or port. |
662 * <p> |
663 * <p> |
663 * Enabling <tt>SO_REUSEADDR</tt> prior to binding the socket |
664 * Enabling {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} prior to |
664 * using {@link #bind(SocketAddress)} allows the socket to be |
665 * binding the socket using {@link #bind(SocketAddress)} allows the socket |
665 * bound even though a previous connection is in a timeout |
666 * to be bound even though a previous connection is in a timeout state. |
666 * state. |
|
667 * <p> |
667 * <p> |
668 * When a <tt>ServerSocket</tt> is created the initial setting |
668 * When a <tt>ServerSocket</tt> is created the initial setting |
669 * of <tt>SO_REUSEADDR</tt> is not defined. Applications can |
669 * of {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is not defined. |
670 * use {@link #getReuseAddress()} to determine the initial |
670 * Applications can use {@link #getReuseAddress()} to determine the initial |
671 * setting of <tt>SO_REUSEADDR</tt>. |
671 * setting of {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}. |
672 * <p> |
672 * <p> |
673 * The behaviour when <tt>SO_REUSEADDR</tt> is enabled or |
673 * The behaviour when {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is |
674 * disabled after a socket is bound (See {@link #isBound()}) |
674 * enabled or disabled after a socket is bound (See {@link #isBound()}) |
675 * is not defined. |
675 * is not defined. |
676 * |
676 * |
677 * @param on whether to enable or disable the socket option |
677 * @param on whether to enable or disable the socket option |
678 * @exception SocketException if an error occurs enabling or |
678 * @exception SocketException if an error occurs enabling or |
679 * disabling the <tt>SO_RESUEADDR</tt> socket option, |
679 * disabling the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} |
680 * or the socket is closed. |
680 * socket option, or the socket is closed. |
681 * @since 1.4 |
681 * @since 1.4 |
682 * @see #getReuseAddress() |
682 * @see #getReuseAddress() |
683 * @see #bind(SocketAddress) |
683 * @see #bind(SocketAddress) |
684 * @see #isBound() |
684 * @see #isBound() |
685 * @see #isClosed() |
685 * @see #isClosed() |
689 throw new SocketException("Socket is closed"); |
689 throw new SocketException("Socket is closed"); |
690 getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); |
690 getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); |
691 } |
691 } |
692 |
692 |
693 /** |
693 /** |
694 * Tests if SO_REUSEADDR is enabled. |
694 * Tests if {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled. |
695 * |
695 * |
696 * @return a <code>boolean</code> indicating whether or not SO_REUSEADDR is enabled. |
696 * @return a <code>boolean</code> indicating whether or not |
|
697 * {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled. |
697 * @exception SocketException if there is an error |
698 * @exception SocketException if there is an error |
698 * in the underlying protocol, such as a TCP error. |
699 * in the underlying protocol, such as a TCP error. |
699 * @since 1.4 |
700 * @since 1.4 |
700 * @see #setReuseAddress(boolean) |
701 * @see #setReuseAddress(boolean) |
701 */ |
702 */ |
766 } |
767 } |
767 factory = fac; |
768 factory = fac; |
768 } |
769 } |
769 |
770 |
770 /** |
771 /** |
771 * Sets a default proposed value for the SO_RCVBUF option for sockets |
772 * Sets a default proposed value for the |
|
773 * {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option for sockets |
772 * accepted from this <tt>ServerSocket</tt>. The value actually set |
774 * accepted from this <tt>ServerSocket</tt>. The value actually set |
773 * in the accepted socket must be determined by calling |
775 * in the accepted socket must be determined by calling |
774 * {@link Socket#getReceiveBufferSize()} after the socket |
776 * {@link Socket#getReceiveBufferSize()} after the socket |
775 * is returned by {@link #accept()}. |
777 * is returned by {@link #accept()}. |
776 * <p> |
778 * <p> |
777 * The value of SO_RCVBUF is used both to set the size of the internal |
779 * The value of {@link SocketOptions#SO_RCVBUF SO_RCVBUF} is used both to |
778 * socket receive buffer, and to set the size of the TCP receive window |
780 * set the size of the internal socket receive buffer, and to set the size |
779 * that is advertized to the remote peer. |
781 * of the TCP receive window that is advertized to the remote peer. |
780 * <p> |
782 * <p> |
781 * It is possible to change the value subsequently, by calling |
783 * It is possible to change the value subsequently, by calling |
782 * {@link Socket#setReceiveBufferSize(int)}. However, if the application |
784 * {@link Socket#setReceiveBufferSize(int)}. However, if the application |
783 * wishes to allow a receive window larger than 64K bytes, as defined by RFC1323 |
785 * wishes to allow a receive window larger than 64K bytes, as defined by RFC1323 |
784 * then the proposed value must be set in the ServerSocket <B>before</B> |
786 * then the proposed value must be set in the ServerSocket <B>before</B> |
810 throw new SocketException("Socket is closed"); |
812 throw new SocketException("Socket is closed"); |
811 getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size)); |
813 getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size)); |
812 } |
814 } |
813 |
815 |
814 /** |
816 /** |
815 * Gets the value of the SO_RCVBUF option for this <tt>ServerSocket</tt>, |
817 * Gets the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option |
816 * that is the proposed buffer size that will be used for Sockets accepted |
818 * for this <tt>ServerSocket</tt>, that is the proposed buffer size that |
817 * from this <tt>ServerSocket</tt>. |
819 * will be used for Sockets accepted from this <tt>ServerSocket</tt>. |
818 * |
820 * |
819 * <p>Note, the value actually set in the accepted socket is determined by |
821 * <p>Note, the value actually set in the accepted socket is determined by |
820 * calling {@link Socket#getReceiveBufferSize()}. |
822 * calling {@link Socket#getReceiveBufferSize()}. |
821 * @return the value of the SO_RCVBUF option for this <tt>Socket</tt>. |
823 * @return the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} |
|
824 * option for this <tt>Socket</tt>. |
822 * @exception SocketException if there is an error |
825 * @exception SocketException if there is an error |
823 * in the underlying protocol, such as a TCP error. |
826 * in the underlying protocol, such as a TCP error. |
824 * @see #setReceiveBufferSize(int) |
827 * @see #setReceiveBufferSize(int) |
825 * @since 1.4 |
828 * @since 1.4 |
826 */ |
829 */ |
827 public synchronized int getReceiveBufferSize() |
830 public synchronized int getReceiveBufferSize() |
828 throws SocketException{ |
831 throws SocketException{ |