harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Ellison (JIRA)" <j...@apache.org>
Subject [jira] Updated: (HARMONY-4961) SocketChannel.socket().getLocalPort() returns -1 from ServerSocketChannel
Date Thu, 18 Oct 2007 12:35:50 GMT

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

Tim Ellison updated HARMONY-4961:
---------------------------------

    Attachment: harmony-4961.patch

Phil, see attached file "harmony-4961.patch" for minimum required patch to resolve the problem.

Fix applied to NIO module at repo revision r585945.

Please check that this resolves your problem.

> 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.


Mime
View raw message