Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit e6bafa4

Browse files
committed
Change timeout unit to millisecond instead of second. #68
1 parent 076b9ef commit e6bafa4

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class RNFetchBlobConfig {
1717
public String key;
1818
public String mime;
1919
public Boolean auto;
20-
public long timeout = -1;
20+
public long timeout = 30000;
2121

2222
RNFetchBlobConfig(ReadableMap options) {
2323
if(options == null)

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.facebook.react.bridge.ReadableArray;
2121
import com.facebook.react.bridge.WritableArray;
2222
import com.facebook.react.bridge.WritableMap;
23+
import com.facebook.react.bridge.WritableNativeArray;
2324
import com.facebook.react.modules.core.DeviceEventManagerModule;
2425

2526
import java.io.File;

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.concurrent.TimeUnit;
3535

3636
import okhttp3.Call;
37+
import okhttp3.ConnectionPool;
3738
import okhttp3.Headers;
3839
import okhttp3.Interceptor;
3940
import okhttp3.MediaType;
@@ -67,6 +68,7 @@ enum ResponseType {
6768
public static HashMap<String, Call> taskTable = new HashMap<>();
6869
static HashMap<String, Boolean> progressReport = new HashMap<>();
6970
static HashMap<String, Boolean> uploadProgressReport = new HashMap<>();
71+
static ConnectionPool pool = new ConnectionPool(5, 30000, TimeUnit.MILLISECONDS);
7072

7173
MediaType contentType = RNFetchBlobConst.MIME_OCTET;
7274
ReactApplicationContext ctx;
@@ -303,10 +305,10 @@ public Response intercept(Chain chain) throws IOException {
303305
});
304306

305307
if(options.timeout > 0) {
306-
clientBuilder.connectTimeout(options.timeout, TimeUnit.SECONDS);
307-
clientBuilder.readTimeout(options.timeout, TimeUnit.SECONDS);
308+
clientBuilder.connectTimeout(options.timeout, TimeUnit.MILLISECONDS);
309+
clientBuilder.readTimeout(options.timeout, TimeUnit.MILLISECONDS);
308310
}
309-
311+
clientBuilder.connectionPool(pool);
310312
OkHttpClient client = clientBuilder.build();
311313
Call call = client.newCall(req);
312314
taskTable.put(taskId, call);

src/ios/RNFetchBlobNetwork.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
137137
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
138138
if([options valueForKey:@"timeout"] != nil)
139139
{
140-
defaultConfigObject.timeoutIntervalForRequest = [[options valueForKey:@"timeout"] floatValue];
140+
defaultConfigObject.timeoutIntervalForRequest = [[options valueForKey:@"timeout"] floatValue]/1000;
141141
}
142142
session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
143143
if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil)

src/polyfill/XMLHttpRequest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
339339
}
340340

341341
set timeout(val) {
342+
this._timeout = val*1000
342343
log.verbose('set timeout', this._timeout)
343-
this._timeout = val
344344
}
345345

346346
get timeout() {

0 commit comments

Comments
 (0)