Changeset 679
- Timestamp:
- 10/12/09 15:38:13 (1 month ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/uploadr/3.2/MacUploadr.app/Contents/Resources/chrome/content/uploadr/upload.js
r661 r679 61 61 62 62 startTime : 0, 63 64 transport: 0, 65 timeoutID: 0, 63 66 64 67 // Generate general error XML document element … … 681 684 wrap.photosets.getList(users.token, users.nsid); 682 685 wrap.people.getUploadStatus(users.token); 686 //wrap.tags.getListUserRaw(users.token); 683 687 684 688 // Send stats to the site … … 877 881 Cc['@mozilla.org/network/socket-transport-service;1'] 878 882 .getService(Ci.nsISocketTransportService); 879 vartransport = service.createTransport(null, 0,883 upload.transport = service.createTransport(null, 0, 880 884 UPLOAD_HOST, 80, null); 881 var ostream = transport.openOutputStream( 885 /* upload.transport.setEventSink({ 886 onTransportStatus: function(aTransport, aStatus, aProgress, aProgressMax) { 887 logStringMessage("status: " + aStatus + " \"" + aProgress + "/" + aProgressMax + "\""); 888 }, 889 } 890 , null); */ 891 var ostream = upload.transport.openOutputStream( 882 892 // Ci.nsITransport.OPEN_BLOCKING, 0, 0); 883 893 Ci.nsITransport.OPEN_BLOCKING, 2520, 128); 884 894 if (conf.console.upload) { 885 895 var connectTimeout, readWriteTimeout; 886 connectTimeout = transport.getTimeout(Ci.nsITransport.TIMEOUT_CONNECT);887 readWriteTimeout = transport.getTimeout(Ci.nsITransport.TIMEOUT_READ_WRITE);896 connectTimeout = upload.transport.getTimeout(Ci.nsITransport.TIMEOUT_CONNECT); 897 readWriteTimeout = upload.transport.getTimeout(Ci.nsITransport.TIMEOUT_READ_WRITE); 888 898 logStringMessage('UPLOAD: connect timeout = ' + connectTimeout + ' R/W timeout = ' + readWriteTimeout); 889 899 } … … 919 929 return; // we are done 920 930 } 921 var _istream = transport.openInputStream(0,0,0);931 var _istream = upload.transport.openInputStream(0,0,0); 922 932 var istream = Cc['@mozilla.org/scriptableinputstream;1'] 923 933 .createInstance(Ci.nsIScriptableInputStream); 924 934 istream.init(_istream); 935 936 // Need huge time out for edge servers to answer, but still timeout 937 // heuristic for time out proportional to file size and at least 2 minutes 30 seconds by conservatism 938 var heuristicTimeout = Math.max(150000,4*mstream.available()/1024); 939 940 threads.main.dispatch(new UploadAboutDoneCallback( 941 this.id, heuristicTimeout), threads.main.DISPATCH_NORMAL); 942 925 943 var pump = Cc['@mozilla.org/network/input-stream-pump;1'] 926 944 .createInstance(Ci.nsIInputStreamPump); … … 929 947 logStringMessage('UPLOAD: Waiting for response'); 930 948 } 949 931 950 pump.asyncRead({ 932 951 id: this.id, … … 934 953 raw: '', 935 954 onStartRequest: function(request, context) { 955 window.clearTimeout(upload.timeoutID); 936 956 if (conf.console.upload) { 937 957 logStringMessage('UPLOAD response: onStartRequest'); … … 951 971 onDataAvailable: function(request, context, 952 972 stream, offset, count) { 973 if (conf.console.upload) { 974 logStringMessage('UPLOAD response: onDataAvailable'); 975 } 953 976 this.raw += istream.read(count); 954 977 … … 975 998 threads.main.dispatch(new UploadDoneCallback( 976 999 this.raw, this.id), threads.main.DISPATCH_NORMAL); 977 transport.close(0); // reason is supposed to be passed as parameter!?1000 upload.transport.close(0); // reason is supposed to be passed as parameter!? OnStopRequest is coming after this, maybe as a result actually 978 1001 979 1002 }, … … 1080 1103 } 1081 1104 }; 1105 1106 var UploadAboutDoneCallback = function(id, timeOut) { 1107 this.id = id; 1108 this.timeOut = timeOut; 1109 } 1110 UploadAboutDoneCallback.prototype = { 1111 run: function() { 1112 if (conf.console.upload) { 1113 logStringMessage('UPLOAD AboutDone '); 1114 } 1115 upload.timeoutID = window.setTimeout(abortPOST,this.timeOut,this.id); 1116 }, 1117 QueryInterface: function(iid) { 1118 if (iid.equals(Ci.nsIRunnable) || iid.equals(Ci.nsISupports)) { 1119 return this; 1120 } 1121 throw Components.results.NS_ERROR_NO_INTERFACE; 1122 } 1123 }; 1124 1125 var abortPOST = function(id) { 1126 // We timeout the transaction 1127 upload.transport.close(Ci.nsIRequest.NS_BINDING_ABORTED); 1128 // We handle this case => retry, or give up. 1129 upload._start("", id); 1130 }