Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4129952

java.net.Socket.setSoLinger sets SO_LINGER value for non-stream sockets.

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.5
    • Not verified



      Name: yyC67448 Date: 04/17/98



      On Solaris java.net.Socket.setSoLinger(boolean, int) does not throw any exceptions when
      attempt is made to set SO_LINGER value for non-stream (UDP) socket, i.e. the Socket created
      with stream=false.

      Linger time is not applicable to non-stream sockets.


      Here is the test demonstrating the bug:

      -------------------------------- Test.java -----------------------------

      import java.net.*;


      class test
      {

        public static void main(String args[])
        {
          InetAddress sin = null;
          Socket soc = null;
          int value = 0;


          /*
           * Try to get localhost address
           */
          try {
            sin = InetAddress.getLocalHost();
          } catch(Exception e)
          {
            System.out.println("Can not get localhost Address:" + e);
            System.exit(-1);
          }


          /*
           * Socket is connection less => can use any port number...
           */
          try {
            soc = new Socket(sin, 23333, false);
          } catch(Exception e)
          {
            System.out.println("Can not create socket:" + e);
            System.exit(-1);
          }

          /*
           * Try to set some value
           */
          try {
            soc.setSoLinger(true, 20);
            value = soc.getSoLinger();
          } catch(SocketException e)
          {
            try {
             soc.close();
            } catch(Exception e)
            {
             System.out.println("Can not close socket :" + e1);
      System.exit(-1);
            }
            System.out.println("OKAY");
            System.exit(0);
          }
          catch(Exception e)
          {
            try {
      soc.close();
            } catch(Exception e1)
            {
      System.out.println("Can not close socket :" + e1);
      System.exit(-1);
            }
            System.out.println("Unexpected exception:" + e);
          }
          
          try {
            soc.close();
          } catch(Exception e)
          {
            System.out.println("Can not close socket:" + e);
            System.exit(-1);
          }

          System.out.println("No exceptions. Val = " + value);
          
        }
      }



      ------------------ Output from the test on Solaris -------------
      No exceptions. Val = 20
      -----------------------------------------------------------------
      ------------------ Output from the test on Windows --------------
      OKAY
      -----------------------------------------------------------------



      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: