classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ServerSocket.getLocalPort possible bug...


From: Mark Wielaard
Subject: Re: ServerSocket.getLocalPort possible bug...
Date: Wed, 21 Sep 2005 21:27:34 +0200

Hi Martin,

On Wed, 2005-09-21 at 13:20 -0400, Martin Cordova wrote:
> Winstone's author explained to me the following:
> 
> "I know what this is - it's because socket.getLocalPort() returns -1. I
> hit this when I was trying to run winstone on GCJ too, about 12 months
> ago, but didn't report it. The listener code does:
> 
>        req.setServerPort(socket.getLocalPort());
> "

Thanks for reporting the bug. For bonus points please file the bug
through http://www.gnu.org/software/classpath/bugs.html
That way it is easier to track (sadly sometimes bug just sent to the
mailinglist get lost in other conversations).

I don't have a patch yet, but a created the attached Mauve
(http://www.sourceware/org/mauve/) unit test that shows the issue:

FAIL: gnu/testlet/java/net/ServerSocket/AcceptGetLocalPort (number 2)
got -1 but expected 5678

Cheers,

Mark
/* AcceptGetLocalPort.java - Test for getLocalPort on accepted Socket.
   Copyright (C) 2005, Mark J. Wielaard  <address@hidden>

This file is part of Mauve.

Mauve is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

Mauve is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with Mauve; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA. */
   
// Tags: JDK1.0

package gnu.testlet.java.net.ServerSocket;

import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;

import java.net.*;
import java.io.*;

public class AcceptGetLocalPort implements Testlet, Runnable
{
  private static int port = 5678;

  public void test (TestHarness harness)
  {
    new Thread(this).start();
    try
      {
        ServerSocket ss = new ServerSocket(port);
        harness.check(ss.getLocalPort(), port);
        Socket s = ss.accept();
        harness.check(s.getLocalPort(), port);
        s.close();
        ss.close();
      }
    catch (IOException ioe)
      {
        harness.debug(ioe);
        harness.check(false, ioe.toString());
      }
  }

  public void run()
  {
    int i = 0;
    while (i < 10)
      {
        try
          {
            Socket s = new Socket("localhost", port);
            break;
          }
        catch (IOException ioe)
          {
            // ignore
          }
        try
          {
            Thread.sleep(1000);
          }
        catch (InterruptedException ie)
          {
            // ignore
          }
      }
  }
}

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]