|
@@ -324,10 +324,9 @@ NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
|
|
|
|
|
|
_selfRetain = self;
|
|
|
|
|
|
- if (_urlRequest.timeoutInterval > 0)
|
|
|
- {
|
|
|
- dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, _urlRequest.timeoutInterval * NSEC_PER_SEC);
|
|
|
- dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
|
|
|
+ if (_urlRequest.timeoutInterval > 0) {
|
|
|
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_urlRequest.timeoutInterval * NSEC_PER_SEC));
|
|
|
+ dispatch_after(popTime, dispatch_get_main_queue(), ^{
|
|
|
if (self.readyState == SR_CONNECTING) {
|
|
|
NSError *error = SRErrorWithDomainCodeDescription(NSURLErrorDomain, NSURLErrorTimedOut, @"Timed out connecting to server.");
|
|
|
[self _failWithError:error];
|
|
@@ -435,7 +434,7 @@ NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
|
|
|
_receivedHTTPHeaders = CFHTTPMessageCreateEmpty(NULL, NO);
|
|
|
}
|
|
|
|
|
|
- [self _readUntilHeaderCompleteWithCallback:^(SRWebSocket *self, NSData *data) {
|
|
|
+ [self _readUntilHeaderCompleteWithCallback:^(SRWebSocket *socket, NSData *data) {
|
|
|
CFHTTPMessageAppendBytes(_receivedHTTPHeaders, (const UInt8 *)data.bytes, data.length);
|
|
|
|
|
|
if (CFHTTPMessageIsHeaderComplete(_receivedHTTPHeaders)) {
|
|
@@ -925,17 +924,16 @@ static inline BOOL closeCodeIsValid(int closeCode) {
|
|
|
}
|
|
|
} else {
|
|
|
assert(frame_header.payload_length <= SIZE_T_MAX);
|
|
|
- [self _addConsumerWithDataLength:(size_t)frame_header.payload_length callback:^(SRWebSocket *self, NSData *newData) {
|
|
|
+ [self _addConsumerWithDataLength:(size_t)frame_header.payload_length callback:^(SRWebSocket *sself, NSData *newData) {
|
|
|
if (isControlFrame) {
|
|
|
- [self _handleFrameWithData:newData opCode:frame_header.opcode];
|
|
|
+ [sself _handleFrameWithData:newData opCode:frame_header.opcode];
|
|
|
} else {
|
|
|
if (frame_header.fin) {
|
|
|
- [self _handleFrameWithData:self->_currentFrameData opCode:frame_header.opcode];
|
|
|
+ [sself _handleFrameWithData:sself->_currentFrameData opCode:frame_header.opcode];
|
|
|
} else {
|
|
|
// TODO add assert that opcode is not a control;
|
|
|
- [self _readFrameContinue];
|
|
|
+ [sself _readFrameContinue];
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
} readToCurrentFrame:!isControlFrame unmaskBytes:frame_header.masked];
|
|
|
}
|
|
@@ -974,14 +972,14 @@ static const uint8_t SRPayloadLenMask = 0x7F;
|
|
|
{
|
|
|
assert((_currentFrameCount == 0 && _currentFrameOpcode == 0) || (_currentFrameCount > 0 && _currentFrameOpcode > 0));
|
|
|
|
|
|
- [self _addConsumerWithDataLength:2 callback:^(SRWebSocket *self, NSData *data) {
|
|
|
+ [self _addConsumerWithDataLength:2 callback:^(SRWebSocket *sself, NSData *data) {
|
|
|
__block frame_header header = {0};
|
|
|
|
|
|
const uint8_t *headerBuffer = data.bytes;
|
|
|
assert(data.length >= 2);
|
|
|
|
|
|
if (headerBuffer[0] & SRRsvMask) {
|
|
|
- [self _closeWithProtocolError:@"Server used RSV bits"];
|
|
|
+ [sself _closeWithProtocolError:@"Server used RSV bits"];
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -989,17 +987,17 @@ static const uint8_t SRPayloadLenMask = 0x7F;
|
|
|
|
|
|
BOOL isControlFrame = (receivedOpcode == SROpCodePing || receivedOpcode == SROpCodePong || receivedOpcode == SROpCodeConnectionClose);
|
|
|
|
|
|
- if (!isControlFrame && receivedOpcode != 0 && self->_currentFrameCount > 0) {
|
|
|
- [self _closeWithProtocolError:@"all data frames after the initial data frame must have opcode 0"];
|
|
|
+ if (!isControlFrame && receivedOpcode != 0 && sself->_currentFrameCount > 0) {
|
|
|
+ [sself _closeWithProtocolError:@"all data frames after the initial data frame must have opcode 0"];
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (receivedOpcode == 0 && self->_currentFrameCount == 0) {
|
|
|
- [self _closeWithProtocolError:@"cannot continue a message"];
|
|
|
+ if (receivedOpcode == 0 && sself->_currentFrameCount == 0) {
|
|
|
+ [sself _closeWithProtocolError:@"cannot continue a message"];
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- header.opcode = receivedOpcode == 0 ? self->_currentFrameOpcode : receivedOpcode;
|
|
|
+ header.opcode = receivedOpcode == 0 ? sself->_currentFrameOpcode : receivedOpcode;
|
|
|
|
|
|
header.fin = !!(SRFinMask & headerBuffer[0]);
|
|
|
|
|
@@ -1010,7 +1008,7 @@ static const uint8_t SRPayloadLenMask = 0x7F;
|
|
|
headerBuffer = NULL;
|
|
|
|
|
|
if (header.masked) {
|
|
|
- [self _closeWithProtocolError:@"Client must receive unmasked data"];
|
|
|
+ [sself _closeWithProtocolError:@"Client must receive unmasked data"];
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -1023,12 +1021,12 @@ static const uint8_t SRPayloadLenMask = 0x7F;
|
|
|
}
|
|
|
|
|
|
if (extra_bytes_needed == 0) {
|
|
|
- [self _handleFrameHeader:header curData:self->_currentFrameData];
|
|
|
+ [sself _handleFrameHeader:header curData:sself->_currentFrameData];
|
|
|
} else {
|
|
|
- [self _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *self, NSData *data) {
|
|
|
- size_t mapped_size = data.length;
|
|
|
+ [sself _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *eself, NSData *edata) {
|
|
|
+ size_t mapped_size = edata.length;
|
|
|
#pragma unused (mapped_size)
|
|
|
- const void *mapped_buffer = data.bytes;
|
|
|
+ const void *mapped_buffer = edata.bytes;
|
|
|
size_t offset = 0;
|
|
|
|
|
|
if (header.payload_length == 126) {
|
|
@@ -1046,10 +1044,10 @@ static const uint8_t SRPayloadLenMask = 0x7F;
|
|
|
|
|
|
if (header.masked) {
|
|
|
assert(mapped_size >= sizeof(_currentReadMaskOffset) + offset);
|
|
|
- memcpy(self->_currentReadMaskKey, ((uint8_t *)mapped_buffer) + offset, sizeof(self->_currentReadMaskKey));
|
|
|
+ memcpy(eself->_currentReadMaskKey, ((uint8_t *)mapped_buffer) + offset, sizeof(eself->_currentReadMaskKey));
|
|
|
}
|
|
|
|
|
|
- [self _handleFrameHeader:header curData:self->_currentFrameData];
|
|
|
+ [eself _handleFrameHeader:header curData:eself->_currentFrameData];
|
|
|
} readToCurrentFrame:NO unmaskBytes:NO];
|
|
|
}
|
|
|
} readToCurrentFrame:NO unmaskBytes:NO];
|
|
@@ -1560,6 +1558,7 @@ static const size_t SRFrameHeaderOverhead = 32;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
+ case NSStreamEventNone:
|
|
|
default:
|
|
|
SRDebugLog(@"(default) %@", aStream);
|
|
|
break;
|