Date: Mon, 16 Oct 2006 15:25:59 -0400 From: "Joseph Gleason" <fireduck@gmail.com> To: freebsd-java@freebsd.org Subject: Re: Bug in java.net.Socket close() behavior? Message-ID: <7956f3200610161225w52ad626fveb8bd7f816f57bc4@mail.gmail.com> In-Reply-To: <7956f3200610161024o3598e217oba81116bd84a7c99@mail.gmail.com> References: <7956f3200610161024o3598e217oba81116bd84a7c99@mail.gmail.com>
index | next in thread | previous in thread | raw e-mail
I have been informed that attachments are removed automaticly.
Here is the code to the test program:
import java.net.Socket;
import java.io.InputStream;
public class SocketCloseStreamTest
{
public static void main(String Args[]) throws Exception
{
new SocketCloseStreamTest();
}
public SocketCloseStreamTest() throws Exception
{
Socket S=new Socket("tesla.fireduck.com",22);
new ReadThread(S.getInputStream()).start();
Thread.sleep(2000);
S.close();
System.out.println("Socket closed. Should see socket
closed exception.");
Thread.sleep(2000);
}
public class ReadThread extends Thread
{
InputStream In;
public ReadThread(InputStream in)
{
In=in;
}
public void run()
{
try
{
int BlockSz=1024;
byte[] buff=new byte[BlockSz];
while(true)
{
int readsize=In.read(buff,0,BlockSz);
System.out.print("In: ");
System.out.write(buff,0,readsize);
System.out.println();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
On 10/16/06, Joseph Gleason <fireduck@gmail.com> wrote:
> According to the API for java.net.Socket close():
>
> "Any thread currently blocked in an I/O operation upon this socket
> will throw a SocketException."
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#close()
>
> I have observed that java 1.5 on FreeBSD does not follow this while
> the Windows and Linux ones I have tested do. On the FreeBSD runtimes
> that I have tested, a thread blocked on reading a socket just hangs
> forever if the socket is closed.
>
> Attached is a simple program that tests this behavior. It just
> connects to a port on one of my servers and has a reader thread
> watching input from the socket and closes the socket in a different
> thread to see if the reader thread gets an exception.
>
> Java runtimes that I have tested this on:
> # java -version
> java version "1.5.0"
> Java(TM) 2 Runtime Environment, Standard Edition (build diablo-1.5.0-b01)
> Java HotSpot(TM) 64-Bit Server VM (build diablo-1.5.0_07-b01, mixed mode)
>
> # java -version
> java version "1.5.0-p2"
> Java(TM) 2 Runtime Environment, Standard Edition (build
> 1.5.0-p2-root_07_mar_2006_02_41)
> Java HotSpot(TM) 64-Bit Server VM (build
> 1.5.0-p2-root_07_mar_2006_02_41, mixed mode)
>
>
>
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7956f3200610161225w52ad626fveb8bd7f816f57bc4>
