Issue: Timeout when buffer ends during ending boundry

This commit is contained in:
Tomohisa Takaoka 2012-11-09 14:23:51 -08:00
parent 247863cfc2
commit c92f306c6d

View file

@ -657,8 +657,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {}
return nil;
}
self.stringEncoding = (NSStringEncoding)[aDecoder decodeIntegerForKey:@"stringEncoding"];
self.parameterEncoding = (AFHTTPClientParameterEncoding)[aDecoder decodeIntegerForKey:@"parameterEncoding"];
self.stringEncoding = [aDecoder decodeIntegerForKey:@"stringEncoding"];
self.parameterEncoding = [aDecoder decodeIntegerForKey:@"parameterEncoding"];
self.registeredHTTPOperationClassNames = [aDecoder decodeObjectForKey:@"registeredHTTPOperationClassNames"];
self.defaultHeaders = [aDecoder decodeObjectForKey:@"defaultHeaders"];
@ -940,7 +940,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
if ([self streamStatus] == NSStreamStatusClosed) {
return 0;
}
NSInteger bytesRead = 0;
while ((NSUInteger)bytesRead < MIN(length, self.numberOfBytesInPacket)) {
@ -955,7 +954,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
}
}
}
return bytesRead;
}
@ -1034,6 +1032,7 @@ typedef enum {
AFHeaderPhase = 2,
AFBodyPhase = 3,
AFFinalBoundaryPhase = 4,
AFEndPhase = 5,
} AFHTTPBodyPartReadPhase;
@interface AFHTTPBodyPart () {
@ -1098,6 +1097,9 @@ typedef enum {
}
- (BOOL)hasBytesAvailable {
if (_phase == AFFinalBoundaryPhase) {
return YES;
}
switch (self.inputStream.streamStatus) {
case NSStreamStatusNotOpen:
case NSStreamStatusOpening:
@ -1114,7 +1116,6 @@ typedef enum {
- (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)length {
NSInteger bytesRead = 0;
if (_phase == AFEncapsulationBoundaryPhase) {
NSData *encapsulationBoundaryData = [([self hasInitialBoundary] ? AFMultipartFormInitialBoundary() : AFMultipartFormEncapsulationBoundary()) dataUsingEncoding:self.stringEncoding];
bytesRead += [self readData:encapsulationBoundaryData intoBuffer:&buffer[bytesRead] maxLength:(length - bytesRead)];
@ -1137,9 +1138,9 @@ typedef enum {
if (_phase == AFFinalBoundaryPhase) {
NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding] : [NSData data]);
bytesRead += [self readData:closingBoundaryData intoBuffer:&buffer[bytesRead] maxLength:(length - bytesRead)];
}
return bytesRead;
}
@ -1178,11 +1179,13 @@ typedef enum {
[self.inputStream close];
_phase = AFFinalBoundaryPhase;
break;
case AFFinalBoundaryPhase:
_phase = AFEndPhase;
break;
default:
_phase = AFEncapsulationBoundaryPhase;
break;
}
_phaseReadOffset = 0;
return YES;