Browse Source

Change timeout unit to millisecond instead of second. #68

Ben Hsieh 8 years ago
parent
commit
e6bafa40bb

+ 1
- 1
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobConfig.java View File

@@ -17,7 +17,7 @@ public class RNFetchBlobConfig {
17 17
     public String key;
18 18
     public String mime;
19 19
     public Boolean auto;
20
-    public long timeout = -1;
20
+    public long timeout = 30000;
21 21
 
22 22
     RNFetchBlobConfig(ReadableMap options) {
23 23
         if(options == null)

+ 1
- 0
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java View File

@@ -20,6 +20,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
20 20
 import com.facebook.react.bridge.ReadableArray;
21 21
 import com.facebook.react.bridge.WritableArray;
22 22
 import com.facebook.react.bridge.WritableMap;
23
+import com.facebook.react.bridge.WritableNativeArray;
23 24
 import com.facebook.react.modules.core.DeviceEventManagerModule;
24 25
 
25 26
 import java.io.File;

+ 5
- 3
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java View File

@@ -34,6 +34,7 @@ import java.util.HashMap;
34 34
 import java.util.concurrent.TimeUnit;
35 35
 
36 36
 import okhttp3.Call;
37
+import okhttp3.ConnectionPool;
37 38
 import okhttp3.Headers;
38 39
 import okhttp3.Interceptor;
39 40
 import okhttp3.MediaType;
@@ -67,6 +68,7 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
67 68
     public static HashMap<String, Call> taskTable = new HashMap<>();
68 69
     static HashMap<String, Boolean> progressReport = new HashMap<>();
69 70
     static HashMap<String, Boolean> uploadProgressReport = new HashMap<>();
71
+    static ConnectionPool pool = new ConnectionPool(5, 30000, TimeUnit.MILLISECONDS);
70 72
 
71 73
     MediaType contentType = RNFetchBlobConst.MIME_OCTET;
72 74
     ReactApplicationContext ctx;
@@ -303,10 +305,10 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
303 305
             });
304 306
 
305 307
             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);
308 310
             }
309
-
311
+            clientBuilder.connectionPool(pool);
310 312
             OkHttpClient client = clientBuilder.build();
311 313
             Call call =  client.newCall(req);
312 314
             taskTable.put(taskId, call);

+ 1
- 1
src/ios/RNFetchBlobNetwork.m View File

@@ -137,7 +137,7 @@ NSOperationQueue *taskQueue;
137 137
     NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
138 138
     if([options valueForKey:@"timeout"] != nil)
139 139
     {
140
-        defaultConfigObject.timeoutIntervalForRequest = [[options valueForKey:@"timeout"] floatValue];
140
+        defaultConfigObject.timeoutIntervalForRequest = [[options valueForKey:@"timeout"] floatValue]/1000;
141 141
     }
142 142
     session = [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:taskQueue];
143 143
     if(path != nil || [self.options valueForKey:CONFIG_USE_TEMP]!= nil)

+ 1
- 1
src/polyfill/XMLHttpRequest.js View File

@@ -339,8 +339,8 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
339 339
   }
340 340
 
341 341
   set timeout(val) {
342
+    this._timeout = val*1000
342 343
     log.verbose('set timeout', this._timeout)
343
-    this._timeout = val
344 344
   }
345 345
 
346 346
   get timeout() {