Skip to content

Commit 9e49982

Browse files
committed
close idle connection after finish a request;
1 parent 7df84b1 commit 9e49982

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/com/qiniu/auth/Client.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.http.util.EntityUtils;
2323

2424
import java.io.IOException;
25+
import java.util.concurrent.TimeUnit;
2526

2627
public class Client {
2728

@@ -119,6 +120,7 @@ protected void onProgressUpdate(Object... values) {
119120

120121
@Override
121122
protected void onPostExecute(Object o) {
123+
mClient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
122124
if (o instanceof Exception) {
123125
mRet.onFailure((Exception) o);
124126
return;

src/com/qiniu/utils/InputStreamAt.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ public byte[] read(long offset, int length) throws IOException {
135135

136136
protected byte[] fileStreamRead(long offset, int length) throws IOException {
137137
if (mFileStream == null) return null;
138+
long fileLength = mFileStream.length();
139+
if (length + offset > fileLength) length = (int) (fileLength - offset);
138140
byte[] data = new byte[length];
139141

140142
int read;

0 commit comments

Comments
 (0)