[Issue #1288] Improving implementation of connection:didRecieveData: to handle case where stream -hasSpaceAvailable returns NO by polling. For in-memory buffers, this will almost never happen.
[Issue #1093] Handling stream errors in connection:didRecieveData:
This commit is contained in:
parent
ca1737c5e0
commit
d587521451
1 changed files with 11 additions and 5 deletions
|
|
@ -569,8 +569,6 @@ static BOOL AFSecKeyIsEqualToKey(SecKeyRef key1, SecKeyRef key2) {
|
||||||
|
|
||||||
if (![self isFinished] && self.connection) {
|
if (![self isFinished] && self.connection) {
|
||||||
[self.connection cancel];
|
[self.connection cancel];
|
||||||
|
|
||||||
// Manually send this delegate message since `[self.connection cancel]` causes the connection to never send another message to its delegate
|
|
||||||
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:error];
|
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:error];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -722,9 +720,17 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
didReceiveData:(NSData *)data
|
didReceiveData:(NSData *)data
|
||||||
{
|
{
|
||||||
NSUInteger length = [data length];
|
NSUInteger length = [data length];
|
||||||
if ([self.outputStream hasSpaceAvailable]) {
|
while (YES) {
|
||||||
const uint8_t *dataBuffer = (uint8_t *) [data bytes];
|
if ([self.outputStream hasSpaceAvailable]) {
|
||||||
[self.outputStream write:&dataBuffer[0] maxLength:length];
|
const uint8_t *dataBuffer = (uint8_t *)[data bytes];
|
||||||
|
if ([self.outputStream write:&dataBuffer[0] maxLength:length] == -1) {
|
||||||
|
[self.connection cancel];
|
||||||
|
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.outputStream.streamError];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue