Avoid flush if no content to flush

This commit is contained in:
Greg Wilkins 2011-11-10 14:45:28 +11:00
parent f37b617481
commit 921b285235
5 changed files with 32 additions and 12 deletions

View File

@ -22,6 +22,8 @@ import java.nio.channels.ByteChannel;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.EndPoint;

View File

@ -1145,11 +1145,11 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
BufferedReader br=null;
StringBuilder sb=new StringBuilder();
try
{
br=new BufferedReader(new InputStreamReader(client.getInputStream()));
StringBuilder sb=new StringBuilder();
String line;
while ((line=br.readLine())!=null)
@ -1160,6 +1160,11 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
return sb.toString();
}
catch(IOException e)
{
System.err.println(e+" while reading '"+sb+"'");
throw e;
}
finally
{
if (br!=null)

View File

@ -247,12 +247,16 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
int filled=_parser.parseNext();
progress = flushed>0 || filled>0;
if (_endp instanceof AsyncEndPoint && ((AsyncEndPoint)_endp).hasProgressed())
progress=true;
}
}
catch(IOException e)
{
try
{
if (_endp.isOpen())
_endp.close();
}
catch(IOException e2)

View File

@ -190,7 +190,7 @@ public class WebSocketGeneratorD13 implements WebSocketGenerator
if (_buffer!=null)
{
int flushed=_endp.flush(_buffer);
int flushed=_buffer.hasContent()?_endp.flush(_buffer):0;
if (_closed&&_buffer.length()==0)
_endp.shutdownOutput();
return flushed;

View File

@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayEndPoint;
import org.eclipse.jetty.io.nio.ChannelEndPoint;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
@ -1122,6 +1123,8 @@ public class WebSocketMessageD13Test
else
assertEquals(tst,tests[t][2],-1);
try
{
output.write(0x88);
output.write(0x80);
output.write(0x00);
@ -1129,6 +1132,12 @@ public class WebSocketMessageD13Test
output.write(0x00);
output.write(0x00);
output.flush();
}
catch(IOException e)
{
System.err.println("socket "+socket);
throw e;
}
len = input.read(buf);
assertEquals(tst,-1,len);