Martin Egholm Nielsen writes:
> Hi there,
>
> When I try the following piece of code:
>
> === 8< 8< 8< ===
>
> import java.io.IOException;
> import java.net.ServerSocket;
> import java.net.Socket;
>
> public class SocketBindTest
> {
> public static void main(String[] args) throws IOException
> {
> System.out.println("Accepting...");
> Socket s = new ServerSocket(80).accept();
> System.out.println(s.isBound());
> System.out.println(s.getLocalPort());
> System.out.println(s.getPort());
> } // main
> } // SocketBindTest
>
> === 8< 8< 8< ===
>
> I would expect the returned Socket instance, s, to be bound to same port
> as my server-socket - namely port 80. However, GCJ's Socket reports the
> socket as unbound, hence the port becomes "-1". A different behaviour is
> seen with Sun's...
It's a bug:
Breakpoint 1, SocketBindTest.main(java.lang.String[]) ([EMAIL PROTECTED])
at SocketBindTest.java:11
(gdb) p _Jv_DeepDebug(socket,2)
[EMAIL PROTECTED]
{
boolean implCreated = false,
boolean outputShutdown = false,
java.net.SocketImpl impl = [EMAIL PROTECTED]
{
int localport = 80,
java.io.OutputStream out = null,
java.io.FileDescriptor fd = null,
int timeout = 0,
java.io.InputStream in = null,
java.net.InetAddress address = 0x15b840,
int native_fd = 15,
java.net.InetAddress localAddress = null,
int port = 41693,
boolean inChannelOperation = false,
},
boolean bound = false,
boolean inputShutdown = false,
}
As you can see, ServerSocket.accept doesn't set BOUND. I think the
right place to fix this is ServerSocket.implAccept().
Andrew.
_______________________________________________
Classpath mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath