[Xlightweb-develop] Bug of HttpClientConnection
Status: Inactive
Brought to you by:
grro
|
From: Hongwenchina <hon...@16...> - 2010-10-18 03:45:38
|
Gregor,
hi, there is a bug in HttpClientConnection. when call setMaxReadBufferThreshold, the ioHandler will be suspended, and the read is never
resumed.
xsocket version is 2.8.14, xlightweb version is 2.13.2. And testing case is below:
public class TestXSocket implements IHttpResponseHandler, IBodyDataHandler{
int x;
ByteBuffer buffer = ByteBuffer.allocate(1024);
public void test() throws Exception{
IHttpRequest request = new GetRequest("http://viewer.tj.cnki.net/CAJViewer%207.0.2.self.exe");
HttpClientConnection httpClientConnection = new HttpClientConnection("viewer.tj.cnki.net", 80);
httpClientConnection.getUnderlyingTcpConnection().setMaxReadBufferThreshold(4096);
httpClientConnection.send(request,this);
}
@Override
public void onException(IOException ioe) throws IOException {
// TODO Auto-generated method stub
}
@Override
public void onResponse(IHttpResponse response) throws IOException {
// TODO Auto-generated method stub
response.getNonBlockingBody().setDataHandler(this);
}
@Override
public boolean onData(NonBlockingBodyDataSource bodyDataSource)
throws BufferUnderflowException {
// TODO Auto-generated method stub
int ava;
try {
ava = bodyDataSource.available();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return true;
}
if(ava<0){
System.out.println(x);
return true;
}
int size;
try {
buffer.clear();
size = bodyDataSource.read(buffer);
buffer.flip();
String str = new String(buffer.array());
x += size;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
public static void main(String []args) throws Exception{
TestXSocket t = new TestXSocket();
Thread.sleep(2000);
t.test();
Thread.sleep(200000);
}
}
|