Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

取消网络请求时,数据还在继续下载 #21

Open
mumu7818 opened this issue May 27, 2016 · 1 comment
Open

取消网络请求时,数据还在继续下载 #21

mumu7818 opened this issue May 27, 2016 · 1 comment

Comments

@mumu7818
Copy link

在调用了request.cancel()后,表面上看起来像是取消下载了,但实质服务器还能给客户端发数据。
分析了原因,是因为DataParser中stream.close()不能立即关闭,需要接收完全部数据,inputstream才能关闭导致。这说明数据链路还是连接的,这样取消下载就没什么意义,还是会消耗流量,但我不知道怎么修改,有大牛知道怎么修改吗?
public T readFromNetStream(InputStream stream, long len,
String charSet) throws IOException {
if (stream != null) {
try {
this.data = parseNetStream(stream, len, charSet);
} finally {
stream.close();
}
}
return this.data;
}

@litesuits
Copy link
Owner

这样看你数据量的大小;
如果你数据小于 框架buffer size 4096 那么无法停止,如果你数据大于4096那么会在完成一波buffer后及时停止。代码如下:
while (!request.isCancelledOrInterrupted() && (l = is.read(buff)) > 0) {
swapStream.write(buff, 0, l);
readLength += l;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants