Skip to content

Commit

Permalink
Fix file transfer error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jech committed Mar 22, 2022
1 parent 8aaa6d1 commit 14bea47
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions static/galene.js
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,11 @@ TransferredFile.get = function(up, userid, fileid) {
};

TransferredFile.prototype.close = function() {
if(this.dc) {
this.dc.onclose = null;
this.dc.onerror = null;
this.dc.onmessage = null;
}
if(this.pc)
this.pc.close();
this.dc = null;
Expand Down Expand Up @@ -2689,12 +2694,14 @@ async function sendFileData(f) {
async function write(a) {
while(f.dc.bufferedAmount > f.dc.bufferedAmountLowThreshold) {
await new Promise((resolve, reject) => {
if(f.dc == null) {
if(!f.dc) {
reject(new Error('File is closed.'));
return;
}
f.dc.onbufferedamountlow = function(e) {
if(f.dc == null) {
if(!f.dc) {
reject(new Error('File is closed.'));
return;
}
f.dc.onbufferedamountlow = null;
resolve();
Expand Down Expand Up @@ -2805,7 +2812,7 @@ async function doneReceiveFileData(f) {
* @param {TransferredFile} f
*/
function closeReceiveFileData(f) {
if(f.datalen != f.size) {
if(f.datalen !== f.size) {
setFileStatus(f, 'Failed.', true, true)
f.close();
}
Expand Down

0 comments on commit 14bea47

Please sign in to comment.