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

java.net.Socket.setSoLinger truncates the linger value on Win32

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: yyC67448 Date: 06/24/98



      The java.net.Socket.setSoLinger(boolean, int) truncates the linger value
      to 2-byte integer on Win32 systems.

      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 linger = 65546;
          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);
          }


          /*
           * Hope Telnet service enabled on localhost
           */
          try {
            soc = new Socket(sin, 23, true);
          } catch(Exception e)
          {
            System.out.println("Can not create socket:" + e);
            System.exit(-1);
          }

          try {
            soc.setSoLinger(true, linger);
            value = soc.getSoLinger();
          }
          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 e1)
          {
            System.out.println("Can not close socket :" + e1);
            System.exit(-1);
          }

          if( value != linger)
          {
            System.out.println("Failed. " + value + " != " + linger);
            System.exit(-1);
          }

          System.out.println("OKAY");
          
        }
      }



      ---------------------- Output from the test -----------------
      Failed. 10 != 65546
      -----------------------------------------------------------------



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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: