reverted possible fix for OS that does not handle half close well

This commit is contained in:
Greg Wilkins 2011-11-16 10:22:49 +11:00
parent 09e8777e21
commit 52275e27b4
3 changed files with 47 additions and 70 deletions

View File

@ -124,7 +124,7 @@ public class ChannelEndPoint implements EndPoint
LOG.debug(e.toString());
LOG.ignore(e);
if (!socket.isClosed())
socket.close();
close();
}
finally
{
@ -162,6 +162,8 @@ public class ChannelEndPoint implements EndPoint
{
LOG.warn(e.toString());
LOG.debug(e);
if (!socket.isClosed())
close();
}
finally
{

View File

@ -61,46 +61,33 @@ public abstract class EndPointTest<T extends EndPoint>
buffer.clear();
len = c.client.fill(buffer);
assertEquals(-1,len);
assertTrue(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertFalse(c.client.isOutputShutdown());
assertTrue(c.server.isOpen());
assertFalse(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
if (!c.client.isOpen())
{
// Half closing is not working - maybe an OS thing
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertFalse(c.server.isOpen());
assertTrue(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
}
else
{
// Half closing is working
c.client.shutdownOutput();
assertTrue(c.client.isInputShutdown());
assertFalse(c.client.isOutputShutdown());
assertTrue(c.server.isOpen());
assertFalse(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertTrue(c.server.isOpen());
assertFalse(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
buffer.clear();
len = c.server.fill(buffer);
assertEquals(-1,len);
c.client.shutdownOutput();
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertTrue(c.server.isOpen());
assertFalse(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
buffer.clear();
len = c.server.fill(buffer);
assertEquals(-1,len);
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertFalse(c.server.isOpen());
assertTrue(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
}
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertFalse(c.server.isOpen());
assertTrue(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
}
@ -136,35 +123,21 @@ public abstract class EndPointTest<T extends EndPoint>
len = c.server.fill(buffer);
assertEquals(-1,len);
if (!c.server.isOpen())
{
// Half closing is not working - maybe an OS thing
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertFalse(c.server.isOpen());
assertTrue(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
}
else
{
// Half closing is working
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertTrue(c.server.isOpen());
assertTrue(c.server.isInputShutdown());
assertFalse(c.server.isOutputShutdown());
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertTrue(c.server.isOpen());
assertTrue(c.server.isInputShutdown());
assertFalse(c.server.isOutputShutdown());
c.server.shutdownOutput();
c.server.shutdownOutput();
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertFalse(c.server.isOpen());
assertTrue(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
}
assertFalse(c.client.isOpen());
assertTrue(c.client.isInputShutdown());
assertTrue(c.client.isOutputShutdown());
assertFalse(c.server.isOpen());
assertTrue(c.server.isInputShutdown());
assertTrue(c.server.isOutputShutdown());
}
}

View File

@ -16,6 +16,7 @@ package org.eclipse.jetty.io;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -24,6 +25,7 @@ import java.net.Socket;
import java.net.SocketException;
import org.eclipse.jetty.util.IO;
import org.junit.Assert;
import org.junit.Test;
/**
@ -75,7 +77,7 @@ public class IOTest
assertEquals(-1,server.getInputStream().read());
// but cannot write
try { client.getOutputStream().write(1); assertTrue(false); } catch (SocketException e) {}
try { client.getOutputStream().write(1); fail("exception expected"); } catch (SocketException e) {}
// but can still write in opposite direction.
server.getOutputStream().write(1);
@ -86,7 +88,7 @@ public class IOTest
server.shutdownInput();
// now we EOF instead of reading -1
try { server.getInputStream().read(); assertTrue(false); } catch (SocketException e) {}
try { server.getInputStream().read(); fail("exception expected"); } catch (SocketException e) {}
// but can still write in opposite direction.
@ -97,7 +99,7 @@ public class IOTest
client.shutdownInput();
// now we EOF instead of reading -1
try { client.getInputStream().read(); assertTrue(false); } catch (SocketException e) {}
try { client.getInputStream().read(); fail("exception expected"); } catch (SocketException e) {}
// But we can still write at the server (data which will never be read)
server.getOutputStream().write(1);
@ -109,7 +111,7 @@ public class IOTest
server.shutdownOutput();
// and now we can't write
try { server.getOutputStream().write(1); assertTrue(false); } catch (SocketException e) {}
try { server.getOutputStream().write(1); fail("exception expected"); } catch (SocketException e) {}
// but the sockets are still open
assertFalse(client.isClosed());