@@ -313,15 +313,6 @@ public class WebDAVStorage: NetworkStorage, URLSessionTaskDelegate, URLSessionDa
313313 return . WebDAV
314314 }
315315
316- public override func cancel( ) {
317- if let acceptRange = acceptRange, !acceptRange {
318- cancelTime = Date ( timeIntervalSinceNow: 10 )
319- }
320- else {
321- super. cancel ( )
322- }
323- }
324-
325316 var cache_accessUsername = " "
326317 var accessUsername : String {
327318 if let name = storageName {
@@ -377,6 +368,7 @@ public class WebDAVStorage: NetworkStorage, URLSessionTaskDelegate, URLSessionDa
377368 var recvData : [ Int : Data ] = [ : ]
378369 var headerHandler : [ Int : ( URLResponse ) -> URLSession . ResponseDisposition ] = [ : ]
379370
371+ let wholeQueue = DispatchQueue ( label: " WholeReading " )
380372 var wholeReading : [ URL ] = [ ]
381373
382374 public func urlSession( _ session: URLSession , task: URLSessionTask , didReceive challenge: URLAuthenticationChallenge , completionHandler: @escaping ( URLSession . AuthChallengeDisposition , URLCredential ? ) -> Void ) {
@@ -1040,9 +1032,8 @@ public class WebDAVStorage: NetworkStorage, URLSessionTaskDelegate, URLSessionDa
10401032 }
10411033 }
10421034 //print(url)
1043-
1044- if wholeReading. contains ( url) {
1045- DispatchQueue . global ( ) . asyncAfter ( deadline: . now( ) + Double. random ( in: 1 ..< 5 ) ) {
1035+ if wholeQueue. sync ( execute: { wholeReading. contains ( url) } ) {
1036+ DispatchQueue . global ( ) . asyncAfter ( deadline: . now( ) + Double. random ( in: 0 ..< 1 ) ) {
10461037 if self . cancelTime. timeIntervalSinceNow > 0 {
10471038 self . cancelTime = Date ( timeIntervalSinceNow: 0.5 )
10481039 onFinish ? ( nil )
@@ -1065,33 +1056,34 @@ public class WebDAVStorage: NetworkStorage, URLSessionTaskDelegate, URLSessionDa
10651056 return
10661057 }
10671058 lastCall = Date ( )
1068- wholeReading += [ url]
1069-
1059+ wholeQueue. async {
1060+ self . wholeReading += [ url]
1061+ }
1062+
10701063 var request : URLRequest
10711064 request = URLRequest ( url: url)
10721065
1073- os_log ( " %{public}@ " , log: log, type: . debug, " readFile(WebDAV: \( storageName ?? " " ) \( fileId) whole read " )
1066+ os_log ( " %{public}@ " , log: log, type: . debug, " readFile(WebDAV: \( storageName ?? " " ) \( fileId) whole read \( start ?? 0 ) \( length ?? - 1 ) " )
10741067
10751068 let task = dataSession. dataTask ( with: request)
1076- let timer1 = Timer . scheduledTimer ( withTimeInterval: 0.1 , repeats: true ) { t in
1077- if self . cancelTime. timeIntervalSinceNow > 0 {
1078- print ( " cancel " )
1079- self . cancelTime = Date ( timeIntervalSinceNow: 1 )
1080- onFinish ? ( nil )
1081- task. cancel ( )
1082- return
1069+ var timer1 : Timer ?
1070+ DispatchQueue . main. async {
1071+ timer1 = Timer . scheduledTimer ( withTimeInterval: 0.1 , repeats: true ) { t in
1072+ if self . cancelTime. timeIntervalSinceNow > 0 {
1073+ print ( " cancel " )
1074+ task. cancel ( )
1075+ self . cancelTime = Date ( timeIntervalSinceNow: 0.5 )
1076+ onFinish ? ( nil )
1077+ return
1078+ }
10831079 }
10841080 }
10851081 dataTasks [ task. taskIdentifier] = { data, error in
1086- self . callSemaphore. signal ( )
1087- timer1. invalidate ( )
1088- var waittime = self . callWait
10891082 if let error = error {
10901083 print ( error)
1091- if ( error as NSError ) . code == - 1009 {
1092- waittime += 30
1093- }
10941084 }
1085+ self . callSemaphore. signal ( )
1086+ timer1? . invalidate ( )
10951087 if let d = data {
10961088 CloudFactory . shared. cache. saveFile ( storage: self . storageName!, id: fileId, data: d)
10971089 let s = Int ( start ?? 0 )
0 commit comments