2016-08-09 18 views
0

私は、ローカルホスト上に簡単な遊び場と単純なTCPサーバーを持っています。私がしたいのは、すでにreadData操作がエンキューされているURLSessionStreamTaskをキャンセルできることだけです。狂ったことは、この正確な遊び場がiOSやtvOSでは全く問題なく動作しますが、macOSではうまく動作しないということです。URLSessionStreamTaskをキャンセルすると、NSURLErrorCancelled(MacOS上)のcompletionHandlerが呼び出されません

は、iOS/tvOSに私は次の出力を得る: "!勝利" MacOSで

Resuming... 
Cancelling... 
After cancel call 
Victory! The session task was properly cancelled! 

(10.11)メッセージは決して印刷されません。ここで

は遊び場です:

import Foundation 
import PlaygroundSupport 

let task = URLSession.shared.streamTask(withHostName: "localhost", port: 12345) 

task.readData(ofMinLength: 1, maxLength: 1024, timeout: 0) { (data, atEOF, error) in 
    if let error = error as? NSError { 
     if error.code == NSURLErrorCancelled { 
      print("Victory! The session task was properly cancelled!") 
     } 
    } 
} 

print("Resuming...") 
task.resume() 

print("Cancelling...") 
task.cancel() 
print("After cancel call") 
PlaygroundPage.current.needsIndefiniteExecution = true 

私はここで何かが足りないのですか?私はXCode 8(ベータ4)を使用しています。どんな助けも大歓迎です。ありがとう。

+0

これはCPU速度の問題である可能性があります。具体的には、セッションはすでにストリームからすべてのデータを読み込んでローカルに保存している可能性があります。あなたのサーバーが...ギガバイトのデータを送信する場合にもこの問題が発生しますか? – dgatwood

答えて

0

これは今では古いと確信していますが、10.12以下では正しく動作しているようです。

Resuming... 
Cancelling... 
After cancel call 
Victory! The session task was properly cancelled! 
関連する問題