harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Loats (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-4961) SocketChannel.socket().getLocalPort() returns -1 from ServerSocketChannel
Date Wed, 17 Oct 2007 20:40:51 GMT
SocketChannel.socket().getLocalPort() returns -1 from ServerSocketChannel
-------------------------------------------------------------------------

                 Key: HARMONY-4961
                 URL: https://issues.apache.org/jira/browse/HARMONY-4961
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
         Environment: Reproduced on Windows XP SP2, on apache-harmony-jdk-r580985-windows-x86-32-snapshot
            Reporter: Phil Loats


The following testcase fails onthe Harmony M3 snapshot build.  
  On J2SE 5.0, the output is "myport is 4321"
  On Harmony M3 is "myport is -1"

It seems that SocketChannelImpl.isBound flag remains false when accessed from
SocketChannelImpl$SocketAdapter.isBound() from
SocketChannelImpl$SocketAdapter(Socket).getLocalPort()

We need this fix in an IBM product, I'd be most helpful if any fix can be clearly identified
in SVN (i.e. don't lump other fixes with this fix).

=========simplified testcase===============

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class Test implements Runnable {
	public static void main(String[] args) {
		new Test().test();
	}
	
	void test() {	
		new Thread(this).start();
	    
	    try {
	        // Create a non-blocking server socket channel on port
	        ServerSocketChannel ssChannel = ServerSocketChannel.open();
	        ssChannel.configureBlocking(true);
	        int port = 4321;
	        ssChannel.socket().bind(new InetSocketAddress(port));

	        // Accept the connection request
	        SocketChannel sChannel = ssChannel.accept();
	    
	        if (sChannel != null) {
	            int myport = sChannel.socket().getLocalPort();
	            System.out.println("myport is "+myport);
	            sChannel.close();
	        }
	    } catch (IOException e) {
	    	e.printStackTrace();
	    }
	}

	public void run() {
		try {
			Thread.sleep(1000);
			Socket socket = new Socket(InetAddress.getByName("localhost"), 4321);
		    BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		    String str;
	        while ((str = rd.readLine()) != null) {
	            System.out.println(str);
	        }
	        rd.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message