You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Phil Loats (JIRA)" <ji...@apache.org> on 2007/10/18 16:23:50 UTC

[jira] Closed: (HARMONY-4961) SocketChannel.socket().getLocalPort() returns -1 from ServerSocketChannel

     [ https://issues.apache.org/jira/browse/HARMONY-4961?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Loats closed HARMONY-4961.
-------------------------------

    Estimated Complexity: Moderate  (was: Unknown)

Funny that this is exactly the fix I was using to workaround the problem, but I was not sure of any side effects of setting the isBound flag.  Thank you for the excellent response on this bug.  Patch is easily applied.  Verified testcase and original problem are resolved.

> 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
>            Assignee: Tim Ellison
>         Attachments: harmony-4961.patch
>
>
> 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.